Subversion Repositories Kolibri OS

Rev

Rev 6779 | Rev 6881 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. ; png.inc - header file for PNG reference library
  3.  
  4. ; libpng version 1.6.25, September 1, 2016
  5.  
  6. ; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  7. ; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  8. ; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  9.  
  10. ; This code is released under the libpng license (See LICENSE, below)
  11.  
  12. ; Authors and maintainers:
  13. ;   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  14. ;   libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
  15. ;   libpng versions 0.97, January 1998, through 1.6.25, September 1, 2016:
  16. ;     Glenn Randers-Pehrson.
  17. ;   See also "Contributing Authors", below.
  18.  
  19.  
  20.  
  21. ; COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
  22.  
  23. ; If you modify libpng you may insert additional notices immediately following
  24. ; this sentence.
  25.  
  26. ; This code is released under the libpng license.
  27.  
  28. ; Some files in the "contrib" directory and some configure-generated
  29. ; files that are distributed with libpng have other copyright owners and
  30. ; are released under other open source licenses.
  31.  
  32. ; libpng versions 1.0.7, July 1, 2000 through 1.6.25, September 1, 2016 are
  33. ; Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are
  34. ; derived from libpng-1.0.6, and are distributed according to the same
  35. ; disclaimer and license as libpng-1.0.6 with the following individuals
  36. ; added to the list of Contributing Authors:
  37.  
  38. ;    Simon-Pierre Cadieux
  39. ;    Eric S. Raymond
  40. ;    Mans Rullgard
  41. ;    Cosmin Truta
  42. ;    Gilles Vollant
  43. ;    James Yu
  44. ;    Mandar Sahastrabuddhe
  45.  
  46. ; and with the following additions to the disclaimer:
  47.  
  48. ;    There is no warranty against interference with your enjoyment of the
  49. ;    library or against infringement.  There is no warranty that our
  50. ;    efforts or the library will fulfill any of your particular purposes
  51. ;    or needs.  This library is provided with all faults, and the entire
  52. ;    risk of satisfactory quality, performance, accuracy, and effort is with
  53. ;    the user.
  54.  
  55. ; Some files in the "contrib" directory have other copyright owners and
  56. ; are released under other open source licenses.
  57.  
  58.  
  59. ; libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
  60. ; Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
  61. ; libpng-0.96, and are distributed according to the same disclaimer and
  62. ; license as libpng-0.96, with the following individuals added to the list
  63. ; of Contributing Authors:
  64.  
  65. ;    Tom Lane
  66. ;    Glenn Randers-Pehrson
  67. ;    Willem van Schaik
  68.  
  69. ; Some files in the "scripts" directory have different copyright owners
  70. ; but are also released under this license.
  71.  
  72. ; libpng versions 0.89, June 1996, through 0.96, May 1997, are
  73. ; Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
  74. ; and are distributed according to the same disclaimer and license as
  75. ; libpng-0.88, with the following individuals added to the list of
  76. ; Contributing Authors:
  77.  
  78. ;    John Bowler
  79. ;    Kevin Bracey
  80. ;    Sam Bushell
  81. ;    Magnus Holmgren
  82. ;    Greg Roelofs
  83. ;    Tom Tanner
  84.  
  85. ; Some files in the "scripts" directory have other copyright owners
  86. ; but are released under this license.
  87.  
  88. ; libpng versions 0.5, May 1995, through 0.88, January 1996, are
  89. ; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
  90.  
  91. ; For the purposes of this copyright and license, "Contributing Authors"
  92. ; is defined as the following set of individuals:
  93.  
  94. ;    Andreas Dilger
  95. ;    Dave Martindale
  96. ;    Guy Eric Schalnat
  97. ;    Paul Schmidt
  98. ;    Tim Wegner
  99.  
  100. ; The PNG Reference Library is supplied "AS IS".  The Contributing Authors
  101. ; and Group 42, Inc. disclaim all warranties, expressed or implied,
  102. ; including, without limitation, the warranties of merchantability and of
  103. ; fitness for any purpose.  The Contributing Authors and Group 42, Inc.
  104. ; assume no liability for direct, indirect, incidental, special, exemplary,
  105. ; or consequential damages, which may result from the use of the PNG
  106. ; Reference Library, even if advised of the possibility of such damage.
  107.  
  108. ; Permission is hereby granted to use, copy, modify, and distribute this
  109. ; source code, or portions hereof, for any purpose, without fee, subject
  110. ; to the following restrictions:
  111.  
  112. ;   1. The origin of this source code must not be misrepresented.
  113.  
  114. ;   2. Altered versions must be plainly marked as such and must not
  115. ;      be misrepresented as being the original source.
  116.  
  117. ;   3. This Copyright notice may not be removed or altered from any
  118. ;      source or altered source distribution.
  119.  
  120. ; The Contributing Authors and Group 42, Inc. specifically permit, without
  121. ; fee, and encourage the use of this source code as a component to
  122. ; supporting the PNG file format in commercial products.  If you use this
  123. ; source code in a product, acknowledgment is not required but would be
  124. ; appreciated.
  125.  
  126. ; END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
  127.  
  128. ; TRADEMARK:
  129.  
  130. ; The name "libpng" has not been registered by the Copyright owner
  131. ; as a trademark in any jurisdiction.  However, because libpng has
  132. ; been distributed and maintained world-wide, continually since 1995,
  133. ; the Copyright owner claims "common-law trademark protection" in any
  134. ; jurisdiction where common-law trademark is recognized.
  135.  
  136. ; OSI CERTIFICATION:
  137.  
  138. ; Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is
  139. ; a certification mark of the Open Source Initiative. OSI has not addressed
  140. ; the additional disclaimers inserted at version 1.0.7.
  141.  
  142. ; EXPORT CONTROL:
  143.  
  144. ; The Copyright owner believes that the Export Control Classification
  145. ; Number (ECCN) for libpng is EAR99, which means not subject to export
  146. ; controls or International Traffic in Arms Regulations (ITAR) because
  147. ; it is open source, publicly available software, that does not contain
  148. ; any encryption software.  See the EAR, paragraphs 734.3(b)(3) and
  149. ; 734.7(b).
  150.  
  151.  
  152.  
  153. ; A "png_get_copyright" function is available, for convenient use in "about"
  154. ; boxes and the like:
  155.  
  156. ;    printf("%s", png_get_copyright(NULL));
  157.  
  158. ; Also, the PNG logo (in PNG format, of course) is supplied in the
  159. ; files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
  160.  
  161.  
  162.  
  163. ; The contributing authors would like to thank all those who helped
  164. ; with testing, bug fixes, and patience.  This wouldn't have been
  165. ; possible without all of you.
  166.  
  167. ; Thanks to Frank J. T. Wojcik for helping with the documentation.
  168.  
  169. ;
  170. ; Note about libpng version numbers:
  171. ;
  172. ;    Due to various miscommunications, unforeseen code incompatibilities
  173. ;    and occasional factors outside the authors' control, version numbering
  174. ;    on the library has not always been consistent and straightforward.
  175. ;    The following table summarizes matters since version 0.89c, which was
  176. ;    the first widely used release:
  177. ;
  178. ;    source                 png.h  png.h  shared-lib
  179. ;    version                string   int  version
  180. ;    -------                ------ -----  ----------
  181. ;    ...
  182. ;    1.2.56                  13    10256  12.so.0.56[.0]
  183. ;    ...
  184. ;    1.5.27                  15    10527  15.so.15.27[.0]
  185. ;    ...
  186. ;    1.6.25                  16    10625  16.so.16.25[.0]
  187.  
  188. ;    Henceforth the source version will match the shared-library major
  189. ;    and minor numbers; the shared-library major version number will be
  190. ;    used for changes in backward compatibility, as it is intended.  The
  191. ;    PNG_LIBPNG_VER macro, which is not used within libpng but is available
  192. ;    for applications, is an unsigned integer of the form xyyzz corresponding
  193. ;    to the source version x.y.z (leading zeros in y and z).  Beta versions
  194. ;    were given the previous public release number plus a letter, until
  195. ;    version 1.0.6j; from then on they were given the upcoming public
  196. ;    release number plus "betaNN" or "rcNN".
  197.  
  198. ;    Binary incompatibility exists only when applications make direct access
  199. ;    to the info_ptr or png_ptr members through png.h, and the compiled
  200. ;    application is loaded with a different version of the library.
  201.  
  202. ;    DLLNUM will change each time there are forward or backward changes
  203. ;    in binary compatibility (e.g., when a new feature is added).
  204.  
  205. ; See libpng.txt or libpng.3 for more information.  The PNG specification
  206. ; is available as a W3C Recommendation and as an ISO Specification,
  207. ; <http://www.w3.org/TR/2003/REC-PNG-20031110/
  208.  
  209.  
  210.  
  211. ; Y2K compliance in libpng:
  212. ; =========================
  213.  
  214. ;    September 1, 2016
  215.  
  216. ;    Since the PNG Development group is an ad-hoc body, we can't make
  217. ;    an official declaration.
  218.  
  219. ;    This is your unofficial assurance that libpng from version 0.71 and
  220. ;    upward through 1.6.25 are Y2K compliant.  It is my belief that
  221. ;    earlier versions were also Y2K compliant.
  222.  
  223. ;    Libpng only has two year fields.  One is a 2-byte unsigned integer
  224. ;    that will hold years up to 65535.  The other, which is deprecated,
  225. ;    holds the date in text format, and will hold years up to 9999.
  226.  
  227. ;    The integer is
  228. ;        "uint_16 year" in png_time_struct.
  229.  
  230. ;    The string is
  231. ;        "char time_buffer[29]" in png_struct.  This is no longer used
  232. ;    in libpng-1.6.x and will be removed from libpng-1.7.0.
  233.  
  234. ;    There are seven time-related functions:
  235. ;        png.asm: png_convert_to_rfc_1123_buffer() in png.asm
  236. ;          (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and
  237. ;          png_convert_to_rfc_1152() in error prior to libpng-0.98)
  238. ;        png_convert_from_struct_tm() in pngwrite.asm, called in pngwrite.asm
  239. ;        png_convert_from_time_t() in pngwrite.asm
  240. ;        png_get_tIME() in pngget.asm
  241. ;        png_handle_tIME() in pngrutil.asm, called in pngread.asm
  242. ;        png_set_tIME() in pngset.asm
  243. ;        png_write_tIME() in pngwutil.asm, called in pngwrite.asm
  244.  
  245. ;    All handle dates properly in a Y2K environment.  The
  246. ;    png_convert_from_time_t() function calls gmtime() to convert from system
  247. ;    clock time, which returns (year - 1900), which we properly convert to
  248. ;    the full 4-digit year.  There is a possibility that libpng applications
  249. ;    are not passing 4-digit years into the png_convert_to_rfc_1123_buffer()
  250. ;    function, or that they are incorrectly passing only a 2-digit year
  251. ;    instead of "year - 1900" into the png_convert_from_struct_tm() function,
  252. ;    but this is not under our control.  The libpng documentation has always
  253. ;    stated that it works with 4-digit years, and the APIs have been
  254. ;    documented as such.
  255.  
  256. ;    The tIME chunk itself is also Y2K compliant.  It uses a 2-byte unsigned
  257. ;    integer to hold the year, and can hold years as large as 65535.
  258.  
  259. ;    zlib, upon which libpng depends, is also Y2K compliant.  It contains
  260. ;    no date-related code.
  261.  
  262. ;       Glenn Randers-Pehrson
  263. ;       libpng maintainer
  264. ;       PNG Development Group
  265.  
  266.  
  267. ; This is not the place to learn how to use libpng. The file libpng-manual.txt
  268. ; describes how to use libpng, and the file example.c summarizes it
  269. ; with some code on which to build.  This file is useful for looking
  270. ; at the actual function definitions and structure components.  If that
  271. ; file has been stripped from your copy of libpng, you can find it at
  272. ; <http://www.libpng.org/pub/png/libpng-manual.txt>
  273.  
  274. ; If you just need to read a PNG file and don't want to read the documentation
  275. ; skip to the end of this file and read the section entitled 'simplified API'.
  276.  
  277.  
  278. ; Version information for png.h - this should match the version in png.asm
  279. PNG_LIBPNG_VER_STRING db '1.6.25',0
  280. PNG_HEADER_VERSION_STRING db ' libpng version 1.6.25 - September 1, 2016',13,10,0
  281.  
  282. PNG_LIBPNG_VER_SONUM  equ 16
  283. PNG_LIBPNG_VER_DLLNUM equ 16
  284.  
  285. ; These should match the first 3 components of PNG_LIBPNG_VER_STRING:
  286. PNG_LIBPNG_VER_MAJOR  equ 1
  287. PNG_LIBPNG_VER_MINOR  equ 6
  288. PNG_LIBPNG_VER_RELEASE equ 25
  289.  
  290. ; This should match the numeric part of the final component of
  291. ; PNG_LIBPNG_VER_STRING, omitting any leading zero:
  292.  
  293.  
  294. PNG_LIBPNG_VER_BUILD equ 0
  295.  
  296. ; Release Status
  297. PNG_LIBPNG_BUILD_ALPHA   equ 1
  298. PNG_LIBPNG_BUILD_BETA    equ 2
  299. PNG_LIBPNG_BUILD_RC      equ 3
  300. PNG_LIBPNG_BUILD_STABLE  equ 4
  301. PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK equ 7
  302.  
  303. ; Release-Specific Flags
  304. PNG_LIBPNG_BUILD_PATCH   equ  8 ;Can be OR'ed with PNG_LIBPNG_BUILD_STABLE only
  305. PNG_LIBPNG_BUILD_PRIVATE equ 16 ;Cannot be OR'ed with PNG_LIBPNG_BUILD_SPECIAL
  306. PNG_LIBPNG_BUILD_SPECIAL equ 32 ;Cannot be OR'ed with PNG_LIBPNG_BUILD_PRIVATE
  307.  
  308. PNG_LIBPNG_BUILD_BASE_TYPE equ PNG_LIBPNG_BUILD_STABLE
  309.  
  310. ; Careful here.  At one time, Guy wanted to use 082, but that would be octal.
  311. ; We must not include leading zeros.
  312. ; Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
  313. ; version 1.0.0 was mis-numbered 100 instead of 10000).  From
  314. ; version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release
  315.  
  316. PNG_LIBPNG_VER equ 10625 ;1.6.25
  317.  
  318. ; Library configuration: these options cannot be changed after
  319. ; the library has been built.
  320.  
  321.  
  322. ; Added at libpng-1.2.8
  323.  
  324. ; Ref MSDN: Private as priority over Special
  325. ; VS_FF_PRIVATEBUILD File *was not* built using standard release
  326. ; procedures. If this value is given, the StringFileInfo block must
  327. ; contain a PrivateBuild string.
  328.  
  329. ; VS_FF_SPECIALBUILD File *was* built by the original company using
  330. ; standard release procedures but is a variation of the standard
  331. ; file of the same version number. If this value is given, the
  332. ; StringFileInfo block must contain a SpecialBuild string.
  333.  
  334. ;if PNG_USER_PRIVATEBUILD /* From pnglibconf.h */
  335. ;#  define PNG_LIBPNG_BUILD_TYPE \
  336. ;       (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  337. ;#else
  338. ;#  ifdef PNG_LIBPNG_SPECIALBUILD
  339. ;#    define PNG_LIBPNG_BUILD_TYPE \
  340. ;         (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  341. ;#  else
  342. ;#    define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  343. ;#  endif
  344. ;end if
  345.  
  346. ;#ifndef PNG_VERSION_INFO_ONLY
  347.  
  348. ; Version information for C files, stored in png.asm.  This had better match
  349. ; the version above.
  350.  
  351. ;#define png_libpng_ver png_get_header_ver(NULL)
  352.  
  353. ; This file is arranged in several sections:
  354.  
  355. ; 1. [omitted]
  356. ; 2. Any configuration options that can be specified by for the application
  357. ;    code when it is built.  (Build time configuration is in pnglibconf.h)
  358. ; 3. Type definitions (base types are defined in pngconf.h), structure
  359. ;    definitions.
  360. ; 4. Exported library functions.
  361. ; 5. Simplified API.
  362. ; 6. Implementation options.
  363.  
  364. ; The library source code has additional files (principally pngpriv.h) that
  365. ; allow configuration of the library.
  366.  
  367.  
  368. ; Section 1: [omitted]
  369.  
  370. ; Section 2: run time configuration
  371. ; See pnglibconf.h for build time configuration
  372.  
  373. ; Run time configuration allows the application to choose between
  374. ; implementations of certain arithmetic APIs.  The default is set
  375. ; at build time and recorded in pnglibconf.h, but it is safe to
  376. ; override these (and only these) settings.  Note that this won't
  377. ; change what the library does, only application code, and the
  378. ; settings can (and probably should) be made on a per-file basis
  379. ; by setting the #defines before including png.h
  380.  
  381. ; Use macros to read integers from PNG data or use the exported
  382. ; functions?
  383. ;   PNG_USE_READ_MACROS: use the macros (see below)  Note that
  384. ;     the macros evaluate their argument multiple times.
  385. ;   PNG_NO_USE_READ_MACROS: call the relevant library function.
  386.  
  387. ; Use the alternative algorithm for compositing alpha samples that
  388. ; does not use division?
  389. ;   PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division'
  390. ;      algorithm.
  391. ;   PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm.
  392.  
  393. ; How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is
  394. ; false?
  395. ;   PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error
  396. ;      APIs to png_warning.
  397. ; Otherwise the calls are mapped to png_error.
  398.  
  399.  
  400. ; Section 3: type definitions, including structures and compile time
  401. ; constants.
  402. ; See pngconf.h for base types that vary by machine/system
  403.  
  404.  
  405. ; This triggers a compiler error in png.c, if png.c and png.h
  406. ; do not agree upon the version number.
  407.  
  408. ;typedef char* png_libpng_version_1_6_25;
  409.  
  410. ; Basic control structions.  Read libpng-manual.txt or libpng.3 for more info.
  411.  
  412. ; png_struct is the cache of information used while reading or writing a single
  413. ; PNG file.  One of these is always required, although the simplified API
  414. ; (below) hides the creation and destruction of it.
  415.  
  416. ; png_info contains information read from or to be written to a PNG file.  One
  417. ; or more of these must exist while reading or creating a PNG file.  The
  418. ; information is not used by libpng during read but is used to control what
  419. ; gets written when a PNG file is created.  "png_get_" function calls read
  420. ; information during read and "png_set_" functions calls write information
  421. ; when creating a PNG.
  422. ; been moved into a separate header file that is not accessible to
  423. ; applications.  Read libpng-manual.txt or libpng.3 for more info.
  424.  
  425. ; Types with names ending 'p' are pointer types.  The corresponding types with
  426. ; names ending 'rp' are identical pointer types except that the pointer is
  427. ; marked 'restrict', which means that it is the only pointer to the object
  428. ; passed to the function.  Applications should not use the 'restrict' types;
  429. ; it is always valid to pass 'p' to a pointer with a function argument of the
  430. ; corresponding 'rp' type.  Different compilers have different rules with
  431. ; regard to type matching in the presence of 'restrict'.  For backward
  432. ; compatibility libpng callbacks never have 'restrict' in their parameters and,
  433. ; consequentially, writing portable application code is extremely difficult if
  434. ; an attempt is made to use 'restrict'.
  435.  
  436. ; Three color definitions.  The order of the red, green, and blue, (and the
  437. ; exact size) is not important, although the size of the fields need to
  438. ; be byte or uint_16 (as defined below).
  439.  
  440. struct png_color
  441.         red   db ? ;byte
  442.         green db ? ;byte
  443.         blue  db ? ;byte
  444. ends
  445.  
  446. struct png_color_16
  447.         index db ? ;byte ;used for palette files
  448.         red   dw ? ;uint_16 ;for use in red green blue files
  449.         green dw ? ;uint_16
  450.         blue  dw ? ;uint_16
  451.         gray  dw ? ;uint_16 ;for use in grayscale files
  452. ends
  453.  
  454. struct png_color_8
  455.         red   db ? ;byte ;for use in red green blue files
  456.         green db ? ;byte
  457.         blue  db ? ;byte
  458.         gray  db ? ;byte ;for use in grayscale files
  459.         alpha db ? ;byte ;for alpha channel files
  460. ends
  461.  
  462.  
  463. ; The following two structures are used for the in-core representation
  464. ; of sPLT chunks.
  465.  
  466. struct png_sPLT_entry
  467.         red   dw ? ;uint_16
  468.         green dw ? ;uint_16
  469.         blue  dw ? ;uint_16
  470.         alpha dw ? ;uint_16
  471.         frequency dw ? ;uint_16
  472. ends
  473.  
  474. ; When the depth of the sPLT palette is 8 bits, the color and alpha samples
  475. ; occupy the LSB of their respective members, and the MSB of each member
  476. ; is zero-filled.  The frequency member always occupies the full 16 bits.
  477.  
  478.  
  479. struct png_sPLT_t
  480.         name    dd ? ;charp ;palette name
  481.         depth   db ? ;byte ;depth of palette samples
  482.         entries dd ? ;png_sPLT_entryp ;palette entries
  483.         nentries dd ? ;int_32 ;number of palette entries
  484. ends
  485.  
  486. if PNG_TEXT_SUPPORTED eq 1
  487. ; png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
  488. ; and whether that contents is compressed or not.  The "key" field
  489. ; points to a regular zero-terminated C string.  The "text" fields can be a
  490. ; regular C string, an empty string, or a NULL pointer.
  491. ; However, the structure returned by png_get_text() will always contain
  492. ; the "text" field as a regular zero-terminated C string (possibly
  493. ; empty), never a NULL pointer, so it can be safely used in printf() and
  494. ; other string-handling functions.  Note that the "itxt_length", "lang", and
  495. ; "lang_key" members of the structure only exist when the library is built
  496. ; with iTXt chunk support.  Prior to libpng-1.4.0 the library was built by
  497. ; default without iTXt support. Also note that when iTXt *is* supported,
  498. ; the "lang" and "lang_key" fields contain NULL pointers when the
  499. ; "compression" field contains * PNG_TEXT_COMPRESSION_NONE or
  500. ; PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the
  501. ; same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag"
  502. ; which is always 0 or 1, or its "compression method" which is always 0.
  503.  
  504. struct png_text
  505.         compression dd ? ;int ;compression value:
  506.                         ;-1: tEXt, none
  507.                         ; 0: zTXt, deflate
  508.                         ; 1: iTXt, none
  509.                         ; 2: iTXt, deflate
  510.         key  dd ? ;charp ;keyword, 1-79 character description of "text"
  511.         text dd ? ;charp ;comment, may be an empty string (ie "")
  512.                         ; or a NULL pointer
  513.         text_length dd ? ;png_size_t ;length of the text string
  514.         itxt_length dd ? ;png_size_t ;length of the itxt string
  515.         lang dd ? ;charp ;language code, 0-79 characters
  516.                         ; or a NULL pointer
  517.         lang_key dd ? ;charp ;keyword translated UTF-8 string, 0 or more
  518.                         ; chars or a NULL pointer
  519. ends
  520. end if
  521.  
  522. ; Supported compression types for text in PNG files (tEXt, and zTXt).
  523. ; The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed.
  524. PNG_TEXT_COMPRESSION_NONE_WR equ -3
  525. PNG_TEXT_COMPRESSION_zTXt_WR equ -2
  526. PNG_TEXT_COMPRESSION_NONE    equ -1
  527. PNG_TEXT_COMPRESSION_zTXt    equ 0
  528. PNG_ITXT_COMPRESSION_NONE    equ 1
  529. PNG_ITXT_COMPRESSION_zTXt    equ 2
  530. PNG_TEXT_COMPRESSION_LAST    equ 3 ;Not a valid value
  531.  
  532. ; png_time is a way to hold the time in an machine independent way.
  533. ; Two conversions are provided, both from time_t and struct tm.  There
  534. ; is no portable way to convert to either of these structures, as far
  535. ; as I know.  If you know of a portable way, send it to me.  As a side
  536. ; note - PNG has always been Year 2000 compliant!
  537.  
  538. struct png_time
  539.         year  dw ? ;uint_16 ;full year, as in, 1995
  540.         month db ? ;byte ;month of year, 1 - 12
  541.         day   db ? ;byte ;day of month, 1 - 31
  542.         hour  db ? ;byte ;hour of day, 0 - 23
  543.         minute db ? ;byte ;minute of hour, 0 - 59
  544.         second db ? ;byte ;second of minute, 0 - 60 (for leap seconds)
  545. ends
  546.  
  547. if (PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED eq 1) | (PNG_USER_CHUNKS_SUPPORTED eq 1)
  548. ; png_unknown_chunk is a structure to hold queued chunks for which there is
  549. ; no specific support.  The idea is that we can use this to queue
  550. ; up private chunks for output even though the library doesn't actually
  551. ; know about their semantics.
  552.  
  553. ; The data in the structure is set by libpng on read and used on write.
  554.  
  555. struct png_unknown_chunk
  556.         name rb 5 ;byte[5] ;Textual chunk name with '\0' terminator
  557.         podata dd ? ;byte* ;Data, should not be modified on read!
  558.         size dd ? ;png_size_t
  559.  
  560.         ; On write 'location' must be set using the flag values listed below.
  561.         ; Notice that on read it is set by libpng however the values stored have
  562.         ; more bits set than are listed below.  Always treat the value as a
  563.         ; bitmask.  On write set only one bit - setting multiple bits may cause the
  564.         ; chunk to be written in multiple places.
  565.  
  566.         location db ? ;byte ;mode of operation at read time
  567. ends
  568. end if
  569.  
  570. ; Flag values for the unknown chunk location byte.
  571. PNG_HAVE_IHDR equ  0x01
  572. PNG_HAVE_PLTE equ  0x02
  573. PNG_AFTER_IDAT equ 0x08
  574.  
  575. ; Maximum positive integer used in PNG is (2^31)-1
  576. PNG_UINT_31_MAX equ 0x7fffffff ;uint_32
  577. PNG_UINT_32_MAX equ -1 ;uint_32
  578. PNG_SIZE_MAX    equ 0x60000000 ;1.5 Gb
  579.  
  580. ; These are constants for fixed point values encoded in the
  581. ; PNG specification manner (x100000)
  582.  
  583. PNG_FP_1   equ 100000
  584. PNG_FP_HALF equ 50000
  585. PNG_FP_MAX equ ((png_fixed_point)0x7fffffffL)
  586. PNG_FP_MIN equ (-PNG_FP_MAX)
  587.  
  588. ; These describe the color_type field in png_info.
  589. ; color type masks
  590. PNG_COLOR_MASK_PALETTE equ 1
  591. PNG_COLOR_MASK_COLOR   equ 2
  592. PNG_COLOR_MASK_ALPHA   equ 4
  593.  
  594. ; color types.  Note that not all combinations are legal
  595. PNG_COLOR_TYPE_GRAY equ 0
  596. PNG_COLOR_TYPE_PALETTE equ (PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_PALETTE)
  597. PNG_COLOR_TYPE_RGB      equ (PNG_COLOR_MASK_COLOR)
  598. PNG_COLOR_TYPE_RGB_ALPHA equ (PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_ALPHA)
  599. PNG_COLOR_TYPE_GRAY_ALPHA equ (PNG_COLOR_MASK_ALPHA)
  600. ; aliases
  601. PNG_COLOR_TYPE_RGBA equ PNG_COLOR_TYPE_RGB_ALPHA
  602. PNG_COLOR_TYPE_GA equ PNG_COLOR_TYPE_GRAY_ALPHA
  603.  
  604. ; This is for compression type. PNG 1.0-1.2 only define the single type.
  605. PNG_COMPRESSION_TYPE_BASE equ 0 ;Deflate method 8, 32K window
  606. PNG_COMPRESSION_TYPE_DEFAULT equ PNG_COMPRESSION_TYPE_BASE
  607.  
  608. ; This is for filter type. PNG 1.0-1.2 only define the single type.
  609. PNG_FILTER_TYPE_BASE     equ 0 ;Single row per-byte filtering
  610. PNG_INTRAPIXEL_DIFFERENCING equ 64 ;Used only in MNG datastreams
  611. PNG_FILTER_TYPE_DEFAULT  equ PNG_FILTER_TYPE_BASE
  612.  
  613. ; These are for the interlacing type.  These values should NOT be changed.
  614. PNG_INTERLACE_NONE       equ 0 ;Non-interlaced image
  615. PNG_INTERLACE_ADAM7      equ 1 ;Adam7 interlacing
  616. PNG_INTERLACE_LAST       equ 2 ;Not a valid value
  617.  
  618. ; These are for the oFFs chunk.  These values should NOT be changed.
  619. PNG_OFFSET_PIXEL         equ 0 ;Offset in pixels
  620. PNG_OFFSET_MICROMETER    equ 1 ;Offset in micrometers (1/10^6 meter)
  621. PNG_OFFSET_LAST          equ 2 ;Not a valid value
  622.  
  623. ; These are for the pCAL chunk.  These values should NOT be changed.
  624. PNG_EQUATION_LINEAR      equ 0 ;Linear transformation
  625. PNG_EQUATION_BASE_E      equ 1 ;Exponential base e transform
  626. PNG_EQUATION_ARBITRARY   equ 2 ;Arbitrary base exponential transform
  627. PNG_EQUATION_HYPERBOLIC  equ 3 ;Hyperbolic sine transformation
  628. PNG_EQUATION_LAST        equ 4 ;Not a valid value
  629.  
  630. ; These are for the sCAL chunk.  These values should NOT be changed.
  631. PNG_SCALE_UNKNOWN        equ 0 ;unknown unit (image scale)
  632. PNG_SCALE_METER          equ 1 ;meters per pixel
  633. PNG_SCALE_RADIAN         equ 2 ;radians per pixel
  634. PNG_SCALE_LAST           equ 3 ;Not a valid value
  635.  
  636. ; These are for the pHYs chunk.  These values should NOT be changed.
  637. PNG_RESOLUTION_UNKNOWN   equ 0 ;pixels/unknown unit (aspect ratio)
  638. PNG_RESOLUTION_METER     equ 1 ;pixels/meter
  639. PNG_RESOLUTION_LAST      equ 2 ;Not a valid value
  640.  
  641. ; These are for the sRGB chunk.  These values should NOT be changed.
  642. PNG_sRGB_INTENT_PERCEPTUAL equ 0
  643. PNG_sRGB_INTENT_RELATIVE   equ 1
  644. PNG_sRGB_INTENT_SATURATION equ 2
  645. PNG_sRGB_INTENT_ABSOLUTE   equ 3
  646. PNG_sRGB_INTENT_LAST       equ 4 ;Not a valid value
  647.  
  648. ; This is for text chunks
  649. PNG_KEYWORD_MAX_LENGTH equ 79
  650.  
  651. ; Maximum number of entries in PLTE/sPLT/tRNS arrays
  652. PNG_MAX_PALETTE_LENGTH equ 256
  653.  
  654. ; These determine if an ancillary chunk's data has been successfully read
  655. ; from the PNG header, or if the application has filled in the corresponding
  656. ; data in the info_struct to be written into the output file.  The values
  657. ; of the PNG_INFO_<chunk> defines should NOT be changed.
  658.  
  659. PNG_INFO_gAMA equ 0x0001
  660. PNG_INFO_sBIT equ 0x0002
  661. PNG_INFO_cHRM equ 0x0004
  662. PNG_INFO_PLTE equ 0x0008
  663. PNG_INFO_tRNS equ 0x0010
  664. PNG_INFO_bKGD equ 0x0020
  665. PNG_INFO_hIST equ 0x0040
  666. PNG_INFO_pHYs equ 0x0080
  667. PNG_INFO_oFFs equ 0x0100
  668. PNG_INFO_tIME equ 0x0200
  669. PNG_INFO_pCAL equ 0x0400
  670. PNG_INFO_sRGB equ 0x0800 ; GR-P, 0.96a
  671. PNG_INFO_iCCP equ 0x1000 ; ESR, 1.0.6
  672. PNG_INFO_sPLT equ 0x2000 ; ESR, 1.0.6
  673. PNG_INFO_sCAL equ 0x4000 ; ESR, 1.0.6
  674. PNG_INFO_IDAT equ 0x8000 ; ESR, 1.0.6
  675.  
  676. ; This is used for the transformation routines, as some of them
  677. ; change these values for the row.  It also should enable using
  678. ; the routines for other purposes.
  679.  
  680. struct png_row_info ;png_row_info_struct
  681.         width      dd ? ;uint_32 ;width of row
  682.         rowbytes   dd ? ;png_size_t ;number of bytes in row
  683.         color_type db ? ;byte ;color type of row
  684.         bit_depth  db ? ;byte ;bit depth of row
  685.         channels   db ? ;byte ;number of channels (1, 2, 3, or 4)
  686.         pixel_depth db ? ;byte ;bits per pixel (depth * channels)
  687. ends
  688.  
  689. if PNG_SETJMP_SUPPORTED eq 1
  690. ; This must match the function definition in <setjmp.h>, and the application
  691. ; must include this before png.h to obtain the definition of jmp_buf.  The
  692. ; function is required to be PNG_NORETURN, but this is not checked.  If the
  693. ; function does return the application will crash via an abort() or similar
  694. ; system level call.
  695.  
  696. ; If you get a warning here while building the library you may need to make
  697. ; changes to ensure that pnglibconf.h records the calling convention used by
  698. ; your compiler.  This may be very difficult - try using a different compiler
  699. ; to build the library!
  700.  
  701. ;PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);
  702. end if
  703.  
  704. ; Transform masks for the high-level interface
  705. PNG_TRANSFORM_IDENTITY      equ 0x0000 ; read and write
  706. PNG_TRANSFORM_STRIP_16      equ 0x0001 ; read only
  707. PNG_TRANSFORM_STRIP_ALPHA   equ 0x0002 ; read only
  708. PNG_TRANSFORM_PACKING       equ 0x0004 ; read and write
  709. PNG_TRANSFORM_PACKSWAP      equ 0x0008 ; read and write
  710. PNG_TRANSFORM_EXPAND        equ 0x0010 ; read only
  711. PNG_TRANSFORM_INVERT_MONO   equ 0x0020 ; read and write
  712. PNG_TRANSFORM_SHIFT         equ 0x0040 ; read and write
  713. PNG_TRANSFORM_BGR           equ 0x0080 ; read and write
  714. PNG_TRANSFORM_SWAP_ALPHA    equ 0x0100 ; read and write
  715. PNG_TRANSFORM_SWAP_ENDIAN   equ 0x0200 ; read and write
  716. PNG_TRANSFORM_INVERT_ALPHA  equ 0x0400 ; read and write
  717. PNG_TRANSFORM_STRIP_FILLER  equ 0x0800 ; write only
  718. ; Added to libpng-1.2.34
  719. PNG_TRANSFORM_STRIP_FILLER_BEFORE equ PNG_TRANSFORM_STRIP_FILLER
  720. PNG_TRANSFORM_STRIP_FILLER_AFTER equ 0x1000 ; write only
  721. ; Added to libpng-1.4.0
  722. PNG_TRANSFORM_GRAY_TO_RGB  equ 0x2000 ; read only
  723. ; Added to libpng-1.5.4
  724. PNG_TRANSFORM_EXPAND_16    equ 0x4000 ;read only
  725. ;if INT_MAX >= 0x8000 ;else this might break
  726. PNG_TRANSFORM_SCALE_16     equ 0x8000 ;read only
  727. ;end if
  728.  
  729. ; Flags for MNG supported features
  730. PNG_FLAG_MNG_EMPTY_PLTE    equ 0x01
  731. PNG_FLAG_MNG_FILTER_64     equ 0x04
  732. PNG_ALL_MNG_FEATURES       equ 0x05
  733.  
  734. ; NOTE: prior to 1.5 these functions had no 'API' style declaration,
  735. ; this allowed the zlib default functions to be used on Windows
  736. ; platforms.  In 1.5 the zlib default malloc (which just calls malloc and
  737. ; ignores the first argument) should be completely compatible with the
  738. ; following.
  739.  
  740. ; Section 4: exported functions
  741. ; Here are the function definitions most commonly used.  This is not
  742. ; the place to find out how to use libpng.  See libpng-manual.txt for the
  743. ; full explanation, see example.c for the summary.  This just provides
  744. ; a simple one line description of the use of each function.
  745.  
  746.  
  747.  
  748. ; Simple signature checking function.  This is the same as calling
  749. ; png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
  750.  
  751. ;#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
  752.  
  753. macro png_setup_abs sum
  754. {
  755. local .end0
  756.         and eax,0xff
  757. if PNG_USE_ABS eq 1
  758.         add sum,128
  759.         sub al,128 ;v - 128
  760.         cmp al,128
  761.         jl @f
  762.                 neg al
  763.                 inc al ;abs(v - 128)
  764.         @@:
  765.         sub sum,eax
  766. else
  767.         cmp eax,128
  768.         jl @f
  769.                 add sum,256
  770.                 sub sum,eax
  771.                 jmp .end0
  772.         @@:
  773.                 add sum,eax
  774.         .end0:
  775. end if
  776. }
  777.  
  778. ; Reduce RGB to grayscale.
  779. PNG_ERROR_ACTION_NONE equ 1
  780. PNG_ERROR_ACTION_WARN equ 2
  781. PNG_ERROR_ACTION_ERROR equ 3
  782. PNG_RGB_TO_GRAY_DEFAULT equ (-1) ;for red/green coefficients
  783.  
  784. ; How the alpha channel is interpreted - this affects how the color channels
  785. ; of a PNG file are returned to the calling application when an alpha channel,
  786. ; or a tRNS chunk in a palette file, is present.
  787.  
  788. ; This has no effect on the way pixels are written into a PNG output
  789. ; datastream. The color samples in a PNG datastream are never premultiplied
  790. ; with the alpha samples.
  791.  
  792. ; The default is to return data according to the PNG specification: the alpha
  793. ; channel is a linear measure of the contribution of the pixel to the
  794. ; corresponding composited pixel, and the color channels are unassociated
  795. ; (not premultiplied).  The gamma encoded color channels must be scaled
  796. ; according to the contribution and to do this it is necessary to undo
  797. ; the encoding, scale the color values, perform the composition and reencode
  798. ; the values.  This is the 'PNG' mode.
  799.  
  800. ; The alternative is to 'associate' the alpha with the color information by
  801. ; storing color channel values that have been scaled by the alpha.
  802. ; image.  These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes
  803. ; (the latter being the two common names for associated alpha color channels).
  804.  
  805. ; For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha
  806. ; value is equal to the maximum value.
  807.  
  808. ; The final choice is to gamma encode the alpha channel as well.  This is
  809. ; broken because, in practice, no implementation that uses this choice
  810. ; correctly undoes the encoding before handling alpha composition.  Use this
  811. ; choice only if other serious errors in the software or hardware you use
  812. ; mandate it; the typical serious error is for dark halos to appear around
  813. ; opaque areas of the composited PNG image because of arithmetic overflow.
  814.  
  815. ; The API function png_set_alpha_mode specifies which of these choices to use
  816. ; with an enumerated 'mode' value and the gamma of the required output:
  817.  
  818. PNG_ALPHA_PNG          equ 0 ;according to the PNG standard
  819. PNG_ALPHA_STANDARD     equ 1 ;according to Porter/Duff
  820. PNG_ALPHA_ASSOCIATED   equ 1 ;as above; this is the normal practice
  821. PNG_ALPHA_PREMULTIPLIED equ 1 ;as above
  822. PNG_ALPHA_OPTIMIZED    equ 2 ;'PNG' for opaque pixels, else 'STANDARD'
  823. PNG_ALPHA_BROKEN       equ 3 ;the alpha channel is gamma encoded
  824.  
  825. if (PNG_GAMMA_SUPPORTED eq 1) | (PNG_READ_ALPHA_MODE_SUPPORTED eq 1)
  826. ; The output_gamma value is a screen gamma in libpng terminology: it expresses
  827. ; how to decode the output values, not how they are encoded.
  828.  
  829. PNG_DEFAULT_sRGB equ -1       ;sRGB gamma and color space
  830. PNG_GAMMA_MAC_18 equ -2       ;Old Mac '1.8' gamma and color space
  831. PNG_GAMMA_sRGB   equ 220000   ;Television standards--matches sRGB gamma
  832. PNG_GAMMA_LINEAR equ PNG_FP_1 ;Linear
  833. end if
  834.  
  835. ; The values of the PNG_FILLER_ defines should NOT be changed
  836. PNG_FILLER_BEFORE equ 0
  837. PNG_FILLER_AFTER equ 1
  838.  
  839. ;#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  840.  
  841. ; Handle alpha and tRNS by replacing with a background color.  Prior to
  842. ; libpng-1.5.4 this API must not be called before the PNG file header has been
  843. ; read.  Doing so will result in unexpected behavior and possible warnings or
  844. ; errors if the PNG file contains a bKGD chunk.
  845.  
  846. if PNG_READ_BACKGROUND_SUPPORTED eq 1
  847. PNG_BACKGROUND_GAMMA_UNKNOWN equ 0
  848. PNG_BACKGROUND_GAMMA_SCREEN equ 1
  849. PNG_BACKGROUND_GAMMA_FILE   equ 2
  850. PNG_BACKGROUND_GAMMA_UNIQUE equ 3
  851. end if
  852.  
  853. ;PNG_READ_16_TO_8_SUPPORTED equ 1 ;Name prior to 1.5.4
  854.  
  855. ; The threshold on gamma processing is configurable but hard-wired into the
  856. ; library.  The following is the floating point variant.
  857.  
  858. PNG_GAMMA_THRESHOLD equ (PNG_GAMMA_THRESHOLD_FIXED*.00001)
  859.  
  860. ; Handle gamma correction. Screen_gamma=(display_exponent).
  861. ; NOTE: this API simply sets the screen and file gamma values. It will
  862. ; therefore override the value for gamma in a PNG file if it is called after
  863. ; the file header has been read - use with care  - call before reading the PNG
  864. ; file for best results!
  865.  
  866.  
  867. ; Values for png_set_crc_action() say how to handle CRC errors in
  868. ; ancillary and critical chunks, and whether to use the data contained
  869. ; therein.  Note that it is impossible to "discard" data in a critical
  870. ; chunk.  For versions prior to 0.90, the action was always error/quit,
  871. ; whereas in version 0.90 and later, the action for CRC errors in ancillary
  872. ; chunks is warn/discard.  These values should NOT be changed.
  873.  
  874. ;      value                       action:critical     action:ancillary
  875.  
  876. PNG_CRC_DEFAULT      equ 0 ;error/quit          warn/discard data
  877. PNG_CRC_ERROR_QUIT   equ 1 ;error/quit          error/quit
  878. PNG_CRC_WARN_DISCARD equ 2 ;(INVALID)           warn/discard data
  879. PNG_CRC_WARN_USE     equ 3 ;warn/use data       warn/use data
  880. PNG_CRC_QUIET_USE    equ 4 ;quiet/use data      quiet/use data
  881. PNG_CRC_NO_CHANGE    equ 5 ;use current value   use current value
  882.  
  883. ; Flags for png_set_filter() to say which filters to use.  The flags
  884. ; are chosen so that they don't conflict with real filter types
  885. ; below, in case they are supplied instead of the #defined constants.
  886. ; These values should NOT be changed.
  887.  
  888. PNG_NO_FILTERS   equ 0x00
  889. PNG_FILTER_NONE  equ 0x08
  890. PNG_FILTER_SUB   equ 0x10
  891. PNG_FILTER_UP    equ 0x20
  892. PNG_FILTER_AVG   equ 0x40
  893. PNG_FILTER_PAETH equ 0x80
  894. PNG_FAST_FILTERS equ (PNG_FILTER_NONE or PNG_FILTER_SUB or PNG_FILTER_UP)
  895. PNG_ALL_FILTERS  equ (PNG_FAST_FILTERS or PNG_FILTER_AVG or PNG_FILTER_PAETH)
  896.  
  897. ; Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
  898. ; These defines should NOT be changed.
  899.  
  900. PNG_FILTER_VALUE_NONE equ 0
  901. PNG_FILTER_VALUE_SUB  equ 1
  902. PNG_FILTER_VALUE_UP   equ 2
  903. PNG_FILTER_VALUE_AVG  equ 3
  904. PNG_FILTER_VALUE_PAETH equ 4
  905. PNG_FILTER_VALUE_LAST equ 5
  906.  
  907. ; The following are no longer used and will be removed from libpng-1.7:
  908. PNG_FILTER_HEURISTIC_DEFAULT   equ 0 ;Currently "UNWEIGHTED"
  909. PNG_FILTER_HEURISTIC_UNWEIGHTED equ 1 ;Used by libpng < 0.95
  910. PNG_FILTER_HEURISTIC_WEIGHTED  equ 2 ;Experimental feature
  911. PNG_FILTER_HEURISTIC_LAST      equ 3 ;Not a valid value
  912.  
  913. ; It is unlikely that this function works correctly as of 1.6.0 and using it
  914. ; may result either in memory leaks or double free of allocated data.
  915.  
  916. ; Assignments for png_data_freer
  917. PNG_DESTROY_WILL_FREE_DATA equ 1
  918. PNG_SET_WILL_FREE_DATA equ 1
  919. PNG_USER_WILL_FREE_DATA equ 2
  920. ; Flags for png_ptr->free_me and info_ptr->free_me
  921. PNG_FREE_HIST equ 0x0008
  922. PNG_FREE_ICCP equ 0x0010
  923. PNG_FREE_SPLT equ 0x0020
  924. PNG_FREE_ROWS equ 0x0040
  925. PNG_FREE_PCAL equ 0x0080
  926. PNG_FREE_SCAL equ 0x0100
  927. if PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED eq 1
  928.         PNG_FREE_UNKN equ 0x0200
  929. end if
  930. PNG_FREE_LIST equ 0x0400 ;removed in 1.6.0 because it is ignored
  931. PNG_FREE_PLTE equ 0x1000
  932. PNG_FREE_TRNS equ 0x2000
  933. PNG_FREE_TEXT equ 0x4000
  934. PNG_FREE_ALL  equ 0x7fff
  935. PNG_FREE_MUL  equ 0x4220 ;PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN
  936.  
  937. ;if PNG_ERROR_TEXT_SUPPORTED
  938.  
  939. ;#else
  940. ;#  define png_chunk_error(s1,s2) png_err(s1)
  941. ;end if
  942.  
  943. ;#else
  944. ;#  define png_warning(s1,s2) ((void)(s1))
  945. ;#  define png_chunk_warning(s1,s2) ((void)(s1))
  946.  
  947. ;if PNG_READ_SUPPORTED
  948.  
  949. ;#else
  950. ;#  ifdef PNG_ALLOW_BENIGN_ERRORS
  951. macro png_benign_error h,txt
  952. {
  953.         png_warning h,txt
  954. }
  955. ;#    define png_chunk_benign_error png_chunk_warning
  956. ;#  else
  957. ;#    define png_benign_error png_error
  958. ;#    define png_chunk_benign_error png_chunk_error
  959. ;#  endif
  960. ;end if
  961.  
  962.  
  963. ; Provide the default handling for all unknown chunks or, optionally, for
  964. ; specific unknown chunks.
  965.  
  966. ; NOTE: prior to 1.6.0 the handling specified for particular chunks on read was
  967. ; ignored and the default was used, the per-chunk setting only had an effect on
  968. ; write.  If you wish to have chunk-specific handling on read in code that must
  969. ; work on earlier versions you must use a user chunk callback to specify the
  970. ; desired handling (keep or discard.)
  971.  
  972. ; The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below.  The
  973. ; parameter is interpreted as follows:
  974.  
  975. ; READ:
  976. ;    PNG_HANDLE_CHUNK_AS_DEFAULT:
  977. ;       Known chunks: do normal libpng processing, do not keep the chunk (but
  978. ;          see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
  979. ;       Unknown chunks: for a specific chunk use the global default, when used
  980. ;          as the default discard the chunk data.
  981. ;    PNG_HANDLE_CHUNK_NEVER:
  982. ;       Discard the chunk data.
  983. ;    PNG_HANDLE_CHUNK_IF_SAFE:
  984. ;       Keep the chunk data if the chunk is not critical else raise a chunk
  985. ;       error.
  986. ;    PNG_HANDLE_CHUNK_ALWAYS:
  987. ;       Keep the chunk data.
  988.  
  989. ; If the chunk data is saved it can be retrieved using png_get_unknown_chunks,
  990. ; below.  Notice that specifying "AS_DEFAULT" as a global default is equivalent
  991. ; to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks
  992. ; it simply resets the behavior to the libpng default.
  993.  
  994. ; INTERACTION WTIH USER CHUNK CALLBACKS:
  995. ; The per-chunk handling is always used when there is a png_user_chunk_ptr
  996. ; callback and the callback returns 0; the chunk is then always stored *unless*
  997. ; it is critical and the per-chunk setting is other than ALWAYS.  Notice that
  998. ; the global default is *not* used in this case.  (In effect the per-chunk
  999. ; value is incremented to at least IF_SAFE.)
  1000.  
  1001. ; IMPORTANT NOTE: this behavior will change in libpng 1.7 - the global and
  1002. ; per-chunk defaults will be honored.  If you want to preserve the current
  1003. ; behavior when your callback returns 0 you must set PNG_HANDLE_CHUNK_IF_SAFE
  1004. ; as the default - if you don't do this libpng 1.6 will issue a warning.
  1005.  
  1006. ; If you want unhandled unknown chunks to be discarded in libpng 1.6 and
  1007. ; earlier simply return '1' (handled).
  1008.  
  1009. ; PNG_HANDLE_AS_UNKNOWN_SUPPORTED:
  1010. ;    If this is *not* set known chunks will always be handled by libpng and
  1011. ;    will never be stored in the unknown chunk list.  Known chunks listed to
  1012. ;    png_set_keep_unknown_chunks will have no effect.  If it is set then known
  1013. ;    chunks listed with a keep other than AS_DEFAULT will *never* be processed
  1014. ;    by libpng, in addition critical chunks must either be processed by the
  1015. ;    callback or saved.
  1016.  
  1017. ;    The IHDR and IEND chunks must not be listed.  Because this turns off the
  1018. ;    default handling for chunks that would otherwise be recognized the
  1019. ;    behavior of libpng transformations may well become incorrect!
  1020.  
  1021. ; WRITE:
  1022. ;    When writing chunks the options only apply to the chunks specified by
  1023. ;    png_set_unknown_chunks (below), libpng will *always* write known chunks
  1024. ;    required by png_set_ calls and will always write the core critical chunks
  1025. ;    (as required for PLTE).
  1026.  
  1027. ;    Each chunk in the png_set_unknown_chunks list is looked up in the
  1028. ;    png_set_keep_unknown_chunks list to find the keep setting, this is then
  1029. ;    interpreted as follows:
  1030.  
  1031. ;    PNG_HANDLE_CHUNK_AS_DEFAULT:
  1032. ;       Write safe-to-copy chunks and write other chunks if the global
  1033. ;       default is set to _ALWAYS, otherwise don't write this chunk.
  1034. ;    PNG_HANDLE_CHUNK_NEVER:
  1035. ;       Do not write the chunk.
  1036. ;    PNG_HANDLE_CHUNK_IF_SAFE:
  1037. ;       Write the chunk if it is safe-to-copy, otherwise do not write it.
  1038. ;    PNG_HANDLE_CHUNK_ALWAYS:
  1039. ;       Write the chunk.
  1040.  
  1041. ; Note that the default behavior is effectively the opposite of the read case -
  1042. ; in read unknown chunks are not stored by default, in write they are written
  1043. ; by default.  Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different
  1044. ; - on write the safe-to-copy bit is checked, on read the critical bit is
  1045. ; checked and on read if the chunk is critical an error will be raised.
  1046.  
  1047. ; num_chunks:
  1048. ; ===========
  1049. ;    If num_chunks is positive, then the "keep" parameter specifies the manner
  1050. ;    for handling only those chunks appearing in the chunk_list array,
  1051. ;    otherwise the chunk list array is ignored.
  1052.  
  1053. ;    If num_chunks is 0 the "keep" parameter specifies the default behavior for
  1054. ;    unknown chunks, as described above.
  1055.  
  1056. ;    If num_chunks is negative, then the "keep" parameter specifies the manner
  1057. ;    for handling all unknown chunks plus all chunks recognized by libpng
  1058. ;    except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to
  1059. ;    be processed by libpng.
  1060.  
  1061.  
  1062. ; For use in png_set_keep_unknown, added to version 1.2.6
  1063. PNG_HANDLE_CHUNK_AS_DEFAULT  equ 0
  1064. PNG_HANDLE_CHUNK_NEVER       equ 1
  1065. PNG_HANDLE_CHUNK_IF_SAFE     equ 2
  1066. PNG_HANDLE_CHUNK_ALWAYS      equ 3
  1067. PNG_HANDLE_CHUNK_LAST        equ 4
  1068.  
  1069. ; Removed from libpng 1.6; use png_get_io_chunk_type.
  1070. ;PNG_REMOVED(200, bytep, png_get_io_chunk_name, (png_structrp png_ptr),
  1071. ;    PNG_DEPRECATED)
  1072.  
  1073. ; The flags returned by png_get_io_state() are the following:
  1074. PNG_IO_NONE        equ 0x0000 ; no I/O at this moment
  1075. PNG_IO_READING     equ 0x0001 ; currently reading
  1076. PNG_IO_WRITING     equ 0x0002 ; currently writing
  1077. PNG_IO_SIGNATURE   equ 0x0010 ; currently at the file signature
  1078. PNG_IO_CHUNK_HDR   equ 0x0020 ; currently at the chunk header
  1079. PNG_IO_CHUNK_DATA  equ 0x0040 ; currently at the chunk data
  1080. PNG_IO_CHUNK_CRC   equ 0x0080 ; currently at the chunk crc
  1081. PNG_IO_MASK_OP     equ 0x000f ; current operation: reading/writing
  1082. PNG_IO_MASK_LOC    equ 0x00f0 ; current location: sig/hdr/data/crc
  1083. ;end if /* IO_STATE */
  1084.  
  1085. ; Interlace support.  The following macros are always defined so that if
  1086. ; libpng interlace handling is turned off the macros may be used to handle
  1087. ; interlaced images within the application.
  1088.  
  1089. PNG_INTERLACE_ADAM7_PASSES equ 7
  1090.  
  1091. ; Two macros to return the first row and first column of the original,
  1092. ; full, image which appears in a given pass.  'pass' is in the range 0
  1093. ; to 6 and the result is in the range 0 to 7.
  1094.  
  1095. macro PNG_PASS_START_ROW pass
  1096. {
  1097.         push ebx ecx
  1098.         mov eax,pass
  1099.         mov ebx,eax
  1100.         not eax
  1101.         and eax,1
  1102.         shr ebx,1
  1103.         mov ecx,3
  1104.         sub ecx,ebx
  1105.         shl eax,cl
  1106.         and eax,7
  1107.         pop ecx ebx
  1108. }
  1109. macro PNG_PASS_START_COL pass
  1110. {
  1111.         push ebx ecx
  1112.         mov eax,pass
  1113.         mov ebx,eax
  1114.         and eax,1
  1115.         inc ebx
  1116.         shr ebx,1
  1117.         mov ecx,3
  1118.         sub ecx,ebx
  1119.         shl eax,cl
  1120.         and eax,7
  1121.         pop ecx ebx
  1122. }
  1123.  
  1124. ; A macro to return the offset between pixels in the output row for a pair of
  1125. ; pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that
  1126. ; follows.  Note that ROW_OFFSET is the offset from one row to the next whereas
  1127. ; COL_OFFSET is from one column to the next, within a row.
  1128.  
  1129. ;#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8)
  1130. ;#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1))
  1131.  
  1132. ; Two macros to help evaluate the number of rows or columns in each
  1133. ; pass.  This is expressed as a shift - effectively log2 of the number or
  1134. ; rows or columns in each 8x8 tile of the original image.
  1135.  
  1136. macro PNG_PASS_ROW_SHIFT pass
  1137. {
  1138. local .end0
  1139.         mov eax,3
  1140.         cmp pass,2
  1141.         jle .end0
  1142.                 mov eax,8
  1143.                 sub eax,pass
  1144.                 shr eax,1
  1145.         .end0:
  1146. }
  1147. macro PNG_PASS_COL_SHIFT pass
  1148. {
  1149. local .end0
  1150.         mov eax,3
  1151.         cmp pass,1
  1152.         jle .end0
  1153.                 mov eax,7
  1154.                 sub eax,pass
  1155.                 shr eax,1
  1156.         .end0:
  1157. }
  1158.  
  1159. ; Hence two macros to determine the number of rows or columns in a given
  1160. ; pass of an image given its height or width.  In fact these macros may
  1161. ; return non-zero even though the sub-image is empty, because the other
  1162. ; dimension may be empty for a small image.
  1163.  
  1164. macro PNG_PASS_ROWS height, pass
  1165. {
  1166. push ecx
  1167. push ebx
  1168.         PNG_PASS_START_ROW pass
  1169.         mov ebx,eax
  1170.         PNG_PASS_ROW_SHIFT pass
  1171.         mov ecx,eax
  1172.         xor eax,eax
  1173.         inc eax
  1174.         shl eax,cl
  1175.         dec eax
  1176.         sub eax,ebx
  1177. pop ebx
  1178.         add eax,height
  1179.         shr eax,cl
  1180. pop ecx
  1181. }
  1182. macro PNG_PASS_COLS width, pass
  1183. {
  1184. push ecx
  1185. push ebx
  1186.         PNG_PASS_START_COL pass
  1187.         mov ebx,eax
  1188.         PNG_PASS_COL_SHIFT pass
  1189.         mov ecx,eax
  1190.         xor eax,eax
  1191.         inc eax
  1192.         shl eax,cl
  1193.         dec eax
  1194.         sub eax,ebx
  1195. pop ebx
  1196.         add eax,width
  1197.         shr eax,cl
  1198. pop ecx
  1199. }
  1200.  
  1201. ; For the reader row callbacks (both progressive and sequential) it is
  1202. ; necessary to find the row in the output image given a row in an interlaced
  1203. ; image, so two more macros:
  1204.  
  1205. ;#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \
  1206. ;   (((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
  1207. ;#define PNG_COL_FROM_PASS_COL(x_in, pass) \
  1208. ;   (((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
  1209.  
  1210. ; Two macros which return a boolean (0 or 1) saying whether the given row
  1211. ; or column is in a particular pass.  These use a common utility macro that
  1212. ; returns a mask for a given pass - the offset 'off' selects the row or
  1213. ; column version.  The mask has the appropriate bit set for each column in
  1214. ; the tile.
  1215.  
  1216. ;#define PNG_PASS_MASK(pass,off) ( \
  1217. ;   ((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \
  1218. ;   ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0))
  1219.  
  1220. ;#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
  1221. ;   ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
  1222. ;#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
  1223. ;   ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
  1224.  
  1225. ;if PNG_READ_COMPOSITE_NODIV_SUPPORTED
  1226. ; With these routines we avoid an integer divide, which will be slower on
  1227. ; most machines.  However, it does take more operations than the corresponding
  1228. ; divide method, so it may be slower on a few RISC systems.  There are two
  1229. ; shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
  1230.  
  1231. ; Note that the rounding factors are NOT supposed to be the same!  128 and
  1232. ; 32768 are correct for the NODIV code; 127 and 32767 are correct for the
  1233. ; standard method.
  1234.  
  1235. ; [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
  1236.  
  1237.  
  1238. ; fg and bg should be in `gamma 1.0' space; alpha is the opacity
  1239.  
  1240. ;#  define png_composite(composite, fg, alpha, bg)        \
  1241. ;   {                                                     \
  1242. ;      uint_16 temp = (uint_16)((uint_16)(fg) \
  1243. ;          * (uint_16)(alpha)                         \
  1244. ;          + (uint_16)(bg)*(uint_16)(255          \
  1245. ;          - (uint_16)(alpha)) + 128);                \
  1246. ;      (composite) = (byte)(((temp + (temp >> 8)) >> 8) & 0xff); \
  1247. ;   }
  1248.  
  1249. ;#  define png_composite_16(composite, fg, alpha, bg)     \
  1250. ;   {                                                     \
  1251. ;      uint_32 temp = (uint_32)((uint_32)(fg) \
  1252. ;          * (uint_32)(alpha)                         \
  1253. ;          + (uint_32)(bg)*(65535                     \
  1254. ;          - (uint_32)(alpha)) + 32768);              \
  1255. ;      (composite) = (uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); \
  1256. ;   }
  1257.  
  1258. ;#else  /* Standard method using integer division */
  1259.  
  1260. ;#  define png_composite(composite, fg, alpha, bg)                      \
  1261. ;   (composite) =                                                       \
  1262. ;       (byte)(0xff & (((uint_16)(fg) * (uint_16)(alpha) +  \
  1263. ;       (uint_16)(bg) * (uint_16)(255 - (uint_16)(alpha)) + \
  1264. ;       127) / 255))
  1265.  
  1266. ;#  define png_composite_16(composite, fg, alpha, bg)                       \
  1267. ;   (composite) =                                                           \
  1268. ;       (uint_16)(0xffff & (((uint_32)(fg) * (uint_32)(alpha) + \
  1269. ;       (uint_32)(bg)*(uint_32)(65535 - (uint_32)(alpha)) +     \
  1270. ;       32767) / 65535))
  1271. ;end if /* READ_COMPOSITE_NODIV */
  1272.  
  1273. if PNG_USE_READ_MACROS eq 1
  1274. ; Inline macros to do direct reads of bytes from the input buffer.
  1275. ; The png_get_int_32() routine assumes we are using two's complement
  1276. ; format for negative values, which is almost certainly true.
  1277.  
  1278. ;#  define PNG_get_uint_32(buf) \
  1279. ;   (((uint_32)(*(buf)) << 24) + \
  1280. ;    ((uint_32)(*((buf) + 1)) << 16) + \
  1281. ;    ((uint_32)(*((buf) + 2)) << 8) + \
  1282. ;    ((uint_32)(*((buf) + 3))))
  1283.  
  1284.         ; From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
  1285.         ; function) incorrectly returned a value of type uint_32.
  1286.  
  1287. ;#  define PNG_get_uint_16(buf) \
  1288. ;   ((uint_16) \
  1289. ;    (((unsigned int)(*(buf)) << 8) + \
  1290. ;    ((unsigned int)(*((buf) + 1)))))
  1291.  
  1292. ;#  define PNG_get_int_32(buf) \
  1293. ;   ((int_32)((*(buf) & 0x80) \
  1294. ;    ? -((int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \
  1295. ;    : (int_32)png_get_uint_32(buf)))
  1296. end if
  1297.  
  1298. ;/*******************************************************************************
  1299. ; Section 5: SIMPLIFIED API
  1300. ; *******************************************************************************
  1301.  
  1302. ; Please read the documentation in libpng-manual.txt (TODO: write said
  1303. ; documentation) if you don't understand what follows.
  1304.  
  1305. ; The simplified API hides the details of both libpng and the PNG file format
  1306. ; itself.  It allows PNG files to be read into a very limited number of
  1307. ; in-memory bitmap formats or to be written from the same formats.  If these
  1308. ; formats do not accomodate your needs then you can, and should, use the more
  1309. ; sophisticated APIs above - these support a wide variety of in-memory formats
  1310. ; and a wide variety of sophisticated transformations to those formats as well
  1311. ; as a wide variety of APIs to manipulate ancillary information.
  1312.  
  1313. ; To read a PNG file using the simplified API:
  1314.  
  1315. ; 1) Declare a 'png_image' structure (see below) on the stack, set the
  1316. ;    version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL
  1317. ;    (this is REQUIRED, your program may crash if you don't do it.)
  1318. ; 2) Call the appropriate png_image_begin_read... function.
  1319. ; 3) Set the png_image 'format' member to the required sample format.
  1320. ; 4) Allocate a buffer for the image and, if required, the color-map.
  1321. ; 5) Call png_image_finish_read to read the image and, if required, the
  1322. ;    color-map into your buffers.
  1323.  
  1324. ; There are no restrictions on the format of the PNG input itself; all valid
  1325. ; color types, bit depths, and interlace methods are acceptable, and the
  1326. ; input image is transformed as necessary to the requested in-memory format
  1327. ; during the png_image_finish_read() step.  The only caveat is that if you
  1328. ; request a color-mapped image from a PNG that is full-color or makes
  1329. ; complex use of an alpha channel the transformation is extremely lossy and the
  1330. ; result may look terrible.
  1331.  
  1332. ; To write a PNG file using the simplified API:
  1333.  
  1334. ; 1) Declare a 'png_image' structure on the stack and memset() it to all zero.
  1335. ; 2) Initialize the members of the structure that describe the image, setting
  1336. ;    the 'format' member to the format of the image samples.
  1337. ; 3) Call the appropriate png_image_write... function with a pointer to the
  1338. ;    image and, if necessary, the color-map to write the PNG data.
  1339.  
  1340. ; png_image is a structure that describes the in-memory format of an image
  1341. ; when it is being read or defines the in-memory format of an image that you
  1342. ; need to write:
  1343.  
  1344. ;#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \
  1345. ;    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
  1346.  
  1347. PNG_IMAGE_VERSION equ 1
  1348.  
  1349. struct png_image
  1350.         opaque  dd ? ;png_controlp ;Initialize to NULL, free with png_image_free
  1351.         version dd ? ;uint_32  ;Set to PNG_IMAGE_VERSION
  1352.         width   dd ? ;uint_32  ;Image width in pixels (columns)
  1353.         height  dd ? ;uint_32  ;Image height in pixels (rows)
  1354.         format  dd ? ;uint_32  ;Image format as defined below
  1355.         flags   dd ? ;uint_32  ;A bit mask containing informational flags
  1356.         colormap_entries dd ? ;uint_32 ;Number of entries in the color-map
  1357.  
  1358.         ; In the event of an error or warning the following field will be set to a
  1359.         ; non-zero value and the 'message' field will contain a '\0' terminated
  1360.         ; string with the libpng error or warning message.  If both warnings and
  1361.         ; an error were encountered, only the error is recorded.  If there
  1362.         ; are multiple warnings, only the first one is recorded.
  1363.  
  1364.         ; The upper 30 bits of this value are reserved, the low two bits contain
  1365.         ; a value as follows:
  1366.  
  1367. PNG_IMAGE_WARNING equ 1
  1368. PNG_IMAGE_ERROR equ 2
  1369.  
  1370. ; The result is a two-bit code such that a value more than 1 indicates
  1371. ; a failure in the API just called:
  1372.  
  1373. ;    0 - no warning or error
  1374. ;    1 - warning
  1375. ;    2 - error
  1376. ;    3 - error preceded by warning
  1377.  
  1378. ;#  define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1)
  1379.  
  1380.         warning_or_error dd ? ;uint_32
  1381.         message rb 64 ;char[64]
  1382. ends
  1383.  
  1384. ; The samples of the image have one to four channels whose components have
  1385. ; original values in the range 0 to 1.0:
  1386.  
  1387. ; 1: A single gray or luminance channel (G).
  1388. ; 2: A gray/luminance channel and an alpha channel (GA).
  1389. ; 3: Three red, green, blue color channels (RGB).
  1390. ; 4: Three color channels and an alpha channel (RGBA).
  1391.  
  1392. ; The components are encoded in one of two ways:
  1393.  
  1394. ; a) As a small integer, value 0..255, contained in a single byte.  For the
  1395. ; alpha channel the original value is simply value/255.  For the color or
  1396. ; luminance channels the value is encoded according to the sRGB specification
  1397. ; and matches the 8-bit format expected by typical display devices.
  1398.  
  1399. ; The color/gray channels are not scaled (pre-multiplied) by the alpha
  1400. ; channel and are suitable for passing to color management software.
  1401.  
  1402. ; b) As a value in the range 0..65535, contained in a 2-byte integer.  All
  1403. ; channels can be converted to the original value by dividing by 65535; all
  1404. ; channels are linear.  Color channels use the RGB encoding (RGB end-points) of
  1405. ; the sRGB specification.  This encoding is identified by the
  1406. ; PNG_FORMAT_FLAG_LINEAR flag below.
  1407.  
  1408. ; When the simplified API needs to convert between sRGB and linear colorspaces,
  1409. ; the actual sRGB transfer curve defined in the sRGB specification (see the
  1410. ; article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
  1411. ; approximation used elsewhere in libpng.
  1412.  
  1413. ; When an alpha channel is present it is expected to denote pixel coverage
  1414. ; of the color or luminance channels and is returned as an associated alpha
  1415. ; channel: the color/gray channels are scaled (pre-multiplied) by the alpha
  1416. ; value.
  1417.  
  1418. ; The samples are either contained directly in the image data, between 1 and 8
  1419. ; bytes per pixel according to the encoding, or are held in a color-map indexed
  1420. ; by bytes in the image data.  In the case of a color-map the color-map entries
  1421. ; are individual samples, encoded as above, and the image data has one byte per
  1422. ; pixel to select the relevant sample from the color-map.
  1423.  
  1424.  
  1425. ; PNG_FORMAT_*
  1426.  
  1427. ; #defines to be used in png_image::format.  Each #define identifies a
  1428. ; particular layout of sample data and, if present, alpha values.  There are
  1429. ; separate defines for each of the two component encodings.
  1430.  
  1431. ; A format is built up using single bit flag values.  All combinations are
  1432. ; valid.  Formats can be built up from the flag values or you can use one of
  1433. ; the predefined values below.  When testing formats always use the FORMAT_FLAG
  1434. ; macros to test for individual features - future versions of the library may
  1435. ; add new flags.
  1436.  
  1437. ; When reading or writing color-mapped images the format should be set to the
  1438. ; format of the entries in the color-map then png_image_{read,write}_colormap
  1439. ; called to read or write the color-map and set the format correctly for the
  1440. ; image data.  Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!
  1441.  
  1442. ; NOTE: libpng can be built with particular features disabled. If you see
  1443. ; compiler errors because the definition of one of the following flags has been
  1444. ; compiled out it is because libpng does not have the required support.  It is
  1445. ; possible, however, for the libpng configuration to enable the format on just
  1446. ; read or just write; in that case you may see an error at run time.  You can
  1447. ; guard against this by checking for the definition of the appropriate
  1448. ; "_SUPPORTED" macro, one of:
  1449.  
  1450. ;    PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED
  1451.  
  1452. PNG_FORMAT_FLAG_ALPHA    equ 0x01 ;format with an alpha channel
  1453. PNG_FORMAT_FLAG_COLOR    equ 0x02 ;color format: otherwise grayscale
  1454. PNG_FORMAT_FLAG_LINEAR   equ 0x04 ;2-byte channels else 1-byte
  1455. PNG_FORMAT_FLAG_COLORMAP equ 0x08 ;image data is color-mapped
  1456.  
  1457. PNG_FORMAT_FLAG_BGR   equ 0x10 ;BGR colors, else order is RGB
  1458.  
  1459. PNG_FORMAT_FLAG_AFIRST equ 0x20 ;alpha channel comes first
  1460.  
  1461. ; Commonly used formats have predefined macros.
  1462.  
  1463. ; First the single byte (sRGB) formats:
  1464.  
  1465. PNG_FORMAT_GRAY equ 0
  1466. PNG_FORMAT_GA  equ PNG_FORMAT_FLAG_ALPHA
  1467. PNG_FORMAT_AG  equ (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)
  1468. PNG_FORMAT_RGB equ PNG_FORMAT_FLAG_COLOR
  1469. PNG_FORMAT_BGR equ (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)
  1470. PNG_FORMAT_RGBA equ (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)
  1471. PNG_FORMAT_ARGB equ (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)
  1472. PNG_FORMAT_BGRA equ (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)
  1473. PNG_FORMAT_ABGR equ (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)
  1474.  
  1475. ; Then the linear 2-byte formats.  When naming these "Y" is used to
  1476. ; indicate a luminance (gray) channel.
  1477.  
  1478. PNG_FORMAT_LINEAR_Y equ PNG_FORMAT_FLAG_LINEAR
  1479. PNG_FORMAT_LINEAR_Y_ALPHA equ (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)
  1480. PNG_FORMAT_LINEAR_RGB equ (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)
  1481. PNG_FORMAT_LINEAR_RGB_ALPHA equ\
  1482.         (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)
  1483.  
  1484. ; With color-mapped formats the image data is one byte for each pixel, the byte
  1485. ; is an index into the color-map which is formatted as above.  To obtain a
  1486. ; color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP
  1487. ; to one of the above definitions, or you can use one of the definitions below.
  1488.  
  1489. PNG_FORMAT_RGB_COLORMAP equ (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP)
  1490. PNG_FORMAT_BGR_COLORMAP equ (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP)
  1491. PNG_FORMAT_RGBA_COLORMAP equ (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP)
  1492. PNG_FORMAT_ARGB_COLORMAP equ (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP)
  1493. PNG_FORMAT_BGRA_COLORMAP equ (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP)
  1494. PNG_FORMAT_ABGR_COLORMAP equ (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP)
  1495.  
  1496. ; PNG_IMAGE macros
  1497.  
  1498. ; These are convenience macros to derive information from a png_image
  1499. ; structure.  The PNG_IMAGE_SAMPLE_ macros return values appropriate to the
  1500. ; actual image sample values - either the entries in the color-map or the
  1501. ; pixels in the image.  The PNG_IMAGE_PIXEL_ macros return corresponding values
  1502. ; for the pixels and will always return 1 for color-mapped formats.  The
  1503. ; remaining macros return information about the rows in the image and the
  1504. ; complete image.
  1505.  
  1506. ; NOTE: All the macros that take a png_image::format parameter are compile time
  1507. ; constants if the format parameter is, itself, a constant.  Therefore these
  1508. ; macros can be used in array declarations and case labels where required.
  1509. ; Similarly the macros are also pre-processor constants (sizeof is not used) so
  1510. ; they can be used in #if tests.
  1511.  
  1512. ; First the information about the samples.
  1513.  
  1514. macro PNG_IMAGE_SAMPLE_CHANNELS fmt
  1515. {
  1516.         mov eax,fmt
  1517.         and eax,PNG_FORMAT_FLAG_COLOR or PNG_FORMAT_FLAG_ALPHA
  1518.         inc eax
  1519. }
  1520. ; Return the total number of channels in a given format: 1..4
  1521.  
  1522. ;#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\
  1523. ;   ((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1)
  1524. ;   /* Return the size in bytes of a single component of a pixel or color-map
  1525. ; entry (as appropriate) in the image: 1 or 2.
  1526.  
  1527.  
  1528. ;#define PNG_IMAGE_SAMPLE_SIZE(fmt)\
  1529. ;   (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt))
  1530. ;   /* This is the size of the sample data for one sample.  If the image is
  1531. ; color-mapped it is the size of one color-map entry (and image pixels are
  1532. ; one byte in size), otherwise it is the size of one image pixel.
  1533.  
  1534.  
  1535. ;#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\
  1536. ;   (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)
  1537. ;   /* The maximum size of the color-map required by the format expressed in a
  1538. ; count of components.  This can be used to compile-time allocate a
  1539. ; color-map:
  1540.  
  1541. ; uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];
  1542.  
  1543. ; byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];
  1544.  
  1545. ; Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the
  1546. ; information from one of the png_image_begin_read_ APIs and dynamically
  1547. ; allocate the required memory.
  1548.  
  1549.  
  1550. ; Corresponding information about the pixels
  1551. macro PNG_IMAGE_PIXEL_ p1,fmt
  1552. {
  1553. local .end0
  1554. local .end1
  1555.         mov eax,fmt
  1556.         and eax,PNG_FORMAT_FLAG_COLORMAP
  1557.         cmp eax,0
  1558.         je .end0
  1559.                 xor eax,eax
  1560.                 inc eax
  1561.                 jmp .end1
  1562.         .end0:
  1563.                 p1 fmt
  1564.         .end1:
  1565. }
  1566.  
  1567. macro PNG_IMAGE_PIXEL_CHANNELS fmt
  1568. {
  1569.         PNG_IMAGE_PIXEL_ PNG_IMAGE_SAMPLE_CHANNELS,fmt
  1570. }
  1571. ; The number of separate channels (components) in a pixel; 1 for a
  1572. ; color-mapped image.
  1573.  
  1574.  
  1575. ;#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\
  1576. ;   PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt)
  1577. ;   /* The size, in bytes, of each component in a pixel; 1 for a color-mapped
  1578. ; image.
  1579.  
  1580.  
  1581. ;#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt)
  1582. ;   /* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */
  1583.  
  1584. ; Information about the whole row, or whole image
  1585. ;#define PNG_IMAGE_ROW_STRIDE(image)\
  1586. ;   (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width)
  1587. ; Return the total number of components in a single row of the image; this
  1588. ; is the minimum 'row stride', the minimum count of components between each
  1589. ; row.  For a color-mapped image this is the minimum number of bytes in a
  1590. ; row.
  1591.  
  1592. ; WARNING: this macro overflows for some images with more than one component
  1593. ; and very large image widths.  libpng will refuse to process an image where
  1594. ; this macro would overflow.
  1595.  
  1596.  
  1597. ;#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\
  1598. ;   (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride))
  1599. ; Return the size, in bytes, of an image buffer given a png_image and a row
  1600. ; stride - the number of components to leave space for in each row.
  1601.  
  1602. ; WARNING: this macro overflows a 32-bit integer for some large PNG images,
  1603. ; libpng will refuse to process an image where such an overflow would occur.
  1604.  
  1605.  
  1606. ;#define PNG_IMAGE_SIZE(image)\
  1607. ;   PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))
  1608. ; Return the size, in bytes, of the image in memory given just a png_image;
  1609. ; the row stride is the minimum stride required for the image.
  1610.  
  1611.  
  1612. ;#define PNG_IMAGE_COLORMAP_SIZE(image)\
  1613. ;   (PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries)
  1614. ; Return the size, in bytes, of the color-map of this image.  If the image
  1615. ; format is not a color-map format this will return a size sufficient for
  1616. ; 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if
  1617. ; you don't want to allocate a color-map in this case.
  1618.  
  1619.  
  1620. ; PNG_IMAGE_FLAG_*
  1621.  
  1622. ; Flags containing additional information about the image are held in the
  1623. ; 'flags' field of png_image.
  1624.  
  1625. PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB equ 0x01
  1626. ; This indicates the the RGB values of the in-memory bitmap do not
  1627. ; correspond to the red, green and blue end-points defined by sRGB.
  1628.  
  1629. PNG_IMAGE_FLAG_FAST equ 0x02
  1630. ; On write emphasise speed over compression; the resultant PNG file will be
  1631. ; larger but will be produced significantly faster, particular for large
  1632. ; images.  Do not use this option for images which will be distributed, only
  1633. ; used it when producing intermediate files that will be read back in
  1634. ; repeatedly.  For a typical 24-bit image the option will double the read
  1635. ; speed at the cost of increasing the image size by 25%, however for many
  1636. ; more compressible images the PNG file can be 10 times larger with only a
  1637. ; slight speed gain.
  1638.  
  1639. PNG_IMAGE_FLAG_16BIT_sRGB equ 0x04
  1640. ; On read if the image is a 16-bit per component image and there is no gAMA
  1641. ; or sRGB chunk assume that the components are sRGB encoded.  Notice that
  1642. ; images output by the simplified API always have gamma information; setting
  1643. ; this flag only affects the interpretation of 16-bit images from an
  1644. ; external source.  It is recommended that the application expose this flag
  1645. ; to the user; the user can normally easily recognize the difference between
  1646. ; linear and sRGB encoding.  This flag has no effect on write - the data
  1647. ; passed to the write APIs must have the correct encoding (as defined
  1648. ; above.)
  1649.  
  1650. ; If the flag is not set (the default) input 16-bit per component data is
  1651. ; assumed to be linear.
  1652.  
  1653. ; NOTE: the flag can only be set after the png_image_begin_read_ call,
  1654. ; because that call initializes the 'flags' field.
  1655.  
  1656. if PNG_SIMPLIFIED_WRITE_SUPPORTED eq 1
  1657. ; WRITE APIS
  1658. ; ----------
  1659. ; For write you must initialize a png_image structure to describe the image to
  1660. ; be written.  To do this use memset to set the whole structure to 0 then
  1661. ; initialize fields describing your image.
  1662.  
  1663. ; version: must be set to PNG_IMAGE_VERSION
  1664. ; opaque: must be initialized to NULL
  1665. ; width: image width in pixels
  1666. ; height: image height in rows
  1667. ; format: the format of the data (image and color-map) you wish to write
  1668. ; flags: set to 0 unless one of the defined flags applies; set
  1669. ;    PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB
  1670. ;    values do not correspond to the colors in sRGB.
  1671. ; colormap_entries: set to the number of entries in the color-map (0 to 256)
  1672.  
  1673. ; With all write APIs if image is in one of the linear formats with 16-bit
  1674. ; data then setting convert_to_8_bit will cause the output to be an 8-bit PNG
  1675. ; gamma encoded according to the sRGB specification, otherwise a 16-bit linear
  1676. ; encoded PNG file is written.
  1677.  
  1678. ; With color-mapped data formats the colormap parameter point to a color-map
  1679. ; with at least image->colormap_entries encoded in the specified format.  If
  1680. ; the format is linear the written PNG color-map will be converted to sRGB
  1681. ; regardless of the convert_to_8_bit flag.
  1682.  
  1683. ; With all APIs row_stride is handled as in the read APIs - it is the spacing
  1684. ; from one row to the next in component sized units (1 or 2 bytes) and if
  1685. ; negative indicates a bottom-up row layout in the buffer.  If row_stride is
  1686. ; zero, libpng will calculate it for you from the image width and number of
  1687. ; channels.
  1688.  
  1689. ; Note that the write API does not support interlacing, sub-8-bit pixels or
  1690. ; most ancillary chunks.  If you need to write text chunks (e.g. for copyright
  1691. ; notices) you need to use one of the other APIs.
  1692.  
  1693.  
  1694. ;#define png_image_write_get_memory_size(image, size, convert_to_8_bit, buffer,\
  1695. ;   row_stride, colormap)\
  1696. ;   png_image_write_to_memory(&(image), 0, &(size), convert_to_8_bit, buffer,\
  1697. ;         row_stride, colormap)
  1698. ; Return the amount of memory in 'size' required to compress this image.
  1699. ; The png_image structure 'image' must be filled in as in the above
  1700. ; function and must not be changed before the actual write call, the buffer
  1701. ; and all other parameters must also be identical to that in the final
  1702. ; write call.  The 'size' variable need not be initialized.
  1703.  
  1704. ; NOTE: the macro returns true/false, if false is returned 'size' will be
  1705. ; set to zero and the write failed and probably will fail if tried again.
  1706.  
  1707. ; You can pre-allocate the buffer by making sure it is of sufficient size
  1708. ; regardless of the amount of compression achieved.  The buffer size will
  1709. ; always be bigger than the original image and it will never be filled.  The
  1710. ; following macros are provided to assist in allocating the buffer.
  1711.  
  1712. ;#define PNG_IMAGE_DATA_SIZE(image) (PNG_IMAGE_SIZE(image)+(image).height)
  1713. ; The number of uncompressed bytes in the PNG byte encoding of the image;
  1714. ; uncompressing the PNG IDAT data will give this number of bytes.
  1715.  
  1716. ; NOTE: while PNG_IMAGE_SIZE cannot overflow for an image in memory this
  1717. ; macro can because of the extra bytes used in the PNG byte encoding.  You
  1718. ; need to avoid this macro if your image size approaches 2^30 in width or
  1719. ; height.  The same goes for the remainder of these macros; they all produce
  1720. ; bigger numbers than the actual in-memory image size.
  1721.  
  1722. ;#ifndef PNG_ZLIB_MAX_SIZE
  1723. ;#  define PNG_ZLIB_MAX_SIZE(b) ((b)+(((b)+7U)>>3)+(((b)+63U)>>6)+11U)
  1724. ; An upper bound on the number of compressed bytes given 'b' uncompressed
  1725. ; bytes.  This is based on deflateBounds() in zlib; different
  1726. ; implementations of zlib compression may conceivably produce more data so
  1727. ; if your zlib implementation is not zlib itself redefine this macro
  1728. ; appropriately.
  1729.  
  1730. ;end if
  1731.  
  1732. ;#define PNG_IMAGE_COMPRESSED_SIZE_MAX(image)\
  1733. ;   PNG_ZLIB_MAX_SIZE((png_alloc_size_t)PNG_IMAGE_DATA_SIZE(image))
  1734.         ; An upper bound on the size of the data in the PNG IDAT chunks.
  1735.  
  1736. ;#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\
  1737. ;   ((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\
  1738. ;    (((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\
  1739. ;    12U+3U*(image).colormap_entries/*PLTE data*/+\
  1740. ;    (((image).format&PNG_FORMAT_FLAG_ALPHA)?\
  1741. ;    12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
  1742. ;    12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))
  1743.  
  1744. ; A helper for the following macro; if your compiler cannot handle the
  1745. ; following macro use this one with the result of
  1746. ; PNG_IMAGE_COMPRESSED_SIZE_MAX(image) as the second argument (most
  1747. ; compilers should handle this just fine.)
  1748.  
  1749. ;#define PNG_IMAGE_PNG_SIZE_MAX(image)\
  1750. ;   PNG_IMAGE_PNG_SIZE_MAX_(image, PNG_IMAGE_COMPRESSED_SIZE_MAX(image))
  1751. ; An upper bound on the total length of the PNG data stream for 'image'.
  1752. ; The result is of type png_alloc_size_t, on 32-bit systems this may
  1753. ; overflow even though PNG_IMAGE_DATA_SIZE does not overflow; the write will
  1754. ; run out of buffer space but return a corrected size which should work.
  1755.  
  1756. end if ;SIMPLIFIED_WRITE
  1757. ;/*******************************************************************************
  1758. ;  END OF SIMPLIFIED API
  1759. ; ******************************************************************************/
  1760. ;end if /* SIMPLIFIED_{READ|WRITE} */
  1761.  
  1762. ;/*******************************************************************************
  1763. ; Section 6: IMPLEMENTATION OPTIONS
  1764. ; *******************************************************************************
  1765.  
  1766. ; Support for arbitrary implementation-specific optimizations.  The API allows
  1767. ; particular options to be turned on or off.  'Option' is the number of the
  1768. ; option and 'onoff' is 0 (off) or non-0 (on).  The value returned is given
  1769. ; by the PNG_OPTION_ defines below.
  1770.  
  1771. ; HARDWARE: normally hardware capabilites, such as the Intel SSE instructions,
  1772. ;           are detected at run time, however sometimes it may be impossible
  1773. ;           to do this in user mode, in which case it is necessary to discover
  1774. ;           the capabilities in an OS specific way.  Such capabilities are
  1775. ;           listed here when libpng has support for them and must be turned
  1776. ;           ON by the application if present.
  1777.  
  1778. ; SOFTWARE: sometimes software optimizations actually result in performance
  1779. ;           decrease on some architectures or systems, or with some sets of
  1780. ;           PNG images.  'Software' options allow such optimizations to be
  1781. ;           selected at run time.
  1782.  
  1783. if PNG_SET_OPTION_SUPPORTED eq 1
  1784. if PNG_ARM_NEON_API_SUPPORTED eq 1
  1785.         PNG_ARM_NEON  equ 0 ;HARDWARE: ARM Neon SIMD instructions supported
  1786. end if
  1787. PNG_MAXIMUM_INFLATE_WINDOW equ 2 ;SOFTWARE: force maximum window
  1788. PNG_SKIP_sRGB_CHECK_PROFILE equ 4 ;SOFTWARE: Check ICC profile for sRGB
  1789. if PNG_MIPS_MSA_API_SUPPORTED eq 1
  1790.         PNG_MIPS_MSA  equ 6 ;HARDWARE: MIPS Msa SIMD instructions supported
  1791. end if
  1792. PNG_OPTION_NEXT equ 8 ;Next option - numbers must be even
  1793.  
  1794. ; Return values: NOTE: there are four values and 'off' is *not* zero
  1795. PNG_OPTION_UNSET  equ 0 ;Unset - defaults to off
  1796. PNG_OPTION_INVALID equ 1 ;Option number out of range
  1797. PNG_OPTION_OFF    equ 2
  1798. PNG_OPTION_ON     equ 3
  1799. end if ;SET_OPTION
  1800.  
  1801. ;/*******************************************************************************
  1802. ;  END OF HARDWARE AND SOFTWARE OPTIONS
  1803. ; ******************************************************************************/
  1804.  
  1805. ; Maintainer: Put new public prototypes here ^, in libpng.3, in project
  1806. ; defs, and in scripts/symbols.def.
  1807.  
  1808.  
  1809. ; The last ordinal number (this is the *last* one already used; the next
  1810. ; one to use is one more than this.)
  1811.  
  1812. ;end if /* PNG_VERSION_INFO_ONLY */
  1813. ; Do not put anything past this line
  1814.