X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd61e8ed01072bc75060245923419eda94ca5d32..b74077ace2413000c5556cbe0c41ab210ac12c54:/src/common/imagpng.cpp?ds=sidebyside diff --git a/src/common/imagpng.cpp b/src/common/imagpng.cpp index da38225970..bb081b809a 100644 --- a/src/common/imagpng.cpp +++ b/src/common/imagpng.cpp @@ -279,6 +279,7 @@ FindMaskColour(unsigned char **lines, png_uint_32 width, png_uint_32 height, r2 = *p++; g2 = *p++; b2 = *p++; + ++p; // jump over alpha wxImageHistogramEntry& entry = h[wxImageHistogram:: MakeKey(r2, g2, b2)]; @@ -384,8 +385,8 @@ void CopyDataFromPNG(wxImage *image, if ( IsTransparent(a) ) { *ptrDst++ = rMask; - *ptrDst++ = bMask; *ptrDst++ = gMask; + *ptrDst++ = bMask; break; } // else: !transparent @@ -452,8 +453,8 @@ void CopyDataFromPNG(wxImage *image, if ( IsTransparent(a) ) { *ptrDst++ = rMask; - *ptrDst++ = bMask; *ptrDst++ = gMask; + *ptrDst++ = bMask; break; } else // !transparent @@ -747,6 +748,33 @@ bool wxPNGHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos if ( iBitDepth == 16 ) iElements *= 2; + // save the image resolution if we have it + int resX, resY; + switch ( GetResolutionFromOptions(*image, &resX, &resY) ) + { + case wxIMAGE_RESOLUTION_INCHES: + { + const double INCHES_IN_METER = 10000.0 / 254; + resX = int(resX * INCHES_IN_METER); + resY = int(resY * INCHES_IN_METER); + } + break; + + case wxIMAGE_RESOLUTION_CM: + resX *= 100; + resY *= 100; + break; + + case wxIMAGE_RESOLUTION_NONE: + break; + + default: + wxFAIL_MSG( _T("unsupported image resolution units") ); + } + + if ( resX && resY ) + png_set_pHYs( png_ptr, info_ptr, resX, resY, PNG_RESOLUTION_METER ); + png_set_sBIT( png_ptr, info_ptr, &sig_bit ); png_write_info( png_ptr, info_ptr ); png_set_shift( png_ptr, &sig_bit );