2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 int WJpeg::init(char* fileName)
25 this->fileName = fileName;
29 void WJpeg::overrideSurface(Surface* newSurface)
36 Log* logger = Log::getInstance();
38 FILE* infile = fopen(fileName, "r");
41 logger->log("BJpeg", Log::ERR, "Can't open JPEG");
44 logger->log("BJpeg", Log::DEBUG, "File opened");
46 struct jpeg_decompress_struct cinfo;
47 struct jpeg_error_mgr jerr;
48 cinfo.err = jpeg_std_error(&jerr);
49 jpeg_create_decompress(&cinfo);
50 jpeg_stdio_src(&cinfo, infile);
51 jpeg_read_header(&cinfo, TRUE);
52 jpeg_start_decompress(&cinfo);
54 logger->log("BJpeg", Log::DEBUG, "JPEG startup done");
57 setDimensions(cinfo.output_width, cinfo.output_height);
62 unsigned char* buffer = (unsigned char*)malloc(height * width * 3);
63 logger->log("BJpeg", Log::DEBUG, "Buffer allocated at %p", buffer);
65 unsigned char* bufferPointers[height];
66 for(int ps = 0; ps < height; ps++) bufferPointers[ps] = buffer + (ps * width * 3);
68 logger->log("BJpeg", Log::DEBUG, "done array check");
71 while (cinfo.output_scanline < cinfo.output_height)
73 rowsread += jpeg_read_scanlines(&cinfo, &bufferPointers[rowsread], height);
76 logger->log("BJpeg", Log::DEBUG, "Done all jpeg_read");
78 jpeg_finish_decompress(&cinfo);
79 jpeg_destroy_decompress(&cinfo);
83 logger->log("BJpeg", Log::DEBUG, "jpeg shutdown done, x, y %u %u", width, height);
89 for (y = 0; y < height; y++)
91 p = bufferPointers[y];
93 for (x = 0; x < width; x++)
102 surface->drawPixel(screenX + x, screenY + y, c);
107 logger->log("BJpeg", Log::DEBUG, "deleted buffer");