Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2392 dunkaist 1
;;================================================================================================;;
2
;;//// wbmp.asm //// (c) dunkaist, 2011-2012 /////////////////////////////////////////////////////;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
19
;;                                                                                                ;;
20
;; References:                                                                                    ;;
21
;;   1. WAP WAE Specification                                                                     ;;
22
;;      http://www.wapforum.org/what/technical/SPEC-WAESpec-19990524.pdf                          ;;
23
;;   2. "Converting a BMP picture to WBMP format"                                                 ;;
24
;;      by Sajjitha Gunawardana                                                                   ;;
25
;;      http://www.codeproject.com/KB/graphics/bmp_to_wbmp_converter.aspx                         ;;
26
;;                                                                                                ;;
27
;;================================================================================================;;
28
 
29
;include 'wbmp.inc'			; wbmp is too simple, so we do not need any *.inc files
30
 
31
;;================================================================================================;;
32
proc img.is.wbmp _data, _length ;/////////////////////////////////////////////////////////////////;;
33
;;------------------------------------------------------------------------------------------------;;
34
;? Determine if raw data could be decoded (is in wbmp format)                                     ;;
35
;;------------------------------------------------------------------------------------------------;;
36
;> _data = raw data as read from file/stream                                                      ;;
37
;> _length = data length                                                                          ;;
38
;;------------------------------------------------------------------------------------------------;;
39
;< eax = false / true                                                                             ;;
40
;;================================================================================================;;
41
 
42
	push	esi
43
 
44
	mov	esi, [_data]
45
	lodsw
46
	test	ax, ax			; two first bytes of any wbmp file are zeros, check this signature
47
	jnz	.is_not_wbmp
48
 
49
					; but two byte signature is not enough to be sure it is wbmp file
50
					; let's calculate the whole image size and compare it with [_length]
51
 
52
					; calculate width first. you can read how this number is stored in wbmp format specification (see "References" above)
53
	xor	eax, eax
54
    @@:
55
	shl	eax, 7
56
	lodsb
57
	sal	al, 1
58
	jc	@b
59
	shr	eax, 1
60
	add	eax, 7
61
	shr	eax, 3
62
	mov	ecx, eax
63
 
64
					; calculate height
65
	xor	eax, eax
66
    @@:
67
	shl	eax, 7
68
	lodsb
69
	sal	al, 1
70
	jc	@b
71
	shr	eax, 1
72
 
73
	imul	eax, ecx		; image_size = width*height
74
					; raw file consists of a header and data. our image_size is the size of data only
75
	sub	esi, [_data]		; get header size
76
	add	eax, esi
77
	cmp	eax, [_length]
78
	je	.is_wbmp
79
 
80
 
81
  .is_not_wbmp:				; return 0
82
	pop	esi
83
	xor	eax, eax
84
	ret
85
 
86
  .is_wbmp:				; return 1
87
	pop	esi
88
	xor	eax, eax
89
	inc	eax
90
	ret
91
endp
92
 
93
;;================================================================================================;;
94
proc img.decode.wbmp _data, _length, _options ;///////////////////////////////////////////////////;;
95
;;------------------------------------------------------------------------------------------------;;
96
;? Decode data into image if it contains correctly formed raw data in wbmp format                 ;;
97
;;------------------------------------------------------------------------------------------------;;
98
;> _data = raw data as read from file/stream                                                      ;;
99
;> _length = data length                                                                          ;;
100
;;------------------------------------------------------------------------------------------------;;
101
;< eax = 0 (error) or pointer to image                                                            ;;
102
;;================================================================================================;;
103
	push	ebx edx esi edi
104
 
105
	mov	esi, [_data]
106
	lodsw
107
 
108
	xor	eax, eax
109
    @@:
110
	shl	eax, 7
111
	lodsb
112
	sal	al, 1
113
	jc	@b
114
	shr	eax, 1
115
	mov	ebx, eax
116
 
117
	xor	eax, eax
118
    @@:
119
	shl	eax, 7
120
	lodsb
121
	sal	al, 1
122
	jc	@b
123
	shr	eax, 1
124
	mov	edx, eax
125
 
126
	push	ebx ecx edx
127
	stdcall	img.create, ebx, edx, Image.bpp1
128
	pop	edx ecx ebx
129
	test	eax, eax
130
	jz	.quit
131
 
132
	mov	edi, [eax + Image.Palette]
133
	mov	[edi], dword 0xff000000
134
	mov	[edi + 4], dword 0xffffffff
135
 
136
	add	ebx, 7
137
	shr	ebx, 3
138
	imul	ebx, edx
139
 
140
	mov	ecx, ebx
141
	mov	edi, [eax + Image.Data]
142
	rep	movsb
143
 
144
  .quit:
145
	pop	edi esi edx ebx
146
	ret
147
endp
148
 
149
 
150
 
151
;;================================================================================================;;
152
proc img.encode.wbmp _img, _p_length, _options ;//////////////////////////////////////////////////;;
153
;;------------------------------------------------------------------------------------------------;;
154
;? Encode image into raw data in wbmp format                                                      ;;
155
;;------------------------------------------------------------------------------------------------;;
156
;> _img = pointer to image                                                                        ;;
157
;;------------------------------------------------------------------------------------------------;;
158
;< eax = 0 (error) or pointer to encoded data                                                     ;;
159
;< _p_length = encoded data length                                                                ;;
160
;;================================================================================================;;
161
	xor	eax, eax
162
	ret
163
endp
164
 
165
 
166
;;================================================================================================;;
167
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
168
;;================================================================================================;;
169
;! Below are private procs you should never call directly from your code                          ;;
170
;;================================================================================================;;
171
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
172
;;================================================================================================;;
173
 
174
;;================================================================================================;;
175
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
176
;;================================================================================================;;
177
;! Below is private data you should never use directly from your code                             ;;
178
;;================================================================================================;;
179
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
180
;;================================================================================================;;