GRAPHICS: Add YUV410 to RGB Conversion Functions, required for SVQ1.

Thanks to clone2727 for these.
This commit is contained in:
D G Turner 2011-10-10 01:54:33 +01:00
parent 93632681c0
commit e1f9598392
2 changed files with 74 additions and 0 deletions

View file

@ -300,4 +300,64 @@ void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uS
convertYUV420ToRGB<uint32>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
}
#define OUTPUT_4_PIXEL_COLUMN() \
PUT_PIXEL(*ySrc, dstPtr); \
PUT_PIXEL(*(ySrc + yPitch), dstPtr + dstPitch); \
PUT_PIXEL(*(ySrc + (yPitch << 1)), dstPtr + dstPitch * 2); \
PUT_PIXEL(*(ySrc + (yPitch * 3)), dstPtr + dstPitch * 3); \
ySrc++; \
dstPtr += sizeof(PixelInt)
template<typename PixelInt>
void convertYUV410ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
int quarterHeight = yHeight >> 2;
int quarterWidth = yWidth >> 2;
// Keep the tables in pointers here to avoid a dereference on each pixel
const int16 *Cr_r_tab = lookup->_colorTab;
const int16 *Cr_g_tab = Cr_r_tab + 256;
const int16 *Cb_g_tab = Cr_g_tab + 256;
const int16 *Cb_b_tab = Cb_g_tab + 256;
const uint32 *rgbToPix = lookup->_rgbToPix;
for (int h = 0; h < quarterHeight; h++) {
for (int w = 0; w < quarterWidth; w++) {
register const uint32 *L;
int16 cr_r = Cr_r_tab[*vSrc];
int16 crb_g = Cr_g_tab[*vSrc] + Cb_g_tab[*uSrc];
int16 cb_b = Cb_b_tab[*uSrc];
++uSrc;
++vSrc;
OUTPUT_4_PIXEL_COLUMN();
OUTPUT_4_PIXEL_COLUMN();
OUTPUT_4_PIXEL_COLUMN();
OUTPUT_4_PIXEL_COLUMN();
}
dstPtr += dstPitch * 3;
ySrc += (yPitch << 2) - yWidth;
uSrc += uvPitch - quarterWidth;
vSrc += uvPitch - quarterWidth;
}
}
void convertYUV410ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
// Sanity checks
assert(dst && dst->pixels);
assert(dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4);
assert(ySrc && uSrc && vSrc);
assert((yWidth & 3) == 0);
assert((yHeight & 3) == 0);
const YUVToRGBLookup *lookup = YUVToRGBMan.getLookup(dst->format);
// Use a templated function to avoid an if check on every pixel
if (dst->format.bytesPerPixel == 2)
convertYUV410ToRGB<uint16>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
else
convertYUV410ToRGB<uint32>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
}
} // End of namespace Graphics

View file

@ -64,6 +64,20 @@ void convertYUV444ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uS
*/
void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch);
/**
* Convert a YUV410 image to an RGB surface
*
* @param dst the destination surface
* @param ySrc the source of the y component
* @param uSrc the source of the u component
* @param vSrc the source of the v component
* @param yWidth the width of the y surface (must be divisible by 4)
* @param yHeight the height of the y surface (must be divisible by 4)
* @param yPitch the pitch of the y surface
* @param uvPitch the pitch of the u and v surfaces
*/
void convertYUV410ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch);
} // End of namespace Graphics
#endif