|
Lines 1-5
Link Here
|
| 1 |
/**************************************************************************** |
1 |
/**************************************************************************** |
| 2 |
** $Id: qt/qjpegio.cpp 3.3.2 edited Oct 13 2003 $ |
2 |
** $Id: qt/qjpegio.cpp 3.3.3 edited Jul 21 14:16 $ |
| 3 |
** |
3 |
** |
| 4 |
** Implementation of JPEG QImage IOHandler |
4 |
** Implementation of JPEG QImage IOHandler |
| 5 |
** |
5 |
** |
|
Lines 254-268
void read_jpeg_image(QImageIO* iio)
Link Here
|
| 254 |
scaleSize( sWidth, sHeight, cinfo.output_width, cinfo.output_height, sMode ); |
254 |
scaleSize( sWidth, sHeight, cinfo.output_width, cinfo.output_height, sMode ); |
| 255 |
// qDebug( "Scaling the jpeg to %i x %i", sWidth, sHeight, sModeStr ); |
255 |
// qDebug( "Scaling the jpeg to %i x %i", sWidth, sHeight, sModeStr ); |
| 256 |
|
256 |
|
|
|
257 |
bool created = FALSE; |
| 257 |
if ( cinfo.output_components == 3 || cinfo.output_components == 4) { |
258 |
if ( cinfo.output_components == 3 || cinfo.output_components == 4) { |
| 258 |
image.create( sWidth, sHeight, 32 ); |
259 |
created = image.create( sWidth, sHeight, 32 ); |
| 259 |
} else if ( cinfo.output_components == 1 ) { |
260 |
} else if ( cinfo.output_components == 1 ) { |
| 260 |
image.create( sWidth, sHeight, 8, 256 ); |
261 |
created = image.create( sWidth, sHeight, 8, 256 ); |
| 261 |
for (int i=0; i<256; i++) |
262 |
for (int i=0; i<256; i++) |
| 262 |
image.setColor(i, qRgb(i,i,i)); |
263 |
image.setColor(i, qRgb(i,i,i)); |
| 263 |
} else { |
264 |
} else { |
| 264 |
// Unsupported format |
265 |
// Unsupported format |
| 265 |
} |
266 |
} |
|
|
267 |
if (!created) |
| 268 |
image = QImage(); |
| 266 |
|
269 |
|
| 267 |
if (!image.isNull()) { |
270 |
if (!image.isNull()) { |
| 268 |
QImage tmpImage( cinfo.output_width, 1, 32 ); |
271 |
QImage tmpImage( cinfo.output_width, 1, 32 ); |
|
Lines 296-348
void read_jpeg_image(QImageIO* iio)
Link Here
|
| 296 |
} |
299 |
} |
| 297 |
} |
300 |
} |
| 298 |
(void) jpeg_finish_decompress(&cinfo); |
301 |
(void) jpeg_finish_decompress(&cinfo); |
| 299 |
} |
302 |
} |
| 300 |
|
303 |
|
| 301 |
} else { |
304 |
} else { |
| 302 |
|
305 |
|
|
|
306 |
bool created = false; |
| 303 |
if ( cinfo.output_components == 3 || cinfo.output_components == 4) { |
307 |
if ( cinfo.output_components == 3 || cinfo.output_components == 4) { |
| 304 |
image.create( cinfo.output_width, cinfo.output_height, 32 ); |
308 |
created = image.create( cinfo.output_width, cinfo.output_height, 32 ); |
| 305 |
} else if ( cinfo.output_components == 1 ) { |
309 |
} else if ( cinfo.output_components == 1 ) { |
| 306 |
image.create( cinfo.output_width, cinfo.output_height, 8, 256 ); |
310 |
created = image.create( cinfo.output_width, cinfo.output_height, 8, 256 ); |
| 307 |
for (int i=0; i<256; i++) |
311 |
for (int i=0; i<256; i++) |
| 308 |
image.setColor(i, qRgb(i,i,i)); |
312 |
image.setColor(i, qRgb(i,i,i)); |
| 309 |
} else { |
313 |
} else { |
| 310 |
// Unsupported format |
314 |
// Unsupported format |
| 311 |
} |
315 |
} |
|
|
316 |
if (!created) |
| 317 |
image = QImage(); |
| 312 |
|
318 |
|
| 313 |
if (!image.isNull()) { |
319 |
if (!image.isNull()) { |
| 314 |
uchar** lines = image.jumpTable(); |
320 |
uchar** lines = image.jumpTable(); |
| 315 |
while (cinfo.output_scanline < cinfo.output_height) |
321 |
while (cinfo.output_scanline < cinfo.output_height) |
| 316 |
(void) jpeg_read_scanlines(&cinfo, |
322 |
(void) jpeg_read_scanlines(&cinfo, |
| 317 |
lines + cinfo.output_scanline, |
323 |
lines + cinfo.output_scanline, |
| 318 |
cinfo.output_height); |
324 |
cinfo.output_height); |
| 319 |
(void) jpeg_finish_decompress(&cinfo); |
325 |
(void) jpeg_finish_decompress(&cinfo); |
| 320 |
} |
|
|
| 321 |
|
326 |
|
| 322 |
if ( cinfo.output_components == 3 ) { |
327 |
if ( cinfo.output_components == 3 ) { |
| 323 |
// Expand 24->32 bpp. |
328 |
// Expand 24->32 bpp. |
| 324 |
for (uint j=0; j<cinfo.output_height; j++) { |
329 |
for (uint j=0; j<cinfo.output_height; j++) { |
| 325 |
uchar *in = image.scanLine(j) + cinfo.output_width * 3; |
330 |
uchar *in = image.scanLine(j) + cinfo.output_width * 3; |
| 326 |
QRgb *out = (QRgb*)image.scanLine(j); |
331 |
QRgb *out = (QRgb*)image.scanLine(j); |
| 327 |
|
332 |
|
| 328 |
for (uint i=cinfo.output_width; i--; ) { |
333 |
for (uint i=cinfo.output_width; i--; ) { |
| 329 |
in-=3; |
334 |
in-=3; |
| 330 |
out[i] = qRgb(in[0], in[1], in[2]); |
335 |
out[i] = qRgb(in[0], in[1], in[2]); |
| 331 |
} |
336 |
} |
| 332 |
} |
337 |
} |
| 333 |
} |
338 |
} |
|
|
339 |
} |
| 334 |
} |
340 |
} |
| 335 |
|
341 |
|
| 336 |
if ( cinfo.density_unit == 1 ) { |
342 |
if (!image.isNull()) { |
| 337 |
image.setDotsPerMeterX( int(100. * cinfo.X_density / 2.54) ); |
343 |
if ( cinfo.density_unit == 1 ) { |
| 338 |
image.setDotsPerMeterY( int(100. * cinfo.Y_density / 2.54) ); |
344 |
image.setDotsPerMeterX( int(100. * cinfo.X_density / 2.54) ); |
| 339 |
} else if ( cinfo.density_unit == 2 ) { |
345 |
image.setDotsPerMeterY( int(100. * cinfo.Y_density / 2.54) ); |
| 340 |
image.setDotsPerMeterX( int(100. * cinfo.X_density) ); |
346 |
} else if ( cinfo.density_unit == 2 ) { |
| 341 |
image.setDotsPerMeterY( int(100. * cinfo.Y_density) ); |
347 |
image.setDotsPerMeterX( int(100. * cinfo.X_density) ); |
| 342 |
} |
348 |
image.setDotsPerMeterY( int(100. * cinfo.Y_density) ); |
|
|
349 |
} |
| 350 |
} |
| 343 |
|
351 |
|
| 344 |
iio->setImage(image); |
352 |
iio->setImage(image); |
| 345 |
iio->setStatus(0); |
353 |
iio->setStatus(image.isNull()); |
| 346 |
} |
354 |
} |
| 347 |
|
355 |
|
| 348 |
jpeg_destroy_decompress(&cinfo); |
356 |
jpeg_destroy_decompress(&cinfo); |
|
Lines 476-481
void write_jpeg_image(QImageIO* iio)
Link Here
|
| 476 |
} |
484 |
} |
| 477 |
|
485 |
|
| 478 |
jpeg_set_defaults(&cinfo); |
486 |
jpeg_set_defaults(&cinfo); |
|
|
487 |
|
| 488 |
float diffInch = QABS(image.dotsPerMeterX()*2.54/100. - qRound(image.dotsPerMeterX()*2.54/100.)) |
| 489 |
+ QABS(image.dotsPerMeterY()*2.54/100. - qRound(image.dotsPerMeterY()*2.54/100.)); |
| 490 |
float diffCm = (QABS(image.dotsPerMeterX()/100. - qRound(image.dotsPerMeterX()/100.)) |
| 491 |
+ QABS(image.dotsPerMeterY()/100. - qRound(image.dotsPerMeterY()/100.)))*2.54; |
| 492 |
if (diffInch < diffCm) { |
| 493 |
cinfo.density_unit = 1; // dots/inch |
| 494 |
cinfo.X_density = qRound(image.dotsPerMeterX()*2.54/100.); |
| 495 |
cinfo.Y_density = qRound(image.dotsPerMeterY()*2.54/100.); |
| 496 |
} else { |
| 497 |
cinfo.density_unit = 2; // dots/cm |
| 498 |
cinfo.X_density = (image.dotsPerMeterX()+50) / 100; |
| 499 |
cinfo.Y_density = (image.dotsPerMeterY()+50) / 100; |
| 500 |
} |
| 501 |
|
| 479 |
int quality = iio->quality() >= 0 ? QMIN(iio->quality(),100) : 75; |
502 |
int quality = iio->quality() >= 0 ? QMIN(iio->quality(),100) : 75; |
| 480 |
#if defined(Q_OS_UNIXWARE) |
503 |
#if defined(Q_OS_UNIXWARE) |
| 481 |
jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */); |
504 |
jpeg_set_quality(&cinfo, quality, B_TRUE /* limit to baseline-JPEG values */); |