]> www.fi.muni.cz Git - evince.git/blob - pdf/Thumb.cc
Hungarian translation updated.
[evince.git] / pdf / Thumb.cc
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-indent-level: 8; c-basic-offset: 8 -*- */
2 /* 
3  *  Copyright (C) 2003 Remi Cohen-Scali
4  *
5  *  Author:
6  *    Remi Cohen-Scali <Remi@Cohen-Scali.com>
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #include <string.h>
24
25 #ifdef USE_GCC_PRAGMAS
26 #pragma implementation
27 #endif
28
29 #include <glib.h>
30 #include <goo/gmem.h>
31 #include <Object.h>
32 #include <Gfx.h>
33 #include <GfxState.h>
34 #include "Thumb.h"
35
36 /*
37  * Thumb
38  */
39
40 Thumb::Thumb(XRef *xrefA, Object *obj) :
41   xref(xrefA),
42   str(NULL),
43   ok_flag(0)
44 {
45         Object obj1, obj2;
46         Dict *dict;
47         GfxColorSpace *colorSpace;
48
49         do {
50                 /* Get stream dict */
51                 dict = obj->streamGetDict ();
52                 str = obj->getStream(); 
53                 
54                 /* Get width */
55                 dict->lookup ("Width", &obj1);
56                 if (obj1.isNull ())
57                 {
58                         obj1.free ();
59                         dict->lookup ("W", &obj1);
60                 }
61                 if (!obj1.isInt ()) {
62                         fprintf (stderr, "Error: Invalid Width object %s\n",
63                                 obj1.getTypeName ());
64                         obj1.free ();
65                         break;
66                 }
67                 width = obj1.getInt ();
68                 obj1.free ();
69                 
70                 /* Get heigth */
71                 dict->lookup ("Height", &obj1);
72                 if (obj1.isNull ()) 
73                 {
74                         obj1.free ();
75                         dict->lookup ("H", &obj1);
76                 }
77                 if (!obj1.isInt ()) {
78                         fprintf (stderr, "Error: Invalid Height object %s\n",
79                                 obj1.getTypeName ());
80                         obj1.free ();
81                         break;
82                 }
83                 height = obj1.getInt ();
84                 obj1.free ();
85                 
86                 /* bit depth */
87                 dict->lookup ("BitsPerComponent", &obj1);
88                 if (obj1.isNull ())
89                 {
90                         obj1.free ();
91                         dict->lookup ("BPC", &obj1);
92                 }
93                 if (!obj1.isInt ()) {
94                         fprintf (stderr, "Error: Invalid BitsPerComponent object %s\n",
95                                 obj1.getTypeName ());
96                         obj1.free ();
97                         break;
98                 }
99                 bits = obj1.getInt ();
100                 obj1.free ();
101                 
102                 /* Get color space */
103                 dict->lookup ("ColorSpace", &obj1);
104                 if (obj1.isNull ()) 
105                 {
106                         obj1.free ();
107                         dict->lookup ("CS", &obj1);
108                 }
109                 colorSpace = GfxColorSpace::parse(&obj1);
110                 obj1.free();
111                 if (!colorSpace) {
112                         fprintf (stderr, "Error: Cannot parse color space\n");
113                         break;
114                 }
115
116                 dict->lookup("Decode", &obj1);
117                 if (obj1.isNull()) {
118                         obj1.free();
119                         dict->lookup("D", &obj1);
120                 }
121                 colorMap = new GfxImageColorMap(bits, &obj1, colorSpace);
122                 obj1.free();
123                 if (!colorMap->isOk()) {
124                         fprintf (stderr, "Error: invalid colormap\n");
125                         delete colorMap;
126                         colorMap = NULL;
127                 }
128
129                 dict->lookup ("Length", &obj1);
130                 if (!obj1.isInt ()) {
131                         fprintf (stderr, "Error: Invalid Length Object %s\n",
132                                 obj1.getTypeName ());
133                         obj1.free ();
134                         break;
135                 }
136                 length = obj1.getInt ();
137                 obj1.free ();
138
139                 str->addFilters(obj);
140
141                 ok_flag = 1; 
142         }
143         while (0);      
144 }
145
146 unsigned char *
147 Thumb::getPixbufData()
148 {
149         ImageStream *imgstr;
150         unsigned char *pixbufdata;
151         unsigned int pixbufdatasize;
152         int row, col;
153         unsigned char *p;
154
155         /* RGB Pixbuf data */
156         pixbufdatasize = width * height * 3;
157         if (colorMap) {
158                 pixbufdata =(unsigned char *)g_malloc(pixbufdatasize);
159         } else {
160                 pixbufdata =(unsigned char *)g_malloc0(pixbufdatasize);
161                 return pixbufdata;
162         }
163
164         p = pixbufdata;
165
166         imgstr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
167         imgstr->reset();
168         for (row = 0; row < height; ++row) {
169             for (col = 0; col < width; ++col) {
170                 Guchar pix[gfxColorMaxComps];
171                 GfxRGB rgb;
172
173                 imgstr->getPixel(pix);
174                 colorMap->getRGB(pix, &rgb);
175
176                 *p++ = (guchar)(rgb.r * 255.99999);
177                 *p++ = (guchar)(rgb.g * 255.99999);
178                 *p++ = (guchar)(rgb.b * 255.99999);
179             }
180         }
181         delete imgstr;
182
183         return pixbufdata;
184 }
185
186 Thumb::~Thumb() {
187         delete colorMap;
188         delete str;
189 }
190