windowscodecs: Add a utility function for swapping 8-bit BGR/RGB data.
This commit is contained in:
parent
d747652102
commit
d9fb1a4b92
|
@ -577,7 +577,7 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
|
|||
UINT first_scanline = This->cinfo.output_scanline;
|
||||
UINT max_rows;
|
||||
JSAMPROW out_rows[4];
|
||||
UINT i, j;
|
||||
UINT i;
|
||||
JDIMENSION ret;
|
||||
|
||||
max_rows = min(This->cinfo.output_height-first_scanline, 4);
|
||||
|
@ -596,18 +596,9 @@ static HRESULT WINAPI JpegDecoder_Frame_CopyPixels(IWICBitmapFrameDecode *iface,
|
|||
if (bpp == 24)
|
||||
{
|
||||
/* libjpeg gives us RGB data and we want BGR, so byteswap the data */
|
||||
for (i=first_scanline; i<This->cinfo.output_scanline; i++)
|
||||
{
|
||||
BYTE *pixel = This->image_data + stride * i;
|
||||
for (j=0; j<This->cinfo.output_width; j++)
|
||||
{
|
||||
BYTE red=pixel[0];
|
||||
BYTE blue=pixel[2];
|
||||
pixel[0]=blue;
|
||||
pixel[2]=red;
|
||||
pixel+=3;
|
||||
}
|
||||
}
|
||||
reverse_bgr8(3, This->image_data + stride * first_scanline,
|
||||
This->cinfo.output_width, This->cinfo.output_scanline - first_scanline,
|
||||
stride);
|
||||
}
|
||||
|
||||
if (This->cinfo.out_color_space == JCS_CMYK && This->cinfo.saw_Adobe_marker)
|
||||
|
|
|
@ -112,3 +112,22 @@ HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
|
|||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride)
|
||||
{
|
||||
UINT x, y;
|
||||
BYTE *pixel, temp;
|
||||
|
||||
for (y=0; y<height; y++)
|
||||
{
|
||||
pixel = bits + stride * y;
|
||||
|
||||
for (x=0; x<width; x++)
|
||||
{
|
||||
temp = pixel[2];
|
||||
pixel[2] = pixel[0];
|
||||
pixel[0] = temp;
|
||||
pixel += bytesperpixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -800,19 +800,10 @@ static HRESULT TiffFrameDecode_ReadTile(TiffFrameDecode *This, UINT tile_x, UINT
|
|||
{
|
||||
if (This->decode_info.bps == 8)
|
||||
{
|
||||
UINT i, total_pixels, sample_count;
|
||||
BYTE *pixel, temp;
|
||||
UINT sample_count = This->decode_info.samples;
|
||||
|
||||
total_pixels = This->decode_info.tile_width * This->decode_info.tile_height;
|
||||
pixel = This->cached_tile;
|
||||
sample_count = This->decode_info.samples;
|
||||
for (i=0; i<total_pixels; i++)
|
||||
{
|
||||
temp = pixel[2];
|
||||
pixel[2] = pixel[0];
|
||||
pixel[0] = temp;
|
||||
pixel += sample_count;
|
||||
}
|
||||
reverse_bgr8(sample_count, This->cached_tile, This->decode_info.tile_width,
|
||||
This->decode_info.tile_height, This->decode_info.tile_width * sample_count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ extern HRESULT copy_pixels(UINT bpp, const BYTE *srcbuffer,
|
|||
UINT srcwidth, UINT srcheight, INT srcstride,
|
||||
const WICRect *rc, UINT dststride, UINT dstbuffersize, BYTE *dstbuffer);
|
||||
|
||||
extern void reverse_bgr8(UINT bytesperpixel, LPBYTE bits, UINT width, UINT height, INT stride);
|
||||
|
||||
extern HRESULT CreatePropertyBag2(IPropertyBag2 **ppPropertyBag2);
|
||||
|
||||
extern HRESULT CreateComponentInfo(REFCLSID clsid, IWICComponentInfo **ppIInfo);
|
||||
|
|
Loading…
Reference in New Issue