Subversion Repositories Kolibri OS

Rev

Rev 2392 | Rev 2691 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2392 Rev 2684
Line 26... Line 26...
26
include '../../../../proc32.inc'
26
include '../../../../proc32.inc'
27
include '../../../../macros.inc'
27
include '../../../../macros.inc'
28
purge section,mov,add,sub
28
purge section,mov,add,sub
Line 29... Line 29...
29
 
29
 
-
 
30
include 'libimg.inc'
Line 30... Line 31...
30
include 'libimg.inc'
31
;include '../../../../system/board/trunk/debug.inc'
Line 31... Line 32...
31
 
32
 
32
section '.flat' code readable align 16
33
section '.flat' code readable align 16
Line 83... Line 84...
83
;> --- TBD ---                                                                                    ;;
84
;> --- TBD ---                                                                                    ;;
84
;;------------------------------------------------------------------------------------------------;;
85
;;------------------------------------------------------------------------------------------------;;
85
;< --- TBD ---                                                                                    ;;
86
;< --- TBD ---                                                                                    ;;
86
;;================================================================================================;;
87
;;================================================================================================;;
87
    push    ebx
88
    push    ebx
88
    mov ebx, img._.formats_table
89
    mov ebx, img.formats_table
89
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
90
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
90
    or  eax, eax
91
    or  eax, eax
91
    jnz @f
92
    jnz @f
92
    add ebx, sizeof.FormatsTableEntry
93
    add ebx, sizeof.FormatsTableEntry
93
    cmp dword[ebx], 0
94
    cmp dword[ebx], 0
Line 150... Line 151...
150
endp
151
endp
Line 151... Line 152...
151
 
152
 
152
;;================================================================================================;;
153
;;================================================================================================;;
153
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
154
proc img.to_rgb2 _img, _out ;/////////////////////////////////////////////////////////////////////;;
154
;;------------------------------------------------------------------------------------------------;;
155
;;------------------------------------------------------------------------------------------------;;
155
;? --- TBD ---                                                                                    ;;
156
;? decodes image data into RGB triplets and stores them where [_out] points to                    ;;
156
;;------------------------------------------------------------------------------------------------;;
157
;;------------------------------------------------------------------------------------------------;;
-
 
158
;> [_img] = pointer to source image                                                               ;;
157
;> --- TBD ---                                                                                    ;;
159
;> [_out] = where to store RGB triplets                                                           ;;
158
;;------------------------------------------------------------------------------------------------;;
160
;;------------------------------------------------------------------------------------------------;;
159
;< --- TBD ---                                                                                    ;;
161
;< none                                                                                           ;;
160
;;================================================================================================;;
162
;;================================================================================================;;
161
    push    esi edi
163
    push    esi edi
162
    mov esi, [_img]
164
    mov esi, [_img]
163
    stdcall img._.validate, esi
165
    stdcall img._.validate, esi
Line 171... Line 173...
171
endp
173
endp
Line 172... Line 174...
172
 
174
 
173
;;================================================================================================;;
175
;;================================================================================================;;
174
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
176
proc img.to_rgb _img ;////////////////////////////////////////////////////////////////////////////;;
175
;;------------------------------------------------------------------------------------------------;;
177
;;------------------------------------------------------------------------------------------------;;
176
;? --- TBD ---                                                                                    ;;
178
;? decodes image data into RGB triplets and returns pointer to memory area containing them        ;;
177
;;------------------------------------------------------------------------------------------------;;
179
;;------------------------------------------------------------------------------------------------;;
178
;> --- TBD ---                                                                                    ;;
180
;> [_img] = pointer to source image                                                               ;;
179
;;------------------------------------------------------------------------------------------------;;
181
;;------------------------------------------------------------------------------------------------;;
180
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                                        ;;
182
;< eax = 0 / pointer to rgb_data (array of [rgb] triplets)                                        ;;
181
;;================================================================================================;;
183
;;================================================================================================;;
182
    push    esi edi
184
    push    esi edi
Line 211... Line 213...
211
endp
213
endp
Line 212... Line 214...
212
 
214
 
213
;;================================================================================================;;
215
;;================================================================================================;;
214
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
216
proc img._.do_rgb ;///////////////////////////////////////////////////////////////////////////////;;
215
;;------------------------------------------------------------------------------------------------;;
217
;;------------------------------------------------------------------------------------------------;;
216
;? --- TBD ---                                                                                    ;;
218
;? decodes [esi + Image.Data] data into RGB triplets and stores them at [edi]                     ;;
217
;;------------------------------------------------------------------------------------------------;;
219
;;------------------------------------------------------------------------------------------------;;
-
 
220
;> esi = pointer to source image                                                                  ;;
218
;> --- TBD ---                                                                                    ;;
221
;> edi = pointer to memory to store RGB triplets                                                  ;;
219
;;------------------------------------------------------------------------------------------------;;
222
;;------------------------------------------------------------------------------------------------;;
220
;< --- TBD ---                                                                                    ;;
223
;< none                                                                                           ;;
221
;;================================================================================================;;
224
;;================================================================================================;;
222
    mov ecx, [esi + Image.Width]
225
    mov ecx, [esi + Image.Width]
223
    imul    ecx, [esi + Image.Height]
226
    imul    ecx, [esi + Image.Height]
224
    mov eax, [esi + Image.Type]
227
    mov eax, [esi + Image.Type]
Line 550... Line 553...
550
endp
553
endp
Line 551... Line 554...
551
 
554
 
552
;;================================================================================================;;
555
;;================================================================================================;;
553
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
556
proc img.decode _data, _length, _options ;////////////////////////////////////////////////////////;;
554
;;------------------------------------------------------------------------------------------------;;
557
;;------------------------------------------------------------------------------------------------;;
555
;? --- TBD ---                                                                                    ;;
558
;? decodes loaded into memory graphic file                                                        ;;
556
;;------------------------------------------------------------------------------------------------;;
559
;;------------------------------------------------------------------------------------------------;;
-
 
560
;> [_data]    = pointer to file in memory                                                         ;;
-
 
561
;> [_length]  = size in bytes of memory area pointed to by [_data]                                ;;
557
;> --- TBD ---                                                                                    ;;
562
;> [_options] = 0 / pointer to the structure of additional options                                ;;
558
;;------------------------------------------------------------------------------------------------;;
563
;;------------------------------------------------------------------------------------------------;;
559
;< eax = 0 / pointer to image                                                                     ;;
564
;< eax = 0 / pointer to image                                                                     ;;
560
;;================================================================================================;;
565
;;================================================================================================;;
561
    push    ebx
566
    push    ebx
562
    mov ebx, img._.formats_table
567
    mov ebx, img.formats_table
563
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
568
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
564
    or  eax, eax
569
    or  eax, eax
565
    jnz @f
570
    jnz @f
566
    add ebx, sizeof.FormatsTableEntry
571
    add ebx, sizeof.FormatsTableEntry
Line 573... Line 578...
573
    leave
578
    leave
574
    jmp eax
579
    jmp eax
575
endp
580
endp
Line 576... Line 581...
576
 
581
 
577
;;================================================================================================;;
582
;;================================================================================================;;
578
proc img.encode _img, _p_length, _options ;///////////////////////////////////////////////////////;;
583
proc img.encode _img, _common, _specific ;////////////////////////////////////////////////////////;;
579
;;------------------------------------------------------------------------------------------------;;
584
;;------------------------------------------------------------------------------------------------;;
580
;? --- TBD ---                                                                                    ;;
585
;? encode image to some format                                                                    ;;
581
;;------------------------------------------------------------------------------------------------;;
586
;;------------------------------------------------------------------------------------------------;;
-
 
587
;> [_img]      = pointer to input image                                                           ;;
-
 
588
;> [_common]   = some most important options                                                      ;;
-
 
589
;     0x00 :  byte : format id (defined in libimg.inc)                                            ;;
-
 
590
;     0x01 :  byte : fast encoding (0) / best compression ratio (255)                             ;;
-
 
591
;                    0 : store uncompressed data (if supported both by the format and libimg)     ;;
-
 
592
;                    1 - 255 : use compression, if supported                                      ;;
-
 
593
;                    this option may be ignored if any format specific options are defined        ;;
-
 
594
;                    i.e. the 0 here will be ignored if some compression algorithm is specified   ;;
-
 
595
;     0x02 :  byte : flags (bitfield)                                                             ;;
-
 
596
;                   0x01 : return an error if format specific conditions cannot be met            ;;
-
 
597
;                   0x02 : preserve current bit depth. means 8bpp/16bpp/24bpp and so on           ;;
-
 
598
;                   0x04 : delete alpha channel, if any                                           ;;
-
 
599
;                   0x08 : flush alpha channel with 0xff, if any; add it if none                  ;;
-
 
600
;     0x03 :  byte : reserved, must be 0                                                          ;;
-
 
601
;> [_specific] = 0 / pointer to the structure of format specific options                          ;;
582
;> --- TBD ---                                                                                    ;;
602
;                   see .inc for description                                         ;;
583
;;------------------------------------------------------------------------------------------------;;
603
;;------------------------------------------------------------------------------------------------;;
-
 
604
;< eax = 0 / pointer to encoded data                                                              ;;
584
;< eax = 0 / pointer to encoded data                                                              ;;
605
;< ecx = error code / the size of encoded data                                                    ;;
-
 
606
;     1 : out of memory                                                                           ;;
-
 
607
;     2 : format is not supported                                                                 ;;
-
 
608
;     3 : specific conditions cannot be satisfied                                                 ;;
585
;< [_p_length] = data length                                                                      ;;
609
;     4 : bit depth cannot be preserved                                                           ;;
-
 
610
;;================================================================================================;;
-
 
611
	mov	ebx, [_img]
-
 
612
 
-
 
613
	movzx	eax, byte[_common]
-
 
614
	dec	eax
-
 
615
	imul	eax, sizeof.FormatsTableEntry
-
 
616
	add	eax, FormatsTableEntry.Capabilities
-
 
617
	add	eax, img.formats_table
-
 
618
	mov	eax, [eax]
-
 
619
	test	eax, 1				; is encoding to this format supported at all?
-
 
620
	jnz	@f
-
 
621
	mov	ecx, LIBIMG_ERROR_FORMAT
-
 
622
	jmp	.error
-
 
623
    @@:
-
 
624
	mov	ecx, [ebx + Image.Type]
-
 
625
	mov	edx, 1
-
 
626
	shl	edx, cl
-
 
627
	test	eax, edx
-
 
628
	jnz	.bit_depth_ok
-
 
629
	test	byte[_common+2], LIBIMG_ENCODE_STRICT_BIT_DEPTH
-
 
630
	jz	@f
-
 
631
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
-
 
632
	jmp	.error
-
 
633
    @@:
-
 
634
	mov	edx, 1 SHL Image.bpp24
-
 
635
	test	eax, edx
-
 
636
	jnz	@f
-
 
637
	mov	ecx, LIBIMG_ERROR_BIT_DEPTH
-
 
638
	jmp	.error
-
 
639
    @@:
-
 
640
	stdcall	img.create, [ebx + Image.Width], [ebx + Image.Height], Image.bpp24
-
 
641
	test	eax, eax
-
 
642
	jnz	@f
-
 
643
	mov	ecx, LIBIMG_ERROR_OUT_OF_MEMORY
-
 
644
	jmp	.error
-
 
645
    @@:
-
 
646
	push	eax
-
 
647
	stdcall	img.to_rgb2, ebx, [eax + Image.Data]
-
 
648
	pop	ebx
-
 
649
 
-
 
650
  .bit_depth_ok:
-
 
651
	movzx	eax, byte[_common]
-
 
652
	dec	eax
-
 
653
	imul	eax, sizeof.FormatsTableEntry
-
 
654
	add	eax, FormatsTableEntry.Encode
-
 
655
	add	eax, img.formats_table
-
 
656
	mov	eax, [eax]
-
 
657
	stdcall	eax, [_img], [_common], [_specific]
-
 
658
	push	eax ecx
-
 
659
	cmp	ebx, [_img]
-
 
660
	je	@f
-
 
661
	stdcall	img.destroy, ebx
-
 
662
    @@:
-
 
663
	pop	ecx eax
-
 
664
	jmp	.quit
-
 
665
 
586
;;================================================================================================;;
666
  .error:
-
 
667
	xor	eax, eax
587
    xor eax, eax
668
  .quit:
588
    ret
669
	ret
Line 589... Line 670...
589
endp
670
endp
590
 
671
 
591
;;================================================================================================;;
672
;;================================================================================================;;
592
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
673
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
593
;;------------------------------------------------------------------------------------------------;;
674
;;------------------------------------------------------------------------------------------------;;
594
;? --- TBD ---                                                                                    ;;
675
;? creates an Image structure and initializes some its fields                                     ;;
-
 
676
;;------------------------------------------------------------------------------------------------;;
-
 
677
;> [_width]  = width of an image in pixels                                                        ;;
595
;;------------------------------------------------------------------------------------------------;;
678
;> [_height] = height of an image in pixels                                                       ;;
596
;> --- TBD ---                                                                                    ;;
679
;> [_type]   = one of the Image.bppN constants from libimg.inc                                    ;;
597
;;------------------------------------------------------------------------------------------------;;
680
;;------------------------------------------------------------------------------------------------;;
598
;< eax = 0 / pointer to image                                                                     ;;
681
;< eax = 0 / pointer to image                                                                     ;;
Line 627... Line 710...
627
endp
710
endp
Line 628... Line 711...
628
 
711
 
629
;;================================================================================================;;
712
;;================================================================================================;;
630
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
713
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
-
 
714
;;------------------------------------------------------------------------------------------------;;
631
;;------------------------------------------------------------------------------------------------;;
715
;? frees memory occupied by an image and all the memory regions its fields point to               ;;
632
;? --- TBD ---                                                                                    ;;
716
;? for image sequences deletes only one frame and fixes Previous/Next pointers                    ;;
633
;;------------------------------------------------------------------------------------------------;;
717
;;------------------------------------------------------------------------------------------------;;
634
;> --- TBD ---                                                                                    ;;
718
;> [_img] = pointer to image                                                                      ;;
635
;;------------------------------------------------------------------------------------------------;;
719
;;------------------------------------------------------------------------------------------------;;
636
;< eax = false / true                                                                             ;;
720
;< eax = 0 (fail) / 1 (success)                                                                   ;;
637
;;================================================================================================;;
721
;;================================================================================================;;
638
    mov eax, [_img]
722
    mov eax, [_img]
639
    mov edx, [eax + Image.Previous]
723
    mov edx, [eax + Image.Previous]
640
    test    edx, edx
724
    test    edx, edx
Line 653... Line 737...
653
endp
737
endp
Line 654... Line 738...
654
 
738
 
655
;;================================================================================================;;
739
;;================================================================================================;;
656
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
740
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
-
 
741
;;------------------------------------------------------------------------------------------------;;
657
;;------------------------------------------------------------------------------------------------;;
742
;? frees memory occupied by an image and all the memory regions its fields point to               ;;
658
;? --- TBD ---                                                                                    ;;
743
;? follows Previous/Next pointers and deletes all the images in sequence                          ;;
659
;;------------------------------------------------------------------------------------------------;;
744
;;------------------------------------------------------------------------------------------------;;
660
;> --- TBD ---                                                                                    ;;
745
;> [_img] = pointer to image                                                                      ;;
661
;;------------------------------------------------------------------------------------------------;;
746
;;------------------------------------------------------------------------------------------------;;
662
;< eax = false / true                                                                             ;;
747
;< eax = 0 (fail) / 1 (success)                                                                   ;;
663
;;================================================================================================;;
748
;;================================================================================================;;
664
    push    1
749
    push    1
665
    mov eax, [_img]
750
    mov eax, [_img]
666
    mov eax, [eax + Image.Previous]
751
    mov eax, [eax + Image.Previous]
Line 1785... Line 1870...
1785
.done:
1870
.done:
1786
    pop edi esi ebx
1871
    pop edi esi ebx
1787
    ret
1872
    ret
1788
endp
1873
endp
Line -... Line 1874...
-
 
1874
 
-
 
1875
 
-
 
1876
align 4
-
 
1877
img.formats_table:
-
 
1878
  .bmp  dd LIBIMG_FORMAT_ID_BMP,  img.is.bmp,  img.decode.bmp,     img.encode.bmp, 0
-
 
1879
  .ico  dd LIBIMG_FORMAT_ID_ICO,  img.is.ico,  img.decode.ico_cur, img.encode.ico, 0
-
 
1880
  .cur  dd LIBIMG_FORMAT_ID_CUR,  img.is.cur,  img.decode.ico_cur, img.encode.cur, 0
-
 
1881
  .gif  dd LIBIMG_FORMAT_ID_GIF,  img.is.gif,  img.decode.gif,     img.encode.gif, 0
-
 
1882
  .png  dd LIBIMG_FORMAT_ID_PNG,  img.is.png,  img.decode.png,     img.encode.png, 0
-
 
1883
  .jpg  dd LIBIMG_FORMAT_ID_JPEG, img.is.jpg,  img.decode.jpg,     img.encode.jpg, 0
-
 
1884
  .tga  dd LIBIMG_FORMAT_ID_TGA,  img.is.tga,  img.decode.tga,     img.encode.tga, 0
-
 
1885
  .pcx  dd LIBIMG_FORMAT_ID_PCX,  img.is.pcx,  img.decode.pcx,     img.encode.pcx, 0
-
 
1886
  .xcf  dd LIBIMG_FORMAT_ID_XCF,  img.is.xcf,  img.decode.xcf,     img.encode.xcf, 0
-
 
1887
  .tiff dd LIBIMG_FORMAT_ID_TIFF, img.is.tiff, img.decode.tiff,    img.encode.tiff,0
-
 
1888
  .pnm  dd LIBIMG_FORMAT_ID_PNM,  img.is.pnm,  img.decode.pnm,     img.encode.pnm, 1 + (1 SHL Image.bpp1) + (1 SHL Image.bpp8) + (1 SHL Image.bpp24)
-
 
1889
  .wbmp dd LIBIMG_FORMAT_ID_WBMP, img.is.wbmp, img.decode.wbmp,    img.encode.wbmp,0
-
 
1890
  .z80  dd LIBIMG_FORMAT_ID_Z80,  img.is.z80,  img.decode.z80,     img.encode.z80, 0 ;this must be the last entry as there are no signatures in z80 screens at all
-
 
1891
        dd 0
1789
 
1892
 
1790
;;================================================================================================;;
1893
;;================================================================================================;;
1791
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1894
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1792
;;================================================================================================;;
1895
;;================================================================================================;;
1793
;! Below are private procs you should never call directly from your code                          ;;
1896
;! Below are private procs you should never call directly from your code                          ;;
Line 1990... Line 2093...
1990
;;================================================================================================;;
2093
;;================================================================================================;;
1991
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
2094
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1992
;;================================================================================================;;
2095
;;================================================================================================;;
Line 1993... Line 2096...
1993
 
2096
 
1994
align 4
-
 
1995
img._.formats_table:
-
 
1996
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
-
 
1997
  .ico dd img.is.ico, img.decode.ico_cur, img.encode.ico
-
 
1998
  .cur dd img.is.cur, img.decode.ico_cur, img.encode.cur
-
 
1999
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
-
 
2000
  .png dd img.is.png, img.decode.png, img.encode.png
-
 
2001
  .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
-
 
2002
  .tga dd img.is.tga, img.decode.tga, img.encode.tga
-
 
2003
  .pcx dd img.is.pcx, img.decode.pcx, img.encode.pcx
-
 
2004
  .xcf dd img.is.xcf, img.decode.xcf, img.encode.xcf
-
 
2005
  .tiff dd img.is.tiff, img.decode.tiff, img.encode.tiff
-
 
2006
  .pnm dd img.is.pnm, img.decode.pnm, img.encode.pnm
-
 
2007
  .wbmp dd img.is.wbmp, img.decode.wbmp, img.encode.wbmp
-
 
2008
  .z80 dd img.is.z80, img.decode.z80, img.encode.z80 ;this must be the last entry as there are no
-
 
2009
  ;signatures in z80 screens at all
-
 
2010
       dd 0
-
 
2011
 
-
 
2012
align 4
2097
align 4
2013
type2bpp    dd  8, 24, 32, 15, 16, 1
2098
type2bpp    dd  8, 24, 32, 15, 16, 1
2014
img._.do_rgb.handlers:
2099
img._.do_rgb.handlers:
2015
    dd  img._.do_rgb.bpp8
2100
    dd  img._.do_rgb.bpp8
2016
    dd  img._.do_rgb.bpp24
2101
    dd  img._.do_rgb.bpp24
Line 2059... Line 2144...
2059
    img.unlock_bits , 'img_unlock_bits' , \
2144
    img.unlock_bits  , 'img_unlock_bits'  , \
2060
    img.flip    , 'img_flip'        , \
2145
    img.flip         , 'img_flip'         , \
2061
    img.flip.layer  , 'img_flip_layer'  , \
2146
    img.flip.layer   , 'img_flip_layer'   , \
2062
    img.rotate  , 'img_rotate'      , \
2147
    img.rotate       , 'img_rotate'       , \
2063
    img.rotate.layer, 'img_rotate_layer', \
2148
    img.rotate.layer , 'img_rotate_layer' , \
2064
    img.draw        , 'img_draw'
2149
    img.draw         , 'img_draw'         , \
-
 
2150
    img.formats_table, 'img_formats_table'
Line 2065... Line 2151...
2065
 
2151
 
2066
; import from deflate unpacker
2152
; import from deflate unpacker
2067
; is initialized only when PNG loading is requested
2153
; is initialized only when PNG loading is requested
2068
align 4
2154
align 4