mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-27 22:42:57 +00:00
- Move bitdepth check outside the loop for grayscale unpacking. Also, don't use a multiply for
1-bit pixels. Use a lookup table for 2-bit pixels, because it's probably faster than a bunch of shifts and register juggling. SVN r4291 (trunk)
This commit is contained in:
parent
f436c02a43
commit
4a8037d66e
1 changed files with 34 additions and 15 deletions
|
@ -1162,6 +1162,8 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *
|
||||||
BYTE pack;
|
BYTE pack;
|
||||||
int lastbyte;
|
int lastbyte;
|
||||||
|
|
||||||
|
assert(bitdepth == 1 || bitdepth == 2 || bitdepth == 4);
|
||||||
|
|
||||||
out = rowout + width;
|
out = rowout + width;
|
||||||
in = rowin + bytesPerRow;
|
in = rowin + bytesPerRow;
|
||||||
|
|
||||||
|
@ -1243,25 +1245,42 @@ static void UnpackPixels (int width, int bytesPerRow, int bitdepth, const BYTE *
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand gray scale to 8bpp
|
// Expand grayscale to 8bpp
|
||||||
if(grayscale)
|
if (grayscale)
|
||||||
{
|
{
|
||||||
out = rowout + width;
|
// Put the 2-bit lookup table on the stack, since it's probably already
|
||||||
while(--out >= rowout)
|
// in a cache line.
|
||||||
|
union
|
||||||
{
|
{
|
||||||
switch(bitdepth)
|
uint32 bits2l;
|
||||||
|
BYTE bits2[4];
|
||||||
|
};
|
||||||
|
|
||||||
|
out = rowout + width;
|
||||||
|
switch (bitdepth)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
while (--out >= rowout)
|
||||||
{
|
{
|
||||||
case 1:
|
// 1 becomes -1 (0xFF), and 0 remains untouched.
|
||||||
*out *= 0xFF;
|
*out = 0 - *out;
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
*out |= (*out<<2)|(*out<<4)|(*out<<6);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
*out |= (*out<<4);
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
bits2l = MAKE_ID(0x00,0x55,0xAA,0xFF);
|
||||||
|
while (--out >= rowout)
|
||||||
|
{
|
||||||
|
*out = bits2[*out];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
while (--out >= rowout)
|
||||||
|
{
|
||||||
|
*out |= (*out << 4);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue