Subversion Repositories Kolibri OS

Rev

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