Subversion Repositories Kolibri OS

Rev

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

Rev 3503 Rev 7735
Line 76... Line 76...
76
locals
76
locals
77
	_endianness		rd 1		; 0 stands for LE, otherwise BE
77
	_endianness		rd 1		; 0 stands for LE, otherwise BE
78
	retvalue		rd 1		; 0 (error) or pointer to image
78
	retvalue		rd 1		; 0 (error) or pointer to image
79
endl
79
endl
Line 80... Line 80...
80
 
80
 
Line 81... Line 81...
81
	push	ebx edx esi edi
81
	push	ebx esi edi
82
 
82
 
83
	mov	esi, [_data]
83
	mov	esi, [_data]
84
	lodsw
84
	lodsw
85
	mov	[_endianness], 0
85
	mov	[_endianness], 0
Line 86... Line 86...
86
	cmp	ax, word 'II'
86
	cmp	ax, word 'II'
87
	seta	byte[_endianness]
87
	seta	byte[_endianness]
88
 
88
 
-
 
89
	lodsw_
89
	lodsw_
90
	lodsd_
-
 
91
    @@:
90
	lodsd_
92
;	push	eax
91
    @@:
93
	stdcall	tiff._.parse_IFD, [_data], eax, [_endianness]
-
 
94
;	pop	esi
-
 
95
;	mov	ebx, eax
-
 
96
;	mov	[retvalue], eax
-
 
97
;	xor	eax, eax
-
 
98
;	lodsw_
92
	stdcall	tiff._.parse_IFD, [_data], eax, [_endianness]
99
;	shl	eax, 2
93
	mov	ebx, eax
100
;	lea	eax, [eax*3]
94
	mov	[retvalue], eax
101
;	add	esi, eax
95
	lodsd_
-
 
96
	test	eax, eax
-
 
97
;	jnz	@b
102
;	lodsd_
98
 
103
;	test	eax, eax
99
 
104
;	jnz	@b
100
  .quit:
105
;  .quit:
101
	mov	eax, [retvalue]
106
;	mov	eax, [retvalue]
Line 102... Line 107...
102
	pop	edi esi edx ebx
107
	pop	edi esi ebx
Line 360... Line 365...
360
	movsb
365
	movsb
361
	mov	byte[esi - 1], al
366
	mov	byte[esi - 1], al
362
	add	edi, 2
367
	add	edi, 2
363
	dec	ecx
368
	dec	ecx
364
	jnz	@b
369
	jnz	@b
-
 
370
	jmp	.post.predictor
Line 365... Line 371...
365
 
371
 
366
  .post.rgba_bgra:
372
  .post.rgba_bgra:
367
	cmp	[ebx + tiff_extra.samples_per_pixel], 4
373
	cmp	[ebx + tiff_extra.samples_per_pixel], 4
368
	jne	.post.bpp8a_to_bpp8g
374
	jne	.post.bpp8a_to_bpp8g
Line 377... Line 383...
377
	mov	byte[esi - 1], al
383
	mov	byte[esi - 1], al
378
	add	edi, 3
384
	add	edi, 3
379
	add	esi, 1
385
	add	esi, 1
380
	dec	ecx
386
	dec	ecx
381
	jnz	@b
387
	jnz	@b
-
 
388
	jmp	.post.predictor
Line 382... Line 389...
382
 
389
 
383
  .post.bpp8a_to_bpp8g:
390
  .post.bpp8a_to_bpp8g:
384
	mov	eax, [retvalue]
391
	mov	eax, [retvalue]
385
	cmp	[eax + Image.Type], Image.bpp8a
392
	cmp	[eax + Image.Type], Image.bpp8a
Line 838... Line 845...
838
  .quit:
845
  .quit:
839
	pop	esi edx ecx ebx
846
	pop	esi edx ecx ebx
840
	ret
847
	ret
841
endp
848
endp
Line -... Line 849...
-
 
849
 
-
 
850
struct lzw_ctx
-
 
851
	bits_left	 dd ?	; in current byte (pointed to by [esi])
-
 
852
	cur_shift	 dd ?	; 9 -- 12
-
 
853
	shift_counter	 dd ?	; how many shifts of current length remained
-
 
854
	table		 dd ?
-
 
855
	last_table_entry dd ?	; zero based
-
 
856
	next_table_entry dd ?	; where to place new entry
-
 
857
	strip_len	 dd ?
-
 
858
	old_code	 dd ?
Line 842... Line 859...
842
 
859
ends
843
 
-
 
844
proc tiff._.decompress.lzw _image
-
 
845
locals
-
 
846
	cur_shift		rd 1	; 9 -- 12
-
 
847
	shift_counter		rd 1	; how many shifts of current length remained
-
 
848
	bits_left		rd 1	; in current byte ( pointed to by [esi] )
-
 
849
	table			rd 1
-
 
850
	table_size		rd 1	; the number of entries
-
 
851
	old_code		rd 1
-
 
852
	next_table_entry	rd 1	; where to place new entry
-
 
853
endl
-
 
854
	push	ebx ecx edx esi
-
 
855
 
-
 
856
	mov	[table], 0
860
 
857
	mov	[bits_left], 8
-
 
858
	mov	[cur_shift], 9
-
 
859
 
-
 
860
  .begin:
-
 
861
 
861
proc tiff._.lzw_get_code
862
 ; .getnextcode:
-
 
863
	xor	eax, eax
-
 
864
	mov	edx, [cur_shift]
862
	mov	edx, [ebx+lzw_ctx.cur_shift]
865
 
863
	xor	eax, eax
866
	lodsb
864
	lodsb
867
	mov	ecx, [bits_left]
865
	mov	ecx, [ebx+lzw_ctx.bits_left]
868
	mov	ch, cl
866
	mov	ch, cl
869
	neg	cl
867
	neg	cl
870
	add	cl, 8
868
	add	cl, 8
871
	shl	al, cl
869
	shl	al, cl
872
	mov	cl, ch
870
	mov	cl, ch
873
	shl	eax, cl
871
	shl	eax, cl
874
	sub	edx, [bits_left]
872
	sub	edx, [ebx+lzw_ctx.bits_left]
875
	; second_byte
873
	; second_byte
876
	cmp	edx, 8
874
	cmp	edx, 8
877
	je	.enough_zero
875
	je	.enough_zero
878
	jb	.enough_nonzero
876
	jb	.enough_nonzero
879
	sub	edx, 8
877
	sub	edx, 8
880
	lodsb
878
	lodsb
881
	shl	eax, 8
879
	shl	eax, 8
882
	jmp	.third_byte
880
	jmp	.enough_nonzero
883
  .enough_zero:
881
  .enough_zero:
884
	mov	[bits_left], 8
882
	mov	[ebx+lzw_ctx.bits_left], 8
885
	lodsb
883
	lodsb
886
	jmp	.code_done
884
	jmp	.code_done
887
  .enough_nonzero:
885
  .enough_nonzero:
888
	mov	al, byte[esi]
886
	mov	al, byte[esi]
889
	neg	edx
887
	neg	edx
890
	add	edx, 8
888
	add	edx, 8
891
	mov	ecx, edx
-
 
892
	mov	[bits_left], edx
-
 
893
	shr	eax, cl
-
 
894
	jmp	.code_done
-
 
895
  .third_byte:
-
 
896
	mov	al, byte[esi]
-
 
897
	neg	edx
-
 
898
	add	edx, 8
-
 
899
	mov	ecx, edx
889
	mov	ecx, edx
900
	mov	[bits_left], edx
890
	mov	[ebx+lzw_ctx.bits_left], edx
-
 
891
	shr	eax, cl
-
 
892
  .code_done:
-
 
893
	dec	[ebx+lzw_ctx.shift_counter]
-
 
894
	jnz	@f
-
 
895
	mov	ecx, [ebx+lzw_ctx.cur_shift]
-
 
896
	add	[ebx+lzw_ctx.cur_shift], 1
-
 
897
	mov	edx, 1
-
 
898
	shl	edx, cl
-
 
899
	mov	[ebx+lzw_ctx.shift_counter], edx
-
 
900
    @@:
-
 
901
	ret
-
 
902
endp
-
 
903
 
-
 
904
proc tiff._.add_string_to_table uses esi
-
 
905
	mov	esi, [ebx+lzw_ctx.table]
Line -... Line 906...
-
 
906
	lea	esi, [esi + eax*8 + 256]
-
 
907
	mov	ecx, dword[esi+4]
-
 
908
 
-
 
909
	mov	edx, [ebx+lzw_ctx.next_table_entry]
-
 
910
	mov	[edx], edi
-
 
911
	lea	eax, [ecx + 1]
Line 901... Line 912...
901
	shr	eax, cl
912
	mov	[edx + 4], eax
902
  .code_done:
913
	add	[ebx+lzw_ctx.next_table_entry], 8
903
 
914
	add	[ebx+lzw_ctx.last_table_entry], 1
904
 
915
 
905
	mov	ebx, eax
916
	mov	esi, [esi]
-
 
917
	cmp	ecx, [ebx+lzw_ctx.strip_len]
-
 
918
	cmovg	ecx, [ebx+lzw_ctx.strip_len]
Line -... Line 919...
-
 
919
	sub	[ebx+lzw_ctx.strip_len], ecx
906
	cmp	ebx, 0x101	; end of information
920
	rep	movsb
907
	je	.quit
921
	ret
908
	cmp	ebx, 0x100	; clear code
922
endp
909
	jne	.no_clear_code
923
 
910
 
924
proc tiff._.init_code_table
911
	cmp	[table], 0
925
	cmp	[ebx+lzw_ctx.table], 0
912
	jne	@f
926
	jne	@f
913
	invoke	mem.alloc, 256 + 63488	; 256 + (2^8 + 2^9 + 2^10 + 2^11 + 2^12)*(4+4)
927
	invoke	mem.alloc, 256 + 63488	; 256 + (2^8 + 2^9 + 2^10 + 2^11 + 2^12)*(4+4)
914
	test	eax, eax
928
	test	eax, eax
915
	jz	.quit
929
	jz	.quit
916
	mov	[table], eax
930
	mov	[ebx+lzw_ctx.table], eax
917
    @@:
931
    @@:
918
	mov	eax, [table]
932
	mov	eax, [ebx+lzw_ctx.table]
Line 919... Line 933...
919
	mov	[next_table_entry], eax
933
	mov	[ebx+lzw_ctx.next_table_entry], eax
920
	add	[next_table_entry], 256 + (256*8) + 2*8
934
	add	[ebx+lzw_ctx.next_table_entry], 256 + (256*8) + 2*8
921
	mov	[cur_shift], 9
935
	mov	[ebx+lzw_ctx.cur_shift], 9
922
	mov	[shift_counter], 256-3	; clear code, end of information, why -3?
936
	mov	[ebx+lzw_ctx.shift_counter], 256-2	; clear code, end of information
923
	mov	[table_size], 257
937
	mov	[ebx+lzw_ctx.last_table_entry], 257	; 0--255, clear, eoi
924
 
938
 
925
	push	edi
939
	push	edi
926
	mov	ecx, 256
940
	mov	ecx, 256
927
	mov	edi, [table]
941
	mov	edi, [ebx+lzw_ctx.table]
928
	mov	ebx, edi
942
	mov	edx, edi
929
	add	edi, 256
943
	add	edi, 256
930
	mov	eax, 0
944
	mov	eax, 0
931
    @@:
945
    @@:
932
	mov	byte[ebx], al
946
	mov	byte[edx], al
933
	mov	[edi], ebx
947
	mov	[edi], edx
934
	add	edi, 4
948
	add	edi, 4
935
	add	ebx, 1
949
	add	edx, 1
936
	add	eax, 1
-
 
937
	mov	[edi], dword 1
-
 
938
	add	edi, 4
-
 
939
	dec	ecx
-
 
940
	jnz	@b
950
	add	eax, 1
941
	pop	edi
-
 
942
;  .getnextcode:
-
 
943
	xor	eax, eax
951
	mov	[edi], dword 1
944
	mov	edx, [cur_shift]
-
 
945
 
-
 
946
	lodsb
-
 
947
	mov	ecx, [bits_left]
-
 
948
	mov	ch, cl
-
 
949
	neg	cl
-
 
950
	add	cl, 8
-
 
951
	shl	al, cl
-
 
952
	mov	cl, ch
-
 
953
	shl	eax, cl
-
 
954
	sub	edx, [bits_left]
-
 
955
	; second_byte
-
 
956
	cmp	edx, 8
-
 
957
	je	.enough_zero2
-
 
958
	jb	.enough_nonzero2
-
 
959
	sub	edx, 8
952
	add	edi, 4
960
	lodsb
-
 
961
	shl	eax, 8
-
 
962
	jmp	.third_byte2
-
 
963
  .enough_zero2:
-
 
964
	mov	[bits_left], 8
-
 
965
	lodsb
-
 
966
	jmp	.code_done2
-
 
967
  .enough_nonzero2:
-
 
968
	mov	al, byte[esi]
-
 
969
	neg	edx
-
 
970
	add	edx, 8
-
 
971
	mov	ecx, edx
-
 
972
	mov	[bits_left], edx
-
 
973
	shr	eax, cl
-
 
974
	jmp	.code_done2
-
 
975
  .third_byte2:
-
 
976
	mov	al, byte[esi]
-
 
Line -... Line 953...
-
 
953
	dec	ecx
-
 
954
	jnz	@b
-
 
955
	pop	edi
-
 
956
.quit:
-
 
957
	ret
-
 
958
endp
-
 
959
 
-
 
960
proc tiff._.decompress.lzw _image
-
 
961
locals
-
 
962
	ctx			lzw_ctx
-
 
963
endl
-
 
964
	push	ebx ecx edx esi
-
 
965
	mov	ecx, [ebx+tiff_extra.rows_per_strip]
-
 
966
	mov	ebx, [_image]
-
 
967
	mov	eax, [ebx+Image.Width]
-
 
968
	call	img._.get_scanline_len
Line -... Line 969...
-
 
969
	imul	eax, ecx
977
	neg	edx
970
 
-
 
971
	lea	ebx, [ctx]
-
 
972
	mov	[ctx.strip_len], eax
978
	add	edx, 8
973
	mov	[ctx.table], 0
979
	mov	ecx, edx
974
	mov	[ctx.bits_left], 8
-
 
975
	mov	[ctx.cur_shift], 9
-
 
976
 
-
 
977
  .begin:
Line 980... Line -...
980
	mov	[bits_left], edx
-
 
981
	shr	eax, cl
978
	cmp	[ctx.strip_len], 0
982
  .code_done2:
979
	jle	.quit
983
 
980
	stdcall	tiff._.lzw_get_code
984
 
-
 
985
	mov	[old_code], eax
981
	cmp	eax, 0x101	; end of information
986
	cmp	eax, 0x101	; end of information
982
	je	.quit
987
	je	.quit
-
 
988
 
-
 
989
	push	esi
983
	cmp	eax, 0x100	; clear code
990
	mov	esi, [table]
-
 
991
	lea	esi, [esi + eax*8 + 256]
-
 
992
	mov	ecx, dword[esi+4]
-
 
993
 
-
 
994
	mov	edx, [next_table_entry]
984
	jne	.no_clear_code
995
	mov	[edx], edi
985
	call	tiff._.init_code_table
996
	lea	eax, [ecx + 1]
986
 
997
	mov	[edx + 4], eax
987
	; getnextcode
998
	add	[next_table_entry], 8
988
	call	tiff._.lzw_get_code
999
 
-
 
1000
	mov	esi, [esi]
-
 
1001
	rep	movsb
-
 
1002
	pop	esi
-
 
1003
	jmp	.begin
-
 
1004
  .no_clear_code:
-
 
1005
	cmp	eax, [table_size]
-
 
1006
	ja	.not_in_table
-
 
1007
	mov	[old_code], eax
-
 
1008
	push	esi
989
	mov	[ctx.old_code], eax
1009
	mov	esi, [table]
-
 
1010
	lea	esi, [esi + eax*8 + 256]
-
 
1011
	mov	ecx, dword[esi + 4]
-
 
1012
 
-
 
1013
	mov	edx, [next_table_entry]
-
 
1014
	mov	[edx], edi
-
 
1015
	lea	eax, [ecx + 1]
-
 
1016
	mov	[edx + 4], eax
-
 
1017
	add	[next_table_entry], 8
-
 
1018
	add	[table_size], 1
-
 
1019
 
-
 
1020
	mov	esi, [esi]
-
 
1021
	rep	movsb
-
 
1022
	pop	esi
-
 
1023
 
990
	cmp	eax, 0x101	; end of information
1024
	dec	[shift_counter]
-
 
1025
	jnz	@f
991
	je	.quit
1026
	mov	ecx, [cur_shift]
992
	call	tiff._.add_string_to_table
1027
	add	[cur_shift], 1
-
 
1028
	mov	edx, 1
-
 
1029
	shl	edx, cl
-
 
1030
	mov	[shift_counter], edx
-
 
1031
    @@:
-
 
1032
	jmp	.begin
993
	jmp	.begin
1033
 
-
 
1034
  .not_in_table:
-
 
1035
	xchg	eax, [old_code]
-
 
1036
	push	esi
994
  .no_clear_code:
1037
	mov	esi, [table]
-
 
1038
	lea	esi, [esi + eax*8 + 256]
-
 
1039
	mov	ecx, dword[esi+4]
-
 
1040
 
995
	cmp	eax, [ctx.last_table_entry]
1041
	mov	edx, [next_table_entry]
996
	ja	.not_in_table
1042
	mov	[edx], edi
997
	mov	[ctx.old_code], eax
1043
	lea	eax, [ecx + 2]
998
	call	tiff._.add_string_to_table
1044
	mov	[edx + 4], eax
-
 
1045
	add	[next_table_entry], 8
-
 
1046
	add	[table_size], 1
-
 
1047
 
-
 
1048
	mov	esi, [esi]
-
 
1049
	mov	al, [esi]
-
 
1050
	rep	movsb
-
 
1051
	mov	byte[edi], al
-
 
1052
	add	edi, 1
-
 
1053
	pop	esi
999
	jmp	.begin
1054
 
1000
  .not_in_table:
1055
	dec	[shift_counter]
-
 
1056
	jnz	@f
1001
	xchg	eax, [ctx.old_code]
1057
	mov	ecx, [cur_shift]
1002
	call	tiff._.add_string_to_table
1058
	add	[cur_shift], 1
1003
	cmp	[ctx.strip_len], 0
1059
	mov	edx, 1
1004
	jle	@f
1060
	shl	edx, cl
1005
	dec	[ctx.strip_len]
1061
	mov	[shift_counter], edx
1006
	mov	byte[edi], al
1062
    @@:
1007
	add	edi, 1
1063
	jmp	.begin
1008
    @@: