diff options
Diffstat (limited to 'graphics/jpeg.cpp')
-rw-r--r-- | graphics/jpeg.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/graphics/jpeg.cpp b/graphics/jpeg.cpp index bb6da33cfe..5fee371225 100644 --- a/graphics/jpeg.cpp +++ b/graphics/jpeg.cpp @@ -23,7 +23,9 @@ * */ +#include "graphics/conversion.h" #include "graphics/jpeg.h" +#include "graphics/pixelformat.h" #include "common/endian.h" #include "common/util.h" @@ -73,6 +75,37 @@ JPEG::~JPEG() { reset(); } +Surface *JPEG::getSurface(const PixelFormat &format) { + // Make sure we have loaded data + if (!isLoaded()) + return 0; + + // Only accept >8bpp surfaces + if (format.bytesPerPixel == 1) + return 0; + + // Get our component surfaces + Graphics::Surface *yComponent = getComponent(1); + Graphics::Surface *uComponent = getComponent(2); + Graphics::Surface *vComponent = getComponent(3); + + Graphics::Surface *output = new Graphics::Surface(); + output->create(yComponent->w, yComponent->h, format.bytesPerPixel); + + for (uint16 i = 0; i < output->h; i++) { + for (uint16 j = 0; j < output->w; j++) { + byte r = 0, g = 0, b = 0; + YUV2RGB(*((byte *)yComponent->getBasePtr(j, i)), *((byte *)uComponent->getBasePtr(j, i)), *((byte *)vComponent->getBasePtr(j, i)), r, g, b); + if (format.bytesPerPixel == 2) + *((uint16 *)output->getBasePtr(j, i)) = format.RGBToColor(r, g, b); + else + *((uint32 *)output->getBasePtr(j, i)) = format.RGBToColor(r, g, b); + } + } + + return output; +} + void JPEG::reset() { // Reset member variables _str = NULL; |