Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ; pngtrans.asm - transforms the data in a row (used by both readers and writers)
  3.  
  4. ; Last changed in libpng 1.6.24 [August 4, 2016]
  5. ; Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
  6. ; (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  7. ; (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  8.  
  9. ; This code is released under the libpng license.
  10. ; For conditions of distribution and use, see the disclaimer
  11. ; and license in png.inc
  12.  
  13.  
  14. if (PNG_READ_SUPPORTED eq 1) | (PNG_WRITE_SUPPORTED eq 1)
  15.  
  16. ; Turn on BGR-to-RGB mapping
  17. ;void (png_structrp png_ptr)
  18. align 4
  19. proc png_set_bgr uses edi, png_ptr:dword
  20.         png_debug 1, 'in png_set_bgr'
  21.  
  22.         mov edi,[png_ptr]
  23.         cmp edi,0
  24.         je @f ;if (..==0) return
  25.                 or dword[edi+png_struct.transformations], PNG_BGR
  26.         @@:
  27.         ret
  28. endp
  29.  
  30. ; Turn on 16-bit byte swapping
  31. ;void (png_structrp png_ptr)
  32. align 4
  33. proc png_set_swap uses edi, png_ptr:dword
  34.         png_debug 1, 'in png_set_swap'
  35.  
  36.         mov edi,[png_ptr]
  37.         cmp edi,0
  38.         je @f ;if (..==0) return
  39.  
  40.         cmp byte[edi+png_struct.bit_depth],16
  41.         jne @f ;if (..==..)
  42.                 or dword[edi+png_struct.transformations], PNG_SWAP_BYTES
  43.         @@:
  44.         ret
  45. endp
  46.  
  47. ; Turn on pixel packing
  48. ;void (png_structrp png_ptr)
  49. align 4
  50. proc png_set_packing uses edi, png_ptr:dword
  51.         png_debug 1, 'in png_set_packing'
  52.  
  53.         mov edi,[png_ptr]
  54.         cmp edi,0
  55.         je @f ;if (..==0) return
  56.  
  57.         cmp byte[edi+png_struct.bit_depth],8
  58.         jge @f ;if (..<..)
  59.                 or dword[edi+png_struct.transformations], PNG_PACK
  60. if PNG_WRITE_SUPPORTED eq 1
  61.                 mov byte[edi+png_struct.usr_bit_depth],8
  62. end if
  63.         @@:
  64.         ret
  65. endp
  66.  
  67. ; Turn on packed pixel swapping
  68. ;void (png_structrp png_ptr)
  69. align 4
  70. proc png_set_packswap uses edi, png_ptr:dword
  71.         png_debug 1, 'in png_set_packswap'
  72.  
  73.         mov edi,[png_ptr]
  74.         cmp edi,0
  75.         je @f ;if (..==0) return
  76.  
  77.         cmp byte[edi+png_struct.bit_depth],8
  78.         jge @f ;if (..<..)
  79.                 or dword[edi+png_struct.transformations], PNG_PACKSWAP
  80.         @@:
  81.         ret
  82. endp
  83.  
  84. ;void (png_structrp png_ptr, png_color_8p true_bits)
  85. align 4
  86. proc png_set_shift uses ecx edi, png_ptr:dword, true_bits:dword
  87.         png_debug 1, 'in png_set_shift'
  88.  
  89.         mov edi,[png_ptr]
  90.         cmp edi,0
  91.         je @f ;if (..==0) return
  92.  
  93.         or dword[edi+png_struct.transformations], PNG_SHIFT
  94.         mov ecx,sizeof.png_color_8
  95.         mov edi,[edi+png_struct.shift]
  96.         mov esi,[true_bits]
  97.         rep movsb
  98.         @@:
  99.         ret
  100. endp
  101.  
  102. ;int (png_structrp png_ptr)
  103. align 4
  104. proc png_set_interlace_handling uses edi, png_ptr:dword
  105.         png_debug 1, 'in png_set_interlace handling'
  106.  
  107.         mov edi,[png_ptr]
  108.         cmp edi,0
  109.         je @f
  110.         cmp byte[edi+png_struct.interlaced],0
  111.         je @f ;if(..!=0 && ..!=0)
  112.                 or dword[edi+png_struct.transformations], PNG_INTERLACE
  113.                 mov eax,7
  114.                 jmp .end_f
  115.         @@:
  116.  
  117.         xor eax,eax
  118.         inc eax
  119. .end_f:
  120.         ret
  121. endp
  122.  
  123. ; Add a filler byte on read, or remove a filler or alpha byte on write.
  124. ; The filler type has changed in v0.95 to allow future 2-byte fillers
  125. ; for 48-bit input data, as well as to avoid problems with some compilers
  126. ; that don't like bytes as parameters.
  127.  
  128. ;void (png_structrp png_ptr, uint_32 filler, int filler_loc)
  129. align 4
  130. proc png_set_filler uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
  131.         png_debug 1, 'in png_set_filler'
  132.  
  133.         mov edi,[png_ptr]
  134.         cmp edi,0
  135.         je .end_f ;if (..==0) return
  136.  
  137.         ; In libpng 1.6 it is possible to determine whether this is a read or write
  138.         ; operation and therefore to do more checking here for a valid call.
  139.  
  140.         mov eax,[edi+png_struct.mode]
  141.         and eax,PNG_IS_READ_STRUCT
  142.         jz @f ;if (..!=0)
  143. if PNG_READ_FILLER_SUPPORTED eq 1
  144.                 ; On read png_set_filler is always valid, regardless of the base PNG
  145.                 ; format, because other transformations can give a format where the
  146.                 ; filler code can execute (basically an 8 or 16-bit component RGB or G
  147.                 ; format.)
  148.  
  149.                 ; NOTE: usr_channels is not used by the read code!  (This has led to
  150.                 ; confusion in the past.)  The filler is only used in the read code.
  151.  
  152.                 mov eax,[filler]
  153.                 mov [edi+png_struct.filler],ax
  154.                 jmp .end0
  155. else
  156.                 cStr ,'png_set_filler not supported on read'
  157.                 stdcall png_app_error, edi, eax
  158.                 jmp .end_f
  159. end if
  160.         @@: ;else ;write
  161. if PNG_WRITE_FILLER_SUPPORTED eq 1
  162.         ; On write the usr_channels parameter must be set correctly at the
  163.         ; start to record the number of channels in the app-supplied data.
  164.  
  165. ;         switch (png_ptr->color_type)
  166. ;         {
  167. ;            case PNG_COLOR_TYPE_RGB:
  168. ;               png_ptr->usr_channels = 4;
  169. ;               break;
  170.  
  171. ;            case PNG_COLOR_TYPE_GRAY:
  172. ;               if (png_ptr->bit_depth >= 8)
  173. ;               {
  174. ;                  png_ptr->usr_channels = 2;
  175. ;                  break;
  176. ;               }
  177.  
  178. ;               else
  179. ;               {
  180.                         ; There simply isn't any code in libpng to strip out bits
  181.                         ; from bytes when the components are less than a byte in
  182.                         ; size!
  183.  
  184. ;                  png_app_error(png_ptr,
  185. ;                      "png_set_filler is invalid for"
  186. ;                      " low bit depth gray output");
  187. ;                  return;
  188. ;               }
  189.  
  190. ;            default:
  191. ;               png_app_error(png_ptr,
  192. ;                   "png_set_filler: inappropriate color type");
  193. ;               return;
  194. ;         }
  195. else
  196.                 cStr ,'png_set_filler not supported on write'
  197.                 stdcall png_app_error, edi, eax
  198.                 jmp .end_f
  199. end if
  200.         .end0:
  201.  
  202.         ; Here on success - libpng supports the operation, set the transformation
  203.         ; and the flag to say where the filler channel is.
  204.  
  205.         or dword[edi+png_struct.transformations],PNG_FILLER
  206.  
  207.         cmp dword[filler_loc],PNG_FILLER_AFTER
  208.         jne @f ;if (..==..)
  209.                 or dword[edi+png_struct.flags],PNG_FLAG_FILLER_AFTER
  210.                 jmp .end_f
  211.         @@: ;else
  212.                 and dword[edi+png_struct.flags],not PNG_FLAG_FILLER_AFTER
  213. .end_f:
  214.         ret
  215. endp
  216.  
  217. ; Added to libpng-1.2.7
  218. ;void (png_structrp png_ptr, uint_32 filler, int filler_loc)
  219. align 4
  220. proc png_set_add_alpha uses eax edi, png_ptr:dword, filler:dword, filler_loc:dword
  221.         png_debug 1, 'in png_set_add_alpha'
  222.  
  223.         mov edi,[png_ptr]
  224.         cmp edi,0
  225.         je .end_f ;if (..==0) return
  226.  
  227.         stdcall png_set_filler, edi, [filler], [filler_loc]
  228.         ; The above may fail to do anything.
  229.         mov eax,[edi+png_struct.transformations]
  230.         and eax,PNG_FILLER
  231.         jz .end_f ;if (..!=0)
  232.                 or dword[edi+png_struct.transformations],PNG_ADD_ALPHA
  233. .end_f:
  234.         ret
  235. endp
  236.  
  237. ;void (png_structrp png_ptr)
  238. align 4
  239. proc png_set_swap_alpha uses edi, png_ptr:dword
  240.         png_debug 1, 'in png_set_swap_alpha'
  241.  
  242.         mov edi,[png_ptr]
  243.         cmp edi,0
  244.         je .end_f ;if (..==0) return
  245.                 or dword[edi+png_struct.transformations], PNG_SWAP_ALPHA
  246. .end_f:
  247.         ret
  248. endp
  249.  
  250.  
  251. ;void (png_structrp png_ptr)
  252. align 4
  253. proc png_set_invert_alpha uses edi, png_ptr:dword
  254.         png_debug 1, 'in png_set_invert_alpha'
  255.  
  256.         mov edi,[png_ptr]
  257.         cmp edi,0
  258.         je .end_f ;if (..==0) return
  259.                 or dword[edi+png_struct.transformations], PNG_INVERT_ALPHA
  260. .end_f:
  261.         ret
  262. endp
  263.  
  264. ;void (png_structrp png_ptr)
  265. align 4
  266. proc png_set_invert_mono uses edi, png_ptr:dword
  267.         png_debug 1, 'in png_set_invert_mono'
  268.  
  269.         mov edi,[png_ptr]
  270.         cmp edi,0
  271.         je .end_f ;if (..==0) return
  272.                 or dword[edi+png_struct.transformations], PNG_INVERT_MONO
  273. .end_f:
  274.         ret
  275. endp
  276.  
  277. ; Invert monochrome grayscale data
  278. ;void (png_row_infop row_info, bytep row)
  279. align 4
  280. proc png_do_invert, row_info:dword, row:dword
  281.         png_debug 1, 'in png_do_invert'
  282.  
  283.         ; This test removed from libpng version 1.0.13 and 1.2.0:
  284.         ;   if (row_info->bit_depth == 1 &&
  285.  
  286. ;   if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  287. ;   {
  288. ;      bytep rp = row;
  289. ;      png_size_t i;
  290. ;      png_size_t istop = row_info->rowbytes;
  291.  
  292. ;      for (i = 0; i < istop; i++)
  293. ;      {
  294. ;         *rp = (byte)(~(*rp));
  295. ;         rp++;
  296. ;      }
  297. ;   }
  298.  
  299. ;   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  300. ;      row_info->bit_depth == 8)
  301. ;   {
  302. ;      bytep rp = row;
  303. ;      png_size_t i;
  304. ;      png_size_t istop = row_info->rowbytes;
  305.  
  306. ;      for (i = 0; i < istop; i += 2)
  307. ;      {
  308. ;         *rp = (byte)(~(*rp));
  309. ;         rp += 2;
  310. ;      }
  311. ;   }
  312.  
  313. if PNG_16BIT_SUPPORTED eq 1
  314. ;   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  315. ;      row_info->bit_depth == 16)
  316. ;   {
  317. ;      bytep rp = row;
  318. ;      png_size_t i;
  319. ;      png_size_t istop = row_info->rowbytes;
  320.  
  321. ;      for (i = 0; i < istop; i += 4)
  322. ;      {
  323. ;         *rp = (byte)(~(*rp));
  324. ;         *(rp + 1) = (byte)(~(*(rp + 1)));
  325. ;         rp += 4;
  326. ;      }
  327. ;   }
  328. end if
  329.         ret
  330. endp
  331.  
  332. ; Swaps byte order on 16-bit depth images
  333. ;void (png_row_infop row_info, bytep row)
  334. align 4
  335. proc png_do_swap, row_info:dword, row:dword
  336.         png_debug 1, 'in png_do_swap'
  337.  
  338. ;   if (row_info->bit_depth == 16)
  339. ;   {
  340. ;      bytep rp = row;
  341. ;      uint_32 i;
  342. ;      uint_32 istop= row_info->width * row_info->channels;
  343.  
  344. ;      for (i = 0; i < istop; i++, rp += 2)
  345. ;      {
  346. if PNG_BUILTIN_BSWAP16_SUPPORTED eq 1
  347.         ; Feature added to libpng-1.6.11 for testing purposes, not
  348.         ; enabled by default.
  349.  
  350. ;         *(uint_16*)rp = __builtin_bswap16(*(uint_16*)rp);
  351. else
  352. ;         byte t = *rp;
  353. ;         *rp = *(rp + 1);
  354. ;         *(rp + 1) = t;
  355. end if
  356. ;      }
  357. ;   }
  358.         ret
  359. endp
  360.  
  361. if (PNG_READ_PACKSWAP_SUPPORTED eq 1) | (PNG_WRITE_PACKSWAP_SUPPORTED eq 1)
  362. align 4
  363. onebppswaptable db 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,\
  364.    0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,\
  365.    0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,\
  366.    0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,\
  367.    0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,\
  368.    0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,\
  369.    0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,\
  370.    0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,\
  371.    0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,\
  372.    0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,\
  373.    0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,\
  374.    0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,\
  375.    0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,\
  376.    0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,\
  377.    0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,\
  378.    0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,\
  379.    0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,\
  380.    0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,\
  381.    0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,\
  382.    0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,\
  383.    0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,\
  384.    0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,\
  385.    0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,\
  386.    0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,\
  387.    0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,\
  388.    0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,\
  389.    0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,\
  390.    0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,\
  391.    0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,\
  392.    0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,\
  393.    0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,\
  394.    0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  395.  
  396. align 4
  397. twobppswaptable db 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,\
  398.    0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,\
  399.    0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,\
  400.    0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,\
  401.    0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,\
  402.    0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,\
  403.    0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,\
  404.    0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,\
  405.    0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,\
  406.    0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,\
  407.    0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,\
  408.    0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,\
  409.    0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,\
  410.    0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,\
  411.    0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,\
  412.    0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,\
  413.    0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,\
  414.    0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,\
  415.    0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,\
  416.    0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,\
  417.    0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,\
  418.    0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,\
  419.    0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,\
  420.    0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,\
  421.    0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,\
  422.    0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,\
  423.    0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,\
  424.    0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,\
  425.    0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,\
  426.    0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,\
  427.    0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,\
  428.    0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  429.  
  430. align 4
  431. fourbppswaptable db 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,\
  432.    0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,\
  433.    0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,\
  434.    0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,\
  435.    0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,\
  436.    0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,\
  437.    0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,\
  438.    0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,\
  439.    0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,\
  440.    0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,\
  441.    0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,\
  442.    0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,\
  443.    0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,\
  444.    0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,\
  445.    0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,\
  446.    0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,\
  447.    0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,\
  448.    0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,\
  449.    0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,\
  450.    0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,\
  451.    0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,\
  452.    0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,\
  453.    0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,\
  454.    0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,\
  455.    0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,\
  456.    0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,\
  457.    0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,\
  458.    0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,\
  459.    0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,\
  460.    0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,\
  461.    0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,\
  462.    0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  463. end if ;PACKSWAP || WRITE_PACKSWAP
  464.  
  465. ; Swaps pixel packing order within bytes
  466. ;void (png_row_infop row_info, bytep row)
  467. align 4
  468. proc png_do_packswap uses eax edx edi esi, row_info:dword, row:dword
  469.         png_debug 1, 'in png_do_packswap'
  470.  
  471.         mov eax,[row_info]
  472.         cmp byte[eax+png_row_info.bit_depth],8
  473.         jge .end_f ;if (..<..)
  474.                 ;edi = rp
  475.                 ;esi = table
  476.  
  477.                 mov edx,[eax+png_row_info.rowbytes]
  478.                 mov edi,[row]
  479.                 add edx,edi
  480.  
  481.                 cmp byte[eax+png_row_info.bit_depth],1
  482.                 jne @f ;if (..==..)
  483.                         mov esi,onebppswaptable
  484.                         jmp .cycle0
  485.                 @@:
  486.                 cmp byte[eax+png_row_info.bit_depth],2
  487.                 jne @f ;else if (..==..)
  488.                         mov esi,twobppswaptable
  489.                         jmp .cycle0
  490.                 @@:
  491.                 cmp byte[eax+png_row_info.bit_depth],4
  492.                 jne .end_f ;else if (..==..)
  493.                         mov esi,fourbppswaptable
  494. align 4
  495.                 .cycle0: ;for (..=..;..<..;..)
  496.                         cmp edi,edx
  497.                         jge .end_f
  498.                         movzx eax,byte[edi]
  499.                         mov al,byte[esi+eax]
  500.                         stosb ;*rp = table[*rp]
  501.                         jmp .cycle0
  502. .end_f:
  503.         ret
  504. endp
  505.  
  506. ; Remove a channel - this used to be 'png_do_strip_filler' but it used a
  507. ; somewhat weird combination of flags to determine what to do.  All the calls
  508. ; to png_do_strip_filler are changed in 1.5.2 to call this instead with the
  509. ; correct arguments.
  510.  
  511. ; The routine isn't general - the channel must be the channel at the start or
  512. ; end (not in the middle) of each pixel.
  513.  
  514. ;void (png_row_infop row_info, bytep row, int at_start)
  515. align 4
  516. proc png_do_strip_channel, row_info:dword, row:dword, at_start:dword
  517. ;   bytep sp = row; /* source pointer */
  518. ;   bytep dp = row; /* destination pointer */
  519. ;   bytep ep = row + row_info->rowbytes; /* One beyond end of row */
  520.  
  521.         ; At the start sp will point to the first byte to copy and dp to where
  522.         ; it is copied to.  ep always points just beyond the end of the row, so
  523.         ; the loop simply copies (channels-1) channels until sp reaches ep.
  524.  
  525.         ; at_start:        0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc.
  526.         ;            nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.
  527.  
  528.  
  529.         ; GA, GX, XG cases
  530. ;   if (row_info->channels == 2)
  531. ;   {
  532. ;      if (row_info->bit_depth == 8)
  533. ;      {
  534. ;         if (at_start != 0) /* Skip initial filler */
  535. ;            ++sp;
  536. ;         else          /* Skip initial channel and, for sp, the filler */
  537. ;            sp += 2, ++dp;
  538.  
  539.         ; For a 1 pixel wide image there is nothing to do
  540. ;         while (sp < ep)
  541. ;            *dp++ = *sp, sp += 2;
  542.  
  543. ;         row_info->pixel_depth = 8;
  544. ;      }
  545.  
  546. ;      else if (row_info->bit_depth == 16)
  547. ;      {
  548. ;         if (at_start != 0) /* Skip initial filler */
  549. ;            sp += 2;
  550. ;         else          /* Skip initial channel and, for sp, the filler */
  551. ;            sp += 4, dp += 2;
  552.  
  553. ;         while (sp < ep)
  554. ;            *dp++ = *sp++, *dp++ = *sp, sp += 3;
  555.  
  556. ;         row_info->pixel_depth = 16;
  557. ;      }
  558.  
  559. ;      else
  560. ;         return; /* bad bit depth */
  561.  
  562. ;      row_info->channels = 1;
  563.  
  564.         ; Finally fix the color type if it records an alpha channel
  565. ;      if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  566. ;         row_info->color_type = PNG_COLOR_TYPE_GRAY;
  567. ;   }
  568.  
  569.         ; RGBA, RGBX, XRGB cases
  570. ;   else if (row_info->channels == 4)
  571. ;   {
  572. ;      if (row_info->bit_depth == 8)
  573. ;      {
  574. ;         if (at_start != 0) /* Skip initial filler */
  575. ;            ++sp;
  576. ;         else          /* Skip initial channels and, for sp, the filler */
  577. ;            sp += 4, dp += 3;
  578.  
  579.         ; Note that the loop adds 3 to dp and 4 to sp each time.
  580. ;         while (sp < ep)
  581. ;            *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
  582.  
  583. ;         row_info->pixel_depth = 24;
  584. ;      }
  585.  
  586. ;      else if (row_info->bit_depth == 16)
  587. ;      {
  588. ;         if (at_start != 0) /* Skip initial filler */
  589. ;            sp += 2;
  590. ;         else          /* Skip initial channels and, for sp, the filler */
  591. ;            sp += 8, dp += 6;
  592.  
  593. ;         while (sp < ep)
  594. ;         {
  595. ;            /* Copy 6 bytes, skip 2 */
  596. ;            *dp++ = *sp++, *dp++ = *sp++;
  597. ;            *dp++ = *sp++, *dp++ = *sp++;
  598. ;            *dp++ = *sp++, *dp++ = *sp, sp += 3;
  599. ;         }
  600.  
  601. ;         row_info->pixel_depth = 48;
  602. ;      }
  603.  
  604. ;      else
  605. ;         return; /* bad bit depth */
  606.  
  607. ;      row_info->channels = 3;
  608.  
  609.         ; Finally fix the color type if it records an alpha channel
  610. ;      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  611. ;         row_info->color_type = PNG_COLOR_TYPE_RGB;
  612. ;   }
  613.  
  614. ;   else
  615. ;      return; /* The filler channel has gone already */
  616.  
  617.         ; Fix the rowbytes value.
  618. ;   row_info->rowbytes = dp-row;
  619.         ret
  620. endp
  621.  
  622. ; Swaps red and blue bytes within a pixel
  623. ;void (png_row_infop row_info, bytep row)
  624. align 4
  625. proc png_do_bgr, row_info:dword, row:dword
  626.         png_debug 1, 'in png_do_bgr'
  627.  
  628. ;   if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
  629. ;   {
  630. ;      uint_32 row_width = row_info->width;
  631. ;      if (row_info->bit_depth == 8)
  632. ;      {
  633. ;         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  634. ;         {
  635. ;            bytep rp;
  636. ;            uint_32 i;
  637.  
  638. ;            for (i = 0, rp = row; i < row_width; i++, rp += 3)
  639. ;            {
  640. ;               byte save = *rp;
  641. ;               *rp = *(rp + 2);
  642. ;               *(rp + 2) = save;
  643. ;            }
  644. ;         }
  645.  
  646. ;         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  647. ;         {
  648. ;            bytep rp;
  649. ;            uint_32 i;
  650.  
  651. ;            for (i = 0, rp = row; i < row_width; i++, rp += 4)
  652. ;            {
  653. ;               byte save = *rp;
  654. ;               *rp = *(rp + 2);
  655. ;               *(rp + 2) = save;
  656. ;            }
  657. ;         }
  658. ;      }
  659.  
  660. if PNG_16BIT_SUPPORTED eq 1
  661. ;      else if (row_info->bit_depth == 16)
  662. ;      {
  663. ;         if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  664. ;         {
  665. ;            bytep rp;
  666. ;            uint_32 i;
  667.  
  668. ;            for (i = 0, rp = row; i < row_width; i++, rp += 6)
  669. ;            {
  670. ;               byte save = *rp;
  671. ;               *rp = *(rp + 4);
  672. ;               *(rp + 4) = save;
  673. ;               save = *(rp + 1);
  674. ;               *(rp + 1) = *(rp + 5);
  675. ;               *(rp + 5) = save;
  676. ;            }
  677. ;         }
  678.  
  679. ;         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  680. ;         {
  681. ;            bytep rp;
  682. ;            uint_32 i;
  683.  
  684. ;            for (i = 0, rp = row; i < row_width; i++, rp += 8)
  685. ;            {
  686. ;               byte save = *rp;
  687. ;               *rp = *(rp + 4);
  688. ;               *(rp + 4) = save;
  689. ;               save = *(rp + 1);
  690. ;               *(rp + 1) = *(rp + 5);
  691. ;               *(rp + 5) = save;
  692. ;            }
  693. ;         }
  694. ;      }
  695. end if
  696. ;   }
  697.         ret
  698. endp
  699.  
  700. ; Added at libpng-1.5.10
  701. ;void (png_structrp png_ptr, png_row_infop row_info)
  702. align 4
  703. proc png_do_check_palette_indexes, png_ptr:dword, row_info:dword
  704. ;   if (png_ptr->num_palette < (1 << row_info->bit_depth) &&
  705. ;      png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */
  706. ;   {
  707.         ; Calculations moved outside switch in an attempt to stop different
  708.         ; compiler warnings.  'padding' is in *bits* within the last byte, it is
  709.         ; an 'int' because pixel_depth becomes an 'int' in the expression below,
  710.         ; and this calculation is used because it avoids warnings that other
  711.         ; forms produced on either GCC or MSVC.
  712.  
  713. ;      int padding = (-row_info->pixel_depth * row_info->width) & 7;
  714. ;      bytep rp = png_ptr->row_buf + row_info->rowbytes;
  715.  
  716. ;      switch (row_info->bit_depth)
  717. ;      {
  718. ;         case 1:
  719. ;         {
  720. ;            /* in this case, all bytes must be 0 so we don't need
  721.         ; to unpack the pixels except for the rightmost one.
  722.  
  723. ;            for (; rp > png_ptr->row_buf; rp--)
  724. ;            {
  725. ;              if ((*rp >> padding) != 0)
  726. ;                 png_ptr->num_palette_max = 1;
  727. ;              padding = 0;
  728. ;            }
  729.  
  730. ;            break;
  731. ;         }
  732.  
  733. ;         case 2:
  734. ;         {
  735. ;            for (; rp > png_ptr->row_buf; rp--)
  736. ;            {
  737. ;              int i = ((*rp >> padding) & 0x03);
  738.  
  739. ;              if (i > png_ptr->num_palette_max)
  740. ;                 png_ptr->num_palette_max = i;
  741.  
  742. ;              i = (((*rp >> padding) >> 2) & 0x03);
  743.  
  744. ;              if (i > png_ptr->num_palette_max)
  745. ;                 png_ptr->num_palette_max = i;
  746.  
  747. ;              i = (((*rp >> padding) >> 4) & 0x03);
  748.  
  749. ;              if (i > png_ptr->num_palette_max)
  750. ;                 png_ptr->num_palette_max = i;
  751.  
  752. ;              i = (((*rp >> padding) >> 6) & 0x03);
  753.  
  754. ;              if (i > png_ptr->num_palette_max)
  755. ;                 png_ptr->num_palette_max = i;
  756.  
  757. ;              padding = 0;
  758. ;            }
  759.  
  760. ;            break;
  761. ;         }
  762.  
  763. ;         case 4:
  764. ;         {
  765. ;            for (; rp > png_ptr->row_buf; rp--)
  766. ;            {
  767. ;              int i = ((*rp >> padding) & 0x0f);
  768.  
  769. ;              if (i > png_ptr->num_palette_max)
  770. ;                 png_ptr->num_palette_max = i;
  771.  
  772. ;              i = (((*rp >> padding) >> 4) & 0x0f);
  773.  
  774. ;              if (i > png_ptr->num_palette_max)
  775. ;                 png_ptr->num_palette_max = i;
  776.  
  777. ;              padding = 0;
  778. ;            }
  779.  
  780. ;            break;
  781. ;         }
  782.  
  783. ;         case 8:
  784. ;         {
  785. ;            for (; rp > png_ptr->row_buf; rp--)
  786. ;            {
  787. ;               if (*rp > png_ptr->num_palette_max)
  788. ;                  png_ptr->num_palette_max = (int) *rp;
  789. ;            }
  790.  
  791. ;            break;
  792. ;         }
  793.  
  794. ;         default:
  795. ;            break;
  796. ;      }
  797. ;   }
  798.         ret
  799. endp
  800.  
  801. ;void (png_structrp png_ptr, voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)
  802. align 4
  803. proc png_set_user_transform_info uses eax edi, png_ptr:dword, user_transform_ptr:dword, user_transform_depth:dword, user_transform_channels:dword
  804.         png_debug 1, 'in png_set_user_transform_info'
  805.  
  806.         mov edi,[png_ptr]
  807.         cmp edi,0
  808.         je .end_f
  809.  
  810. if PNG_READ_USER_TRANSFORM_SUPPORTED eq 1
  811.         mov eax,[edi+png_struct.mode]
  812.         and eax,PNG_IS_READ_STRUCT
  813.         jz @f
  814.         mov eax,[edi+png_struct.flags]
  815.         and eax,PNG_FLAG_ROW_INIT
  816.         jz @f ;if (..!=0 && ..!=0)
  817.                 cStr ,'info change after png_start_read_image or png_read_update_info'
  818.                 stdcall png_app_error, edi, eax
  819.                 jmp .end_f
  820.         @@:
  821. end if
  822.  
  823.         mov eax,[user_transform_ptr]
  824.         mov [edi+png_struct.user_transform_ptr],eax
  825.         mov eax,[user_transform_depth]
  826.         mov [edi+png_struct.user_transform_depth],al
  827.         mov eax,[user_transform_channels]
  828.         mov [edi+png_struct.user_transform_channels],al
  829. .end_f:
  830.         ret
  831. endp
  832.  
  833. ; This function returns a pointer to the user_transform_ptr associated with
  834. ; the user transform functions.  The application should free any memory
  835. ; associated with this pointer before png_write_destroy and png_read_destroy
  836. ; are called.
  837.  
  838. ;voidp (png_structrp png_ptr)
  839. align 4
  840. proc png_get_user_transform_ptr, png_ptr:dword
  841.         mov eax,[png_ptr]
  842.         cmp eax,0
  843.         je @f
  844.                 mov eax,[eax+png_struct.user_transform_ptr]
  845.         @@:
  846.         ret
  847. endp
  848.  
  849. ;uint_32 (png_structrp png_ptr)
  850. align 4
  851. proc png_get_current_row_number, png_ptr:dword
  852.         ; See the comments in png.inc - this is the sub-image row when reading an
  853.         ; interlaced image.
  854.  
  855.         mov eax,[png_ptr]
  856.         cmp eax,0
  857.         je @f ;if (..!=0)
  858.                 mov eax,[eax+png_struct.row_number]
  859.                 jmp .end_f
  860.         @@:
  861.         mov eax,PNG_UINT_32_MAX ;help the app not to fail silently
  862. .end_f:
  863.         ret
  864. endp
  865.  
  866. ;byte (png_structrp png_ptr)
  867. align 4
  868. proc png_get_current_pass_number, png_ptr:dword
  869.         mov eax,[png_ptr]
  870.         cmp eax,0
  871.         je @f ;if (..!=0)
  872.                 mov eax,[eax+png_struct.pass]
  873.                 jmp .end_f
  874.         @@:
  875.         mov eax,8 ;invalid
  876. .end_f:
  877.         ret
  878. endp
  879. end if
  880.