1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/system.h"
24 #include "titanic/support/image_decoders.h"
25
26 namespace Titanic {
27
decode(OSVideoSurface & surface,const CString & name)28 void CJPEGDecode::decode(OSVideoSurface &surface, const CString &name) {
29 // Open up the resource
30 StdCWadFile file;
31 file.open(name);
32
33 // Use the ScummVM decoder to decode it
34 setOutputPixelFormat(g_system->getScreenFormat());
35 loadStream(*file.readStream());
36 const Graphics::Surface *srcSurf = getSurface();
37
38 // Resize the surface if necessary
39 if (!surface.hasSurface() || surface.getWidth() != srcSurf->w
40 || surface.getHeight() != srcSurf->h)
41 surface.recreate(srcSurf->w, srcSurf->h, 16);
42
43 // Copy the decoded surface
44 surface.lock();
45
46 assert(srcSurf->format == surface._rawSurface->format);
47
48 Common::copy((const byte *)srcSurf->getPixels(), (const byte *)srcSurf->getPixels() +
49 surface.getPitch() * surface.getHeight(), (byte *)surface._rawSurface->getPixels());
50
51 surface.unlock();
52 }
53
54 /*------------------------------------------------------------------------*/
55
decode(OSVideoSurface & surface,const CString & name)56 void CTargaDecode::decode(OSVideoSurface &surface, const CString &name) {
57 // Open up the resource
58 StdCWadFile file;
59 file.open(name);
60
61 // Use the ScucmmVM deoder to decode it
62 loadStream(*file.readStream());
63 const Graphics::Surface *srcSurf = getSurface();
64
65 // Resize the surface if necessary
66 if (!surface.hasSurface() || surface.getWidth() != srcSurf->w
67 || surface.getHeight() != srcSurf->h)
68 surface.recreate(srcSurf->w, srcSurf->h, 16);
69
70 // Convert the decoded surface to the correct pixel format, and then copy it over
71 surface.lock();
72 Graphics::Surface *convertedSurface = srcSurf->convertTo(surface._rawSurface->format);
73
74 Common::copy((byte *)convertedSurface->getPixels(), (byte *)convertedSurface->getPixels() +
75 surface.getPitch() * surface.getHeight(), (byte *)surface._rawSurface->getPixels());
76
77 convertedSurface->free();
78 delete convertedSurface;
79 surface.unlock();
80 }
81
82 } // End of namespace Titanic
83