diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2013-08-06 21:39:25 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-07 23:46:29 +0200 |
commit | 0b62a5d3c931aa4d91b986ec518567e9463a6360 (patch) | |
tree | 55daf807cd88ed7324631552362cac7706bda79b /src/gui/image/qpnghandler.cpp | |
parent | cffd1633b267d0034627756296e61abcc0ef50be (diff) |
Add offset reading support in pnghandler
This patch adds the offset reading that matches the offset writing in
writeImage
Task-number: QTBUG-32674
Change-Id: I264ba41163e59638d7219e0a8913f9d455830883
Reviewed-by: aavit <eirik.aavitsland@digia.com>
Diffstat (limited to 'src/gui/image/qpnghandler.cpp')
-rw-r--r-- | src/gui/image/qpnghandler.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index 1e906e0d92..e43ac666c7 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -408,9 +408,14 @@ static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop i png_uint_32 width; png_uint_32 height; + png_int_32 offset_x; + png_int_32 offset_y; + int bit_depth; int color_type; + int unit_type; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); + png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, &unit_type); uchar *data = outImage->bits(); int bpl = outImage->bytesPerLine(); @@ -470,6 +475,10 @@ static void read_image_scaled(QImage *outImage, png_structp png_ptr, png_infop i outImage->setDotsPerMeterX((png_get_x_pixels_per_meter(png_ptr,info_ptr)*oxsz)/ixsz); outImage->setDotsPerMeterY((png_get_y_pixels_per_meter(png_ptr,info_ptr)*oysz)/iysz); + + if (unit_type == PNG_OFFSET_PIXEL) + outImage->setOffset(QPoint(offset_x*oxsz/ixsz, offset_y*oysz/iysz)); + } #if defined(Q_C_CALLBACKS) @@ -550,7 +559,6 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngHeader() return true; } - bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) { if (state == Error) @@ -585,9 +593,14 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) } else { png_uint_32 width; png_uint_32 height; + png_int_32 offset_x; + png_int_32 offset_y; + int bit_depth; int color_type; + int unit_type; png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, 0, 0, 0); + png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y, &unit_type); uchar *data = outImage->bits(); int bpl = outImage->bytesPerLine(); amp.row_pointers = new png_bytep[height]; @@ -601,6 +614,9 @@ bool Q_INTERNAL_WIN_NO_THROW QPngHandlerPrivate::readPngImage(QImage *outImage) outImage->setDotsPerMeterX(png_get_x_pixels_per_meter(png_ptr,info_ptr)); outImage->setDotsPerMeterY(png_get_y_pixels_per_meter(png_ptr,info_ptr)); + if (unit_type == PNG_OFFSET_PIXEL) + outImage->setOffset(QPoint(offset_x, offset_y)); + // sanity check palette entries if (color_type == PNG_COLOR_TYPE_PALETTE && outImage->format() == QImage::Format_Indexed8) { int color_table_size = outImage->colorCount(); |