Subversion Repositories Kolibri OS

Rev

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