Changeset View
Changeset View
Standalone View
Standalone View
src/ksanepreviewimagebuilder.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 89 | { | |||
---|---|---|---|---|---|
90 | int index; | 90 | int index; | ||
91 | uchar *imgBits = m_img->bits(); | 91 | uchar *imgBits = m_img->bits(); | ||
92 | switch (m_params.format) { | 92 | switch (m_params.format) { | ||
93 | case SANE_FRAME_GRAY: | 93 | case SANE_FRAME_GRAY: | ||
94 | if (m_params.depth == 1) { | 94 | if (m_params.depth == 1) { | ||
95 | int i, j; | 95 | int i, j; | ||
96 | for (i = 0; i < read_bytes; i++) { | 96 | for (i = 0; i < read_bytes; i++) { | ||
97 | if (m_pixel_y >= m_img->height()) { | 97 | if (m_pixel_y >= m_img->height()) { | ||
98 | // resize the image | 98 | renewImage(); | ||
99 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
100 | m_imageResized = true; | | |||
101 | } | 99 | } | ||
102 | for (j = 7; j >= 0; --j) { | 100 | for (j = 7; j >= 0; --j) { | ||
103 | if ((readData[i] & (1 << j)) == 0) { | 101 | if ((readData[i] & (1 << j)) == 0) { | ||
104 | m_img->setPixel(m_pixel_x, | 102 | m_img->setPixel(m_pixel_x, | ||
105 | m_pixel_y, | 103 | m_pixel_y, | ||
106 | qRgb(255, 255, 255)); | 104 | qRgb(255, 255, 255)); | ||
107 | } else { | 105 | } else { | ||
108 | m_img->setPixel(m_pixel_x, | 106 | m_img->setPixel(m_pixel_x, | ||
Show All 12 Lines | |||||
121 | } | 119 | } | ||
122 | m_frameRead++; | 120 | m_frameRead++; | ||
123 | } | 121 | } | ||
124 | return true; | 122 | return true; | ||
125 | } else if (m_params.depth == 8) { | 123 | } else if (m_params.depth == 8) { | ||
126 | for (int i = 0; i < read_bytes; i++) { | 124 | for (int i = 0; i < read_bytes; i++) { | ||
127 | index = m_frameRead * 4; | 125 | index = m_frameRead * 4; | ||
128 | if ((index + 2) > m_img->byteCount()) { | 126 | if ((index + 2) > m_img->byteCount()) { | ||
129 | // resize the image | 127 | renewImage(); | ||
130 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
131 | imgBits = m_img->bits(); | 128 | imgBits = m_img->bits(); | ||
132 | m_imageResized = true; | | |||
133 | } | 129 | } | ||
134 | imgBits[index ] = readData[i]; | 130 | imgBits[index ] = readData[i]; | ||
135 | imgBits[index + 1] = readData[i]; | 131 | imgBits[index + 1] = readData[i]; | ||
136 | imgBits[index + 2] = readData[i]; | 132 | imgBits[index + 2] = readData[i]; | ||
137 | m_frameRead++; | 133 | m_frameRead++; | ||
138 | } | 134 | } | ||
139 | return true; | 135 | return true; | ||
140 | } else if (m_params.depth == 16) { | 136 | } else if (m_params.depth == 16) { | ||
141 | for (int i = 0; i < read_bytes; i++) { | 137 | for (int i = 0; i < read_bytes; i++) { | ||
142 | if (m_frameRead % 2 == 0) { | 138 | if (m_frameRead % 2 == 0) { | ||
143 | index = m_frameRead * 2; | 139 | index = m_frameRead * 2; | ||
144 | if ((index + 2) > m_img->byteCount()) { | 140 | if ((index + 2) > m_img->byteCount()) { | ||
145 | // resize the image | 141 | renewImage(); | ||
146 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
147 | imgBits = m_img->bits(); | 142 | imgBits = m_img->bits(); | ||
148 | m_imageResized = true; | | |||
149 | } | 143 | } | ||
150 | imgBits[index ] = readData[i + 1]; | 144 | imgBits[index ] = readData[i + 1]; | ||
151 | imgBits[index + 1] = readData[i + 1]; | 145 | imgBits[index + 1] = readData[i + 1]; | ||
152 | imgBits[index + 2] = readData[i + 1]; | 146 | imgBits[index + 2] = readData[i + 1]; | ||
153 | } | 147 | } | ||
154 | m_frameRead++; | 148 | m_frameRead++; | ||
155 | } | 149 | } | ||
156 | return true; | 150 | return true; | ||
157 | } | 151 | } | ||
158 | break; | 152 | break; | ||
159 | 153 | | |||
160 | case SANE_FRAME_RGB: | 154 | case SANE_FRAME_RGB: | ||
161 | if (m_params.depth == 8) { | 155 | if (m_params.depth == 8) { | ||
162 | for (int i = 0; i < read_bytes; i++) { | 156 | for (int i = 0; i < read_bytes; i++) { | ||
163 | m_px_colors[m_px_c_index] = readData[i]; | 157 | m_px_colors[m_px_c_index] = readData[i]; | ||
164 | inc_color_index(m_px_c_index); | 158 | inc_color_index(m_px_c_index); | ||
165 | m_frameRead++; | 159 | m_frameRead++; | ||
166 | if (m_px_c_index == 0) { | 160 | if (m_px_c_index == 0) { | ||
167 | if (m_pixel_y >= m_img->height()) { | 161 | if (m_pixel_y >= m_img->height()) { | ||
168 | // resize the image | 162 | renewImage(); | ||
169 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
170 | m_imageResized = true; | | |||
171 | } | 163 | } | ||
172 | m_img->setPixel(m_pixel_x, | 164 | m_img->setPixel(m_pixel_x, | ||
173 | m_pixel_y, | 165 | m_pixel_y, | ||
174 | qRgb(m_px_colors[0], | 166 | qRgb(m_px_colors[0], | ||
175 | m_px_colors[1], | 167 | m_px_colors[1], | ||
176 | m_px_colors[2])); | 168 | m_px_colors[2])); | ||
177 | inc_pixel(m_pixel_x, m_pixel_y, m_params.pixels_per_line); | 169 | inc_pixel(m_pixel_x, m_pixel_y, m_params.pixels_per_line); | ||
178 | } | 170 | } | ||
179 | } | 171 | } | ||
180 | return true; | 172 | return true; | ||
181 | } else if (m_params.depth == 16) { | 173 | } else if (m_params.depth == 16) { | ||
182 | for (int i = 0; i < read_bytes; i++) { | 174 | for (int i = 0; i < read_bytes; i++) { | ||
183 | m_frameRead++; | 175 | m_frameRead++; | ||
184 | if (m_frameRead % 2 == 0) { | 176 | if (m_frameRead % 2 == 0) { | ||
185 | m_px_colors[m_px_c_index] = readData[i]; | 177 | m_px_colors[m_px_c_index] = readData[i]; | ||
186 | inc_color_index(m_px_c_index); | 178 | inc_color_index(m_px_c_index); | ||
187 | if (m_px_c_index == 0) { | 179 | if (m_px_c_index == 0) { | ||
188 | if (m_pixel_y >= m_img->height()) { | 180 | if (m_pixel_y >= m_img->height()) { | ||
189 | // resize the image | 181 | renewImage(); | ||
190 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
191 | m_imageResized = true; | | |||
192 | } | 182 | } | ||
193 | m_img->setPixel(m_pixel_x, | 183 | m_img->setPixel(m_pixel_x, | ||
194 | m_pixel_y, | 184 | m_pixel_y, | ||
195 | qRgb(m_px_colors[0], | 185 | qRgb(m_px_colors[0], | ||
196 | m_px_colors[1], | 186 | m_px_colors[1], | ||
197 | m_px_colors[2])); | 187 | m_px_colors[2])); | ||
198 | inc_pixel(m_pixel_x, m_pixel_y, m_params.pixels_per_line); | 188 | inc_pixel(m_pixel_x, m_pixel_y, m_params.pixels_per_line); | ||
199 | } | 189 | } | ||
200 | } | 190 | } | ||
201 | } | 191 | } | ||
202 | return true; | 192 | return true; | ||
203 | } | 193 | } | ||
204 | break; | 194 | break; | ||
205 | 195 | | |||
206 | case SANE_FRAME_RED: | 196 | case SANE_FRAME_RED: | ||
207 | if (m_params.depth == 8) { | 197 | if (m_params.depth == 8) { | ||
208 | for (int i = 0; i < read_bytes; i++) { | 198 | for (int i = 0; i < read_bytes; i++) { | ||
209 | if (index_red8_to_argb8(m_frameRead) > m_img->byteCount()) { | 199 | if (index_red8_to_argb8(m_frameRead) > m_img->byteCount()) { | ||
210 | // resize the image | 200 | renewImage(); | ||
211 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
212 | imgBits = m_img->bits(); | 201 | imgBits = m_img->bits(); | ||
213 | m_imageResized = true; | | |||
214 | } | 202 | } | ||
215 | imgBits[index_red8_to_argb8(m_frameRead)] = readData[i]; | 203 | imgBits[index_red8_to_argb8(m_frameRead)] = readData[i]; | ||
216 | m_frameRead++; | 204 | m_frameRead++; | ||
217 | } | 205 | } | ||
218 | return true; | 206 | return true; | ||
219 | } else if (m_params.depth == 16) { | 207 | } else if (m_params.depth == 16) { | ||
220 | for (int i = 0; i < read_bytes; i++) { | 208 | for (int i = 0; i < read_bytes; i++) { | ||
221 | if (m_frameRead % 2 == 0) { | 209 | if (m_frameRead % 2 == 0) { | ||
222 | if (index_red16_to_argb8(m_frameRead) > m_img->byteCount()) { | 210 | if (index_red16_to_argb8(m_frameRead) > m_img->byteCount()) { | ||
223 | // resize the image | 211 | renewImage(); | ||
224 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
225 | imgBits = m_img->bits(); | 212 | imgBits = m_img->bits(); | ||
226 | m_imageResized = true; | | |||
227 | } | 213 | } | ||
228 | imgBits[index_red16_to_argb8(m_frameRead)] = readData[i + 1]; | 214 | imgBits[index_red16_to_argb8(m_frameRead)] = readData[i + 1]; | ||
229 | } | 215 | } | ||
230 | m_frameRead++; | 216 | m_frameRead++; | ||
231 | } | 217 | } | ||
232 | return true; | 218 | return true; | ||
233 | } | 219 | } | ||
234 | break; | 220 | break; | ||
235 | 221 | | |||
236 | case SANE_FRAME_GREEN: | 222 | case SANE_FRAME_GREEN: | ||
237 | if (m_params.depth == 8) { | 223 | if (m_params.depth == 8) { | ||
238 | for (int i = 0; i < read_bytes; i++) { | 224 | for (int i = 0; i < read_bytes; i++) { | ||
239 | if (index_green8_to_argb8(m_frameRead) > m_img->byteCount()) { | 225 | if (index_green8_to_argb8(m_frameRead) > m_img->byteCount()) { | ||
240 | // resize the image | 226 | renewImage(); | ||
241 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
242 | imgBits = m_img->bits(); | 227 | imgBits = m_img->bits(); | ||
243 | m_imageResized = true; | | |||
244 | } | 228 | } | ||
245 | imgBits[index_green8_to_argb8(m_frameRead)] = readData[i]; | 229 | imgBits[index_green8_to_argb8(m_frameRead)] = readData[i]; | ||
246 | m_frameRead++; | 230 | m_frameRead++; | ||
247 | } | 231 | } | ||
248 | return true; | 232 | return true; | ||
249 | } else if (m_params.depth == 16) { | 233 | } else if (m_params.depth == 16) { | ||
250 | for (int i = 0; i < read_bytes; i++) { | 234 | for (int i = 0; i < read_bytes; i++) { | ||
251 | if (m_frameRead % 2 == 0) { | 235 | if (m_frameRead % 2 == 0) { | ||
252 | if (index_green16_to_argb8(m_frameRead) > m_img->byteCount()) { | 236 | if (index_green16_to_argb8(m_frameRead) > m_img->byteCount()) { | ||
253 | // resize the image | 237 | renewImage(); | ||
254 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
255 | imgBits = m_img->bits(); | 238 | imgBits = m_img->bits(); | ||
256 | m_imageResized = true; | | |||
257 | } | 239 | } | ||
258 | imgBits[index_green16_to_argb8(m_frameRead)] = readData[i + 1]; | 240 | imgBits[index_green16_to_argb8(m_frameRead)] = readData[i + 1]; | ||
259 | } | 241 | } | ||
260 | m_frameRead++; | 242 | m_frameRead++; | ||
261 | } | 243 | } | ||
262 | return true; | 244 | return true; | ||
263 | } | 245 | } | ||
264 | break; | 246 | break; | ||
265 | 247 | | |||
266 | case SANE_FRAME_BLUE: | 248 | case SANE_FRAME_BLUE: | ||
267 | if (m_params.depth == 8) { | 249 | if (m_params.depth == 8) { | ||
268 | for (int i = 0; i < read_bytes; i++) { | 250 | for (int i = 0; i < read_bytes; i++) { | ||
269 | if (index_blue8_to_argb8(m_frameRead) > m_img->byteCount()) { | 251 | if (index_blue8_to_argb8(m_frameRead) > m_img->byteCount()) { | ||
270 | // resize the image | 252 | renewImage(); | ||
271 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
272 | imgBits = m_img->bits(); | 253 | imgBits = m_img->bits(); | ||
273 | m_imageResized = true; | | |||
274 | } | 254 | } | ||
275 | imgBits[index_blue8_to_argb8(m_frameRead)] = readData[i]; | 255 | imgBits[index_blue8_to_argb8(m_frameRead)] = readData[i]; | ||
276 | m_frameRead++; | 256 | m_frameRead++; | ||
277 | } | 257 | } | ||
278 | return true; | 258 | return true; | ||
279 | } else if (m_params.depth == 16) { | 259 | } else if (m_params.depth == 16) { | ||
280 | for (int i = 0; i < read_bytes; i++) { | 260 | for (int i = 0; i < read_bytes; i++) { | ||
281 | if (m_frameRead % 2 == 0) { | 261 | if (m_frameRead % 2 == 0) { | ||
282 | if (index_blue16_to_argb8(m_frameRead) > m_img->byteCount()) { | 262 | if (index_blue16_to_argb8(m_frameRead) > m_img->byteCount()) { | ||
283 | // resize the image | 263 | renewImage(); | ||
284 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | | |||
285 | imgBits = m_img->bits(); | 264 | imgBits = m_img->bits(); | ||
286 | m_imageResized = true; | | |||
287 | } | 265 | } | ||
288 | imgBits[index_blue16_to_argb8(m_frameRead)] = readData[i + 1]; | 266 | imgBits[index_blue16_to_argb8(m_frameRead)] = readData[i + 1]; | ||
289 | } | 267 | } | ||
290 | m_frameRead++; | 268 | m_frameRead++; | ||
291 | } | 269 | } | ||
292 | return true; | 270 | return true; | ||
293 | } | 271 | } | ||
294 | break; | 272 | break; | ||
295 | } | 273 | } | ||
296 | 274 | | |||
297 | qWarning() << "Format" << m_params.format | 275 | qWarning() << "Format" << m_params.format | ||
298 | << "and depth" << m_params.depth | 276 | << "and depth" << m_params.depth | ||
299 | << "is not yet supported by libksane!"; | 277 | << "is not yet supported by libksane!"; | ||
300 | return false; | 278 | return false; | ||
301 | } | 279 | } | ||
302 | 280 | | |||
303 | bool KSanePreviewImageBuilder::imageResized() | 281 | bool KSanePreviewImageBuilder::imageResized() | ||
304 | { | 282 | { | ||
305 | if (m_imageResized) { | 283 | if (m_imageResized) { | ||
306 | m_imageResized = false; | 284 | m_imageResized = false; | ||
307 | return true; | 285 | return true; | ||
308 | } | 286 | } | ||
309 | return false; | 287 | return false; | ||
310 | } | 288 | } | ||
289 | | ||||
290 | void KSanePreviewImageBuilder::renewImage() | ||||
291 | { | ||||
292 | // resize the image | ||||
293 | *m_img = m_img->copy(0, 0, m_img->width(), m_img->height() + m_img->width()); | ||||
294 | m_imageResized = true; | ||||
295 | } | ||||
311 | } // NameSpace KSaneIface | 296 | } // NameSpace KSaneIface |