1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-indent-level: 8; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003 Remi Cohen-Scali
6 * Remi Cohen-Scali <Remi@Cohen-Scali.com>
8 * GPdf is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * GPdf is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 * License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
25 #ifdef USE_GCC_PRAGMAS
26 #pragma implementation
40 Thumb::Thumb(XRef *xrefA, Object *obj) :
47 GfxColorSpace *colorSpace;
51 dict = obj->streamGetDict ();
52 str = obj->getStream();
55 dict->lookup ("Width", &obj1);
59 dict->lookup ("W", &obj1);
62 fprintf (stderr, "Error: Invalid Width object %s\n",
67 width = obj1.getInt ();
71 dict->lookup ("Height", &obj1);
75 dict->lookup ("H", &obj1);
78 fprintf (stderr, "Error: Invalid Height object %s\n",
83 height = obj1.getInt ();
87 dict->lookup ("BitsPerComponent", &obj1);
91 dict->lookup ("BPC", &obj1);
94 fprintf (stderr, "Error: Invalid BitsPerComponent object %s\n",
99 bits = obj1.getInt ();
102 /* Get color space */
103 dict->lookup ("ColorSpace", &obj1);
107 dict->lookup ("CS", &obj1);
109 colorSpace = GfxColorSpace::parse(&obj1);
112 fprintf (stderr, "Error: Cannot parse color space\n");
116 dict->lookup("Decode", &obj1);
119 dict->lookup("D", &obj1);
121 colorMap = new GfxImageColorMap(bits, &obj1, colorSpace);
123 if (!colorMap->isOk()) {
124 fprintf (stderr, "Error: invalid colormap\n");
129 dict->lookup ("Length", &obj1);
130 if (!obj1.isInt ()) {
131 fprintf (stderr, "Error: Invalid Length Object %s\n",
132 obj1.getTypeName ());
136 length = obj1.getInt ();
139 str->addFilters(obj);
147 Thumb::getPixbufData()
150 unsigned char *pixbufdata;
151 unsigned int pixbufdatasize;
155 /* RGB Pixbuf data */
156 pixbufdatasize = width * height * 3;
158 pixbufdata =(unsigned char *)g_malloc(pixbufdatasize);
160 pixbufdata =(unsigned char *)g_malloc0(pixbufdatasize);
166 imgstr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
168 for (row = 0; row < height; ++row) {
169 for (col = 0; col < width; ++col) {
170 Guchar pix[gfxColorMaxComps];
173 imgstr->getPixel(pix);
174 colorMap->getRGB(pix, &rgb);
176 *p++ = (guchar)(rgb.r * 255.99999);
177 *p++ = (guchar)(rgb.g * 255.99999);
178 *p++ = (guchar)(rgb.b * 255.99999);