Subversion Repositories Kolibri OS

Rev

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

  1. ;;================================================================================================;;
  2. ;;//// bmp.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
  3. ;;================================================================================================;;
  4. ;;                                                                                                ;;
  5. ;; This file is part of Common development libraries (Libs-Dev).                                  ;;
  6. ;;                                                                                                ;;
  7. ;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
  8. ;; General Public License as published by the Free Software Foundation, either version 3 of the   ;;
  9. ;; License, or (at your option) any later version.                                                ;;
  10. ;;                                                                                                ;;
  11. ;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
  12. ;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
  13. ;; General Public License for more details.                                                       ;;
  14. ;;                                                                                                ;;
  15. ;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
  16. ;; see <http://www.gnu.org/licenses/>.                                                            ;;
  17. ;;                                                                                                ;;
  18. ;;================================================================================================;;
  19. ;;                                                                                                ;;
  20. ;; References:                                                                                    ;;
  21. ;;   1. "Microsoft Windows Bitmap File Format Summary"                                            ;;
  22. ;;      from "Encyclopedia of Graphics File Formats" by O'Reilly                                  ;;
  23. ;;      http://www.fileformat.info/format/bmp/                                                    ;;
  24. ;;                                                                                                ;;
  25. ;;================================================================================================;;
  26.  
  27.  
  28. include 'bmp.inc'
  29.  
  30. ;;================================================================================================;;
  31. proc img.is.bmp _data, _length ;//////////////////////////////////////////////////////////////////;;
  32. ;;------------------------------------------------------------------------------------------------;;
  33. ;? Determine if raw data could be decoded (is in BMP format)                                      ;;
  34. ;;------------------------------------------------------------------------------------------------;;
  35. ;> _data = raw data as read from file/stream                                                      ;;
  36. ;> _length = data length                                                                          ;;
  37. ;;------------------------------------------------------------------------------------------------;;
  38. ;< eax = false / true                                                                             ;;
  39. ;;================================================================================================;;
  40.         cmp     [_length], 2
  41.         jb      .nope
  42.         mov     eax, [_data]
  43.         cmp     word[eax], 'BM'
  44.         je      .yep
  45.  
  46.   .nope:
  47.         xor     eax, eax
  48.         ret
  49.  
  50.   .yep:
  51.         xor     eax,eax
  52.         inc     eax
  53.         ret
  54. endp
  55.  
  56. ;;================================================================================================;;
  57. proc img.decode.bmp _data, _length ;//////////////////////////////////////////////////////////////;;
  58. ;;------------------------------------------------------------------------------------------------;;
  59. ;? Decode data into image if it contains correctly formed raw data in BMP format                  ;;
  60. ;;------------------------------------------------------------------------------------------------;;
  61. ;> _data = raw data as read from file/stream                                                      ;;
  62. ;> _length = data length                                                                          ;;
  63. ;;------------------------------------------------------------------------------------------------;;
  64. ;< eax = 0 (error) or pointer to image                                                            ;;
  65. ;;================================================================================================;;
  66. locals
  67.   img dd ?
  68. endl
  69.  
  70.         push    ebx
  71.  
  72.         stdcall img.is.bmp, [_data], [_length]
  73.         or      eax, eax
  74.         jz      .error
  75.  
  76.         mov     ebx, [_data]
  77. ;       cmp     [ebx + bmp.Header.info.Compression], bmp.BI_RGB
  78. ;       je      @f
  79. ;       mov     eax, [ebx + bmp.Header.file.Size]
  80. ;       cmp     eax, [_length]
  81. ;       jne     .error
  82.  
  83.     @@: stdcall img.create, [ebx + bmp.Header.info.Width], [ebx + bmp.Header.info.Height]
  84.         or      eax, eax
  85.         jz      .error
  86.         mov     [img], eax
  87.         mov     edx, eax
  88.  
  89.         invoke  mem.alloc, sizeof.bmp.Image
  90.         or      eax, eax
  91.         jz      .error
  92.         mov     [edx + Image.Extended], eax
  93.         mov     esi, ebx
  94.         add     esi, sizeof.bmp.FileHeader
  95.         mov     edi, eax
  96.         mov     ecx, sizeof.bmp.InfoHeader
  97.         rep     movsb
  98.  
  99.         mov     eax, [ebx + bmp.Header.info.Compression]
  100.         cmp     eax, bmp.BI_RGB
  101.         jne     @f
  102.         stdcall ._.rgb
  103.         jmp     .decoded
  104.     @@: cmp     eax, bmp.BI_RLE8
  105.         jne     @f
  106.         stdcall ._.rle
  107.         jmp     .decoded
  108.     @@: cmp     eax, bmp.BI_RLE4
  109.         jne     @f
  110.         stdcall ._.rle
  111.         jmp     .decoded
  112.     @@: cmp     eax, bmp.BI_BITFIELDS
  113.         jne     @f
  114.         stdcall ._.bitfields
  115.         jmp     .decoded
  116.     @@: cmp     eax, bmp.BI_JPEG
  117.         jne     @f
  118.         stdcall ._.jpeg
  119.         jmp     .decoded
  120.     @@: cmp     eax, bmp.BI_PNG
  121.         jne     .error
  122.         stdcall ._.png
  123.  
  124.   .decoded:
  125.         or      eax, eax
  126.         jz      @f
  127.         stdcall img.destroy, [img]
  128.         jmp     .error
  129.        
  130.     @@: stdcall img.flip, [img], FLIP_VERTICAL
  131.         mov     eax, [img]
  132.         ret
  133.  
  134.   .error:
  135.         xor     eax, eax
  136.         pop     ebx
  137.         ret
  138. endp
  139.  
  140. ;;================================================================================================;;
  141. proc img.encode.bmp _img, _p_length ;/////////////////////////////////////////////////////////////;;
  142. ;;------------------------------------------------------------------------------------------------;;
  143. ;? Encode image into raw data in BMP format                                                       ;;
  144. ;;------------------------------------------------------------------------------------------------;;
  145. ;> _img = pointer to image                                                                        ;;
  146. ;;------------------------------------------------------------------------------------------------;;
  147. ;< eax = 0 (error) or pointer to encoded data                                                     ;;
  148. ;< _p_length = encoded data length                                                                ;;
  149. ;;================================================================================================;;
  150.         xor     eax, eax
  151.         ret
  152. endp
  153.  
  154.  
  155. ;;================================================================================================;;
  156. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  157. ;;================================================================================================;;
  158. ;! Below are private procs you should never call directly from your code                          ;;
  159. ;;================================================================================================;;
  160. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  161. ;;================================================================================================;;
  162.  
  163.  
  164. ;;================================================================================================;;
  165. proc img.decode.bmp._.rgb ;///////////////////////////////////////////////////////////////////////;;
  166. ;;------------------------------------------------------------------------------------------------;;
  167. ;? --- TBD ---                                                                                    ;;
  168. ;;------------------------------------------------------------------------------------------------;;
  169. ;> ebx = raw image data                                                                           ;;
  170. ;> edx = image data                                                                               ;;
  171. ;;------------------------------------------------------------------------------------------------;;
  172. ;< --- TBD ---                                                                                    ;;
  173. ;;================================================================================================;;
  174.         mov     ecx, [edx + Image.Extended]
  175.         mov     [ecx + bmp.Image.info.AlphaMask], 0
  176.         mov     edi, [edx + Image.Data]
  177.  
  178.         movzx   eax, [ebx + bmp.Header.info.BitCount]
  179.         cmp     eax, 32
  180.         je      .32bpp
  181.         cmp     eax, 24
  182.         je      .24bpp
  183.         cmp     eax, 16
  184.         je      .16bpp
  185.         cmp     eax, 8
  186.         je      .8bpp
  187.         cmp     eax, 4
  188.         je      .4bpp
  189.         cmp     eax, 1
  190.         je      .1bpp
  191.         jmp     .error
  192.  
  193. ;;------------------------------------------------------------------------------------------------;;
  194.  
  195. img.decode.bmp._.rgb.32bpp:
  196.         mov     [ecx + bmp.Image.info.RedMask],   00000000111111110000000000000000b ; 8-0-0
  197.         mov     [ecx + bmp.Image.info.GreenMask], 00000000000000001111111100000000b ; 0-8-0
  198.         mov     [ecx + bmp.Image.info.BlueMask],  00000000000000000000000011111111b ; 0-0-8
  199.         stdcall img.decode.bmp._.bitfields
  200.         ret
  201.  
  202. ;;------------------------------------------------------------------------------------------------;;
  203.  
  204. img.decode.bmp._.rgb.24bpp:
  205.         mov     esi, ebx
  206.         add     esi, [ebx + bmp.Header.file.OffBits]
  207.         mov     ecx, [ebx + bmp.Header.info.Height]
  208.  
  209.   .next_line:
  210.         push    ecx
  211.         mov     ecx, [ebx + bmp.Header.info.Width]
  212.         xor     edx, edx
  213.  
  214.   .next_line_pixel:
  215.         movsd
  216.         dec     esi
  217.         inc     edx
  218.         dec     ecx
  219.         jnz     .next_line_pixel
  220.  
  221.         and     edx, 0x03
  222.         add     esi, edx
  223.         pop     ecx
  224.         dec     ecx
  225.         jnz     .next_line
  226.  
  227.         jmp     img.decode.bmp._.rgb.exit
  228.  
  229. ;;------------------------------------------------------------------------------------------------;;
  230.  
  231. img.decode.bmp._.rgb.16bpp:
  232.         mov     [ecx + bmp.Image.info.RedMask],   00000000000000000111110000000000b ; 5-0-0
  233.         mov     [ecx + bmp.Image.info.GreenMask], 00000000000000000000001111100000b ; 0-5-0
  234.         mov     [ecx + bmp.Image.info.BlueMask],  00000000000000000000000000011111b ; 0-0-5
  235.         stdcall img.decode.bmp._.bitfields
  236.         ret
  237.  
  238. ;;------------------------------------------------------------------------------------------------;;
  239.  
  240. img.decode.bmp._.rgb.8bpp:
  241.         mov     esi, ebx
  242.         add     esi, [ebx + bmp.Header.file.OffBits]
  243.         mov     ecx, [ebx + bmp.Header.info.Height]
  244.  
  245.   .next_line:
  246.         push    ecx
  247.         mov     ecx, [ebx + bmp.Header.info.Width]
  248.  
  249.   .next_line_dword:
  250.         lodsb
  251.         and     eax, 0x000000FF
  252.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  253.         stosd
  254.         dec     ecx
  255.         jnz     .next_line_dword
  256.  
  257.         pop     ecx
  258.         dec     ecx
  259.         jnz     .next_line
  260.  
  261.         jmp     img.decode.bmp._.rgb.exit
  262.  
  263. ;;------------------------------------------------------------------------------------------------;;
  264.  
  265. img.decode.bmp._.rgb.4bpp:
  266.         mov     esi, ebx
  267.         add     esi, [ebx + bmp.Header.file.OffBits]
  268.         mov     ecx, [ebx + bmp.Header.info.Height]
  269.  
  270.   .next_line:
  271.         push    ecx
  272.         mov     ecx, [ebx + bmp.Header.info.Width]
  273.  
  274.   .next_line_dword:
  275.         push    ecx
  276.         lodsd
  277.         bswap   eax
  278.         xchg    edx, eax
  279.         mov     ecx, 32 / 4
  280.  
  281.   .next_pixel:
  282.         rol     edx, 4
  283.         mov     al, dl
  284.         and     eax, 0x0000000F
  285.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  286.         stosd
  287.         dec     dword[esp]
  288.         jz      @f
  289.         dec     ecx
  290.         jnz     .next_pixel
  291.  
  292.     @@: pop     ecx
  293.         or      ecx, ecx
  294.         jnz     .next_line_dword
  295.  
  296.         pop     ecx
  297.         dec     ecx
  298.         jnz     .next_line
  299.  
  300.         jmp     img.decode.bmp._.rgb.exit
  301.  
  302. ;;------------------------------------------------------------------------------------------------;;
  303.  
  304. img.decode.bmp._.rgb.1bpp:
  305.         mov     esi, ebx
  306.         add     esi, [ebx + bmp.Header.file.OffBits]
  307.         mov     ecx, [ebx + bmp.Header.info.Height]
  308.  
  309.   .next_line:
  310.         push    ecx
  311.         mov     ecx, [ebx + bmp.Header.info.Width]
  312.  
  313.   .next_line_dword:
  314.         push    ecx
  315.         lodsd
  316.         bswap   eax
  317.         xchg    edx, eax
  318.         mov     ecx, 32 / 1
  319.  
  320.   .next_pixel:
  321.         rol     edx, 1
  322.         mov     al, dl
  323.         and     eax, 0x00000001
  324.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  325.         stosd
  326.         dec     dword[esp]
  327.         jz      @f
  328.         dec     ecx
  329.         jnz     .next_pixel
  330.  
  331.     @@: pop     ecx
  332.         or      ecx, ecx
  333.         jnz     .next_line_dword
  334.  
  335.         pop     ecx
  336.         dec     ecx
  337.         jnz     .next_line
  338.  
  339.         jmp     img.decode.bmp._.rgb.exit
  340.  
  341. ;;------------------------------------------------------------------------------------------------;;
  342.  
  343.   img.decode.bmp._.rgb.exit:
  344.         xor     eax, eax
  345.         ret
  346.  
  347.   img.decode.bmp._.rgb.error:
  348.         or      eax, -1
  349.         ret
  350. endp
  351.  
  352. ;;================================================================================================;;
  353. proc img.decode.bmp._.rle ;///////////////////////////////////////////////////////////////////////;;
  354. ;;------------------------------------------------------------------------------------------------;;
  355. ;? --- TBD ---                                                                                    ;;
  356. ;;------------------------------------------------------------------------------------------------;;
  357. ;> ebx = raw image data                                                                           ;;
  358. ;> edx = image data                                                                               ;;
  359. ;;------------------------------------------------------------------------------------------------;;
  360. ;< --- TBD ---                                                                                    ;;
  361. ;;================================================================================================;;
  362. locals
  363.   scanline_len  dd ?
  364.   marker_x      dd ?
  365.   marker_y      dd ?
  366.   abs_mode_addr dd ?
  367.   enc_mode_addr dd ?
  368. endl
  369.  
  370.         mov     edi, [edx + Image.Data]
  371.  
  372.         mov     [abs_mode_addr], .absolute_mode.rle8
  373.         mov     [enc_mode_addr], .encoded_mode.rle8
  374.         cmp     [ebx + bmp.Header.info.Compression], bmp.BI_RLE4
  375.         jne     @f
  376.         mov     [abs_mode_addr], .absolute_mode.rle4
  377.         mov     [enc_mode_addr], .encoded_mode.rle4
  378.  
  379.     @@: mov     esi, ebx
  380.         add     esi, [ebx + bmp.Header.file.OffBits]
  381.         mov     eax, [edx + Image.Width]
  382.         shl     eax, 2
  383.         mov     [scanline_len], eax
  384.         xor     eax, eax
  385.         mov     [marker_x], eax
  386.         mov     [marker_y], eax
  387.  
  388.   .next_run:
  389.         xor     eax, eax
  390.         lodsb
  391.         or      al, al
  392.         jz      .escape_mode
  393.         jmp     [enc_mode_addr]
  394.  
  395.   .escape_mode:
  396.         lodsb
  397.         cmp     al, 0
  398.         je      .end_of_scanline
  399.         cmp     al, 1
  400.         je      .exit
  401.         cmp     al, 2
  402.         je      .offset_marker
  403.         jmp     [abs_mode_addr]
  404.  
  405.   .end_of_scanline: ; 0
  406.         mov     eax, [marker_x]
  407.         shl     eax, 2
  408.         neg     eax
  409.         add     eax, [scanline_len]
  410.         add     edi, eax
  411.         mov     [marker_x], 0
  412.         inc     [marker_y]
  413.         jmp     .next_run
  414.  
  415.   .offset_marker: ; 2: dx, dy
  416.         lodsb
  417.         mov     edx, [marker_x]
  418.         add     edx, eax
  419.         cmp     edx, [ebx + bmp.Header.info.Width]
  420.         jae     .exit
  421.         mov     [marker_x], edx
  422.         shl     eax, 2
  423.         add     edi, eax
  424.         lodsb
  425.         and     eax, 0x0FF
  426.         mov     edx, [marker_y]
  427.         add     edx, eax
  428.         cmp     edx, [ebx + bmp.Header.info.Height]
  429.         jae     .exit
  430.         mov     [marker_y], edx
  431.         imul    eax, [scanline_len]
  432.         add     edi, eax
  433.         jmp     .next_run
  434.  
  435.   .encoded_mode.rle8: ; N: b1 * N
  436.         mov     edx, eax
  437.         lodsb
  438.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  439.     @@: dec     edx
  440.         js      .fix_marker
  441.         stosd
  442.         inc     [marker_x]
  443.         jmp     @b
  444.  
  445.   .absolute_mode.rle8: ; N: b1 .. bN
  446.         mov     edx, eax
  447.         push    eax
  448.     @@: dec     edx
  449.         js      @f
  450.         lodsb
  451.         and     eax, 0x0FF
  452.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  453.         stosd
  454.         inc     [marker_x]
  455.         jmp     @b
  456.     @@: pop     eax
  457.         test    eax, 1
  458.         jz      .fix_marker
  459.         inc     esi
  460.         jmp     .fix_marker
  461.  
  462.   .encoded_mode.rle4: ; N: b1 * N
  463.         mov     edx, eax
  464.         lodsb
  465.         mov     ecx, eax
  466.         shr     ecx, 4
  467.         mov     ecx, [ebx + ecx * 4 + bmp.Header.info.Palette]
  468.         and     eax, 0x00F
  469.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  470.     @@: dec     edx
  471.         js      .fix_marker
  472.         test    edx, 1
  473.         jz      .odd
  474.         mov     [edi], ecx
  475.         add     edi, 4
  476.         inc     [marker_x]
  477.         jmp     @b
  478.     .odd:
  479.         stosd
  480.         inc     [marker_x]
  481.         jmp     @b
  482.  
  483.   .absolute_mode.rle4: ; N: b1 .. bN
  484.         mov     edx, eax
  485.         push    eax
  486.     @@: dec     edx
  487.         js      @f
  488.         lodsb
  489.         and     eax, 0x0FF
  490.         mov     ecx, eax
  491.         shr     eax, 4
  492.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  493.         stosd
  494.         inc     [marker_x]
  495.         dec     edx
  496.         js      @f
  497.         mov     eax, ecx
  498.         and     eax, 0x00F
  499.         mov     eax, [ebx + eax * 4 + bmp.Header.info.Palette]
  500.         stosd
  501.         inc     [marker_x]
  502.         jmp     @b
  503.     @@: pop     eax
  504.         and     eax, 0x03
  505.         jz      .fix_marker
  506.         cmp     eax, 3
  507.         je      .fix_marker
  508.         inc     esi
  509.         jmp     .fix_marker
  510.  
  511.   .fix_marker:
  512.         mov     eax, [marker_x]
  513.     @@: sub     eax, [ebx + bmp.Header.info.Width]
  514.         jle     .next_run
  515.         mov     [marker_x], eax
  516.         inc     [marker_y]
  517.         jmp     @b
  518.  
  519.   .exit:
  520.         xor     eax, eax
  521.         ret
  522.  
  523.   .error:
  524.         or      eax, -1
  525.         ret
  526. endp
  527.  
  528. ;;================================================================================================;;
  529. proc img.decode.bmp._.bitfields ;/////////////////////////////////////////////////////////////////;;
  530. ;;------------------------------------------------------------------------------------------------;;
  531. ;? --- TBD ---                                                                                    ;;
  532. ;;------------------------------------------------------------------------------------------------;;
  533. ;> ebx = raw image data                                                                           ;;
  534. ;> edx = image data                                                                               ;;
  535. ;;------------------------------------------------------------------------------------------------;;
  536. ;< --- TBD ---                                                                                    ;;
  537. ;;================================================================================================;;
  538. locals
  539.   shift   bmp.RgbByteQuad
  540.   unshift bmp.RgbByteQuad
  541.   mask    bmp.RgbQuad
  542.   delta   dd ?
  543. endl
  544.  
  545.         push    esi edi
  546.         mov     esi, [edx + Image.Extended]
  547.  
  548.         mov     ecx, [esi + bmp.Image.info.RedMask]
  549.         call    .calc_shift
  550.         mov     [shift.Red], al
  551.         mov     [mask.Red], ecx
  552.         call    .calc_unshift
  553.         mov     [unshift.Red], al
  554.         mov     ecx, [esi + bmp.Image.info.GreenMask]
  555.         call    .calc_shift
  556.         mov     [shift.Green], al
  557.         mov     [unshift.Green], al
  558.         mov     [mask.Green], ecx
  559.         call    .calc_unshift
  560.         mov     [unshift.Green], al
  561.         mov     ecx, [esi + bmp.Image.info.BlueMask]
  562.         call    .calc_shift
  563.         mov     [shift.Blue], al
  564.         mov     [unshift.Blue], al
  565.         mov     [mask.Blue], ecx
  566.         call    .calc_unshift
  567.         mov     [unshift.Blue], al
  568.         mov     ecx, [esi + bmp.Image.info.AlphaMask]
  569.         call    .calc_shift
  570.         mov     [shift.Alpha], al
  571.         mov     [unshift.Alpha], al
  572.         mov     [mask.Alpha], ecx
  573.         call    .calc_unshift
  574.         mov     [unshift.Alpha], al
  575.  
  576.         mov     edi, [edx + Image.Data]
  577.         mov     esi, ebx
  578.         add     esi, [ebx + bmp.Header.file.OffBits]
  579.  
  580.         mov     [delta], 4
  581.         movzx   eax, [ebx + bmp.Header.info.BitCount]
  582.         cmp     eax, 32
  583.         je      @f
  584.         cmp     eax, 16
  585.         jne     .error
  586.         mov     [delta], 2
  587.  
  588. ;;------------------------------------------------------------------------------------------------;;
  589.  
  590.     @@: mov     ecx, [edx + Image.Height]
  591.  
  592.   .next_line:
  593.         push    ecx
  594.         mov     ecx, [edx + Image.Width]
  595.        
  596.   .next_pixel:
  597.         push    ecx
  598.  
  599.         mov     eax, [esi]
  600.         mov     cl, [shift.Blue]
  601.         shr     eax, cl
  602.         and     eax, [mask.Blue]
  603.         mov     cl, [unshift.Blue]
  604.         shl     eax, cl
  605.         stosb
  606.  
  607.         mov     eax, [esi]
  608.         mov     cl, [shift.Green]
  609.         shr     eax, cl
  610.         and     eax, [mask.Green]
  611.         mov     cl, [unshift.Green]
  612.         shl     eax, cl
  613.         stosb
  614.  
  615.         mov     eax, [esi]
  616.         mov     cl, [shift.Red]
  617.         shr     eax, cl
  618.         and     eax, [mask.Red]
  619.         mov     cl, [unshift.Red]
  620.         shl     eax, cl
  621.         stosb
  622.  
  623.         mov     eax, [esi]
  624.         mov     cl, [shift.Alpha]
  625.         shr     eax, cl
  626.         and     eax, [mask.Alpha]
  627.         mov     cl, [unshift.Alpha]
  628.         shl     eax, cl
  629.         stosb
  630.  
  631.         add     esi, [delta]
  632.  
  633.         pop     ecx
  634.         dec     ecx
  635.         jnz     .next_pixel
  636.  
  637.         pop     ecx
  638.         dec     ecx
  639.         jnz     .next_line
  640.  
  641. ;;------------------------------------------------------------------------------------------------;;
  642.  
  643.   .exit:
  644.         xor     eax, eax
  645.         pop     edi esi
  646.         ret
  647.  
  648.   .error:
  649.         or      eax, -1
  650.         pop     edi esi
  651.         ret
  652.        
  653. .calc_shift:
  654.         xor     eax, eax
  655.         or      ecx, ecx
  656.         jnz     @f
  657.         retn
  658.     @@: test    ecx, 1
  659.         jnz     @f
  660.    .zz: shr     ecx, 1
  661.         inc     eax
  662.         jmp     @b
  663.     @@: test    ecx, 0100000000b
  664.         jnz     .zz
  665.         retn
  666. .calc_unshift:
  667.         xor     eax, eax
  668.         or      ecx, ecx
  669.         jnz     @f
  670.         retn
  671.     @@: test    ecx, 1
  672.         jz      @f
  673.         shr     ecx, 1
  674.         inc     eax
  675.         jmp     @b
  676.     @@: sub     eax, 8
  677.         neg     eax
  678.         retn
  679. endp
  680.  
  681. ;;================================================================================================;;
  682. proc img.decode.bmp._.jpeg ;//////////////////////////////////////////////////////////////////////;;
  683. ;;------------------------------------------------------------------------------------------------;;
  684. ;? --- TBD ---                                                                                    ;;
  685. ;;------------------------------------------------------------------------------------------------;;
  686. ;> ebx = raw image data                                                                           ;;
  687. ;> edx = image data                                                                               ;;
  688. ;;------------------------------------------------------------------------------------------------;;
  689. ;< --- TBD ---                                                                                    ;;
  690. ;;================================================================================================;;
  691.         xor     eax, eax
  692.         ret
  693. endp
  694.  
  695. ;;================================================================================================;;
  696. proc img.decode.bmp._.png ;///////////////////////////////////////////////////////////////////////;;
  697. ;;------------------------------------------------------------------------------------------------;;
  698. ;? --- TBD ---                                                                                    ;;
  699. ;;------------------------------------------------------------------------------------------------;;
  700. ;> ebx = raw image data                                                                           ;;
  701. ;> edx = image data                                                                               ;;
  702. ;;------------------------------------------------------------------------------------------------;;
  703. ;< --- TBD ---                                                                                    ;;
  704. ;;================================================================================================;;
  705.         xor     eax, eax
  706.         ret
  707. endp
  708.  
  709.  
  710. ;;================================================================================================;;
  711. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  712. ;;================================================================================================;;
  713. ;! Below is private data you should never use directly from your code                             ;;
  714. ;;================================================================================================;;
  715. ;;////////////////////////////////////////////////////////////////////////////////////////////////;;
  716. ;;================================================================================================;;
  717.  
  718.  
  719. ;
  720.