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.
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
30 #include <gpdf-g-switch.h>
32 #include <gpdf-g-switch.h>
43 Thumb::Thumb(XRef *xrefA, Object *obj) :
50 GfxColorSpace *colorSpace;
54 dict = obj->streamGetDict ();
55 str = obj->getStream();
58 dict->lookup ("Width", &obj1);
62 dict->lookup ("W", &obj1);
65 fprintf (stderr, "Error: Invalid Width object %s\n",
70 width = obj1.getInt ();
74 dict->lookup ("Height", &obj1);
78 dict->lookup ("H", &obj1);
81 fprintf (stderr, "Error: Invalid Height object %s\n",
86 height = obj1.getInt ();
90 dict->lookup ("BitsPerComponent", &obj1);
94 dict->lookup ("BPC", &obj1);
97 fprintf (stderr, "Error: Invalid BitsPerComponent object %s\n",
102 bits = obj1.getInt ();
105 /* Get color space */
106 dict->lookup ("ColorSpace", &obj1);
110 dict->lookup ("CS", &obj1);
112 colorSpace = GfxColorSpace::parse(&obj1);
115 fprintf (stderr, "Error: Cannot parse color space\n");
119 dict->lookup("Decode", &obj1);
122 dict->lookup("D", &obj1);
124 colorMap = new GfxImageColorMap(bits, &obj1, colorSpace);
126 if (!colorMap->isOk()) {
127 fprintf (stderr, "Error: invalid colormap\n");
132 dict->lookup ("Length", &obj1);
133 if (!obj1.isInt ()) {
134 fprintf (stderr, "Error: Invalid Length Object %s\n",
135 obj1.getTypeName ());
139 length = obj1.getInt ();
142 str->addFilters(obj);
150 Thumb::getPixbufData()
153 unsigned char *pixbufdata;
154 unsigned int pixbufdatasize;
158 /* RGB Pixbuf data */
159 pixbufdatasize = width * height * 3;
161 pixbufdata =(unsigned char *)g_malloc(pixbufdatasize);
163 pixbufdata =(unsigned char *)g_malloc0(pixbufdatasize);
169 imgstr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
171 for (row = 0; row < height; ++row) {
172 for (col = 0; col < width; ++col) {
173 Guchar pix[gfxColorMaxComps];
176 imgstr->getPixel(pix);
177 colorMap->getRGB(pix, &rgb);
179 *p++ = (guchar)(rgb.r * 255.99999);
180 *p++ = (guchar)(rgb.g * 255.99999);
181 *p++ = (guchar)(rgb.b * 255.99999);