1.
Buffer[(X + Y * (lPitch >> 1)] = RGB16BIT(Red, Green, Blue);
Shouldn't you shift left, because lPitch is the width of the image and 16-bit = 2 bytes per pixel? (prefer *2 by the way, compiler can optimize it to bit shifting)
2.
Don't inline the DrawLine-function. It's just too huge. I once tried inlining a largish function and it led to *reduced* runtime speed.
3.
Don't use RGB macro. Use inline function
4.
In RGB function, /8 instead of %32, like Kylotan said. That way it's linear. Now R=G=B=224 will result in a full black pixel.
5.
In DrawLine, don't initialize or even define variables before you use them. Initializing them all with 0 and then soon replacing that with some other number looks goofy. And DeltaY is never used.
Also, your comments are useless.. Don't put comments like "here we assign start position to X and Y". Or "here we calculate the difference between x1 and x0". Those are obvious from the code. You should comment about the algorithm used instead.
void DirectDraw::DrawLine16(int StartX, int StartY, int EndX, int EndY, UCHAR Red, UCHAR Green, UCHAR Blue, UCHAR *Buffer){ int DifferX = EndX - StartX; int DifferY = EndY - StartY; int XInc = (DifferX >= 0) ? 1 : -1; int YInc = (DifferY >= 0) ? 1 : -1; int X = StartX; //X and Y are useless variables. You could int Y = StartY; //use StartX and StartY directly instead if (DifferX >= DifferY) { DifferY /= 2; int Balance = DifferY - DifferX;//and so on...
I know only 1. addressed your question
....
[edited by - civguy on September 20, 2002 5:40:05 PM]