diff options
Diffstat (limited to 'src/plugins/old/thumbnailqt_extractor.cc')
-rw-r--r-- | src/plugins/old/thumbnailqt_extractor.cc | 199 |
1 files changed, 0 insertions, 199 deletions
diff --git a/src/plugins/old/thumbnailqt_extractor.cc b/src/plugins/old/thumbnailqt_extractor.cc deleted file mode 100644 index 61a2132..0000000 --- a/src/plugins/old/thumbnailqt_extractor.cc +++ /dev/null | |||
@@ -1,199 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of libextractor. | ||
3 | (C) 2006, 2009 Vidyut Samanta and Christian Grothoff | ||
4 | |||
5 | libextractor is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libextractor is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libextractor; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file thumbnailqt_extractor.cc | ||
23 | * @author Nils Durner | ||
24 | * @brief this extractor produces a binary (!) encoded | ||
25 | * thumbnail of images (using Qt). | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "extractor.h" | ||
30 | #include <Qt/qpixmap.h> | ||
31 | #include <Qt/qbytearray.h> | ||
32 | #include <Qt/qbuffer.h> | ||
33 | #include <Qt/qapplication.h> | ||
34 | #include <pthread.h> | ||
35 | |||
36 | #ifdef HAVE_QT_SVG | ||
37 | #include <Qt/qsvgrenderer.h> | ||
38 | #include <Qt/qpainter.h> | ||
39 | #endif | ||
40 | |||
41 | #define THUMBSIZE 128 | ||
42 | |||
43 | extern "C" | ||
44 | { | ||
45 | |||
46 | |||
47 | static void | ||
48 | mh (QtMsgType mtype, const char *msg) | ||
49 | { | ||
50 | /* just discard */ | ||
51 | } | ||
52 | |||
53 | |||
54 | int | ||
55 | EXTRACTOR_thumbnailqt_extract (const char *data, | ||
56 | size_t size, | ||
57 | EXTRACTOR_MetaDataProcessor proc, | ||
58 | void *proc_cls, | ||
59 | const char *options) | ||
60 | { | ||
61 | QImage *img; | ||
62 | QByteArray bytes; | ||
63 | QBuffer buffer; | ||
64 | unsigned long width; | ||
65 | unsigned long height; | ||
66 | char format[64]; | ||
67 | QImage::Format colors; | ||
68 | QtMsgHandler oh; | ||
69 | int ret; | ||
70 | |||
71 | oh = qInstallMsgHandler (&mh); | ||
72 | /* Determine image format to use */ | ||
73 | if (options == NULL) | ||
74 | colors = QImage::Format_Indexed8; | ||
75 | else | ||
76 | switch (atoi(options)) | ||
77 | { | ||
78 | case 1: | ||
79 | colors = QImage::Format_Mono; | ||
80 | break; | ||
81 | case 8: | ||
82 | colors = QImage::Format_Indexed8; | ||
83 | break; | ||
84 | case 16: | ||
85 | case 24: | ||
86 | colors = QImage::Format_RGB32; | ||
87 | break; | ||
88 | default: | ||
89 | colors = QImage::Format_ARGB32; | ||
90 | break; | ||
91 | } | ||
92 | QByteArray din (data, (int) size); | ||
93 | |||
94 | #ifdef HAVE_QT_SVG | ||
95 | /* Render SVG image */ | ||
96 | QSvgRenderer svg; | ||
97 | QSize qsize; | ||
98 | if (svg.load(din)) | ||
99 | { | ||
100 | qsize = svg.defaultSize(); | ||
101 | img = new QImage(qsize, QImage::Format_ARGB32); | ||
102 | QPainter painter(img); | ||
103 | painter.setViewport(0, 0, qsize.width(), qsize.height()); | ||
104 | painter.eraseRect(0, 0, qsize.width(), qsize.height()); | ||
105 | svg.render(&painter); | ||
106 | } | ||
107 | else | ||
108 | #endif | ||
109 | { | ||
110 | /* Load image */ | ||
111 | img = new QImage(); | ||
112 | img->loadFromData(din); | ||
113 | } | ||
114 | |||
115 | height = img->height(); | ||
116 | width = img->width(); | ||
117 | if ( (height == 0) || (width == 0) ) | ||
118 | { | ||
119 | delete img; | ||
120 | qInstallMsgHandler (oh); | ||
121 | return 0; | ||
122 | } | ||
123 | snprintf(format, | ||
124 | sizeof(format), | ||
125 | "%ux%u", | ||
126 | (unsigned int) width, | ||
127 | (unsigned int) height); | ||
128 | if (0 != proc (proc_cls, | ||
129 | "thumbnailqt", | ||
130 | EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, | ||
131 | EXTRACTOR_METAFORMAT_UTF8, | ||
132 | "text/plain", | ||
133 | format, | ||
134 | strlen(format)+1)) | ||
135 | { | ||
136 | delete img; | ||
137 | qInstallMsgHandler (oh); | ||
138 | return 1; | ||
139 | } | ||
140 | /* Change color depth */ | ||
141 | QImage thumb = img->convertToFormat(colors); | ||
142 | delete img; | ||
143 | |||
144 | /* Resize image | ||
145 | * | ||
146 | * Qt's scaled() produces poor quality if the image is resized to less than | ||
147 | * half the size. Therefore, we resize the image in multiple steps. | ||
148 | * http://lists.trolltech.com/qt-interest/2006-04/msg00376.html */ | ||
149 | while ( (width > 32*THUMBSIZE) || (height > 32*THUMBSIZE) ) | ||
150 | { | ||
151 | width /= 2; | ||
152 | height /= 2; | ||
153 | } | ||
154 | while ( (width > THUMBSIZE) || (height > THUMBSIZE) ) | ||
155 | { | ||
156 | width /= 2; | ||
157 | if (width < THUMBSIZE) | ||
158 | width = THUMBSIZE; | ||
159 | height /= 2; | ||
160 | if (height < THUMBSIZE) | ||
161 | height = THUMBSIZE; | ||
162 | thumb = thumb.scaled(width, | ||
163 | height, | ||
164 | Qt::KeepAspectRatio, | ||
165 | Qt::SmoothTransformation); | ||
166 | } | ||
167 | buffer.setBuffer(&bytes); | ||
168 | buffer.open(QIODevice::WriteOnly); | ||
169 | if (TRUE != thumb.save(&buffer, "PNG")) | ||
170 | { | ||
171 | qInstallMsgHandler (oh); | ||
172 | return 0; | ||
173 | } | ||
174 | buffer.close (); | ||
175 | ret = proc (proc_cls, | ||
176 | "thumbnailqt", | ||
177 | EXTRACTOR_METATYPE_THUMBNAIL, | ||
178 | EXTRACTOR_METAFORMAT_BINARY, | ||
179 | "image/png", | ||
180 | bytes.data(), | ||
181 | bytes.size()); | ||
182 | qInstallMsgHandler (oh); | ||
183 | return ret; | ||
184 | } | ||
185 | |||
186 | |||
187 | int | ||
188 | EXTRACTOR_thumbnail_extract (const unsigned char *data, | ||
189 | size_t size, | ||
190 | EXTRACTOR_MetaDataProcessor proc, | ||
191 | void *proc_cls, | ||
192 | const char *options) | ||
193 | { | ||
194 | return EXTRACTOR_thumbnail_extract (data, size, proc, proc_cls, options); | ||
195 | } | ||
196 | |||
197 | } // extern "C" | ||
198 | |||
199 | /* end of thumbnailqt_extractor.cc */ | ||