Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;  VNC client for KolibriOS                                       ;;
  7. ;;                                                                 ;;
  8. ;;  Written by hidnplayr@kolibrios.org                             ;;
  9. ;;                                                                 ;;
  10. ;;          GNU GENERAL PUBLIC LICENSE                             ;;
  11. ;;             Version 2, June 1991                                ;;
  12. ;;                                                                 ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. deflate_callback:
  16.         mov     eax, [deflate_length]
  17.         mov     ecx, [esp+8]
  18.         mov     [ecx], eax
  19.         mov     eax, [deflate_buffer]
  20.         ret     8
  21.  
  22. encoding_ZRLE:
  23.  
  24.         DEBUGF  2, "ZRLE\n"
  25.   @@:
  26.         lea     eax, [esi+4]
  27.         cmp     [datapointer], eax
  28.         jae     @f
  29.         call    read_data.more
  30.         jmp     @b
  31.   @@:
  32.  
  33.         lodsd
  34.         bswap   eax                             ; number of packed bytes
  35.         DEBUGF  2, "packed length=%u bytes\n", eax
  36.  
  37.   @@:
  38.         push    eax
  39.         add     eax, esi
  40.         cmp     [datapointer], eax
  41.         jae     @f
  42.         call    read_data.more
  43.         pop     eax
  44.         jmp     @b
  45.   @@:
  46.         pop     ecx
  47.         lea     eax, [esi+ecx]
  48.         push    eax                             ; end of data ptr
  49.  
  50.         cmp     [deflate_buffer], 0             ; first chunk of the stream?
  51.         jne     @f
  52.         lodsw                                   ; load zlib header
  53.         cmp     ax, 0x9c78                      ; default compression?
  54.         jne     .deflate_fail
  55.         sub     ecx, 2                          ; subtract 2 byte header
  56.  
  57. ;        invoke  deflate_init
  58. ;        mov     [deflate_str], eax
  59.   @@:
  60.  
  61.         sub     ecx, 4                          ; subtract 4 byte check value trailer
  62.         mov     [deflate_buffer], esi
  63.         mov     [deflate_length], ecx
  64.  
  65. ;        mov     eax, [deflate_str]
  66.         push    eax                                             ; allocate place on stack
  67.         invoke  deflate_unpack2, deflate_callback, 0, esp       ; unpack the data
  68.         pop     ecx                                             ; get size in ecx
  69.         test    eax, eax
  70.         jz      .deflate_fail
  71.         push    eax
  72.         DEBUGF  2, "%u bytes unpacked succesfully\n", ecx
  73.         test    ecx, ecx
  74.         jz      .fail
  75.  
  76.         mov     esi, eax
  77.         mov     [subrectangle.x], 0
  78.         mov     [subrectangle.y], 0
  79.   .tile:
  80.         mov     eax, [rectangle.width]
  81.         sub     eax, [subrectangle.x]
  82.         cmp     eax, 64
  83.         jb      @f
  84.         mov     eax, 64
  85.   @@:
  86.         mov     [subrectangle.width], eax
  87.  
  88.         mov     edx, [rectangle.height]
  89.         sub     edx, [subrectangle.y]
  90.         cmp     edx, 64
  91.         jb      @f
  92.         mov     edx, 64
  93.   @@:
  94.         mov     [subrectangle.height], edx
  95.         DEBUGF  1, "Subrectangle: x=%u y=%u width=%u height=%u ", \
  96.         [subrectangle.x], [subrectangle.y], [subrectangle.width], [subrectangle.height]
  97.  
  98. ; Calculate first pixel pos
  99.         mov     eax, [rectangle.y]
  100.         add     eax, [subrectangle.y]
  101.         movzx   ebx, [screen.width]
  102.         mul     ebx
  103.         add     eax, [rectangle.x]
  104.         add     eax, [subrectangle.x]
  105.         lea     edi, [framebuffer_data+eax*3]
  106.  
  107. ; Calculate offset between two rows of pixels
  108.         movzx   eax, [screen.width]
  109.         sub     eax, [subrectangle.width]
  110.         lea     ebp, [eax*3]
  111.  
  112.         mov     edx, [subrectangle.height]
  113.  
  114. ;;;;
  115.         lodsb                   ; subencoding type
  116.         DEBUGF  1, "encoding=%u\n", al
  117.         test    al, al
  118.         jz      .raw
  119.         cmp     al, 1
  120.         je      .solid
  121.         cmp     al, 16
  122.         jbe     .palette_packed
  123.         cmp     al, 127
  124.         je      .reuse_palette
  125.         jb      .invalid
  126.         and     al, 0x7f
  127.         jz      .plain_rle
  128.         cmp     al, 1
  129.         je      .prle_reuse_palette
  130.  
  131. ; Palette Run Length Encoded tile
  132.         mov     [palettesize], al
  133.         call    create_palette
  134.   .prle_reuse_palette:
  135.         DEBUGF  1, "Pallete RLE tile\n"
  136.  
  137.         mov     eax, 1
  138.   .prle_line:
  139.         mov     ebx, [subrectangle.width]
  140.   .prle_pixel:
  141.         dec     eax
  142.         jz      .prle_reload
  143.  
  144.         mov     word[edi], cx
  145.         rol     ecx, 16
  146.         add     edi, 2
  147.         mov     byte[edi], cl
  148.         rol     ecx, 16
  149.         inc     edi
  150.         dec     ebx
  151.         jnz     .prle_pixel
  152.  
  153.         add     edi, ebp
  154.         dec     edx
  155.         jnz     .prle_line
  156.         jmp     .next_tile
  157.  
  158.   .prle_reload:
  159. ;;;
  160. ; load palette index and get color from palette
  161.         xor     eax, eax
  162.         lodsb
  163.         push    ebx
  164.         mov     bl, al
  165.         and     al, 0x7f
  166.         mov     ecx, [palette+eax*4]
  167.  
  168. ; run length follows?
  169.         xor     eax, eax
  170.         test    bl, 0x80
  171.         pop     ebx
  172.         jz      .plength_ok
  173.  
  174. ;;;
  175.  
  176. ; load runlength
  177.         push    ebx
  178.         xor     eax, eax
  179.         xor     ebx, ebx
  180.   @@:
  181.         lodsb
  182.         cmp     al, 255
  183.         jne     @f
  184.         add     ebx, eax
  185.         jmp     @b
  186.   @@:
  187.         add     eax, ebx
  188.         pop     ebx
  189.   .plength_ok:
  190.         add     eax, 2
  191.         jmp     .prle_pixel
  192.  
  193.  
  194.  
  195.  
  196. ; Run Length Encoded tile
  197.   .plain_rle:
  198.  
  199.         DEBUGF  1, "Plain RLE tile\n"
  200.  
  201.         mov     eax, 1
  202.   .rle_line:
  203.         mov     ebx, [subrectangle.width]
  204.   .rle_pixel:
  205.         dec     eax
  206.         jz      .rle_reload
  207.  
  208.         mov     word[edi], cx
  209.         rol     ecx, 16
  210.         add     edi, 2
  211.         mov     byte[edi], cl
  212.         rol     ecx, 16
  213.         inc     edi
  214.         dec     ebx
  215.         jnz     .rle_pixel
  216.         add     edi, ebp
  217.         dec     edx
  218.         jnz     .rle_line
  219.         jmp     .next_tile
  220.  
  221.   .rle_reload:
  222.         ; load pixel value
  223.         call    pixel_to_24bpp
  224.  
  225. ;;;
  226.  
  227.         ; load length
  228.         xor     eax, eax
  229.         push    ebx
  230.         xor     ebx, ebx
  231.   @@:
  232.         lodsb
  233.         cmp     al, 255
  234.         jne     @f
  235.         add     ebx, eax
  236.         jmp     @b
  237.   @@:
  238.         add     eax, ebx
  239.         add     eax, 2
  240.         pop     ebx
  241.         jmp     .rle_pixel
  242.  
  243.  
  244.  
  245.   .reuse_palette:
  246.         cmp     [palettesize], 1
  247.         jne     .reuse_palette_
  248.         mov     ecx, [palette]
  249.         mov     eax, ecx
  250.         shr     eax, 16
  251.         jmp     .solid_line
  252.  
  253. ; Palette packed tile
  254.   .palette_packed:
  255.         DEBUGF  1, "Palette packed tile\n"
  256.  
  257.         mov     [palettesize], al
  258.         call    create_palette
  259.  
  260.   .reuse_palette_:
  261.         cmp     [palettesize], 2
  262.         je      .palette_1bit
  263.         cmp     [palettesize], 4
  264.         jbe     .palette_2bit
  265.         jmp     .palette_4bit
  266.  
  267.   .palette_1bit:
  268.         DEBUGF  1, "1-bit palette\n"
  269.   .palette_1bit_line:
  270.         mov     ebx, [subrectangle.width]
  271.   .palette_1bit_byte:
  272.         lodsb
  273.         rol     al, 1
  274.         mov     ecx, eax
  275.         and     eax, 0x1
  276.         mov     eax, [palette+4*eax]
  277.         stosw
  278.         shr     eax, 16
  279.         stosb
  280.         dec     ebx
  281.         jz      .palette_1bit_next_line
  282.  
  283.         rol     cl, 1
  284.         mov     eax, ecx
  285.         and     eax, 0x1
  286.         mov     eax, [palette+4*eax]
  287.         stosw
  288.         shr     eax, 16
  289.         stosb
  290.         dec     ebx
  291.         jz      .palette_1bit_next_line
  292.  
  293.         rol     cl, 1
  294.         mov     eax, ecx
  295.         and     eax, 0x1
  296.         mov     eax, [palette+4*eax]
  297.         stosw
  298.         shr     eax, 16
  299.         stosb
  300.         dec     ebx
  301.         jz      .palette_1bit_next_line
  302.  
  303.         rol     cl, 1
  304.         mov     eax, ecx
  305.         and     eax, 0x1
  306.         mov     eax, [palette+4*eax]
  307.         stosw
  308.         shr     eax, 16
  309.         stosb
  310.         dec     ebx
  311.         jz      .palette_1bit_next_line
  312.  
  313.         rol     cl, 1
  314.         mov     eax, ecx
  315.         and     eax, 0x1
  316.         mov     eax, [palette+4*eax]
  317.         stosw
  318.         shr     eax, 16
  319.         stosb
  320.         dec     ebx
  321.         jz      .palette_1bit_next_line
  322.  
  323.         rol     cl, 1
  324.         mov     eax, ecx
  325.         and     eax, 0x1
  326.         mov     eax, [palette+4*eax]
  327.         stosw
  328.         shr     eax, 16
  329.         stosb
  330.         dec     ebx
  331.         jz      .palette_1bit_next_line
  332.  
  333.         rol     cl, 1
  334.         mov     eax, ecx
  335.         and     eax, 0x1
  336.         mov     eax, [palette+4*eax]
  337.         stosw
  338.         shr     eax, 16
  339.         stosb
  340.         dec     ebx
  341.         jz      .palette_1bit_next_line
  342.  
  343.         rol     cl, 1
  344.         and     ecx, 0x1
  345.         mov     eax, [palette+4*ecx]
  346.         stosw
  347.         shr     eax, 16
  348.         stosb
  349.         dec     ebx
  350.         jnz     .palette_1bit_byte
  351.  
  352.   .palette_1bit_next_line:
  353.         add     edi, ebp
  354.         dec     edx
  355.         jnz     .palette_1bit_line
  356.         jmp     .next_tile
  357.  
  358.  
  359.  
  360.   .palette_2bit:
  361.         DEBUGF  1, "2-bit palette\n"
  362.   .palette_2bit_line:
  363.         mov     ebx, [subrectangle.width]
  364.   .palette_2bit_byte:
  365.         lodsb
  366.         mov     ecx, eax
  367.         and     eax, 0xc0
  368.         shr     eax, 4
  369.         mov     eax, [palette+eax]
  370.         stosw
  371.         shr     eax, 16
  372.         stosb
  373.         dec     ebx
  374.         jz      .palette_2bit_next_line
  375.  
  376.         mov     eax, ecx
  377.         and     eax, 0x30
  378.         shr     eax, 2
  379.         mov     eax, [palette+eax]
  380.         stosw
  381.         shr     eax, 16
  382.         stosb
  383.         dec     ebx
  384.         jz      .palette_2bit_next_line
  385.  
  386.         mov     eax, ecx
  387.         and     eax, 0x0c
  388.         mov     eax, [palette+eax]
  389.         stosw
  390.         shr     eax, 16
  391.         stosb
  392.         dec     ebx
  393.         jz      .palette_2bit_next_line
  394.  
  395.         and     ecx, 0x03
  396.         mov     eax, [palette+4*ecx]
  397.         stosw
  398.         shr     eax, 16
  399.         stosb
  400.         dec     ebx
  401.         jnz     .palette_2bit_byte
  402.  
  403.   .palette_2bit_next_line:
  404.         add     edi, ebp
  405.         dec     edx
  406.         jnz     .palette_2bit_line
  407.         jmp     .next_tile
  408.  
  409.  
  410.  
  411.  
  412.   .palette_4bit:
  413.         DEBUGF  1, "4-bit palette\n"
  414.   .palette_4bit_line:
  415.         mov     ebx, [subrectangle.width]
  416.   .palette_4bit_byte:
  417.         lodsb
  418.         mov     cl, al
  419.         and     eax, 0xf0
  420.         shr     eax, 2
  421.         mov     eax, [palette+eax]
  422.         stosw
  423.         shr     eax, 16
  424.         stosb
  425.         dec     ebx
  426.         jz      .palette_4bit_next_line
  427.  
  428.         and     ecx, 0x0f
  429.         shl     ecx, 2
  430.         mov     eax, [palette+ecx]
  431.         stosw
  432.         shr     eax, 16
  433.         stosb
  434.         dec     ebx
  435.         jnz     .palette_4bit_byte
  436.   .palette_4bit_next_line:
  437.         add     edi, ebp
  438.         dec     edx
  439.         jnz     .palette_4bit_line
  440.         jmp     .next_tile
  441.  
  442.  
  443. ; RAW tile
  444.   .raw:
  445.         push    edx
  446.         mov     eax, [subrectangle.width]
  447.         mul     [subrectangle.height]
  448.         lea     eax, [eax*3]
  449.         pop     edx
  450.  
  451. ;;;
  452.  
  453.         DEBUGF  1, "RAW tile\n"
  454.   .raw_line:
  455.         mov     ebx, [subrectangle.width]
  456.   .raw_pixel:
  457.         call    pixel_to_24bpp
  458.         mov     word[edi], cx
  459.         shr     ecx, 16
  460.         add     edi, 2
  461.         mov     byte[edi], cl
  462.         inc     edi
  463.         dec     ebx
  464.         jnz     .raw_pixel
  465.         add     edi, ebp
  466.         dec     edx
  467.         jnz     .raw_line
  468.         jmp     .next_tile
  469.  
  470.  
  471.  
  472. ; Single color tile
  473.   .solid:
  474.         DEBUGF  1, "Solid tile\n"
  475.         call    pixel_to_24bpp
  476.         mov     eax, ecx
  477.         shr     eax, 16
  478.  
  479.         mov     [palettesize], 1
  480.         mov     [palette], ecx
  481.  
  482.   .solid_line:
  483.         mov     ebx, [subrectangle.width]
  484.   .solid_pixel:
  485.         mov     [edi], cx
  486.         add     edi, 2
  487.         mov     [edi], al
  488.         inc     edi
  489.         dec     ebx
  490.         jnz     .solid_pixel
  491.         add     edi, ebp
  492.         dec     edx
  493.         jnz     .solid_line
  494. ;        jmp     .next_tile
  495.  
  496.  
  497. ; Go to the next tile
  498.   .next_tile:
  499.         mov     eax, [subrectangle.x]
  500.         add     eax, 64
  501.         cmp     eax, [rectangle.width]
  502.         jae     .next_row
  503.         mov     [subrectangle.x], eax
  504.         jmp     .tile
  505.   .next_row:
  506.         mov     [subrectangle.x], 0
  507.         mov     eax, [subrectangle.y]
  508.         add     eax, 64
  509.         cmp     eax, [rectangle.height]
  510.         jae     .done
  511.         mov     [subrectangle.y], eax
  512.         jmp     .tile
  513.  
  514.   .done:
  515.         DEBUGF  1, "ZRLE complete!\n"
  516.         pop     ecx
  517.         mcall   68, 13                          ; free the unpacked data
  518.         pop     esi
  519.         jmp     next_rectangle
  520.  
  521.   .invalid:
  522.         DEBUGF  2, "Invalid subencoding type!\n"
  523.   .fail:
  524.         DEBUGF  2, "ZRLE failed!\n"
  525.         pop     ecx
  526.         mcall   68, 13                          ; free unpacked data
  527.         pop     esi
  528.         jmp     next_rectangle
  529.  
  530.  
  531.   .deflate_fail:
  532.         DEBUGF  2,"Unpacking failed!\n"
  533.         pop     esi
  534.         jmp     next_rectangle