pngmem.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. /* pngmem.c - stub functions for memory allocation
  2. *
  3. * Last changed in libpng 1.5.7 [December 15, 2011]
  4. * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  5. * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  6. * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  7. *
  8. * This code is released under the libpng license.
  9. * For conditions of distribution and use, see the disclaimer
  10. * and license in png.h
  11. *
  12. * This file provides a location for all memory allocation. Users who
  13. * need special memory handling are expected to supply replacement
  14. * functions for png_malloc() and png_free(), and to use
  15. * png_create_read_struct_2() and png_create_write_struct_2() to
  16. * identify the replacement functions.
  17. */
  18. #include "pngpriv.h"
  19. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  20. /* Borland DOS special memory handler */
  21. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  22. /* If you change this, be sure to change the one in png.h also */
  23. /* Allocate memory for a png_struct. The malloc and memset can be replaced
  24. by a single call to calloc() if this is thought to improve performance. */
  25. PNG_FUNCTION(png_voidp /* PRIVATE */,
  26. png_create_struct,(int type),PNG_ALLOCATED)
  27. {
  28. # ifdef PNG_USER_MEM_SUPPORTED
  29. return (png_create_struct_2(type, NULL, NULL));
  30. }
  31. /* Alternate version of png_create_struct, for use with user-defined malloc. */
  32. PNG_FUNCTION(png_voidp /* PRIVATE */,
  33. png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
  34. PNG_ALLOCATED)
  35. {
  36. # endif /* PNG_USER_MEM_SUPPORTED */
  37. png_size_t size;
  38. png_voidp struct_ptr;
  39. if (type == PNG_STRUCT_INFO)
  40. size = png_sizeof(png_info);
  41. else if (type == PNG_STRUCT_PNG)
  42. size = png_sizeof(png_struct);
  43. else
  44. return (png_get_copyright(NULL));
  45. # ifdef PNG_USER_MEM_SUPPORTED
  46. if (malloc_fn != NULL)
  47. {
  48. png_struct dummy_struct;
  49. memset(&dummy_struct, 0, sizeof dummy_struct);
  50. dummy_struct.mem_ptr=mem_ptr;
  51. struct_ptr = (*(malloc_fn))(&dummy_struct, (png_alloc_size_t)size);
  52. }
  53. else
  54. # endif /* PNG_USER_MEM_SUPPORTED */
  55. struct_ptr = (png_voidp)farmalloc(size);
  56. if (struct_ptr != NULL)
  57. png_memset(struct_ptr, 0, size);
  58. return (struct_ptr);
  59. }
  60. /* Free memory allocated by a png_create_struct() call */
  61. void /* PRIVATE */
  62. png_destroy_struct(png_voidp struct_ptr)
  63. {
  64. # ifdef PNG_USER_MEM_SUPPORTED
  65. png_destroy_struct_2(struct_ptr, NULL, NULL);
  66. }
  67. /* Free memory allocated by a png_create_struct() call */
  68. void /* PRIVATE */
  69. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  70. png_voidp mem_ptr)
  71. {
  72. # endif
  73. if (struct_ptr != NULL)
  74. {
  75. # ifdef PNG_USER_MEM_SUPPORTED
  76. if (free_fn != NULL)
  77. {
  78. png_struct dummy_struct;
  79. memset(&dummy_struct, 0, sizeof dummy_struct);
  80. dummy_struct.mem_ptr=mem_ptr;
  81. (*(free_fn))(&dummy_struct, struct_ptr);
  82. return;
  83. }
  84. # endif /* PNG_USER_MEM_SUPPORTED */
  85. farfree (struct_ptr);
  86. }
  87. }
  88. /* Allocate memory. For reasonable files, size should never exceed
  89. * 64K. However, zlib may allocate more then 64K if you don't tell
  90. * it not to. See zconf.h and png.h for more information. zlib does
  91. * need to allocate exactly 64K, so whatever you call here must
  92. * have the ability to do that.
  93. *
  94. * Borland seems to have a problem in DOS mode for exactly 64K.
  95. * It gives you a segment with an offset of 8 (perhaps to store its
  96. * memory stuff). zlib doesn't like this at all, so we have to
  97. * detect and deal with it. This code should not be needed in
  98. * Windows or OS/2 modes, and only in 16 bit mode. This code has
  99. * been updated by Alexander Lehmann for version 0.89 to waste less
  100. * memory.
  101. *
  102. * Note that we can't use png_size_t for the "size" declaration,
  103. * since on some systems a png_size_t is a 16-bit quantity, and as a
  104. * result, we would be truncating potentially larger memory requests
  105. * (which should cause a fatal error) and introducing major problems.
  106. */
  107. PNG_FUNCTION(png_voidp,PNGAPI
  108. png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  109. {
  110. png_voidp ret;
  111. ret = (png_malloc(png_ptr, size));
  112. if (ret != NULL)
  113. png_memset(ret,0,(png_size_t)size);
  114. return (ret);
  115. }
  116. PNG_FUNCTION(png_voidp,PNGAPI
  117. png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  118. {
  119. png_voidp ret;
  120. if (png_ptr == NULL || size == 0)
  121. return (NULL);
  122. # ifdef PNG_USER_MEM_SUPPORTED
  123. if (png_ptr->malloc_fn != NULL)
  124. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
  125. else
  126. ret = (png_malloc_default(png_ptr, size));
  127. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  128. png_error(png_ptr, "Out of memory");
  129. return (ret);
  130. }
  131. PNG_FUNCTION(png_voidp,PNGAPI
  132. png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  133. {
  134. png_voidp ret;
  135. # endif /* PNG_USER_MEM_SUPPORTED */
  136. if (png_ptr == NULL || size == 0)
  137. return (NULL);
  138. # ifdef PNG_MAX_MALLOC_64K
  139. if (size > (png_uint_32)65536L)
  140. {
  141. png_warning(png_ptr, "Cannot Allocate > 64K");
  142. ret = NULL;
  143. }
  144. else
  145. # endif
  146. if (size != (size_t)size)
  147. ret = NULL;
  148. else if (size == (png_uint_32)65536L)
  149. {
  150. if (png_ptr->offset_table == NULL)
  151. {
  152. /* Try to see if we need to do any of this fancy stuff */
  153. ret = farmalloc(size);
  154. if (ret == NULL || ((png_size_t)ret & 0xffff))
  155. {
  156. int num_blocks;
  157. png_uint_32 total_size;
  158. png_bytep table;
  159. int i, mem_level, window_bits;
  160. png_byte huge * hptr;
  161. int window_bits
  162. if (ret != NULL)
  163. {
  164. farfree(ret);
  165. ret = NULL;
  166. }
  167. window_bits =
  168. png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ?
  169. png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits;
  170. if (window_bits > 14)
  171. num_blocks = (int)(1 << (window_bits - 14));
  172. else
  173. num_blocks = 1;
  174. mem_level =
  175. png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ?
  176. png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level;
  177. if (mem_level >= 7)
  178. num_blocks += (int)(1 << (mem_level - 7));
  179. else
  180. num_blocks++;
  181. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  182. table = farmalloc(total_size);
  183. if (table == NULL)
  184. {
  185. # ifndef PNG_USER_MEM_SUPPORTED
  186. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  187. png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */
  188. else
  189. png_warning(png_ptr, "Out Of Memory");
  190. # endif
  191. return (NULL);
  192. }
  193. if ((png_size_t)table & 0xfff0)
  194. {
  195. # ifndef PNG_USER_MEM_SUPPORTED
  196. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  197. png_error(png_ptr,
  198. "Farmalloc didn't return normalized pointer");
  199. else
  200. png_warning(png_ptr,
  201. "Farmalloc didn't return normalized pointer");
  202. # endif
  203. return (NULL);
  204. }
  205. png_ptr->offset_table = table;
  206. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  207. png_sizeof(png_bytep));
  208. if (png_ptr->offset_table_ptr == NULL)
  209. {
  210. # ifndef PNG_USER_MEM_SUPPORTED
  211. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  212. png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */
  213. else
  214. png_warning(png_ptr, "Out Of memory");
  215. # endif
  216. return (NULL);
  217. }
  218. hptr = (png_byte huge *)table;
  219. if ((png_size_t)hptr & 0xf)
  220. {
  221. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  222. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  223. }
  224. for (i = 0; i < num_blocks; i++)
  225. {
  226. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  227. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  228. }
  229. png_ptr->offset_table_number = num_blocks;
  230. png_ptr->offset_table_count = 0;
  231. png_ptr->offset_table_count_free = 0;
  232. }
  233. }
  234. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  235. {
  236. # ifndef PNG_USER_MEM_SUPPORTED
  237. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  238. png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */
  239. else
  240. png_warning(png_ptr, "Out of Memory");
  241. # endif
  242. return (NULL);
  243. }
  244. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  245. }
  246. else
  247. ret = farmalloc(size);
  248. # ifndef PNG_USER_MEM_SUPPORTED
  249. if (ret == NULL)
  250. {
  251. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  252. png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
  253. else
  254. png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
  255. }
  256. # endif
  257. return (ret);
  258. }
  259. /* Free a pointer allocated by png_malloc(). In the default
  260. * configuration, png_ptr is not used, but is passed in case it
  261. * is needed. If ptr is NULL, return without taking any action.
  262. */
  263. void PNGAPI
  264. png_free(png_structp png_ptr, png_voidp ptr)
  265. {
  266. if (png_ptr == NULL || ptr == NULL)
  267. return;
  268. # ifdef PNG_USER_MEM_SUPPORTED
  269. if (png_ptr->free_fn != NULL)
  270. {
  271. (*(png_ptr->free_fn))(png_ptr, ptr);
  272. return;
  273. }
  274. else
  275. png_free_default(png_ptr, ptr);
  276. }
  277. void PNGAPI
  278. png_free_default(png_structp png_ptr, png_voidp ptr)
  279. {
  280. # endif /* PNG_USER_MEM_SUPPORTED */
  281. if (png_ptr == NULL || ptr == NULL)
  282. return;
  283. if (png_ptr->offset_table != NULL)
  284. {
  285. int i;
  286. for (i = 0; i < png_ptr->offset_table_count; i++)
  287. {
  288. if (ptr == png_ptr->offset_table_ptr[i])
  289. {
  290. ptr = NULL;
  291. png_ptr->offset_table_count_free++;
  292. break;
  293. }
  294. }
  295. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  296. {
  297. farfree(png_ptr->offset_table);
  298. farfree(png_ptr->offset_table_ptr);
  299. png_ptr->offset_table = NULL;
  300. png_ptr->offset_table_ptr = NULL;
  301. }
  302. }
  303. if (ptr != NULL)
  304. farfree(ptr);
  305. }
  306. #else /* Not the Borland DOS special memory handler */
  307. /* Allocate memory for a png_struct or a png_info. The malloc and
  308. memset can be replaced by a single call to calloc() if this is thought
  309. to improve performance noticably. */
  310. PNG_FUNCTION(png_voidp /* PRIVATE */,
  311. png_create_struct,(int type),PNG_ALLOCATED)
  312. {
  313. # ifdef PNG_USER_MEM_SUPPORTED
  314. return (png_create_struct_2(type, NULL, NULL));
  315. }
  316. /* Allocate memory for a png_struct or a png_info. The malloc and
  317. memset can be replaced by a single call to calloc() if this is thought
  318. to improve performance noticably. */
  319. PNG_FUNCTION(png_voidp /* PRIVATE */,
  320. png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
  321. PNG_ALLOCATED)
  322. {
  323. # endif /* PNG_USER_MEM_SUPPORTED */
  324. png_size_t size;
  325. png_voidp struct_ptr;
  326. if (type == PNG_STRUCT_INFO)
  327. size = png_sizeof(png_info);
  328. else if (type == PNG_STRUCT_PNG)
  329. size = png_sizeof(png_struct);
  330. else
  331. return (NULL);
  332. # ifdef PNG_USER_MEM_SUPPORTED
  333. if (malloc_fn != NULL)
  334. {
  335. png_struct dummy_struct;
  336. png_structp png_ptr = &dummy_struct;
  337. png_ptr->mem_ptr=mem_ptr;
  338. struct_ptr = (*(malloc_fn))(png_ptr, size);
  339. if (struct_ptr != NULL)
  340. png_memset(struct_ptr, 0, size);
  341. return (struct_ptr);
  342. }
  343. # endif /* PNG_USER_MEM_SUPPORTED */
  344. # if defined(__TURBOC__) && !defined(__FLAT__)
  345. struct_ptr = (png_voidp)farmalloc(size);
  346. # else
  347. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  348. struct_ptr = (png_voidp)halloc(size, 1);
  349. # else
  350. struct_ptr = (png_voidp)malloc(size);
  351. # endif
  352. # endif
  353. if (struct_ptr != NULL)
  354. png_memset(struct_ptr, 0, size);
  355. return (struct_ptr);
  356. }
  357. /* Free memory allocated by a png_create_struct() call */
  358. void /* PRIVATE */
  359. png_destroy_struct(png_voidp struct_ptr)
  360. {
  361. # ifdef PNG_USER_MEM_SUPPORTED
  362. png_destroy_struct_2(struct_ptr, NULL, NULL);
  363. }
  364. /* Free memory allocated by a png_create_struct() call */
  365. void /* PRIVATE */
  366. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  367. png_voidp mem_ptr)
  368. {
  369. # endif /* PNG_USER_MEM_SUPPORTED */
  370. if (struct_ptr != NULL)
  371. {
  372. # ifdef PNG_USER_MEM_SUPPORTED
  373. if (free_fn != NULL)
  374. {
  375. png_struct dummy_struct;
  376. png_structp png_ptr = &dummy_struct;
  377. png_ptr->mem_ptr=mem_ptr;
  378. (*(free_fn))(png_ptr, struct_ptr);
  379. return;
  380. }
  381. # endif /* PNG_USER_MEM_SUPPORTED */
  382. # if defined(__TURBOC__) && !defined(__FLAT__)
  383. farfree(struct_ptr);
  384. # else
  385. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  386. hfree(struct_ptr);
  387. # else
  388. free(struct_ptr);
  389. # endif
  390. # endif
  391. }
  392. }
  393. /* Allocate memory. For reasonable files, size should never exceed
  394. * 64K. However, zlib may allocate more then 64K if you don't tell
  395. * it not to. See zconf.h and png.h for more information. zlib does
  396. * need to allocate exactly 64K, so whatever you call here must
  397. * have the ability to do that.
  398. */
  399. PNG_FUNCTION(png_voidp,PNGAPI
  400. png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  401. {
  402. png_voidp ret;
  403. ret = (png_malloc(png_ptr, size));
  404. if (ret != NULL)
  405. png_memset(ret,0,(png_size_t)size);
  406. return (ret);
  407. }
  408. PNG_FUNCTION(png_voidp,PNGAPI
  409. png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  410. {
  411. png_voidp ret;
  412. # ifdef PNG_USER_MEM_SUPPORTED
  413. if (png_ptr == NULL || size == 0)
  414. return (NULL);
  415. if (png_ptr->malloc_fn != NULL)
  416. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  417. else
  418. ret = (png_malloc_default(png_ptr, size));
  419. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  420. png_error(png_ptr, "Out of Memory");
  421. return (ret);
  422. }
  423. PNG_FUNCTION(png_voidp,PNGAPI
  424. png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  425. {
  426. png_voidp ret;
  427. # endif /* PNG_USER_MEM_SUPPORTED */
  428. if (png_ptr == NULL || size == 0)
  429. return (NULL);
  430. # ifdef PNG_MAX_MALLOC_64K
  431. if (size > (png_uint_32)65536L)
  432. {
  433. # ifndef PNG_USER_MEM_SUPPORTED
  434. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  435. png_error(png_ptr, "Cannot Allocate > 64K");
  436. else
  437. # endif
  438. return NULL;
  439. }
  440. # endif
  441. /* Check for overflow */
  442. # if defined(__TURBOC__) && !defined(__FLAT__)
  443. if (size != (unsigned long)size)
  444. ret = NULL;
  445. else
  446. ret = farmalloc(size);
  447. # else
  448. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  449. if (size != (unsigned long)size)
  450. ret = NULL;
  451. else
  452. ret = halloc(size, 1);
  453. # else
  454. if (size != (size_t)size)
  455. ret = NULL;
  456. else
  457. ret = malloc((size_t)size);
  458. # endif
  459. # endif
  460. # ifndef PNG_USER_MEM_SUPPORTED
  461. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  462. png_error(png_ptr, "Out of Memory");
  463. # endif
  464. return (ret);
  465. }
  466. /* Free a pointer allocated by png_malloc(). If ptr is NULL, return
  467. * without taking any action.
  468. */
  469. void PNGAPI
  470. png_free(png_structp png_ptr, png_voidp ptr)
  471. {
  472. if (png_ptr == NULL || ptr == NULL)
  473. return;
  474. # ifdef PNG_USER_MEM_SUPPORTED
  475. if (png_ptr->free_fn != NULL)
  476. {
  477. (*(png_ptr->free_fn))(png_ptr, ptr);
  478. return;
  479. }
  480. else
  481. png_free_default(png_ptr, ptr);
  482. }
  483. void PNGAPI
  484. png_free_default(png_structp png_ptr, png_voidp ptr)
  485. {
  486. if (png_ptr == NULL || ptr == NULL)
  487. return;
  488. # endif /* PNG_USER_MEM_SUPPORTED */
  489. # if defined(__TURBOC__) && !defined(__FLAT__)
  490. farfree(ptr);
  491. # else
  492. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  493. hfree(ptr);
  494. # else
  495. free(ptr);
  496. # endif
  497. # endif
  498. }
  499. #endif /* Not Borland DOS special memory handler */
  500. /* This function was added at libpng version 1.2.3. The png_malloc_warn()
  501. * function will set up png_malloc() to issue a png_warning and return NULL
  502. * instead of issuing a png_error, if it fails to allocate the requested
  503. * memory.
  504. */
  505. PNG_FUNCTION(png_voidp,PNGAPI
  506. png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
  507. {
  508. png_voidp ptr;
  509. png_uint_32 save_flags;
  510. if (png_ptr == NULL)
  511. return (NULL);
  512. save_flags = png_ptr->flags;
  513. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  514. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  515. png_ptr->flags=save_flags;
  516. return(ptr);
  517. }
  518. #ifdef PNG_USER_MEM_SUPPORTED
  519. /* This function is called when the application wants to use another method
  520. * of allocating and freeing memory.
  521. */
  522. void PNGAPI
  523. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  524. malloc_fn, png_free_ptr free_fn)
  525. {
  526. if (png_ptr != NULL)
  527. {
  528. png_ptr->mem_ptr = mem_ptr;
  529. png_ptr->malloc_fn = malloc_fn;
  530. png_ptr->free_fn = free_fn;
  531. }
  532. }
  533. /* This function returns a pointer to the mem_ptr associated with the user
  534. * functions. The application should free any memory associated with this
  535. * pointer before png_write_destroy and png_read_destroy are called.
  536. */
  537. png_voidp PNGAPI
  538. png_get_mem_ptr(png_const_structp png_ptr)
  539. {
  540. if (png_ptr == NULL)
  541. return (NULL);
  542. return ((png_voidp)png_ptr->mem_ptr);
  543. }
  544. #endif /* PNG_USER_MEM_SUPPORTED */
  545. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */