Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ; Options
  3. ;
  4.  
  5. PNG_RELEASE_BUILD equ 1
  6.  
  7. ;---
  8. ; Various modes of operation.  Note that after an init, mode is set to
  9. ; zero automatically when the structure is created.  Three of these
  10. ; are defined in png.inc because they need to be visible to applications
  11. ; that call png_set_unknown_chunk().
  12.  
  13. ;PNG_HAVE_IHDR            0x01 (defined in png.inc)
  14. ;PNG_HAVE_PLTE            0x02 (defined in png.inc)
  15. PNG_HAVE_IDAT              equ 0x04
  16. ;PNG_AFTER_IDAT           0x08 (defined in png.inc)
  17. PNG_HAVE_IEND              equ 0x10
  18.         ;0x20 (unused)
  19.         ;0x40 (unused)
  20.         ;0x80 (unused)
  21. PNG_HAVE_CHUNK_HEADER     equ 0x100
  22. PNG_WROTE_tIME            equ 0x200
  23. PNG_WROTE_INFO_BEFORE_PLTE equ 0x400
  24. PNG_BACKGROUND_IS_GRAY    equ 0x800
  25. PNG_HAVE_PNG_SIGNATURE   equ 0x1000
  26. PNG_HAVE_CHUNK_AFTER_IDAT equ 0x2000 ;Have another chunk after IDAT
  27.         ;0x4000 (unused)
  28. PNG_IS_READ_STRUCT       equ 0x8000 ;Else is a write struct
  29.  
  30. ; Flags for the transformations the PNG library does on the image data
  31. PNG_BGR                equ 0x0001
  32. PNG_INTERLACE          equ 0x0002
  33. PNG_PACK               equ 0x0004
  34. PNG_SHIFT              equ 0x0008
  35. PNG_SWAP_BYTES         equ 0x0010
  36. PNG_INVERT_MONO        equ 0x0020
  37. PNG_QUANTIZE           equ 0x0040
  38. PNG_COMPOSE            equ 0x0080 ;Was PNG_BACKGROUND
  39. PNG_BACKGROUND_EXPAND  equ 0x0100
  40. PNG_EXPAND_16          equ 0x0200 ;Added to libpng 1.5.2
  41. PNG_16_TO_8            equ 0x0400 ;Becomes 'chop' in 1.5.4
  42. PNG_RGBA               equ 0x0800
  43. PNG_EXPAND             equ 0x1000
  44. PNG_GAMMA              equ 0x2000
  45. PNG_GRAY_TO_RGB        equ 0x4000
  46. PNG_FILLER             equ 0x8000
  47. PNG_PACKSWAP          equ 0x10000
  48. PNG_SWAP_ALPHA        equ 0x20000
  49. PNG_STRIP_ALPHA       equ 0x40000
  50. PNG_INVERT_ALPHA      equ 0x80000
  51. PNG_USER_TRANSFORM   equ 0x100000
  52. PNG_RGB_TO_GRAY_ERR  equ 0x200000
  53. PNG_RGB_TO_GRAY_WARN equ 0x400000
  54. PNG_RGB_TO_GRAY      equ 0x600000 ;two bits, RGB_TO_GRAY_ERR|WARN
  55. PNG_ENCODE_ALPHA     equ 0x800000 ;Added to libpng-1.5.4
  56. PNG_ADD_ALPHA       equ 0x1000000 ;Added to libpng-1.2.7
  57. PNG_EXPAND_tRNS     equ 0x2000000 ;Added to libpng-1.2.9
  58. PNG_SCALE_16_TO_8   equ 0x4000000 ;Added to libpng-1.5.4
  59.         ;0x8000000 unused
  60.         ;0x10000000 unused
  61.         ;0x20000000 unused
  62.         ;0x40000000 unused
  63. ; Flags for png_create_struct
  64. PNG_STRUCT_PNG  equ 0x0001
  65. PNG_STRUCT_INFO equ 0x0002
  66.  
  67. ; Flags for the png_ptr->flags rather than declaring a byte for each one
  68. PNG_FLAG_ZLIB_CUSTOM_STRATEGY    equ 0x0001
  69. PNG_FLAG_ZSTREAM_INITIALIZED     equ 0x0002 ;Added to libpng-1.6.0
  70.         ;0x0004    unused
  71. PNG_FLAG_ZSTREAM_ENDED           equ 0x0008 ;Added to libpng-1.6.0
  72.         ;0x0010    unused
  73.         ;0x0020    unused
  74. PNG_FLAG_ROW_INIT                equ 0x0040
  75. PNG_FLAG_FILLER_AFTER            equ 0x0080
  76. PNG_FLAG_CRC_ANCILLARY_USE       equ 0x0100
  77. PNG_FLAG_CRC_ANCILLARY_NOWARN    equ 0x0200
  78. PNG_FLAG_CRC_CRITICAL_USE        equ 0x0400
  79. PNG_FLAG_CRC_CRITICAL_IGNORE     equ 0x0800
  80. PNG_FLAG_ASSUME_sRGB             equ 0x1000 ;Added to libpng-1.5.4
  81. PNG_FLAG_OPTIMIZE_ALPHA          equ 0x2000 ;Added to libpng-1.5.4
  82. PNG_FLAG_DETECT_UNINITIALIZED    equ 0x4000 ;Added to libpng-1.5.4
  83. ;PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x8000
  84. ;PNG_FLAG_KEEP_UNSAFE_CHUNKS      0x10000
  85. PNG_FLAG_LIBRARY_MISMATCH       equ 0x20000
  86. PNG_FLAG_STRIP_ERROR_NUMBERS    equ 0x40000
  87. PNG_FLAG_STRIP_ERROR_TEXT       equ 0x80000
  88. PNG_FLAG_BENIGN_ERRORS_WARN    equ 0x100000 ;Added to libpng-1.4.0
  89. PNG_FLAG_APP_WARNINGS_WARN     equ 0x200000 ;Added to libpng-1.6.0
  90. PNG_FLAG_APP_ERRORS_WARN       equ 0x400000 ;Added to libpng-1.6.0
  91.  
  92. ; Gamma values (new at libpng-1.5.4):
  93. PNG_GAMMA_MAC_OLD equ 151724  ;Assume '1.8' is really 2.2/1.45!
  94. PNG_GAMMA_MAC_INVERSE equ 65909
  95. PNG_GAMMA_sRGB_INVERSE equ 45455
  96.  
  97. macro PNG_ROWBYTES pixel_bits, width
  98. {
  99. local .end0
  100. if pixel_bits eq eax
  101. else
  102.         mov eax,pixel_bits
  103. end if
  104.         cmp eax,8
  105.         jge .end0
  106.                 add eax,7
  107.         .end0:
  108.         shr eax,3
  109.         imul eax,width
  110. }
  111.  
  112. ; In 1.7.0 the definitions will be made public in png.inc to avoid having to
  113. ; duplicate the same definitions in application code.
  114.  
  115. png_IDAT equ 'IDAT'
  116. png_IEND equ 'IEND'
  117. png_IHDR equ 'IHDR'
  118. png_PLTE equ 'PLTE'
  119. png_bKGD equ 'bKGD'
  120. png_cHRM equ 'cHRM'
  121. png_fRAc equ 'fRAc' ;registered, not defined
  122. png_gAMA equ 'gAMA'
  123. png_gIFg equ 'gIFg'
  124. png_gIFt equ 'gIFt' ;deprecated
  125. png_gIFx equ 'gIFx'
  126. png_hIST equ 'hIST'
  127. png_iCCP equ 'iCCP'
  128. png_iTXt equ 'iTXt'
  129. png_oFFs equ 'oFFs'
  130. png_pCAL equ 'pCAL'
  131. png_pHYs equ 'pHYs'
  132. png_sBIT equ 'sBIT'
  133. png_sCAL equ 'sCAL'
  134. png_sPLT equ 'sPLT'
  135. png_sRGB equ 'sRGB'
  136. png_sTER equ 'sTER'
  137. png_tEXt equ 'tEXt'
  138. png_tIME equ 'tIME'
  139. png_tRNS equ 'tRNS'
  140. png_zTXt equ 'zTXt'
  141.  
  142. ;Test on flag values as defined in the spec (section 5.4):
  143. macro PNG_CHUNK_ANCILLARY c
  144. {
  145.         mov eax,c
  146.         shr eax,29
  147.         and eax,1
  148. }
  149. macro PNG_CHUNK_CRITICAL c
  150. {
  151.         PNG_CHUNK_ANCILLARY c
  152.         xor eax,1
  153. }
  154. macro PNG_CHUNK_PRIVATE c
  155. {
  156.         mov eax,c
  157.         shr eax,21
  158.         and eax,1
  159. }
  160. macro PNG_CHUNK_RESERVED c
  161. {
  162.         mov eax,c
  163.         shr eax,13
  164.         and eax,1
  165. }
  166. macro PNG_CHUNK_SAFE_TO_COPY c
  167. {
  168.         mov eax,c
  169.         shr eax,5
  170.         and eax,1
  171. }
  172.  
  173. PNG_FLAG_CRC_ANCILLARY_MASK equ (PNG_FLAG_CRC_ANCILLARY_USE or PNG_FLAG_CRC_ANCILLARY_NOWARN)
  174. PNG_FLAG_CRC_CRITICAL_MASK  equ (PNG_FLAG_CRC_CRITICAL_USE or PNG_FLAG_CRC_CRITICAL_IGNORE)
  175. PNG_FLAG_CRC_MASK           equ (PNG_FLAG_CRC_ANCILLARY_MASK or PNG_FLAG_CRC_CRITICAL_MASK)
  176.  
  177. macro PNG_sRGB_FROM_LINEAR linear
  178. {
  179.         mov eax,linear
  180.         shr eax,15
  181.         shl eax,1
  182.         add eax,png_sRGB_base
  183.         movzx eax,word[eax]
  184. push ebx ecx
  185.         mov ebx,linear
  186.         shr ebx,15
  187.         add ebx,png_sRGB_delta
  188.         mov ecx,linear
  189.         and ecx,0x7fff
  190.         imul ecx,ebx
  191.         shr ecx,12
  192.         add eax,ecx
  193. pop ecx ebx
  194.         shr eax,8
  195.         ;;;and eax,0xff
  196. }
  197. ; Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB
  198. ; encoded value with maximum error 0.646365.  Note that the input is not a
  199. ; 16-bit value; it has been multiplied by 255!
  200.  
  201. PNG_UNEXPECTED_ZLIB_RETURN equ (-7)
  202.  
  203. ;...
  204.  
  205. ; Suggested size for a number buffer (enough for 64 bits and a sign!)
  206. PNG_NUMBER_BUFFER_SIZE equ 24
  207.  
  208. ; These are the integer formats currently supported, the name is formed from
  209. ; the standard printf(3) format string.
  210.  
  211. PNG_NUMBER_FORMAT_u    equ 1 ;chose unsigned API!
  212. PNG_NUMBER_FORMAT_02u  equ 2
  213. PNG_NUMBER_FORMAT_d    equ 1 ;chose signed API!
  214. PNG_NUMBER_FORMAT_02d  equ 2
  215. PNG_NUMBER_FORMAT_x    equ 3
  216. PNG_NUMBER_FORMAT_02x  equ 4
  217. PNG_NUMBER_FORMAT_fixed equ 5 ;choose the signed API
  218.  
  219. ; New defines and members adding in libpng-1.5.4
  220. PNG_WARNING_PARAMETER_SIZE equ 32
  221. PNG_WARNING_PARAMETER_COUNT equ 8 ;Maximum 9; see pngerror.asm
  222.  
  223. PNG_CHUNK_WARNING     equ 0 ;never an error
  224. PNG_CHUNK_WRITE_ERROR equ 1 ;an error only on write
  225. PNG_CHUNK_ERROR       equ 2 ;always an error
  226.  
  227. ; ASCII to FP interfaces, currently only implemented if sCAL
  228. ; support is required.
  229.  
  230. ; MAX_DIGITS is actually the maximum number of characters in an sCAL
  231. ; width or height, derived from the precision (number of significant
  232. ; digits - a build time settable option) and assumptions about the
  233. ; maximum ridiculous exponent.
  234.  
  235. PNG_sCAL_MAX_DIGITS equ PNG_sCAL_PRECISION+1+1+10 ;. E exponent
  236.  
  237. ; An internal API to validate the format of a floating point number.
  238. ; The result is the index of the next character.  If the number is
  239. ; not valid it will be the index of a character in the supposed number.
  240.  
  241. ; The format of a number is defined in the PNG extensions specification
  242. ; and this API is strictly conformant to that spec, not anyone elses!
  243.  
  244. ; The format as a regular expression is:
  245.  
  246. ; [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
  247.  
  248. ; or:
  249.  
  250. ; [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
  251.  
  252. ; The complexity is that either integer or fraction must be present and the
  253. ; fraction is permitted to have no digits only if the integer is present.
  254.  
  255. ; NOTE: The dangling E problem.
  256. ;   There is a PNG valid floating point number in the following:
  257.  
  258. ;       PNG floating point numbers are not greedy.
  259.  
  260. ;   Working this out requires *TWO* character lookahead (because of the
  261. ;   sign), the parser does not do this - it will fail at the 'r' - this
  262. ;   doesn't matter for PNG sCAL chunk values, but it requires more care
  263. ;   if the value were ever to be embedded in something more complex.  Use
  264. ;   ANSI-C strtod if you need the lookahead.
  265.  
  266. ; State table for the parser.
  267. PNG_FP_INTEGER   equ 0 ;before or in integer
  268. PNG_FP_FRACTION  equ 1 ;before or in fraction
  269. PNG_FP_EXPONENT  equ 2 ;before or in exponent
  270. PNG_FP_STATE     equ 3 ;mask for the above
  271. PNG_FP_SAW_SIGN  equ 4 ;Saw +/- in current state
  272. PNG_FP_SAW_DIGIT equ 8 ;Saw a digit in current state
  273. PNG_FP_SAW_DOT  equ 16 ;Saw a dot in current state
  274. PNG_FP_SAW_E    equ 32 ;Saw an E (or e) in current state
  275. PNG_FP_SAW_ANY  equ 60 ;Saw any of the above 4
  276.  
  277. ; These three values don't affect the parser.  They are set but not used.
  278.  
  279. PNG_FP_WAS_VALID equ 64 ;Preceding substring is a valid fp number
  280. PNG_FP_NEGATIVE equ 128 ;A negative number, including "-0"
  281. PNG_FP_NONZERO  equ 256 ;A non-zero value
  282. PNG_FP_STICKY   equ 448 ;The above three flags
  283.  
  284. ; This is available for the caller to store in 'state' if required.  Do not
  285. ; call the parser after setting it (the parser sometimes clears it.)
  286.  
  287. PNG_FP_INVALID equ 512 ;Available for callers as a distinct value
  288.  
  289. ; Result codes for the parser (boolean - true meants ok, false means
  290. ; not ok yet.)
  291.  
  292. PNG_FP_MAYBE     equ 0 ;The number may be valid in the future
  293. PNG_FP_OK        equ 1 ;The number is valid
  294.  
  295. ; The internal structure that png_image::opaque points to.
  296. struct png_control
  297.         png_ptr dd ? ;png_structp
  298.         info_ptr dd ? ;png_infop
  299.         error_buf dd ? ;voidp ;Always a jmp_buf at present.
  300.  
  301.         memory dd ? ;bytep ;Memory buffer.
  302.         size dd ? ;png_size_t ;Size of the memory buffer.
  303.  
  304.         for_write dd ? ;uint ;:1;Otherwise it is a read structure
  305.         owned_file dd ? ;uint ;:1;We own the file in io_ptr
  306. ends
  307.