Unrolled most inner loop of ColorRasterizer::MergePlaneBuffersToCurrentLine to gain a total speed up of about 5 percent.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11440 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -182,51 +182,97 @@ ColorRasterizer::MergePlaneBuffersToCurrentLine()
|
|||||||
|
|
||||||
// iterate over the three plane buffers
|
// iterate over the three plane buffers
|
||||||
for (int i = 0; i < fPlaneBufferSize; i ++) {
|
for (int i = 0; i < fPlaneBufferSize; i ++) {
|
||||||
const uchar values[3] = {
|
|
||||||
fPlaneBuffers[0][i],
|
|
||||||
fPlaneBuffers[1][i],
|
|
||||||
fPlaneBuffers[2][i]
|
|
||||||
};
|
|
||||||
|
|
||||||
int pixels = 8;
|
int pixels = 8;
|
||||||
if (remainingPixels < 8) {
|
if (remainingPixels < 8) {
|
||||||
pixels = remainingPixels;
|
pixels = remainingPixels;
|
||||||
}
|
}
|
||||||
remainingPixels -= pixels;
|
remainingPixels -= pixels;
|
||||||
|
|
||||||
// for each bit in the current byte of each plane
|
if (remainingPixels >= 8) {
|
||||||
uchar mask = 0x80;
|
register const uchar
|
||||||
for (; pixels > 0; pixels --) {
|
red = fPlaneBuffers[0][i],
|
||||||
int rgb = 0;
|
green = fPlaneBuffers[1][i],
|
||||||
|
blue = fPlaneBuffers[2][i];
|
||||||
|
|
||||||
if (values[0] & mask) {
|
register uchar value = 0;
|
||||||
rgb |= kRed;
|
if (red & 0x80) value = 0x80;
|
||||||
}
|
if (red & 0x40) value |= 0x10;
|
||||||
if (values[1] & mask) {
|
if (red & 0x20) value |= 0x02;
|
||||||
rgb |= kGreen;
|
|
||||||
}
|
|
||||||
if (values[2] & mask) {
|
|
||||||
rgb |= kBlue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int plane = 0; plane < 3; plane ++) {
|
if (green & 0x80) value |= 0x40;
|
||||||
// copy pixel value to output value
|
if (green & 0x40) value |= 0x08;
|
||||||
if (rgb & (1 << plane)) {
|
if (green & 0x20) value |= 0x01;
|
||||||
value |= outMask;
|
|
||||||
|
if (blue & 0x80) value |= 0x20;
|
||||||
|
if (blue & 0x40) value |= 0x04;
|
||||||
|
|
||||||
|
*out++ = value;
|
||||||
|
|
||||||
|
value = 0;
|
||||||
|
if (blue & 0x20) value = 0x80;
|
||||||
|
if (blue & 0x10) value |= 0x10;
|
||||||
|
if (blue & 0x08) value |= 0x02;
|
||||||
|
|
||||||
|
if (red & 0x10) value |= 0x40;
|
||||||
|
if (red & 0x08) value |= 0x08;
|
||||||
|
if (red & 0x04) value |= 0x01;
|
||||||
|
|
||||||
|
if (green & 0x10) value |= 0x20;
|
||||||
|
if (green & 0x08) value |= 0x04;
|
||||||
|
*out++ = value;
|
||||||
|
|
||||||
|
value = 0;
|
||||||
|
if (green & 0x04) value = 0x80;
|
||||||
|
if (green & 0x02) value |= 0x10;
|
||||||
|
if (green & 0x01) value |= 0x02;
|
||||||
|
|
||||||
|
if (blue & 0x04) value |= 0x40;
|
||||||
|
if (blue & 0x02) value |= 0x08;
|
||||||
|
if (blue & 0x01) value |= 0x01;
|
||||||
|
|
||||||
|
if (red & 0x02) value |= 0x20;
|
||||||
|
if (red & 0x01) value |= 0x04;
|
||||||
|
*out++ = value;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
register const uchar
|
||||||
|
red = fPlaneBuffers[0][i],
|
||||||
|
green = fPlaneBuffers[1][i],
|
||||||
|
blue = fPlaneBuffers[2][i];
|
||||||
|
// for each bit in the current byte of each plane
|
||||||
|
uchar mask = 0x80;
|
||||||
|
for (; pixels > 0; pixels --) {
|
||||||
|
int rgb = 0;
|
||||||
|
|
||||||
|
if (red & mask) {
|
||||||
|
rgb |= kRed;
|
||||||
|
}
|
||||||
|
if (green & mask) {
|
||||||
|
rgb |= kGreen;
|
||||||
|
}
|
||||||
|
if (blue & mask) {
|
||||||
|
rgb |= kBlue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// increment output mask
|
for (int plane = 0; plane < 3; plane ++) {
|
||||||
if (outMask == 0x01) {
|
// copy pixel value to output value
|
||||||
outMask = 0x80;
|
if (rgb & (1 << plane)) {
|
||||||
// write output value to output buffer
|
value |= outMask;
|
||||||
*out = value;
|
}
|
||||||
out ++;
|
|
||||||
value = 0;
|
// increment output mask
|
||||||
} else {
|
if (outMask == 0x01) {
|
||||||
outMask >>= 1;
|
outMask = 0x80;
|
||||||
|
// write output value to output buffer
|
||||||
|
*out = value;
|
||||||
|
out ++;
|
||||||
|
value = 0;
|
||||||
|
} else {
|
||||||
|
outMask >>= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mask >>= 1;
|
||||||
}
|
}
|
||||||
mask >>= 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +404,6 @@ static void initializeBitmap(BBitmap *bitmap, int width, int height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const int width = 10;
|
const int width = 10;
|
||||||
@@ -379,10 +424,8 @@ int main()
|
|||||||
rasterizer.SetBitmap(0, 0, &bitmap, height);
|
rasterizer.SetBitmap(0, 0, &bitmap, height);
|
||||||
rasterizer.InitializeBuffer();
|
rasterizer.InitializeBuffer();
|
||||||
while (rasterizer.HasNextLine()) {
|
while (rasterizer.HasNextLine()) {
|
||||||
// const uchar *rowBuffer = (uchar*)
|
|
||||||
rasterizer.RasterizeNextLine();
|
rasterizer.RasterizeNextLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user