Subversion Repositories Kolibri OS

Rev

Rev 6780 | Rev 8341 | 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.         rb 3 ;align
  558.         podata dd ? ;byte* ;Data, should not be modified on read!
  559.         size dd ? ;png_size_t
  560.  
  561.         ; On write 'location' must be set using the flag values listed below.
  562.         ; Notice that on read it is set by libpng however the values stored have
  563.         ; more bits set than are listed below.  Always treat the value as a
  564.         ; bitmask.  On write set only one bit - setting multiple bits may cause the
  565.         ; chunk to be written in multiple places.
  566.  
  567.         location db ? ;byte ;mode of operation at read time
  568. ends
  569. end if
  570.  
  571. ; Flag values for the unknown chunk location byte.
  572. PNG_HAVE_IHDR equ  0x01
  573. PNG_HAVE_PLTE equ  0x02
  574. PNG_AFTER_IDAT equ 0x08
  575.  
  576. ; Maximum positive integer used in PNG is (2^31)-1
  577. PNG_UINT_31_MAX equ 0x7fffffff ;uint_32
  578. PNG_UINT_32_MAX equ -1 ;uint_32
  579. PNG_SIZE_MAX    equ 0x60000000 ;1.5 Gb
  580.  
  581. ; These are constants for fixed point values encoded in the
  582. ; PNG specification manner (x100000)
  583.  
  584. PNG_FP_1   equ 100000
  585. PNG_FP_HALF equ 50000
  586. PNG_FP_MAX equ ((png_fixed_point)0x7fffffffL)
  587. PNG_FP_MIN equ (-PNG_FP_MAX)
  588.  
  589. ; These describe the color_type field in png_info.
  590. ; color type masks
  591. PNG_COLOR_MASK_PALETTE equ 1
  592. PNG_COLOR_MASK_COLOR   equ 2
  593. PNG_COLOR_MASK_ALPHA   equ 4
  594.  
  595. ; color types.  Note that not all combinations are legal
  596. PNG_COLOR_TYPE_GRAY equ 0
  597. PNG_COLOR_TYPE_PALETTE equ (PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_PALETTE)
  598. PNG_COLOR_TYPE_RGB      equ (PNG_COLOR_MASK_COLOR)
  599. PNG_COLOR_TYPE_RGB_ALPHA equ (PNG_COLOR_MASK_COLOR or PNG_COLOR_MASK_ALPHA)
  600. PNG_COLOR_TYPE_GRAY_ALPHA equ (PNG_COLOR_MASK_ALPHA)
  601. ; aliases
  602. PNG_COLOR_TYPE_RGBA equ PNG_COLOR_TYPE_RGB_ALPHA
  603. PNG_COLOR_TYPE_GA equ PNG_COLOR_TYPE_GRAY_ALPHA
  604.  
  605. ; This is for compression type. PNG 1.0-1.2 only define the single type.
  606. PNG_COMPRESSION_TYPE_BASE equ 0 ;Deflate method 8, 32K window
  607. PNG_COMPRESSION_TYPE_DEFAULT equ PNG_COMPRESSION_TYPE_BASE
  608.  
  609. ; This is for filter type. PNG 1.0-1.2 only define the single type.
  610. PNG_FILTER_TYPE_BASE     equ 0 ;Single row per-byte filtering
  611. PNG_INTRAPIXEL_DIFFERENCING equ 64 ;Used only in MNG datastreams
  612. PNG_FILTER_TYPE_DEFAULT  equ PNG_FILTER_TYPE_BASE
  613.  
  614. ; These are for the interlacing type.  These values should NOT be changed.
  615. PNG_INTERLACE_NONE       equ 0 ;Non-interlaced image
  616. PNG_INTERLACE_ADAM7      equ 1 ;Adam7 interlacing
  617. PNG_INTERLACE_LAST       equ 2 ;Not a valid value
  618.  
  619. ; These are for the oFFs chunk.  These values should NOT be changed.
  620. PNG_OFFSET_PIXEL         equ 0 ;Offset in pixels
  621. PNG_OFFSET_MICROMETER    equ 1 ;Offset in micrometers (1/10^6 meter)
  622. PNG_OFFSET_LAST          equ 2 ;Not a valid value
  623.  
  624. ; These are for the pCAL chunk.  These values should NOT be changed.
  625. PNG_EQUATION_LINEAR      equ 0 ;Linear transformation
  626. PNG_EQUATION_BASE_E      equ 1 ;Exponential base e transform
  627. PNG_EQUATION_ARBITRARY   equ 2 ;Arbitrary base exponential transform
  628. PNG_EQUATION_HYPERBOLIC  equ 3 ;Hyperbolic sine transformation
  629. PNG_EQUATION_LAST        equ 4 ;Not a valid value
  630.  
  631. ; These are for the sCAL chunk.  These values should NOT be changed.
  632. PNG_SCALE_UNKNOWN        equ 0 ;unknown unit (image scale)
  633. PNG_SCALE_METER          equ 1 ;meters per pixel
  634. PNG_SCALE_RADIAN         equ 2 ;radians per pixel
  635. PNG_SCALE_LAST           equ 3 ;Not a valid value
  636.  
  637. ; These are for the pHYs chunk.  These values should NOT be changed.
  638. PNG_RESOLUTION_UNKNOWN   equ 0 ;pixels/unknown unit (aspect ratio)
  639. PNG_RESOLUTION_METER     equ 1 ;pixels/meter
  640. PNG_RESOLUTION_LAST      equ 2 ;Not a valid value
  641.  
  642. ; These are for the sRGB chunk.  These values should NOT be changed.
  643. PNG_sRGB_INTENT_PERCEPTUAL equ 0
  644. PNG_sRGB_INTENT_RELATIVE   equ 1
  645. PNG_sRGB_INTENT_SATURATION equ 2
  646. PNG_sRGB_INTENT_ABSOLUTE   equ 3
  647. PNG_sRGB_INTENT_LAST       equ 4 ;Not a valid value
  648.  
  649. ; This is for text chunks
  650. PNG_KEYWORD_MAX_LENGTH equ 79
  651.  
  652. ; Maximum number of entries in PLTE/sPLT/tRNS arrays
  653. PNG_MAX_PALETTE_LENGTH equ 256
  654.  
  655. ; These determine if an ancillary chunk's data has been successfully read
  656. ; from the PNG header, or if the application has filled in the corresponding
  657. ; data in the info_struct to be written into the output file.  The values
  658. ; of the PNG_INFO_<chunk> defines should NOT be changed.
  659.  
  660. PNG_INFO_gAMA equ 0x0001
  661. PNG_INFO_sBIT equ 0x0002
  662. PNG_INFO_cHRM equ 0x0004
  663. PNG_INFO_PLTE equ 0x0008
  664. PNG_INFO_tRNS equ 0x0010
  665. PNG_INFO_bKGD equ 0x0020
  666. PNG_INFO_hIST equ 0x0040
  667. PNG_INFO_pHYs equ 0x0080
  668. PNG_INFO_oFFs equ 0x0100
  669. PNG_INFO_tIME equ 0x0200
  670. PNG_INFO_pCAL equ 0x0400
  671. PNG_INFO_sRGB equ 0x0800 ; GR-P, 0.96a
  672. PNG_INFO_iCCP equ 0x1000 ; ESR, 1.0.6
  673. PNG_INFO_sPLT equ 0x2000 ; ESR, 1.0.6
  674. PNG_INFO_sCAL equ 0x4000 ; ESR, 1.0.6
  675. PNG_INFO_IDAT equ 0x8000 ; ESR, 1.0.6
  676.  
  677. ; This is used for the transformation routines, as some of them
  678. ; change these values for the row.  It also should enable using
  679. ; the routines for other purposes.
  680.  
  681. struct png_row_info ;png_row_info_struct
  682.         width      dd ? ;uint_32 ;width of row
  683.         rowbytes   dd ? ;png_size_t ;number of bytes in row
  684.         color_type db ? ;byte ;color type of row
  685.         bit_depth  db ? ;byte ;bit depth of row
  686.         channels   db ? ;byte ;number of channels (1, 2, 3, or 4)
  687.         pixel_depth db ? ;byte ;bits per pixel (depth * channels)
  688. ends
  689.  
  690. if PNG_SETJMP_SUPPORTED eq 1
  691. ; This must match the function definition in <setjmp.h>, and the application
  692. ; must include this before png.h to obtain the definition of jmp_buf.  The
  693. ; function is required to be PNG_NORETURN, but this is not checked.  If the
  694. ; function does return the application will crash via an abort() or similar
  695. ; system level call.
  696.  
  697. ; If you get a warning here while building the library you may need to make
  698. ; changes to ensure that pnglibconf.h records the calling convention used by
  699. ; your compiler.  This may be very difficult - try using a different compiler
  700. ; to build the library!
  701.  
  702. ;PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);
  703. end if
  704.  
  705. ; Transform masks for the high-level interface
  706. PNG_TRANSFORM_IDENTITY      equ 0x0000 ; read and write
  707. PNG_TRANSFORM_STRIP_16      equ 0x0001 ; read only
  708. PNG_TRANSFORM_STRIP_ALPHA   equ 0x0002 ; read only
  709. PNG_TRANSFORM_PACKING       equ 0x0004 ; read and write
  710. PNG_TRANSFORM_PACKSWAP      equ 0x0008 ; read and write
  711. PNG_TRANSFORM_EXPAND        equ 0x0010 ; read only
  712. PNG_TRANSFORM_INVERT_MONO   equ 0x0020 ; read and write
  713. PNG_TRANSFORM_SHIFT         equ 0x0040 ; read and write
  714. PNG_TRANSFORM_BGR           equ 0x0080 ; read and write
  715. PNG_TRANSFORM_SWAP_ALPHA    equ 0x0100 ; read and write
  716. PNG_TRANSFORM_SWAP_ENDIAN   equ 0x0200 ; read and write
  717. PNG_TRANSFORM_INVERT_ALPHA  equ 0x0400 ; read and write
  718. PNG_TRANSFORM_STRIP_FILLER  equ 0x0800 ; write only
  719. ; Added to libpng-1.2.34
  720. PNG_TRANSFORM_STRIP_FILLER_BEFORE equ PNG_TRANSFORM_STRIP_FILLER
  721. PNG_TRANSFORM_STRIP_FILLER_AFTER equ 0x1000 ; write only
  722. ; Added to libpng-1.4.0
  723. PNG_TRANSFORM_GRAY_TO_RGB  equ 0x2000 ; read only
  724. ; Added to libpng-1.5.4
  725. PNG_TRANSFORM_EXPAND_16    equ 0x4000 ;read only
  726. ;if INT_MAX >= 0x8000 ;else this might break
  727. PNG_TRANSFORM_SCALE_16     equ 0x8000 ;read only
  728. ;end if
  729.  
  730. ; Flags for MNG supported features
  731. PNG_FLAG_MNG_EMPTY_PLTE    equ 0x01
  732. PNG_FLAG_MNG_FILTER_64     equ 0x04
  733. PNG_ALL_MNG_FEATURES       equ 0x05
  734.  
  735. ; NOTE: prior to 1.5 these functions had no 'API' style declaration,
  736. ; this allowed the zlib default functions to be used on Windows
  737. ; platforms.  In 1.5 the zlib default malloc (which just calls malloc and
  738. ; ignores the first argument) should be completely compatible with the
  739. ; following.
  740.  
  741. ; Section 4: exported functions
  742. ; Here are the function definitions most commonly used.  This is not
  743. ; the place to find out how to use libpng.  See libpng-manual.txt for the
  744. ; full explanation, see example.c for the summary.  This just provides
  745. ; a simple one line description of the use of each function.
  746.  
  747.  
  748.  
  749. ; Simple signature checking function.  This is the same as calling
  750. ; png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
  751.  
  752. ;#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
  753.  
  754. macro png_setup_abs sum
  755. {
  756. local .end0
  757.         and eax,0xff
  758. if PNG_USE_ABS eq 1
  759.         add sum,128
  760.         sub al,128 ;v - 128
  761.         cmp al,128
  762.         jl @f
  763.                 neg al
  764.                 inc al ;abs(v - 128)
  765.         @@:
  766.         sub sum,eax
  767. else
  768.         cmp eax,128
  769.         jl @f
  770.                 add sum,256
  771.                 sub sum,eax
  772.                 jmp .end0
  773.         @@:
  774.                 add sum,eax
  775.         .end0:
  776. end if
  777. }
  778.  
  779. ; Reduce RGB to grayscale.
  780. PNG_ERROR_ACTION_NONE equ 1
  781. PNG_ERROR_ACTION_WARN equ 2
  782. PNG_ERROR_ACTION_ERROR equ 3
  783. PNG_RGB_TO_GRAY_DEFAULT equ (-1) ;for red/green coefficients
  784.  
  785. ; How the alpha channel is interpreted - this affects how the color channels
  786. ; of a PNG file are returned to the calling application when an alpha channel,
  787. ; or a tRNS chunk in a palette file, is present.
  788.  
  789. ; This has no effect on the way pixels are written into a PNG output
  790. ; datastream. The color samples in a PNG datastream are never premultiplied
  791. ; with the alpha samples.
  792.  
  793. ; The default is to return data according to the PNG specification: the alpha
  794. ; channel is a linear measure of the contribution of the pixel to the
  795. ; corresponding composited pixel, and the color channels are unassociated
  796. ; (not premultiplied).  The gamma encoded color channels must be scaled
  797. ; according to the contribution and to do this it is necessary to undo
  798. ; the encoding, scale the color values, perform the composition and reencode
  799. ; the values.  This is the 'PNG' mode.
  800.  
  801. ; The alternative is to 'associate' the alpha with the color information by
  802. ; storing color channel values that have been scaled by the alpha.
  803. ; image.  These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes
  804. ; (the latter being the two common names for associated alpha color channels).
  805.  
  806. ; For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha
  807. ; value is equal to the maximum value.
  808.  
  809. ; The final choice is to gamma encode the alpha channel as well.  This is
  810. ; broken because, in practice, no implementation that uses this choice
  811. ; correctly undoes the encoding before handling alpha composition.  Use this
  812. ; choice only if other serious errors in the software or hardware you use
  813. ; mandate it; the typical serious error is for dark halos to appear around
  814. ; opaque areas of the composited PNG image because of arithmetic overflow.
  815.  
  816. ; The API function png_set_alpha_mode specifies which of these choices to use
  817. ; with an enumerated 'mode' value and the gamma of the required output:
  818.  
  819. PNG_ALPHA_PNG          equ 0 ;according to the PNG standard
  820. PNG_ALPHA_STANDARD     equ 1 ;according to Porter/Duff
  821. PNG_ALPHA_ASSOCIATED   equ 1 ;as above; this is the normal practice
  822. PNG_ALPHA_PREMULTIPLIED equ 1 ;as above
  823. PNG_ALPHA_OPTIMIZED    equ 2 ;'PNG' for opaque pixels, else 'STANDARD'
  824. PNG_ALPHA_BROKEN       equ 3 ;the alpha channel is gamma encoded
  825.  
  826. if (PNG_GAMMA_SUPPORTED eq 1) | (PNG_READ_ALPHA_MODE_SUPPORTED eq 1)
  827. ; The output_gamma value is a screen gamma in libpng terminology: it expresses
  828. ; how to decode the output values, not how they are encoded.
  829.  
  830. PNG_DEFAULT_sRGB equ -1       ;sRGB gamma and color space
  831. PNG_GAMMA_MAC_18 equ -2       ;Old Mac '1.8' gamma and color space
  832. PNG_GAMMA_sRGB   equ 220000   ;Television standards--matches sRGB gamma
  833. PNG_GAMMA_LINEAR equ PNG_FP_1 ;Linear
  834. end if
  835.  
  836. ; The values of the PNG_FILLER_ defines should NOT be changed
  837. PNG_FILLER_BEFORE equ 0
  838. PNG_FILLER_AFTER equ 1
  839.  
  840. ;#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  841.  
  842. ; Handle alpha and tRNS by replacing with a background color.  Prior to
  843. ; libpng-1.5.4 this API must not be called before the PNG file header has been
  844. ; read.  Doing so will result in unexpected behavior and possible warnings or
  845. ; errors if the PNG file contains a bKGD chunk.
  846.  
  847. if PNG_READ_BACKGROUND_SUPPORTED eq 1
  848. PNG_BACKGROUND_GAMMA_UNKNOWN equ 0
  849. PNG_BACKGROUND_GAMMA_SCREEN equ 1
  850. PNG_BACKGROUND_GAMMA_FILE   equ 2
  851. PNG_BACKGROUND_GAMMA_UNIQUE equ 3
  852. end if
  853.  
  854. ;PNG_READ_16_TO_8_SUPPORTED equ 1 ;Name prior to 1.5.4
  855.  
  856. ; The threshold on gamma processing is configurable but hard-wired into the
  857. ; library.  The following is the floating point variant.
  858.  
  859. PNG_GAMMA_THRESHOLD equ (PNG_GAMMA_THRESHOLD_FIXED*.00001)
  860.  
  861. ; Handle gamma correction. Screen_gamma=(display_exponent).
  862. ; NOTE: this API simply sets the screen and file gamma values. It will
  863. ; therefore override the value for gamma in a PNG file if it is called after
  864. ; the file header has been read - use with care  - call before reading the PNG
  865. ; file for best results!
  866.  
  867.  
  868. ; Values for png_set_crc_action() say how to handle CRC errors in
  869. ; ancillary and critical chunks, and whether to use the data contained
  870. ; therein.  Note that it is impossible to "discard" data in a critical
  871. ; chunk.  For versions prior to 0.90, the action was always error/quit,
  872. ; whereas in version 0.90 and later, the action for CRC errors in ancillary
  873. ; chunks is warn/discard.  These values should NOT be changed.
  874.  
  875. ;      value                       action:critical     action:ancillary
  876.  
  877. PNG_CRC_DEFAULT      equ 0 ;error/quit          warn/discard data
  878. PNG_CRC_ERROR_QUIT   equ 1 ;error/quit          error/quit
  879. PNG_CRC_WARN_DISCARD equ 2 ;(INVALID)           warn/discard data
  880. PNG_CRC_WARN_USE     equ 3 ;warn/use data       warn/use data
  881. PNG_CRC_QUIET_USE    equ 4 ;quiet/use data      quiet/use data
  882. PNG_CRC_NO_CHANGE    equ 5 ;use current value   use current value
  883.  
  884. ; Flags for png_set_filter() to say which filters to use.  The flags
  885. ; are chosen so that they don't conflict with real filter types
  886. ; below, in case they are supplied instead of the #defined constants.
  887. ; These values should NOT be changed.
  888.  
  889. PNG_NO_FILTERS   equ 0x00
  890. PNG_FILTER_NONE  equ 0x08
  891. PNG_FILTER_SUB   equ 0x10
  892. PNG_FILTER_UP    equ 0x20
  893. PNG_FILTER_AVG   equ 0x40
  894. PNG_FILTER_PAETH equ 0x80
  895. PNG_FAST_FILTERS equ (PNG_FILTER_NONE or PNG_FILTER_SUB or PNG_FILTER_UP)
  896. PNG_ALL_FILTERS  equ (PNG_FAST_FILTERS or PNG_FILTER_AVG or PNG_FILTER_PAETH)
  897.  
  898. ; Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
  899. ; These defines should NOT be changed.
  900.  
  901. PNG_FILTER_VALUE_NONE equ 0
  902. PNG_FILTER_VALUE_SUB  equ 1
  903. PNG_FILTER_VALUE_UP   equ 2
  904. PNG_FILTER_VALUE_AVG  equ 3
  905. PNG_FILTER_VALUE_PAETH equ 4
  906. PNG_FILTER_VALUE_LAST equ 5
  907.  
  908. ; The following are no longer used and will be removed from libpng-1.7:
  909. PNG_FILTER_HEURISTIC_DEFAULT   equ 0 ;Currently "UNWEIGHTED"
  910. PNG_FILTER_HEURISTIC_UNWEIGHTED equ 1 ;Used by libpng < 0.95
  911. PNG_FILTER_HEURISTIC_WEIGHTED  equ 2 ;Experimental feature
  912. PNG_FILTER_HEURISTIC_LAST      equ 3 ;Not a valid value
  913.  
  914. ; It is unlikely that this function works correctly as of 1.6.0 and using it
  915. ; may result either in memory leaks or double free of allocated data.
  916.  
  917. ; Assignments for png_data_freer
  918. PNG_DESTROY_WILL_FREE_DATA equ 1
  919. PNG_SET_WILL_FREE_DATA equ 1
  920. PNG_USER_WILL_FREE_DATA equ 2
  921. ; Flags for png_ptr->free_me and info_ptr->free_me
  922. PNG_FREE_HIST equ 0x0008
  923. PNG_FREE_ICCP equ 0x0010
  924. PNG_FREE_SPLT equ 0x0020
  925. PNG_FREE_ROWS equ 0x0040
  926. PNG_FREE_PCAL equ 0x0080
  927. PNG_FREE_SCAL equ 0x0100
  928. if PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED eq 1
  929.         PNG_FREE_UNKN equ 0x0200
  930. end if
  931. PNG_FREE_LIST equ 0x0400 ;removed in 1.6.0 because it is ignored
  932. PNG_FREE_PLTE equ 0x1000
  933. PNG_FREE_TRNS equ 0x2000
  934. PNG_FREE_TEXT equ 0x4000
  935. PNG_FREE_ALL  equ 0x7fff
  936. PNG_FREE_MUL  equ 0x4220 ;PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN
  937.  
  938. ;if PNG_ERROR_TEXT_SUPPORTED
  939.  
  940. ;#else
  941. ;#  define png_chunk_error(s1,s2) png_err(s1)
  942. ;end if
  943.  
  944. ;#else
  945. ;#  define png_warning(s1,s2) ((void)(s1))
  946. ;#  define png_chunk_warning(s1,s2) ((void)(s1))
  947.  
  948. ;if PNG_READ_SUPPORTED
  949.  
  950. ;#else
  951. ;#  ifdef PNG_ALLOW_BENIGN_ERRORS
  952. macro png_benign_error h,txt
  953. {
  954.         png_warning h,txt
  955. }
  956. ;#    define png_chunk_benign_error png_chunk_warning
  957. ;#  else
  958. ;#    define png_benign_error png_error
  959. ;#    define png_chunk_benign_error png_chunk_error
  960. ;#  endif
  961. ;end if
  962.  
  963.  
  964. ; Provide the default handling for all unknown chunks or, optionally, for
  965. ; specific unknown chunks.
  966.  
  967. ; NOTE: prior to 1.6.0 the handling specified for particular chunks on read was
  968. ; ignored and the default was used, the per-chunk setting only had an effect on
  969. ; write.  If you wish to have chunk-specific handling on read in code that must
  970. ; work on earlier versions you must use a user chunk callback to specify the
  971. ; desired handling (keep or discard.)
  972.  
  973. ; The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below.  The
  974. ; parameter is interpreted as follows:
  975.  
  976. ; READ:
  977. ;    PNG_HANDLE_CHUNK_AS_DEFAULT:
  978. ;       Known chunks: do normal libpng processing, do not keep the chunk (but
  979. ;          see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
  980. ;       Unknown chunks: for a specific chunk use the global default, when used
  981. ;          as the default discard the chunk data.
  982. ;    PNG_HANDLE_CHUNK_NEVER:
  983. ;       Discard the chunk data.
  984. ;    PNG_HANDLE_CHUNK_IF_SAFE:
  985. ;       Keep the chunk data if the chunk is not critical else raise a chunk
  986. ;       error.
  987. ;    PNG_HANDLE_CHUNK_ALWAYS:
  988. ;       Keep the chunk data.
  989.  
  990. ; If the chunk data is saved it can be retrieved using png_get_unknown_chunks,
  991. ; below.  Notice that specifying "AS_DEFAULT" as a global default is equivalent
  992. ; to specifying "NEVER", however when "AS_DEFAULT" is used for specific chunks
  993. ; it simply resets the behavior to the libpng default.
  994.  
  995. ; INTERACTION WTIH USER CHUNK CALLBACKS:
  996. ; The per-chunk handling is always used when there is a png_user_chunk_ptr
  997. ; callback and the callback returns 0; the chunk is then always stored *unless*
  998. ; it is critical and the per-chunk setting is other than ALWAYS.  Notice that
  999. ; the global default is *not* used in this case.  (In effect the per-chunk
  1000. ; value is incremented to at least IF_SAFE.)
  1001.  
  1002. ; IMPORTANT NOTE: this behavior will change in libpng 1.7 - the global and
  1003. ; per-chunk defaults will be honored.  If you want to preserve the current
  1004. ; behavior when your callback returns 0 you must set PNG_HANDLE_CHUNK_IF_SAFE
  1005. ; as the default - if you don't do this libpng 1.6 will issue a warning.
  1006.  
  1007. ; If you want unhandled unknown chunks to be discarded in libpng 1.6 and
  1008. ; earlier simply return '1' (handled).
  1009.  
  1010. ; PNG_HANDLE_AS_UNKNOWN_SUPPORTED:
  1011. ;    If this is *not* set known chunks will always be handled by libpng and
  1012. ;    will never be stored in the unknown chunk list.  Known chunks listed to
  1013. ;    png_set_keep_unknown_chunks will have no effect.  If it is set then known
  1014. ;    chunks listed with a keep other than AS_DEFAULT will *never* be processed
  1015. ;    by libpng, in addition critical chunks must either be processed by the
  1016. ;    callback or saved.
  1017.  
  1018. ;    The IHDR and IEND chunks must not be listed.  Because this turns off the
  1019. ;    default handling for chunks that would otherwise be recognized the
  1020. ;    behavior of libpng transformations may well become incorrect!
  1021.  
  1022. ; WRITE:
  1023. ;    When writing chunks the options only apply to the chunks specified by
  1024. ;    png_set_unknown_chunks (below), libpng will *always* write known chunks
  1025. ;    required by png_set_ calls and will always write the core critical chunks
  1026. ;    (as required for PLTE).
  1027.  
  1028. ;    Each chunk in the png_set_unknown_chunks list is looked up in the
  1029. ;    png_set_keep_unknown_chunks list to find the keep setting, this is then
  1030. ;    interpreted as follows:
  1031.  
  1032. ;    PNG_HANDLE_CHUNK_AS_DEFAULT:
  1033. ;       Write safe-to-copy chunks and write other chunks if the global
  1034. ;       default is set to _ALWAYS, otherwise don't write this chunk.
  1035. ;    PNG_HANDLE_CHUNK_NEVER:
  1036. ;       Do not write the chunk.
  1037. ;    PNG_HANDLE_CHUNK_IF_SAFE:
  1038. ;       Write the chunk if it is safe-to-copy, otherwise do not write it.
  1039. ;    PNG_HANDLE_CHUNK_ALWAYS:
  1040. ;       Write the chunk.
  1041.  
  1042. ; Note that the default behavior is effectively the opposite of the read case -
  1043. ; in read unknown chunks are not stored by default, in write they are written
  1044. ; by default.  Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different
  1045. ; - on write the safe-to-copy bit is checked, on read the critical bit is
  1046. ; checked and on read if the chunk is critical an error will be raised.
  1047.  
  1048. ; num_chunks:
  1049. ; ===========
  1050. ;    If num_chunks is positive, then the "keep" parameter specifies the manner
  1051. ;    for handling only those chunks appearing in the chunk_list array,
  1052. ;    otherwise the chunk list array is ignored.
  1053.  
  1054. ;    If num_chunks is 0 the "keep" parameter specifies the default behavior for
  1055. ;    unknown chunks, as described above.
  1056.  
  1057. ;    If num_chunks is negative, then the "keep" parameter specifies the manner
  1058. ;    for handling all unknown chunks plus all chunks recognized by libpng
  1059. ;    except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to
  1060. ;    be processed by libpng.
  1061.  
  1062.  
  1063. ; For use in png_set_keep_unknown, added to version 1.2.6
  1064. PNG_HANDLE_CHUNK_AS_DEFAULT  equ 0
  1065. PNG_HANDLE_CHUNK_NEVER       equ 1
  1066. PNG_HANDLE_CHUNK_IF_SAFE     equ 2
  1067. PNG_HANDLE_CHUNK_ALWAYS      equ 3
  1068. PNG_HANDLE_CHUNK_LAST        equ 4
  1069.  
  1070. ; Removed from libpng 1.6; use png_get_io_chunk_type.
  1071. ;PNG_REMOVED(200, bytep, png_get_io_chunk_name, (png_structrp png_ptr),
  1072. ;    PNG_DEPRECATED)
  1073.  
  1074. ; The flags returned by png_get_io_state() are the following:
  1075. PNG_IO_NONE        equ 0x0000 ; no I/O at this moment
  1076. PNG_IO_READING     equ 0x0001 ; currently reading
  1077. PNG_IO_WRITING     equ 0x0002 ; currently writing
  1078. PNG_IO_SIGNATURE   equ 0x0010 ; currently at the file signature
  1079. PNG_IO_CHUNK_HDR   equ 0x0020 ; currently at the chunk header
  1080. PNG_IO_CHUNK_DATA  equ 0x0040 ; currently at the chunk data
  1081. PNG_IO_CHUNK_CRC   equ 0x0080 ; currently at the chunk crc
  1082. PNG_IO_MASK_OP     equ 0x000f ; current operation: reading/writing
  1083. PNG_IO_MASK_LOC    equ 0x00f0 ; current location: sig/hdr/data/crc
  1084. ;end if /* IO_STATE */
  1085.  
  1086. ; Interlace support.  The following macros are always defined so that if
  1087. ; libpng interlace handling is turned off the macros may be used to handle
  1088. ; interlaced images within the application.
  1089.  
  1090. PNG_INTERLACE_ADAM7_PASSES equ 7
  1091.  
  1092. ; Two macros to return the first row and first column of the original,
  1093. ; full, image which appears in a given pass.  'pass' is in the range 0
  1094. ; to 6 and the result is in the range 0 to 7.
  1095.  
  1096. macro PNG_PASS_START_ROW pass
  1097. {
  1098.         push ebx ecx
  1099.         mov eax,pass
  1100.         mov ebx,eax
  1101.         not eax
  1102.         and eax,1
  1103.         shr ebx,1
  1104.         mov ecx,3
  1105.         sub ecx,ebx
  1106.         shl eax,cl
  1107.         and eax,7
  1108.         pop ecx ebx
  1109. }
  1110. macro PNG_PASS_START_COL pass
  1111. {
  1112.         push ebx ecx
  1113.         mov eax,pass
  1114.         mov ebx,eax
  1115.         and eax,1
  1116.         inc ebx
  1117.         shr ebx,1
  1118.         mov ecx,3
  1119.         sub ecx,ebx
  1120.         shl eax,cl
  1121.         and eax,7
  1122.         pop ecx ebx
  1123. }
  1124.  
  1125. ; A macro to return the offset between pixels in the output row for a pair of
  1126. ; pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that
  1127. ; follows.  Note that ROW_OFFSET is the offset from one row to the next whereas
  1128. ; COL_OFFSET is from one column to the next, within a row.
  1129.  
  1130. ;#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8)
  1131. ;#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1))
  1132.  
  1133. ; Two macros to help evaluate the number of rows or columns in each
  1134. ; pass.  This is expressed as a shift - effectively log2 of the number or
  1135. ; rows or columns in each 8x8 tile of the original image.
  1136.  
  1137. macro PNG_PASS_ROW_SHIFT pass
  1138. {
  1139. local .end0
  1140.         mov eax,3
  1141.         cmp pass,2
  1142.         jle .end0
  1143.                 mov eax,8
  1144.                 sub eax,pass
  1145.                 shr eax,1
  1146.         .end0:
  1147. }
  1148. macro PNG_PASS_COL_SHIFT pass
  1149. {
  1150. local .end0
  1151.         mov eax,3
  1152.         cmp pass,1
  1153.         jle .end0
  1154.                 mov eax,7
  1155.                 sub eax,pass
  1156.                 shr eax,1
  1157.         .end0:
  1158. }
  1159.  
  1160. ; Hence two macros to determine the number of rows or columns in a given
  1161. ; pass of an image given its height or width.  In fact these macros may
  1162. ; return non-zero even though the sub-image is empty, because the other
  1163. ; dimension may be empty for a small image.
  1164.  
  1165. macro PNG_PASS_ROWS height, pass
  1166. {
  1167. push ecx
  1168. push ebx
  1169.         PNG_PASS_START_ROW pass
  1170.         mov ebx,eax
  1171.         PNG_PASS_ROW_SHIFT pass
  1172.         mov ecx,eax
  1173.         xor eax,eax
  1174.         inc eax
  1175.         shl eax,cl
  1176.         dec eax
  1177.         sub eax,ebx
  1178. pop ebx
  1179.         add eax,height
  1180.         shr eax,cl
  1181. pop ecx
  1182. }
  1183. macro PNG_PASS_COLS width, pass
  1184. {
  1185. push ecx
  1186. push ebx
  1187.         PNG_PASS_START_COL pass
  1188.         mov ebx,eax
  1189.         PNG_PASS_COL_SHIFT pass
  1190.         mov ecx,eax
  1191.         xor eax,eax
  1192.         inc eax
  1193.         shl eax,cl
  1194.         dec eax
  1195.         sub eax,ebx
  1196. pop ebx
  1197.         add eax,width
  1198.         shr eax,cl
  1199. pop ecx
  1200. }
  1201.  
  1202. ; For the reader row callbacks (both progressive and sequential) it is
  1203. ; necessary to find the row in the output image given a row in an interlaced
  1204. ; image, so two more macros:
  1205.  
  1206. ;#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \
  1207. ;   (((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
  1208. ;#define PNG_COL_FROM_PASS_COL(x_in, pass) \
  1209. ;   (((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
  1210.  
  1211. ; Two macros which return a boolean (0 or 1) saying whether the given row
  1212. ; or column is in a particular pass.  These use a common utility macro that
  1213. ; returns a mask for a given pass - the offset 'off' selects the row or
  1214. ; column version.  The mask has the appropriate bit set for each column in
  1215. ; the tile.
  1216.  
  1217. ;#define PNG_PASS_MASK(pass,off) ( \
  1218. ;   ((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \
  1219. ;   ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0))
  1220.  
  1221. ;#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
  1222. ;   ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
  1223. ;#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
  1224. ;   ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
  1225.  
  1226. ;if PNG_READ_COMPOSITE_NODIV_SUPPORTED
  1227. ; With these routines we avoid an integer divide, which will be slower on
  1228. ; most machines.  However, it does take more operations than the corresponding
  1229. ; divide method, so it may be slower on a few RISC systems.  There are two
  1230. ; shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
  1231.  
  1232. ; Note that the rounding factors are NOT supposed to be the same!  128 and
  1233. ; 32768 are correct for the NODIV code; 127 and 32767 are correct for the
  1234. ; standard method.
  1235.  
  1236. ; [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
  1237.  
  1238.  
  1239. ; fg and bg should be in `gamma 1.0' space; alpha is the opacity
  1240.  
  1241. ;#  define png_composite(composite, fg, alpha, bg)        \
  1242. ;   {                                                     \
  1243. ;      uint_16 temp = (uint_16)((uint_16)(fg) \
  1244. ;          * (uint_16)(alpha)                         \
  1245. ;          + (uint_16)(bg)*(uint_16)(255          \
  1246. ;          - (uint_16)(alpha)) + 128);                \
  1247. ;      (composite) = (byte)(((temp + (temp >> 8)) >> 8) & 0xff); \
  1248. ;   }
  1249.  
  1250. ;#  define png_composite_16(composite, fg, alpha, bg)     \
  1251. ;   {                                                     \
  1252. ;      uint_32 temp = (uint_32)((uint_32)(fg) \
  1253. ;          * (uint_32)(alpha)                         \
  1254. ;          + (uint_32)(bg)*(65535                     \
  1255. ;          - (uint_32)(alpha)) + 32768);              \
  1256. ;      (composite) = (uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); \
  1257. ;   }
  1258.  
  1259. ;#else  /* Standard method using integer division */
  1260.  
  1261. ;#  define png_composite(composite, fg, alpha, bg)                      \
  1262. ;   (composite) =                                                       \
  1263. ;       (byte)(0xff & (((uint_16)(fg) * (uint_16)(alpha) +  \
  1264. ;       (uint_16)(bg) * (uint_16)(255 - (uint_16)(alpha)) + \
  1265. ;       127) / 255))
  1266.  
  1267. ;#  define png_composite_16(composite, fg, alpha, bg)                       \
  1268. ;   (composite) =                                                           \
  1269. ;       (uint_16)(0xffff & (((uint_32)(fg) * (uint_32)(alpha) + \
  1270. ;       (uint_32)(bg)*(uint_32)(65535 - (uint_32)(alpha)) +     \
  1271. ;       32767) / 65535))
  1272. ;end if /* READ_COMPOSITE_NODIV */
  1273.  
  1274. if PNG_USE_READ_MACROS eq 1
  1275. ; Inline macros to do direct reads of bytes from the input buffer.
  1276. ; The png_get_int_32() routine assumes we are using two's complement
  1277. ; format for negative values, which is almost certainly true.
  1278.  
  1279. ;#  define PNG_get_uint_32(buf) \
  1280. ;   (((uint_32)(*(buf)) << 24) + \
  1281. ;    ((uint_32)(*((buf) + 1)) << 16) + \
  1282. ;    ((uint_32)(*((buf) + 2)) << 8) + \
  1283. ;    ((uint_32)(*((buf) + 3))))
  1284.  
  1285.         ; From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
  1286.         ; function) incorrectly returned a value of type uint_32.
  1287.  
  1288. ;#  define PNG_get_uint_16(buf) \
  1289. ;   ((uint_16) \
  1290. ;    (((unsigned int)(*(buf)) << 8) + \
  1291. ;    ((unsigned int)(*((buf) + 1)))))
  1292.  
  1293. ;#  define PNG_get_int_32(buf) \
  1294. ;   ((int_32)((*(buf) & 0x80) \
  1295. ;    ? -((int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \
  1296. ;    : (int_32)png_get_uint_32(buf)))
  1297. end if
  1298.  
  1299. ;/*******************************************************************************
  1300. ; Section 5: SIMPLIFIED API
  1301. ; *******************************************************************************
  1302.  
  1303. ; Please read the documentation in libpng-manual.txt (TODO: write said
  1304. ; documentation) if you don't understand what follows.
  1305.  
  1306. ; The simplified API hides the details of both libpng and the PNG file format
  1307. ; itself.  It allows PNG files to be read into a very limited number of
  1308. ; in-memory bitmap formats or to be written from the same formats.  If these
  1309. ; formats do not accomodate your needs then you can, and should, use the more
  1310. ; sophisticated APIs above - these support a wide variety of in-memory formats
  1311. ; and a wide variety of sophisticated transformations to those formats as well
  1312. ; as a wide variety of APIs to manipulate ancillary information.
  1313.  
  1314. ; To read a PNG file using the simplified API:
  1315.  
  1316. ; 1) Declare a 'png_image' structure (see below) on the stack, set the
  1317. ;    version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL
  1318. ;    (this is REQUIRED, your program may crash if you don't do it.)
  1319. ; 2) Call the appropriate png_image_begin_read... function.
  1320. ; 3) Set the png_image 'format' member to the required sample format.
  1321. ; 4) Allocate a buffer for the image and, if required, the color-map.
  1322. ; 5) Call png_image_finish_read to read the image and, if required, the
  1323. ;    color-map into your buffers.
  1324.  
  1325. ; There are no restrictions on the format of the PNG input itself; all valid
  1326. ; color types, bit depths, and interlace methods are acceptable, and the
  1327. ; input image is transformed as necessary to the requested in-memory format
  1328. ; during the png_image_finish_read() step.  The only caveat is that if you
  1329. ; request a color-mapped image from a PNG that is full-color or makes
  1330. ; complex use of an alpha channel the transformation is extremely lossy and the
  1331. ; result may look terrible.
  1332.  
  1333. ; To write a PNG file using the simplified API:
  1334.  
  1335. ; 1) Declare a 'png_image' structure on the stack and memset() it to all zero.
  1336. ; 2) Initialize the members of the structure that describe the image, setting
  1337. ;    the 'format' member to the format of the image samples.
  1338. ; 3) Call the appropriate png_image_write... function with a pointer to the
  1339. ;    image and, if necessary, the color-map to write the PNG data.
  1340.  
  1341. ; png_image is a structure that describes the in-memory format of an image
  1342. ; when it is being read or defines the in-memory format of an image that you
  1343. ; need to write:
  1344.  
  1345. ;#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \
  1346. ;    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
  1347.  
  1348. PNG_IMAGE_VERSION equ 1
  1349.  
  1350. struct png_image
  1351.         opaque  dd ? ;png_controlp ;Initialize to NULL, free with png_image_free
  1352.         version dd ? ;uint_32  ;Set to PNG_IMAGE_VERSION
  1353.         width   dd ? ;uint_32  ;Image width in pixels (columns)
  1354.         height  dd ? ;uint_32  ;Image height in pixels (rows)
  1355.         format  dd ? ;uint_32  ;Image format as defined below
  1356.         flags   dd ? ;uint_32  ;A bit mask containing informational flags
  1357.         colormap_entries dd ? ;uint_32 ;Number of entries in the color-map
  1358.  
  1359.         ; In the event of an error or warning the following field will be set to a
  1360.         ; non-zero value and the 'message' field will contain a '\0' terminated
  1361.         ; string with the libpng error or warning message.  If both warnings and
  1362.         ; an error were encountered, only the error is recorded.  If there
  1363.         ; are multiple warnings, only the first one is recorded.
  1364.  
  1365.         ; The upper 30 bits of this value are reserved, the low two bits contain
  1366.         ; a value as follows:
  1367.  
  1368. PNG_IMAGE_WARNING equ 1
  1369. PNG_IMAGE_ERROR equ 2
  1370.  
  1371. ; The result is a two-bit code such that a value more than 1 indicates
  1372. ; a failure in the API just called:
  1373.  
  1374. ;    0 - no warning or error
  1375. ;    1 - warning
  1376. ;    2 - error
  1377. ;    3 - error preceded by warning
  1378.  
  1379. ;#  define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1)
  1380.  
  1381.         warning_or_error dd ? ;uint_32
  1382.         message rb 64 ;char[64]
  1383. ends
  1384.  
  1385. ; The samples of the image have one to four channels whose components have
  1386. ; original values in the range 0 to 1.0:
  1387.  
  1388. ; 1: A single gray or luminance channel (G).
  1389. ; 2: A gray/luminance channel and an alpha channel (GA).
  1390. ; 3: Three red, green, blue color channels (RGB).
  1391. ; 4: Three color channels and an alpha channel (RGBA).
  1392.  
  1393. ; The components are encoded in one of two ways:
  1394.  
  1395. ; a) As a small integer, value 0..255, contained in a single byte.  For the
  1396. ; alpha channel the original value is simply value/255.  For the color or
  1397. ; luminance channels the value is encoded according to the sRGB specification
  1398. ; and matches the 8-bit format expected by typical display devices.
  1399.  
  1400. ; The color/gray channels are not scaled (pre-multiplied) by the alpha
  1401. ; channel and are suitable for passing to color management software.
  1402.  
  1403. ; b) As a value in the range 0..65535, contained in a 2-byte integer.  All
  1404. ; channels can be converted to the original value by dividing by 65535; all
  1405. ; channels are linear.  Color channels use the RGB encoding (RGB end-points) of
  1406. ; the sRGB specification.  This encoding is identified by the
  1407. ; PNG_FORMAT_FLAG_LINEAR flag below.
  1408.  
  1409. ; When the simplified API needs to convert between sRGB and linear colorspaces,
  1410. ; the actual sRGB transfer curve defined in the sRGB specification (see the
  1411. ; article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
  1412. ; approximation used elsewhere in libpng.
  1413.  
  1414. ; When an alpha channel is present it is expected to denote pixel coverage
  1415. ; of the color or luminance channels and is returned as an associated alpha
  1416. ; channel: the color/gray channels are scaled (pre-multiplied) by the alpha
  1417. ; value.
  1418.  
  1419. ; The samples are either contained directly in the image data, between 1 and 8
  1420. ; bytes per pixel according to the encoding, or are held in a color-map indexed
  1421. ; by bytes in the image data.  In the case of a color-map the color-map entries
  1422. ; are individual samples, encoded as above, and the image data has one byte per
  1423. ; pixel to select the relevant sample from the color-map.
  1424.  
  1425.  
  1426. ; PNG_FORMAT_*
  1427.  
  1428. ; #defines to be used in png_image::format.  Each #define identifies a
  1429. ; particular layout of sample data and, if present, alpha values.  There are
  1430. ; separate defines for each of the two component encodings.
  1431.  
  1432. ; A format is built up using single bit flag values.  All combinations are
  1433. ; valid.  Formats can be built up from the flag values or you can use one of
  1434. ; the predefined values below.  When testing formats always use the FORMAT_FLAG
  1435. ; macros to test for individual features - future versions of the library may
  1436. ; add new flags.
  1437.  
  1438. ; When reading or writing color-mapped images the format should be set to the
  1439. ; format of the entries in the color-map then png_image_{read,write}_colormap
  1440. ; called to read or write the color-map and set the format correctly for the
  1441. ; image data.  Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!
  1442.  
  1443. ; NOTE: libpng can be built with particular features disabled. If you see
  1444. ; compiler errors because the definition of one of the following flags has been
  1445. ; compiled out it is because libpng does not have the required support.  It is
  1446. ; possible, however, for the libpng configuration to enable the format on just
  1447. ; read or just write; in that case you may see an error at run time.  You can
  1448. ; guard against this by checking for the definition of the appropriate
  1449. ; "_SUPPORTED" macro, one of:
  1450.  
  1451. ;    PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED
  1452.  
  1453. PNG_FORMAT_FLAG_ALPHA    equ 0x01 ;format with an alpha channel
  1454. PNG_FORMAT_FLAG_COLOR    equ 0x02 ;color format: otherwise grayscale
  1455. PNG_FORMAT_FLAG_LINEAR   equ 0x04 ;2-byte channels else 1-byte
  1456. PNG_FORMAT_FLAG_COLORMAP equ 0x08 ;image data is color-mapped
  1457.  
  1458. PNG_FORMAT_FLAG_BGR   equ 0x10 ;BGR colors, else order is RGB
  1459.  
  1460. PNG_FORMAT_FLAG_AFIRST equ 0x20 ;alpha channel comes first
  1461.  
  1462. ; Commonly used formats have predefined macros.
  1463.  
  1464. ; First the single byte (sRGB) formats:
  1465.  
  1466. PNG_FORMAT_GRAY equ 0
  1467. PNG_FORMAT_GA  equ PNG_FORMAT_FLAG_ALPHA
  1468. PNG_FORMAT_AG  equ (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)
  1469. PNG_FORMAT_RGB equ PNG_FORMAT_FLAG_COLOR
  1470. PNG_FORMAT_BGR equ (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)
  1471. PNG_FORMAT_RGBA equ (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)
  1472. PNG_FORMAT_ARGB equ (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)
  1473. PNG_FORMAT_BGRA equ (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)
  1474. PNG_FORMAT_ABGR equ (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)
  1475.  
  1476. ; Then the linear 2-byte formats.  When naming these "Y" is used to
  1477. ; indicate a luminance (gray) channel.
  1478.  
  1479. PNG_FORMAT_LINEAR_Y equ PNG_FORMAT_FLAG_LINEAR
  1480. PNG_FORMAT_LINEAR_Y_ALPHA equ (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)
  1481. PNG_FORMAT_LINEAR_RGB equ (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)
  1482. PNG_FORMAT_LINEAR_RGB_ALPHA equ\
  1483.         (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)
  1484.  
  1485. ; With color-mapped formats the image data is one byte for each pixel, the byte
  1486. ; is an index into the color-map which is formatted as above.  To obtain a
  1487. ; color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP
  1488. ; to one of the above definitions, or you can use one of the definitions below.
  1489.  
  1490. PNG_FORMAT_RGB_COLORMAP equ (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP)
  1491. PNG_FORMAT_BGR_COLORMAP equ (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP)
  1492. PNG_FORMAT_RGBA_COLORMAP equ (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP)
  1493. PNG_FORMAT_ARGB_COLORMAP equ (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP)
  1494. PNG_FORMAT_BGRA_COLORMAP equ (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP)
  1495. PNG_FORMAT_ABGR_COLORMAP equ (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP)
  1496.  
  1497. ; PNG_IMAGE macros
  1498.  
  1499. ; These are convenience macros to derive information from a png_image
  1500. ; structure.  The PNG_IMAGE_SAMPLE_ macros return values appropriate to the
  1501. ; actual image sample values - either the entries in the color-map or the
  1502. ; pixels in the image.  The PNG_IMAGE_PIXEL_ macros return corresponding values
  1503. ; for the pixels and will always return 1 for color-mapped formats.  The
  1504. ; remaining macros return information about the rows in the image and the
  1505. ; complete image.
  1506.  
  1507. ; NOTE: All the macros that take a png_image::format parameter are compile time
  1508. ; constants if the format parameter is, itself, a constant.  Therefore these
  1509. ; macros can be used in array declarations and case labels where required.
  1510. ; Similarly the macros are also pre-processor constants (sizeof is not used) so
  1511. ; they can be used in #if tests.
  1512.  
  1513. ; First the information about the samples.
  1514.  
  1515. macro PNG_IMAGE_SAMPLE_CHANNELS fmt
  1516. {
  1517.         mov eax,fmt
  1518.         and eax,PNG_FORMAT_FLAG_COLOR or PNG_FORMAT_FLAG_ALPHA
  1519.         inc eax
  1520. }
  1521. ; Return the total number of channels in a given format: 1..4
  1522.  
  1523. ;#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\
  1524. ;   ((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1)
  1525. ;   /* Return the size in bytes of a single component of a pixel or color-map
  1526. ; entry (as appropriate) in the image: 1 or 2.
  1527.  
  1528.  
  1529. ;#define PNG_IMAGE_SAMPLE_SIZE(fmt)\
  1530. ;   (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt))
  1531. ;   /* This is the size of the sample data for one sample.  If the image is
  1532. ; color-mapped it is the size of one color-map entry (and image pixels are
  1533. ; one byte in size), otherwise it is the size of one image pixel.
  1534.  
  1535.  
  1536. ;#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\
  1537. ;   (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)
  1538. ;   /* The maximum size of the color-map required by the format expressed in a
  1539. ; count of components.  This can be used to compile-time allocate a
  1540. ; color-map:
  1541.  
  1542. ; uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];
  1543.  
  1544. ; byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];
  1545.  
  1546. ; Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the
  1547. ; information from one of the png_image_begin_read_ APIs and dynamically
  1548. ; allocate the required memory.
  1549.  
  1550.  
  1551. ; Corresponding information about the pixels
  1552. macro PNG_IMAGE_PIXEL_ p1,fmt
  1553. {
  1554. local .end0
  1555. local .end1
  1556.         mov eax,fmt
  1557.         and eax,PNG_FORMAT_FLAG_COLORMAP
  1558.         cmp eax,0
  1559.         je .end0
  1560.                 xor eax,eax
  1561.                 inc eax
  1562.                 jmp .end1
  1563.         .end0:
  1564.                 p1 fmt
  1565.         .end1:
  1566. }
  1567.  
  1568. macro PNG_IMAGE_PIXEL_CHANNELS fmt
  1569. {
  1570.         PNG_IMAGE_PIXEL_ PNG_IMAGE_SAMPLE_CHANNELS,fmt
  1571. }
  1572. ; The number of separate channels (components) in a pixel; 1 for a
  1573. ; color-mapped image.
  1574.  
  1575.  
  1576. ;#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\
  1577. ;   PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt)
  1578. ;   /* The size, in bytes, of each component in a pixel; 1 for a color-mapped
  1579. ; image.
  1580.  
  1581.  
  1582. ;#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt)
  1583. ;   /* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */
  1584.  
  1585. ; Information about the whole row, or whole image
  1586. ;#define PNG_IMAGE_ROW_STRIDE(image)\
  1587. ;   (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width)
  1588. ; Return the total number of components in a single row of the image; this
  1589. ; is the minimum 'row stride', the minimum count of components between each
  1590. ; row.  For a color-mapped image this is the minimum number of bytes in a
  1591. ; row.
  1592.  
  1593. ; WARNING: this macro overflows for some images with more than one component
  1594. ; and very large image widths.  libpng will refuse to process an image where
  1595. ; this macro would overflow.
  1596.  
  1597.  
  1598. ;#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\
  1599. ;   (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride))
  1600. ; Return the size, in bytes, of an image buffer given a png_image and a row
  1601. ; stride - the number of components to leave space for in each row.
  1602.  
  1603. ; WARNING: this macro overflows a 32-bit integer for some large PNG images,
  1604. ; libpng will refuse to process an image where such an overflow would occur.
  1605.  
  1606.  
  1607. ;#define PNG_IMAGE_SIZE(image)\
  1608. ;   PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))
  1609. ; Return the size, in bytes, of the image in memory given just a png_image;
  1610. ; the row stride is the minimum stride required for the image.
  1611.  
  1612.  
  1613. ;#define PNG_IMAGE_COLORMAP_SIZE(image)\
  1614. ;   (PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries)
  1615. ; Return the size, in bytes, of the color-map of this image.  If the image
  1616. ; format is not a color-map format this will return a size sufficient for
  1617. ; 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if
  1618. ; you don't want to allocate a color-map in this case.
  1619.  
  1620.  
  1621. ; PNG_IMAGE_FLAG_*
  1622.  
  1623. ; Flags containing additional information about the image are held in the
  1624. ; 'flags' field of png_image.
  1625.  
  1626. PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB equ 0x01
  1627. ; This indicates the the RGB values of the in-memory bitmap do not
  1628. ; correspond to the red, green and blue end-points defined by sRGB.
  1629.  
  1630. PNG_IMAGE_FLAG_FAST equ 0x02
  1631. ; On write emphasise speed over compression; the resultant PNG file will be
  1632. ; larger but will be produced significantly faster, particular for large
  1633. ; images.  Do not use this option for images which will be distributed, only
  1634. ; used it when producing intermediate files that will be read back in
  1635. ; repeatedly.  For a typical 24-bit image the option will double the read
  1636. ; speed at the cost of increasing the image size by 25%, however for many
  1637. ; more compressible images the PNG file can be 10 times larger with only a
  1638. ; slight speed gain.
  1639.  
  1640. PNG_IMAGE_FLAG_16BIT_sRGB equ 0x04
  1641. ; On read if the image is a 16-bit per component image and there is no gAMA
  1642. ; or sRGB chunk assume that the components are sRGB encoded.  Notice that
  1643. ; images output by the simplified API always have gamma information; setting
  1644. ; this flag only affects the interpretation of 16-bit images from an
  1645. ; external source.  It is recommended that the application expose this flag
  1646. ; to the user; the user can normally easily recognize the difference between
  1647. ; linear and sRGB encoding.  This flag has no effect on write - the data
  1648. ; passed to the write APIs must have the correct encoding (as defined
  1649. ; above.)
  1650.  
  1651. ; If the flag is not set (the default) input 16-bit per component data is
  1652. ; assumed to be linear.
  1653.  
  1654. ; NOTE: the flag can only be set after the png_image_begin_read_ call,
  1655. ; because that call initializes the 'flags' field.
  1656.  
  1657. if PNG_SIMPLIFIED_WRITE_SUPPORTED eq 1
  1658. ; WRITE APIS
  1659. ; ----------
  1660. ; For write you must initialize a png_image structure to describe the image to
  1661. ; be written.  To do this use memset to set the whole structure to 0 then
  1662. ; initialize fields describing your image.
  1663.  
  1664. ; version: must be set to PNG_IMAGE_VERSION
  1665. ; opaque: must be initialized to NULL
  1666. ; width: image width in pixels
  1667. ; height: image height in rows
  1668. ; format: the format of the data (image and color-map) you wish to write
  1669. ; flags: set to 0 unless one of the defined flags applies; set
  1670. ;    PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB
  1671. ;    values do not correspond to the colors in sRGB.
  1672. ; colormap_entries: set to the number of entries in the color-map (0 to 256)
  1673.  
  1674. ; With all write APIs if image is in one of the linear formats with 16-bit
  1675. ; data then setting convert_to_8_bit will cause the output to be an 8-bit PNG
  1676. ; gamma encoded according to the sRGB specification, otherwise a 16-bit linear
  1677. ; encoded PNG file is written.
  1678.  
  1679. ; With color-mapped data formats the colormap parameter point to a color-map
  1680. ; with at least image->colormap_entries encoded in the specified format.  If
  1681. ; the format is linear the written PNG color-map will be converted to sRGB
  1682. ; regardless of the convert_to_8_bit flag.
  1683.  
  1684. ; With all APIs row_stride is handled as in the read APIs - it is the spacing
  1685. ; from one row to the next in component sized units (1 or 2 bytes) and if
  1686. ; negative indicates a bottom-up row layout in the buffer.  If row_stride is
  1687. ; zero, libpng will calculate it for you from the image width and number of
  1688. ; channels.
  1689.  
  1690. ; Note that the write API does not support interlacing, sub-8-bit pixels or
  1691. ; most ancillary chunks.  If you need to write text chunks (e.g. for copyright
  1692. ; notices) you need to use one of the other APIs.
  1693.  
  1694.  
  1695. ;#define png_image_write_get_memory_size(image, size, convert_to_8_bit, buffer,\
  1696. ;   row_stride, colormap)\
  1697. ;   png_image_write_to_memory(&(image), 0, &(size), convert_to_8_bit, buffer,\
  1698. ;         row_stride, colormap)
  1699. ; Return the amount of memory in 'size' required to compress this image.
  1700. ; The png_image structure 'image' must be filled in as in the above
  1701. ; function and must not be changed before the actual write call, the buffer
  1702. ; and all other parameters must also be identical to that in the final
  1703. ; write call.  The 'size' variable need not be initialized.
  1704.  
  1705. ; NOTE: the macro returns true/false, if false is returned 'size' will be
  1706. ; set to zero and the write failed and probably will fail if tried again.
  1707.  
  1708. ; You can pre-allocate the buffer by making sure it is of sufficient size
  1709. ; regardless of the amount of compression achieved.  The buffer size will
  1710. ; always be bigger than the original image and it will never be filled.  The
  1711. ; following macros are provided to assist in allocating the buffer.
  1712.  
  1713. ;#define PNG_IMAGE_DATA_SIZE(image) (PNG_IMAGE_SIZE(image)+(image).height)
  1714. ; The number of uncompressed bytes in the PNG byte encoding of the image;
  1715. ; uncompressing the PNG IDAT data will give this number of bytes.
  1716.  
  1717. ; NOTE: while PNG_IMAGE_SIZE cannot overflow for an image in memory this
  1718. ; macro can because of the extra bytes used in the PNG byte encoding.  You
  1719. ; need to avoid this macro if your image size approaches 2^30 in width or
  1720. ; height.  The same goes for the remainder of these macros; they all produce
  1721. ; bigger numbers than the actual in-memory image size.
  1722.  
  1723. ;#ifndef PNG_ZLIB_MAX_SIZE
  1724. ;#  define PNG_ZLIB_MAX_SIZE(b) ((b)+(((b)+7U)>>3)+(((b)+63U)>>6)+11U)
  1725. ; An upper bound on the number of compressed bytes given 'b' uncompressed
  1726. ; bytes.  This is based on deflateBounds() in zlib; different
  1727. ; implementations of zlib compression may conceivably produce more data so
  1728. ; if your zlib implementation is not zlib itself redefine this macro
  1729. ; appropriately.
  1730.  
  1731. ;end if
  1732.  
  1733. ;#define PNG_IMAGE_COMPRESSED_SIZE_MAX(image)\
  1734. ;   PNG_ZLIB_MAX_SIZE((png_alloc_size_t)PNG_IMAGE_DATA_SIZE(image))
  1735.         ; An upper bound on the size of the data in the PNG IDAT chunks.
  1736.  
  1737. ;#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\
  1738. ;   ((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\
  1739. ;    (((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\
  1740. ;    12U+3U*(image).colormap_entries/*PLTE data*/+\
  1741. ;    (((image).format&PNG_FORMAT_FLAG_ALPHA)?\
  1742. ;    12U/*tRNS*/+(image).colormap_entries:0U):0U)+\
  1743. ;    12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))
  1744.  
  1745. ; A helper for the following macro; if your compiler cannot handle the
  1746. ; following macro use this one with the result of
  1747. ; PNG_IMAGE_COMPRESSED_SIZE_MAX(image) as the second argument (most
  1748. ; compilers should handle this just fine.)
  1749.  
  1750. ;#define PNG_IMAGE_PNG_SIZE_MAX(image)\
  1751. ;   PNG_IMAGE_PNG_SIZE_MAX_(image, PNG_IMAGE_COMPRESSED_SIZE_MAX(image))
  1752. ; An upper bound on the total length of the PNG data stream for 'image'.
  1753. ; The result is of type png_alloc_size_t, on 32-bit systems this may
  1754. ; overflow even though PNG_IMAGE_DATA_SIZE does not overflow; the write will
  1755. ; run out of buffer space but return a corrected size which should work.
  1756.  
  1757. end if ;SIMPLIFIED_WRITE
  1758. ;/*******************************************************************************
  1759. ;  END OF SIMPLIFIED API
  1760. ; ******************************************************************************/
  1761. ;end if /* SIMPLIFIED_{READ|WRITE} */
  1762.  
  1763. ;/*******************************************************************************
  1764. ; Section 6: IMPLEMENTATION OPTIONS
  1765. ; *******************************************************************************
  1766.  
  1767. ; Support for arbitrary implementation-specific optimizations.  The API allows
  1768. ; particular options to be turned on or off.  'Option' is the number of the
  1769. ; option and 'onoff' is 0 (off) or non-0 (on).  The value returned is given
  1770. ; by the PNG_OPTION_ defines below.
  1771.  
  1772. ; HARDWARE: normally hardware capabilites, such as the Intel SSE instructions,
  1773. ;           are detected at run time, however sometimes it may be impossible
  1774. ;           to do this in user mode, in which case it is necessary to discover
  1775. ;           the capabilities in an OS specific way.  Such capabilities are
  1776. ;           listed here when libpng has support for them and must be turned
  1777. ;           ON by the application if present.
  1778.  
  1779. ; SOFTWARE: sometimes software optimizations actually result in performance
  1780. ;           decrease on some architectures or systems, or with some sets of
  1781. ;           PNG images.  'Software' options allow such optimizations to be
  1782. ;           selected at run time.
  1783.  
  1784. if PNG_SET_OPTION_SUPPORTED eq 1
  1785. if PNG_ARM_NEON_API_SUPPORTED eq 1
  1786.         PNG_ARM_NEON  equ 0 ;HARDWARE: ARM Neon SIMD instructions supported
  1787. end if
  1788. PNG_MAXIMUM_INFLATE_WINDOW equ 2 ;SOFTWARE: force maximum window
  1789. PNG_SKIP_sRGB_CHECK_PROFILE equ 4 ;SOFTWARE: Check ICC profile for sRGB
  1790. if PNG_MIPS_MSA_API_SUPPORTED eq 1
  1791.         PNG_MIPS_MSA  equ 6 ;HARDWARE: MIPS Msa SIMD instructions supported
  1792. end if
  1793. PNG_OPTION_NEXT equ 8 ;Next option - numbers must be even
  1794.  
  1795. ; Return values: NOTE: there are four values and 'off' is *not* zero
  1796. PNG_OPTION_UNSET  equ 0 ;Unset - defaults to off
  1797. PNG_OPTION_INVALID equ 1 ;Option number out of range
  1798. PNG_OPTION_OFF    equ 2
  1799. PNG_OPTION_ON     equ 3
  1800. end if ;SET_OPTION
  1801.  
  1802. ;/*******************************************************************************
  1803. ;  END OF HARDWARE AND SOFTWARE OPTIONS
  1804. ; ******************************************************************************/
  1805.  
  1806. ; Maintainer: Put new public prototypes here ^, in libpng.3, in project
  1807. ; defs, and in scripts/symbols.def.
  1808.  
  1809.  
  1810. ; The last ordinal number (this is the *last* one already used; the next
  1811. ; one to use is one more than this.)
  1812.  
  1813. ;end if /* PNG_VERSION_INFO_ONLY */
  1814. ; Do not put anything past this line
  1815.