From 765a8704454d705acc9ce5aa7a90c1c3079fb989 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sat, 2 Jul 2011 22:05:45 -0400 Subject: GRAPHICS: Convert JPEG to the ImageDecoder API --- video/codecs/mjpeg.cpp | 25 +++++++++---------------- video/codecs/mjpeg.h | 3 +-- 2 files changed, 10 insertions(+), 18 deletions(-) (limited to 'video/codecs') diff --git a/video/codecs/mjpeg.cpp b/video/codecs/mjpeg.cpp index 248a80d714..10fd9d7c50 100644 --- a/video/codecs/mjpeg.cpp +++ b/video/codecs/mjpeg.cpp @@ -22,8 +22,8 @@ #include "common/system.h" #include "common/textconsole.h" -#include "graphics/jpeg.h" #include "graphics/surface.h" +#include "graphics/decoders/jpeg.h" #include "video/codecs/mjpeg.h" @@ -34,38 +34,31 @@ class SeekableReadStream; namespace Video { JPEGDecoder::JPEGDecoder() : Codec() { - _jpeg = new Graphics::JPEG(); _pixelFormat = g_system->getScreenFormat(); _surface = NULL; } JPEGDecoder::~JPEGDecoder() { - delete _jpeg; - if (_surface) { _surface->free(); delete _surface; } } -const Graphics::Surface *JPEGDecoder::decodeImage(Common::SeekableReadStream* stream) { - if (!_jpeg->read(stream)) { +const Graphics::Surface *JPEGDecoder::decodeImage(Common::SeekableReadStream *stream) { + Graphics::JPEGDecoder jpeg; + + if (!jpeg.loadStream(*stream)) { warning("Failed to decode JPEG frame"); return 0; } - if (!_surface) { - _surface = new Graphics::Surface(); - _surface->create(_jpeg->getWidth(), _jpeg->getHeight(), _pixelFormat); + if (_surface) { + _surface->free(); + delete _surface; } - Graphics::Surface *frame = _jpeg->getSurface(_pixelFormat); - assert(frame); - - _surface->copyFrom(*frame); - - frame->free(); - delete frame; + _surface = jpeg.getSurface()->convertTo(_pixelFormat); return _surface; } diff --git a/video/codecs/mjpeg.h b/video/codecs/mjpeg.h index 45cb57dea2..0c3b668a74 100644 --- a/video/codecs/mjpeg.h +++ b/video/codecs/mjpeg.h @@ -31,7 +31,7 @@ class SeekableReadStream; } namespace Graphics { -class JPEG; +struct Surface; } namespace Video { @@ -50,7 +50,6 @@ public: private: Graphics::PixelFormat _pixelFormat; - Graphics::JPEG *_jpeg; Graphics::Surface *_surface; }; -- cgit v1.2.3