aboutsummaryrefslogtreecommitdiff
path: root/graphics/video/codecs
diff options
context:
space:
mode:
authorMatthew Hoops2011-01-18 16:18:10 +0000
committerMatthew Hoops2011-01-18 16:18:10 +0000
commit503fdb61470484d952634fc1fab5200371810c3f (patch)
tree0eaacb8b39485bad12d5dae6ae4bd982a5c4dd89 /graphics/video/codecs
parent5da1718beb7bdc1b034e12739be783873fd133df (diff)
downloadscummvm-rg350-503fdb61470484d952634fc1fab5200371810c3f.tar.gz
scummvm-rg350-503fdb61470484d952634fc1fab5200371810c3f.tar.bz2
scummvm-rg350-503fdb61470484d952634fc1fab5200371810c3f.zip
GRAPHICS: Add a getSurface() function to JPEG to automatically convert to RGB
svn-id: r55301
Diffstat (limited to 'graphics/video/codecs')
-rw-r--r--graphics/video/codecs/mjpeg.cpp27
1 files changed, 12 insertions, 15 deletions
diff --git a/graphics/video/codecs/mjpeg.cpp b/graphics/video/codecs/mjpeg.cpp
index 1efaa6ac19..dc8eb4a58b 100644
--- a/graphics/video/codecs/mjpeg.cpp
+++ b/graphics/video/codecs/mjpeg.cpp
@@ -46,26 +46,23 @@ JPEGDecoder::~JPEGDecoder() {
}
const Surface *JPEGDecoder::decodeImage(Common::SeekableReadStream* stream) {
- _jpeg->read(stream);
- Surface *ySurface = _jpeg->getComponent(1);
- Surface *uSurface = _jpeg->getComponent(2);
- Surface *vSurface = _jpeg->getComponent(3);
+ if (!_jpeg->read(stream)) {
+ warning("Failed to decode JPEG frame");
+ return 0;
+ }
if (!_surface) {
_surface = new Surface();
- _surface->create(ySurface->w, ySurface->h, _pixelFormat.bytesPerPixel);
+ _surface->create(_jpeg->getWidth(), _jpeg->getHeight(), _pixelFormat.bytesPerPixel);
}
- for (uint16 i = 0; i < _surface->h; i++) {
- for (uint16 j = 0; j < _surface->w; j++) {
- byte r = 0, g = 0, b = 0;
- YUV2RGB(*((byte *)ySurface->getBasePtr(j, i)), *((byte *)uSurface->getBasePtr(j, i)), *((byte *)vSurface->getBasePtr(j, i)), r, g, b);
- if (_pixelFormat.bytesPerPixel == 2)
- *((uint16 *)_surface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b);
- else
- *((uint32 *)_surface->getBasePtr(j, i)) = _pixelFormat.RGBToColor(r, g, b);
- }
- }
+ Graphics::Surface *frame = _jpeg->getSurface(_pixelFormat);
+ assert(frame);
+
+ _surface->copyFrom(*frame);
+
+ frame->free();
+ delete frame;
return _surface;
}