The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

547 lines
18KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #if JUCE_MSVC
  19. #pragma warning (push)
  20. #pragma warning (disable: 4390 4611 4365 4267)
  21. #ifdef __INTEL_COMPILER
  22. #pragma warning (disable: 2544 2545)
  23. #endif
  24. #endif
  25. namespace zlibNamespace
  26. {
  27. #if JUCE_INCLUDE_ZLIB_CODE
  28. #undef OS_CODE
  29. #undef fdopen
  30. #include "../../juce_core/zip/zlib/zlib.h"
  31. #undef OS_CODE
  32. #else
  33. #include JUCE_ZLIB_INCLUDE_PATH
  34. #endif
  35. }
  36. namespace pnglibNamespace
  37. {
  38. using namespace zlibNamespace;
  39. #if JUCE_INCLUDE_PNGLIB_CODE || ! defined (JUCE_INCLUDE_PNGLIB_CODE)
  40. #if _MSC_VER != 1310
  41. using std::calloc; // (causes conflict in VS.NET 2003)
  42. using std::malloc;
  43. using std::free;
  44. #endif
  45. #if JUCE_CLANG
  46. #pragma clang diagnostic push
  47. #pragma clang diagnostic ignored "-Wsign-conversion"
  48. #endif
  49. using std::abs;
  50. #define NO_DUMMY_DECL
  51. #define PNGLCONF_H 1
  52. #if JUCE_ANDROID
  53. #define PNG_ARM_NEON_SUPPORTED
  54. #endif
  55. #define PNG_16BIT_SUPPORTED
  56. #define PNG_ALIGNED_MEMORY_SUPPORTED
  57. #define PNG_BENIGN_ERRORS_SUPPORTED
  58. #define PNG_BENIGN_READ_ERRORS_SUPPORTED
  59. #define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
  60. #define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
  61. #define PNG_COLORSPACE_SUPPORTED
  62. #define PNG_CONSOLE_IO_SUPPORTED
  63. #define PNG_EASY_ACCESS_SUPPORTED
  64. #define PNG_FIXED_POINT_SUPPORTED
  65. #define PNG_FLOATING_ARITHMETIC_SUPPORTED
  66. #define PNG_FLOATING_POINT_SUPPORTED
  67. #define PNG_FORMAT_AFIRST_SUPPORTED
  68. #define PNG_FORMAT_BGR_SUPPORTED
  69. #define PNG_GAMMA_SUPPORTED
  70. #define PNG_GET_PALETTE_MAX_SUPPORTED
  71. #define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  72. #define PNG_INCH_CONVERSIONS_SUPPORTED
  73. #define PNG_INFO_IMAGE_SUPPORTED
  74. #define PNG_IO_STATE_SUPPORTED
  75. #define PNG_MNG_FEATURES_SUPPORTED
  76. #define PNG_POINTER_INDEXING_SUPPORTED
  77. #define PNG_PROGRESSIVE_READ_SUPPORTED
  78. #define PNG_READ_16BIT_SUPPORTED
  79. #define PNG_READ_ALPHA_MODE_SUPPORTED
  80. #define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  81. #define PNG_READ_BACKGROUND_SUPPORTED
  82. #define PNG_READ_BGR_SUPPORTED
  83. #define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED
  84. #define PNG_READ_COMPOSITE_NODIV_SUPPORTED
  85. #define PNG_READ_COMPRESSED_TEXT_SUPPORTED
  86. #define PNG_READ_EXPAND_16_SUPPORTED
  87. #define PNG_READ_EXPAND_SUPPORTED
  88. #define PNG_READ_FILLER_SUPPORTED
  89. #define PNG_READ_GAMMA_SUPPORTED
  90. #define PNG_READ_GET_PALETTE_MAX_SUPPORTED
  91. #define PNG_READ_GRAY_TO_RGB_SUPPORTED
  92. #define PNG_READ_INTERLACING_SUPPORTED
  93. #define PNG_READ_INT_FUNCTIONS_SUPPORTED
  94. #define PNG_READ_INVERT_ALPHA_SUPPORTED
  95. #define PNG_READ_INVERT_SUPPORTED
  96. #define PNG_READ_OPT_PLTE_SUPPORTED
  97. #define PNG_READ_PACKSWAP_SUPPORTED
  98. #define PNG_READ_PACK_SUPPORTED
  99. #define PNG_READ_QUANTIZE_SUPPORTED
  100. #define PNG_READ_RGB_TO_GRAY_SUPPORTED
  101. #define PNG_READ_SCALE_16_TO_8_SUPPORTED
  102. #define PNG_READ_SHIFT_SUPPORTED
  103. #define PNG_READ_STRIP_16_TO_8_SUPPORTED
  104. #define PNG_READ_STRIP_ALPHA_SUPPORTED
  105. #define PNG_READ_SUPPORTED
  106. #define PNG_READ_SWAP_ALPHA_SUPPORTED
  107. #define PNG_READ_SWAP_SUPPORTED
  108. #define PNG_READ_TEXT_SUPPORTED
  109. #define PNG_READ_TRANSFORMS_SUPPORTED
  110. #define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  111. #define PNG_READ_USER_CHUNKS_SUPPORTED
  112. #define PNG_READ_USER_TRANSFORM_SUPPORTED
  113. #define PNG_READ_bKGD_SUPPORTED
  114. #define PNG_READ_cHRM_SUPPORTED
  115. #define PNG_READ_gAMA_SUPPORTED
  116. #define PNG_READ_hIST_SUPPORTED
  117. #define PNG_READ_iCCP_SUPPORTED
  118. #define PNG_READ_iTXt_SUPPORTED
  119. #define PNG_READ_oFFs_SUPPORTED
  120. #define PNG_READ_pCAL_SUPPORTED
  121. #define PNG_READ_pHYs_SUPPORTED
  122. #define PNG_READ_sBIT_SUPPORTED
  123. #define PNG_READ_sCAL_SUPPORTED
  124. #define PNG_READ_sPLT_SUPPORTED
  125. #define PNG_READ_sRGB_SUPPORTED
  126. #define PNG_READ_tEXt_SUPPORTED
  127. #define PNG_READ_tIME_SUPPORTED
  128. #define PNG_READ_tRNS_SUPPORTED
  129. #define PNG_READ_zTXt_SUPPORTED
  130. #define PNG_SAVE_INT_32_SUPPORTED
  131. #define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  132. #define PNG_SEQUENTIAL_READ_SUPPORTED
  133. #define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
  134. #define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
  135. #define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
  136. #define PNG_SET_USER_LIMITS_SUPPORTED
  137. #define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED
  138. #define PNG_SIMPLIFIED_READ_BGR_SUPPORTED
  139. #define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
  140. #define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
  141. #define PNG_STDIO_SUPPORTED
  142. #define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
  143. #define PNG_TEXT_SUPPORTED
  144. #define PNG_TIME_RFC1123_SUPPORTED
  145. #define PNG_UNKNOWN_CHUNKS_SUPPORTED
  146. #define PNG_USER_CHUNKS_SUPPORTED
  147. #define PNG_USER_LIMITS_SUPPORTED
  148. #define PNG_USER_TRANSFORM_INFO_SUPPORTED
  149. #define PNG_USER_TRANSFORM_PTR_SUPPORTED
  150. #define PNG_WARNINGS_SUPPORTED
  151. #define PNG_WRITE_16BIT_SUPPORTED
  152. #define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  153. #define PNG_WRITE_BGR_SUPPORTED
  154. #define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
  155. #define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
  156. #define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
  157. #define PNG_WRITE_FILLER_SUPPORTED
  158. #define PNG_WRITE_FILTER_SUPPORTED
  159. #define PNG_WRITE_FLUSH_SUPPORTED
  160. #define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED
  161. #define PNG_WRITE_INTERLACING_SUPPORTED
  162. #define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
  163. #define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  164. #define PNG_WRITE_INVERT_SUPPORTED
  165. #define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
  166. #define PNG_WRITE_PACKSWAP_SUPPORTED
  167. #define PNG_WRITE_PACK_SUPPORTED
  168. #define PNG_WRITE_SHIFT_SUPPORTED
  169. #define PNG_WRITE_SUPPORTED
  170. #define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  171. #define PNG_WRITE_SWAP_SUPPORTED
  172. #define PNG_WRITE_TEXT_SUPPORTED
  173. #define PNG_WRITE_TRANSFORMS_SUPPORTED
  174. #define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  175. #define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  176. #define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  177. #define PNG_WRITE_bKGD_SUPPORTED
  178. #define PNG_WRITE_cHRM_SUPPORTED
  179. #define PNG_WRITE_gAMA_SUPPORTED
  180. #define PNG_WRITE_hIST_SUPPORTED
  181. #define PNG_WRITE_iCCP_SUPPORTED
  182. #define PNG_WRITE_iTXt_SUPPORTED
  183. #define PNG_WRITE_oFFs_SUPPORTED
  184. #define PNG_WRITE_pCAL_SUPPORTED
  185. #define PNG_WRITE_pHYs_SUPPORTED
  186. #define PNG_WRITE_sBIT_SUPPORTED
  187. #define PNG_WRITE_sCAL_SUPPORTED
  188. #define PNG_WRITE_sPLT_SUPPORTED
  189. #define PNG_WRITE_sRGB_SUPPORTED
  190. #define PNG_WRITE_tEXt_SUPPORTED
  191. #define PNG_WRITE_tIME_SUPPORTED
  192. #define PNG_WRITE_tRNS_SUPPORTED
  193. #define PNG_WRITE_zTXt_SUPPORTED
  194. #define PNG_bKGD_SUPPORTED
  195. #define PNG_cHRM_SUPPORTED
  196. #define PNG_gAMA_SUPPORTED
  197. #define PNG_hIST_SUPPORTED
  198. #define PNG_iCCP_SUPPORTED
  199. #define PNG_iTXt_SUPPORTED
  200. #define PNG_oFFs_SUPPORTED
  201. #define PNG_pCAL_SUPPORTED
  202. #define PNG_pHYs_SUPPORTED
  203. #define PNG_sBIT_SUPPORTED
  204. #define PNG_sCAL_SUPPORTED
  205. #define PNG_sPLT_SUPPORTED
  206. #define PNG_sRGB_SUPPORTED
  207. #define PNG_tEXt_SUPPORTED
  208. #define PNG_tIME_SUPPORTED
  209. #define PNG_tRNS_SUPPORTED
  210. #define PNG_zTXt_SUPPORTED
  211. #define PNG_STRING_COPYRIGHT "";
  212. #define PNG_STRING_NEWLINE "\n"
  213. #define PNG_LITERAL_SHARP 0x23
  214. #define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
  215. #define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
  216. #define PNG_API_RULE 0
  217. #define PNG_CALLOC_SUPPORTED
  218. #define PNG_COST_SHIFT 3
  219. #define PNG_DEFAULT_READ_MACROS 1
  220. #define PNG_GAMMA_THRESHOLD_FIXED 5000
  221. #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE
  222. #define PNG_INFLATE_BUF_SIZE 1024
  223. #define PNG_MAX_GAMMA_8 11
  224. #define PNG_QUANTIZE_BLUE_BITS 5
  225. #define PNG_QUANTIZE_GREEN_BITS 5
  226. #define PNG_QUANTIZE_RED_BITS 5
  227. #define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)
  228. #define PNG_TEXT_Z_DEFAULT_STRATEGY 0
  229. #define PNG_WEIGHT_SHIFT 8
  230. #define PNG_ZBUF_SIZE 8192
  231. #define PNG_Z_DEFAULT_COMPRESSION (-1)
  232. #define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0
  233. #define PNG_Z_DEFAULT_STRATEGY 1
  234. #define PNG_sCAL_PRECISION 5
  235. #define PNG_sRGB_PROFILE_CHECKS 2
  236. #define png_debug(a, b)
  237. #define png_debug1(a, b, c)
  238. #define png_debug2(a, b, c, d)
  239. #include "pnglib/png.h"
  240. #include "pnglib/pngconf.h"
  241. #define PNG_NO_EXTERN
  242. #include "pnglib/png.c"
  243. #include "pnglib/pngerror.c"
  244. #include "pnglib/pngget.c"
  245. #include "pnglib/pngmem.c"
  246. #include "pnglib/pngread.c"
  247. #include "pnglib/pngpread.c"
  248. #include "pnglib/pngrio.c"
  249. #include "pnglib/pngrtran.c"
  250. #include "pnglib/pngrutil.c"
  251. #include "pnglib/pngset.c"
  252. #include "pnglib/pngtrans.c"
  253. #include "pnglib/pngwio.c"
  254. #include "pnglib/pngwrite.c"
  255. #include "pnglib/pngwtran.c"
  256. #include "pnglib/pngwutil.c"
  257. #if JUCE_CLANG
  258. #pragma clang diagnostic pop
  259. #endif
  260. #else
  261. extern "C"
  262. {
  263. #include <png.h>
  264. #include <pngconf.h>
  265. }
  266. #endif
  267. }
  268. #undef max
  269. #undef min
  270. #undef fdopen
  271. #if JUCE_MSVC
  272. #pragma warning (pop)
  273. #endif
  274. //==============================================================================
  275. namespace PNGHelpers
  276. {
  277. using namespace pnglibNamespace;
  278. static void JUCE_CDECL writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  279. {
  280. static_cast<OutputStream*> (png_get_io_ptr (png))->write (data, length);
  281. }
  282. #if ! JUCE_USING_COREIMAGE_LOADER
  283. static void JUCE_CDECL readCallback (png_structp png, png_bytep data, png_size_t length)
  284. {
  285. static_cast<InputStream*> (png_get_io_ptr (png))->read (data, (int) length);
  286. }
  287. struct PNGErrorStruct {};
  288. static void JUCE_CDECL errorCallback (png_structp, png_const_charp)
  289. {
  290. throw PNGErrorStruct();
  291. }
  292. static void JUCE_CDECL warningCallback (png_structp, png_const_charp) {}
  293. #endif
  294. }
  295. //==============================================================================
  296. PNGImageFormat::PNGImageFormat() {}
  297. PNGImageFormat::~PNGImageFormat() {}
  298. String PNGImageFormat::getFormatName() { return "PNG"; }
  299. bool PNGImageFormat::usesFileExtension (const File& f) { return f.hasFileExtension ("png"); }
  300. bool PNGImageFormat::canUnderstand (InputStream& in)
  301. {
  302. const int bytesNeeded = 4;
  303. char header [bytesNeeded];
  304. return in.read (header, bytesNeeded) == bytesNeeded
  305. && header[1] == 'P'
  306. && header[2] == 'N'
  307. && header[3] == 'G';
  308. }
  309. #if JUCE_USING_COREIMAGE_LOADER
  310. Image juce_loadWithCoreImage (InputStream& input);
  311. #endif
  312. Image PNGImageFormat::decodeImage (InputStream& in)
  313. {
  314. #if JUCE_USING_COREIMAGE_LOADER
  315. return juce_loadWithCoreImage (in);
  316. #else
  317. using namespace pnglibNamespace;
  318. Image image;
  319. if (png_structp pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0))
  320. {
  321. try
  322. {
  323. png_infop pngInfoStruct = png_create_info_struct (pngReadStruct);
  324. if (pngInfoStruct == nullptr)
  325. {
  326. png_destroy_read_struct (&pngReadStruct, 0, 0);
  327. return Image::null;
  328. }
  329. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::warningCallback);
  330. // read the header..
  331. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  332. png_uint_32 width, height;
  333. int bitDepth, colorType, interlaceType;
  334. png_read_info (pngReadStruct, pngInfoStruct);
  335. png_get_IHDR (pngReadStruct, pngInfoStruct,
  336. &width, &height,
  337. &bitDepth, &colorType,
  338. &interlaceType, 0, 0);
  339. if (bitDepth == 16)
  340. png_set_strip_16 (pngReadStruct);
  341. if (colorType == PNG_COLOR_TYPE_PALETTE)
  342. png_set_expand (pngReadStruct);
  343. if (bitDepth < 8)
  344. png_set_expand (pngReadStruct);
  345. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  346. png_set_expand (pngReadStruct);
  347. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  348. png_set_gray_to_rgb (pngReadStruct);
  349. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  350. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  351. || pngInfoStruct->num_trans > 0;
  352. // Load the image into a temp buffer in the pnglib format..
  353. const size_t lineStride = width * 4;
  354. HeapBlock <uint8> tempBuffer (height * lineStride);
  355. HeapBlock <png_bytep> rows (height);
  356. for (int y = (int) height; --y >= 0;)
  357. rows[y] = (png_bytep) (tempBuffer + lineStride * y);
  358. try
  359. {
  360. png_read_image (pngReadStruct, rows);
  361. png_read_end (pngReadStruct, pngInfoStruct);
  362. }
  363. catch (PNGHelpers::PNGErrorStruct&)
  364. {}
  365. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  366. // now convert the data to a juce image format..
  367. image = Image (hasAlphaChan ? Image::ARGB : Image::RGB,
  368. (int) width, (int) height, hasAlphaChan);
  369. image.getProperties()->set ("originalImageHadAlpha", image.hasAlphaChannel());
  370. hasAlphaChan = image.hasAlphaChannel(); // (the native image creator may not give back what we expect)
  371. const Image::BitmapData destData (image, Image::BitmapData::writeOnly);
  372. for (int y = 0; y < (int) height; ++y)
  373. {
  374. const uint8* src = rows[y];
  375. uint8* dest = destData.getLinePointer (y);
  376. if (hasAlphaChan)
  377. {
  378. for (int i = (int) width; --i >= 0;)
  379. {
  380. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  381. ((PixelARGB*) dest)->premultiply();
  382. dest += destData.pixelStride;
  383. src += 4;
  384. }
  385. }
  386. else
  387. {
  388. for (int i = (int) width; --i >= 0;)
  389. {
  390. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  391. dest += destData.pixelStride;
  392. src += 4;
  393. }
  394. }
  395. }
  396. }
  397. catch (PNGHelpers::PNGErrorStruct&)
  398. {}
  399. }
  400. return image;
  401. #endif
  402. }
  403. bool PNGImageFormat::writeImageToStream (const Image& image, OutputStream& out)
  404. {
  405. using namespace pnglibNamespace;
  406. const int width = image.getWidth();
  407. const int height = image.getHeight();
  408. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  409. if (pngWriteStruct == nullptr)
  410. return false;
  411. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  412. if (pngInfoStruct == nullptr)
  413. {
  414. png_destroy_write_struct (&pngWriteStruct, (png_infopp) nullptr);
  415. return false;
  416. }
  417. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  418. png_set_IHDR (pngWriteStruct, pngInfoStruct, (png_uint_32) width, (png_uint_32) height, 8,
  419. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  420. : PNG_COLOR_TYPE_RGB,
  421. PNG_INTERLACE_NONE,
  422. PNG_COMPRESSION_TYPE_BASE,
  423. PNG_FILTER_TYPE_BASE);
  424. HeapBlock <uint8> rowData ((size_t) width * 4);
  425. png_color_8 sig_bit;
  426. sig_bit.red = 8;
  427. sig_bit.green = 8;
  428. sig_bit.blue = 8;
  429. sig_bit.alpha = 8;
  430. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  431. png_write_info (pngWriteStruct, pngInfoStruct);
  432. png_set_shift (pngWriteStruct, &sig_bit);
  433. png_set_packing (pngWriteStruct);
  434. const Image::BitmapData srcData (image, Image::BitmapData::readOnly);
  435. for (int y = 0; y < height; ++y)
  436. {
  437. uint8* dst = rowData;
  438. const uint8* src = srcData.getLinePointer (y);
  439. if (image.hasAlphaChannel())
  440. {
  441. for (int i = width; --i >= 0;)
  442. {
  443. PixelARGB p (*(const PixelARGB*) src);
  444. p.unpremultiply();
  445. *dst++ = p.getRed();
  446. *dst++ = p.getGreen();
  447. *dst++ = p.getBlue();
  448. *dst++ = p.getAlpha();
  449. src += srcData.pixelStride;
  450. }
  451. }
  452. else
  453. {
  454. for (int i = width; --i >= 0;)
  455. {
  456. *dst++ = ((const PixelRGB*) src)->getRed();
  457. *dst++ = ((const PixelRGB*) src)->getGreen();
  458. *dst++ = ((const PixelRGB*) src)->getBlue();
  459. src += srcData.pixelStride;
  460. }
  461. }
  462. png_bytep rowPtr = rowData;
  463. png_write_rows (pngWriteStruct, &rowPtr, 1);
  464. }
  465. png_write_end (pngWriteStruct, pngInfoStruct);
  466. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  467. return true;
  468. }