Subversion Repositories Kolibri OS

Rev

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

Rev 717 Rev 999
Line 1... Line 1...
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// bmp.asm //// (c) mike.dld, 2007-2008 //////////////////////////////////////////////////////;;
2
;;//// bmp.asm //// (c) mike.dld, 2007-2008, (c) diamond, 2009 ///////////////////////////////////;;
3
;;================================================================================================;;
3
;;================================================================================================;;
4
;;                                                                                                ;;
4
;;                                                                                                ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
5
;; This file is part of Common development libraries (Libs-Dev).                                  ;;
6
;;                                                                                                ;;
6
;;                                                                                                ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
7
;; Libs-Dev is free software: you can redistribute it and/or modify it under the terms of the GNU ;;
8
;; General Public License as published by the Free Software Foundation, either version 3 of the   ;;
8
;; Lesser General Public License as published by the Free Software Foundation, either version 2.1 ;;
9
;; License, or (at your option) any later version.                                                ;;
9
;; of the License, or (at your option) any later version.                                         ;;
10
;;                                                                                                ;;
10
;;                                                                                                ;;
11
;; Libs-Dev is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without  ;;
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  ;;
12
;; even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  ;;
13
;; General Public License for more details.                                                       ;;
13
;; Lesser General Public License for more details.                                                ;;
14
;;                                                                                                ;;
14
;;                                                                                                ;;
15
;; You should have received a copy of the GNU General Public License along with Libs-Dev. If not, ;;
15
;; You should have received a copy of the GNU Lesser General Public License along with Libs-Dev.  ;;
16
;; see .                                                            ;;
16
;; If not, see .                                                    ;;
17
;;                                                                                                ;;
17
;;                                                                                                ;;
18
;;================================================================================================;;
18
;;================================================================================================;;
19
;;                                                                                                ;;
19
;;                                                                                                ;;
20
;; References:                                                                                    ;;
20
;; References:                                                                                    ;;
21
;;   1. "Microsoft Windows Bitmap File Format Summary"                                            ;;
21
;;   1. "Microsoft Windows Bitmap File Format Summary"                                            ;;
Line 26... Line 26...
26
 
26
 
Line 27... Line 27...
27
 
27
 
28
include 'bmp.inc'
28
include 'bmp.inc'
-
 
29
 
29
 
30
;;================================================================================================;;
30
;;================================================================================================;;
31
;;proc img.is.bmp _data, _length ;////////////////////////////////////////////////////////////////;;
31
proc img.is.bmp _data, _length ;//////////////////////////////////////////////////////////////////;;
32
img.is.bmp:
32
;;------------------------------------------------------------------------------------------------;;
33
;;------------------------------------------------------------------------------------------------;;
33
;? Determine if raw data could be decoded (is in BMP format)                                      ;;
34
;? Determine if raw data could be decoded (is in BMP format)                                      ;;
34
;;------------------------------------------------------------------------------------------------;;
35
;;------------------------------------------------------------------------------------------------;;
35
;> _data = raw data as read from file/stream                                                      ;;
36
;> _data = raw data as read from file/stream                                                      ;;
36
;> _length = data length                                                                          ;;
37
;> _length = data length                                                                          ;;
-
 
38
;;------------------------------------------------------------------------------------------------;;
37
;;------------------------------------------------------------------------------------------------;;
39
;< eax = false / true                                                                             ;;
38
;< eax = false / true                                                                             ;;
40
;;================================================================================================;;
-
 
41
; test 1 (length of data): data must contain FileHeader and required fields from InfoHeader
39
;;================================================================================================;;
42
	cmp	dword [esp+8], sizeof.bmp.FileHeader + 12
40
	cmp	[_length], 2
43
	jb	.nope
41
	jb	.nope
44
; test 2: signature
Line 42... Line 45...
42
	mov	eax, [_data]
45
	mov	eax, [esp+4]
43
	cmp	word[eax], 'BM'
46
	cmp	word [eax], 'BM'
44
	je	.yep
47
	je	.yep
Line 45... Line 48...
45
 
48
 
46
  .nope:
49
  .nope:
47
	xor	eax, eax
50
	xor	eax, eax
48
	ret
51
	ret	8
49
 
52
 
Line 50... Line 53...
50
  .yep:
53
  .yep:
51
	xor	eax,eax
54
	xor	eax, eax
52
	inc	eax
55
	inc	eax
53
	ret
56
	ret	8
Line 63... Line 66...
63
;;------------------------------------------------------------------------------------------------;;
66
;;------------------------------------------------------------------------------------------------;;
64
;< eax = 0 (error) or pointer to image                                                            ;;
67
;< eax = 0 (error) or pointer to image                                                            ;;
65
;;================================================================================================;;
68
;;================================================================================================;;
66
locals
69
locals
67
  img dd ?
70
  img dd ?
-
 
71
  bTopDown db ?
68
endl
72
endl
Line 69... Line 73...
69
 
73
 
Line -... Line 74...
-
 
74
	push	ebx esi edi
70
	push	ebx
75
 
71
 
76
; img.is.bmp has been already called by img.decode
72
	stdcall img.is.bmp, [_data], [_length]
77
;	stdcall img.is.bmp, [_data], [_length]
Line 73... Line 78...
73
	or	eax, eax
78
;	or	eax, eax
74
	jz	.error
79
;	jz	.error
75
 
80
 
76
	mov	ebx, [_data]
81
	mov	ebx, [_data]
77
;       cmp     [ebx + bmp.Header.info.Compression], bmp.BI_RGB
82
;       cmp     [ebx + bmp.Header.info.Compression], bmp.BI_RGB
78
;       je      @f
83
;       je      @f
-
 
84
;       mov     eax, [ebx + bmp.Header.file.Size]
-
 
85
;       cmp     eax, [_length]
-
 
86
;       jne     .error
-
 
87
;   @@:
-
 
88
 
-
 
89
	mov	eax, [ebx + bmp.Header.info.Size]
-
 
90
; sanity check: file length must be greater than size of headers
-
 
91
	add	eax, sizeof.bmp.FileHeader
-
 
92
	cmp	[_length], eax
-
 
93
	jbe	.error
-
 
94
 
-
 
95
	mov	[bTopDown], 0
-
 
96
 
-
 
97
	cmp	eax, sizeof.bmp.FileHeader + 12
-
 
98
	jz	.old1
-
 
99
	cmp	eax, sizeof.bmp.FileHeader + 40
-
 
100
	jz	.normal
-
 
101
	cmp	eax, sizeof.bmp.FileHeader + 56
-
 
102
	jnz	.error
-
 
103
; convert images with <= 8 bpp to 8bpp, other - to 32 bpp
-
 
104
.normal:
-
 
105
	xor	eax, eax
-
 
106
	inc	eax	; Image.bpp8
-
 
107
	cmp	[ebx + bmp.Header.info.BitCount], 8
-
 
108
	jbe	@f
-
 
109
	mov	al, Image.bpp32
-
 
110
@@:
-
 
111
	push	eax
-
 
112
	mov	eax, [ebx + bmp.Header.info.Height]
-
 
113
	test	eax, eax
-
 
114
	jns	@f
-
 
115
	inc	[bTopDown]
-
 
116
	neg	eax
-
 
117
@@:
-
 
118
	pushd	eax
-
 
119
	pushd	[ebx + bmp.Header.info.Width]
-
 
120
	jmp	.create
-
 
121
.old1:
-
 
122
	xor	eax, eax
-
 
123
	inc	eax	; Image.bpp8
-
 
124
	cmp	[ebx + bmp.Header.info.OldBitCount], 8
-
 
125
	jbe	@f
-
 
126
	mov	al, Image.bpp32
-
 
127
@@:
-
 
128
	push	eax
-
 
129
	movsx	eax, [ebx + bmp.Header.info.OldHeight]
-
 
130
	test	eax, eax
-
 
131
	jns	@f
-
 
132
	inc	[bTopDown]
-
 
133
	neg	eax
-
 
134
@@:
-
 
135
	push	eax
-
 
136
	movzx	eax, [ebx + bmp.Header.info.OldWidth]
Line 79... Line -...
79
;       mov     eax, [ebx + bmp.Header.file.Size]
-
 
80
;       cmp     eax, [_length]
137
	push	eax
81
;       jne     .error
138
.create:
82
 
139
	call	img.create
83
    @@: stdcall img.create, [ebx + bmp.Header.info.Width], [ebx + bmp.Header.info.Height]
140
 
Line 84... Line 141...
84
	or	eax, eax
141
	or	eax, eax
85
	jz	.error
142
	jz	.error
86
	mov	[img], eax
143
	mov	[img], eax
87
	mov	edx, eax
144
	mov	edx, eax
88
 
145
 
89
	invoke	mem.alloc, sizeof.bmp.Image
-
 
90
	or	eax, eax
146
	invoke	mem.alloc, sizeof.bmp.Image
91
	jz	.error
147
	or	eax, eax
-
 
148
	jz	.error.free
-
 
149
	mov	[edx + Image.Extended], eax
-
 
150
	push	eax
-
 
151
	mov	edi, eax
-
 
152
	mov	ecx, sizeof.bmp.Image/4
-
 
153
	xor	eax, eax
-
 
154
	rep	stosd
-
 
155
	pop	edi
92
	mov	[edx + Image.Extended], eax
156
	lea	esi, [ebx + sizeof.bmp.FileHeader]
-
 
157
	pushd	[ebx + bmp.FileHeader.OffBits]
-
 
158
	mov	ecx, [esi + bmp.InfoHeader.Size]
-
 
159
	cmp	ecx, 12
-
 
160
	jz	.old2
-
 
161
	rep	movsb
-
 
162
	jmp	.decode
-
 
163
.old2:
-
 
164
	movsd	; Size
-
 
165
	movzx	eax, word [esi]	; OldWidth -> Width
-
 
166
	stosd
-
 
167
	movsx	eax, word [esi+2]	; OldHeight -> Height
-
 
168
	stosd
-
 
169
	lodsd	; skip OldWidth+OldHeight
-
 
170
	movsd	; Planes+BitCount
-
 
171
.decode:
Line -... Line 172...
-
 
172
 
93
	mov	esi, ebx
173
	pop	eax
94
	add	esi, sizeof.bmp.FileHeader
174
	mov	esi, [_length]
95
	mov	edi, eax
175
	sub	esi, eax
96
	mov	ecx, sizeof.bmp.InfoHeader
176
	jbe	.error.free
97
	rep	movsb
177
 
98
 
178
	mov	eax, [edx + Image.Extended]
99
	mov	eax, [ebx + bmp.Header.info.Compression]
179
	mov	eax, [eax + bmp.Image.info.Compression]
-
 
180
	cmp	eax, bmp.BI_RGB
-
 
181
	jne	@f
100
	cmp	eax, bmp.BI_RGB
182
	stdcall ._.rgb
101
	jne	@f
183
	jmp	.decoded
102
	stdcall ._.rgb
184
    @@: cmp	eax, bmp.BI_RLE8
103
	jmp	.decoded
185
	jne	@f
-
 
186
	cmp	[ebx + bmp.Header.info.BitCount], 8
-
 
187
	jnz	.error.free
104
    @@: cmp	eax, bmp.BI_RLE8
188
	stdcall ._.rle
105
	jne	@f
189
	jmp	.decoded
106
	stdcall ._.rle
190
    @@: cmp	eax, bmp.BI_RLE4
107
	jmp	.decoded
191
	jne	@f
108
    @@: cmp	eax, bmp.BI_RLE4
192
	cmp	[ebx + bmp.Header.info.BitCount], 4
109
	jne	@f
193
	jnz	.error.free
-
 
194
	stdcall ._.rle
-
 
195
	jmp	.decoded
110
	stdcall ._.rle
196
    @@: cmp	eax, bmp.BI_BITFIELDS
111
	jmp	.decoded
197
	jne	.error.free
112
    @@: cmp	eax, bmp.BI_BITFIELDS
198
	stdcall ._.bitfields
113
	jne	@f
199
	jmp	.decoded
114
	stdcall ._.bitfields
200
; BI_JPEG and BI_PNG constants are not valid values for BMP file,
115
	jmp	.decoded
201
; they are intended for WinAPI
116
    @@: cmp	eax, bmp.BI_JPEG
202
;    @@: cmp	eax, bmp.BI_JPEG
Line 117... Line 203...
117
	jne	@f
203
;	jne	@f
118
	stdcall ._.jpeg
204
;	stdcall ._.jpeg
119
	jmp	.decoded
205
;	jmp	.decoded
-
 
206
;    @@: cmp	eax, bmp.BI_PNG
120
    @@: cmp	eax, bmp.BI_PNG
207
;	jne	.error
121
	jne	.error
208
;	stdcall ._.png
Line -... Line 209...
-
 
209
 
-
 
210
  .decoded:
-
 
211
	or	eax, eax
122
	stdcall ._.png
212
	jz	@f
-
 
213
  .error.free:
123
 
214
	stdcall img.destroy, [img]
-
 
215
	jmp	.error
124
  .decoded:
216
 
Line 125... Line 217...
125
	or	eax, eax
217
    @@:
126
	jz	@f
218
	cmp	[bTopDown], 0
127
	stdcall img.destroy, [img]
219
	jnz	@f
128
	jmp	.error
220
	stdcall img.flip, [img], FLIP_VERTICAL
129
	
221
    @@:
Line 130... Line 222...
130
    @@: stdcall img.flip, [img], FLIP_VERTICAL
222
	mov	eax, [img]
131
	mov	eax, [img]
223
	pop	edi esi ebx
Line 173... Line 265...
173
;;================================================================================================;;
265
;;================================================================================================;;
174
	mov	ecx, [edx + Image.Extended]
266
	mov	ecx, [edx + Image.Extended]
175
	mov	[ecx + bmp.Image.info.AlphaMask], 0
267
	mov	[ecx + bmp.Image.info.AlphaMask], 0
176
	mov	edi, [edx + Image.Data]
268
	mov	edi, [edx + Image.Data]
Line 177... Line 269...
177
 
269
 
178
	movzx	eax, [ebx + bmp.Header.info.BitCount]
270
	movzx	eax, [ecx + bmp.Image.info.BitCount]
179
	cmp	eax, 32
271
	cmp	eax, 32
180
	je	.32bpp
272
	je	.32bpp
181
	cmp	eax, 24
273
	cmp	eax, 24
182
	je	.24bpp
274
	je	.24bpp
Line 200... Line 292...
200
	ret
292
	ret
Line 201... Line 293...
201
 
293
 
Line 202... Line 294...
202
;;------------------------------------------------------------------------------------------------;;
294
;;------------------------------------------------------------------------------------------------;;
-
 
295
 
-
 
296
img.decode.bmp._.rgb.24bpp:
-
 
297
	mov	eax, [edx + Image.Width]
-
 
298
	lea	eax, [eax*3 + 3]
-
 
299
	and	eax, not 3
-
 
300
	mov	ecx, [edx + Image.Height]
-
 
301
	imul	eax, ecx
203
 
302
	cmp	esi, eax
204
img.decode.bmp._.rgb.24bpp:
303
	jb	img.decode.bmp._.rgb.error
205
	mov	esi, ebx
-
 
Line 206... Line 304...
206
	add	esi, [ebx + bmp.Header.file.OffBits]
304
	mov	esi, ebx
207
	mov	ecx, [ebx + bmp.Header.info.Height]
305
	add	esi, [ebx + bmp.Header.file.OffBits]
208
 
306
 
209
  .next_line:
307
  .next_line:
Line 210... Line 308...
210
	push	ecx
308
	push	ecx edx
211
	mov	ecx, [ebx + bmp.Header.info.Width]
309
	mov	ecx, [edx + Image.Width]
212
	xor	edx, edx
310
	xor	edx, edx
Line 218... Line 316...
218
	dec	ecx
316
	dec	ecx
219
	jnz	.next_line_pixel
317
	jnz	.next_line_pixel
Line 220... Line 318...
220
 
318
 
221
	and	edx, 0x03
319
	and	edx, 0x03
222
	add	esi, edx
320
	add	esi, edx
223
	pop	ecx
321
	pop	edx ecx
224
	dec	ecx
322
	dec	ecx
Line 225... Line 323...
225
	jnz	.next_line
323
	jnz	.next_line
Line 236... Line 334...
236
	ret
334
	ret
Line 237... Line 335...
237
 
335
 
Line 238... Line 336...
238
;;------------------------------------------------------------------------------------------------;;
336
;;------------------------------------------------------------------------------------------------;;
-
 
337
 
239
 
338
img.decode.bmp._.rgb.8bpp:
240
img.decode.bmp._.rgb.8bpp:
339
	mov	eax, [edx + Image.Width]
241
	mov	esi, ebx
340
	add	eax, 3
Line 242... Line 341...
242
	add	esi, [ebx + bmp.Header.file.OffBits]
341
	call	img.decode.bmp._.rgb.prepare_palette
243
	mov	ecx, [ebx + bmp.Header.info.Height]
342
	jc	img.decode.bmp._.rgb.error
244
 
343
 
245
  .next_line:
-
 
246
	push	ecx
344
  .next_line:
247
	mov	ecx, [ebx + bmp.Header.info.Width]
345
	push	ecx
248
 
346
	mov	ecx, [edx + Image.Width]
249
  .next_line_dword:
-
 
250
	lodsb
347
	mov	eax, ecx
251
	and	eax, 0x000000FF
348
	neg	eax
252
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
-
 
253
	stosd
-
 
254
	dec	ecx
349
	and	eax, 3
255
	jnz	.next_line_dword
350
	rep	movsb
256
 
351
	add	esi, eax
Line 257... Line 352...
257
	pop	ecx
352
	pop	ecx
Line 258... Line 353...
258
	dec	ecx
353
	dec	ecx
Line 259... Line 354...
259
	jnz	.next_line
354
	jnz	.next_line
-
 
355
 
-
 
356
	jmp	img.decode.bmp._.rgb.exit
260
 
357
 
261
	jmp	img.decode.bmp._.rgb.exit
358
;;------------------------------------------------------------------------------------------------;;
262
 
359
 
Line 263... Line 360...
263
;;------------------------------------------------------------------------------------------------;;
360
img.decode.bmp._.rgb.4bpp:
264
 
361
	mov	eax, [edx + Image.Width]
265
img.decode.bmp._.rgb.4bpp:
362
	add	eax, 7
Line 266... Line 363...
266
	mov	esi, ebx
363
	shr	eax, 1
267
	add	esi, [ebx + bmp.Header.file.OffBits]
364
	call	img.decode.bmp._.rgb.prepare_palette
268
	mov	ecx, [ebx + bmp.Header.info.Height]
365
	jc	img.decode.bmp._.rgb.error
269
 
366
 
Line 279... Line 376...
279
	mov	ecx, 32 / 4
376
	mov	ecx, 32 / 4
Line 280... Line 377...
280
 
377
 
281
  .next_pixel:
378
  .next_pixel:
282
	rol	edx, 4
379
	rol	edx, 4
283
	mov	al, dl
380
	mov	al, dl
284
	and	eax, 0x0000000F
-
 
285
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
381
	and	al, 0x0000000F
286
	stosd
382
	stosb
287
	dec	dword[esp]
383
	dec	dword[esp]
288
	jz	@f
384
	jz	@f
289
	dec	ecx
385
	dec	ecx
Line 290... Line 386...
290
	jnz	.next_pixel
386
	jnz	.next_pixel
291
 
387
 
292
    @@: pop	ecx
388
    @@: pop	ecx
Line 293... Line 389...
293
	or	ecx, ecx
389
	or	ecx, ecx
294
	jnz	.next_line_dword
390
	jnz	.next_line_dword
295
 
391
 
Line 296... Line 392...
296
	pop	ecx
392
	pop	edx ecx
Line 297... Line 393...
297
	dec	ecx
393
	dec	ecx
Line 298... Line 394...
298
	jnz	.next_line
394
	jnz	.next_line
-
 
395
 
299
 
396
	jmp	img.decode.bmp._.rgb.exit
-
 
397
 
300
	jmp	img.decode.bmp._.rgb.exit
398
;;------------------------------------------------------------------------------------------------;;
301
 
399
 
Line 302... Line 400...
302
;;------------------------------------------------------------------------------------------------;;
400
img.decode.bmp._.rgb.1bpp:
303
 
401
	mov	eax, [edx + Image.Width]
304
img.decode.bmp._.rgb.1bpp:
402
	add	eax, 31
Line 305... Line 403...
305
	mov	esi, ebx
403
	shr	eax, 3
306
	add	esi, [ebx + bmp.Header.file.OffBits]
404
	call	img.decode.bmp._.rgb.prepare_palette
307
	mov	ecx, [ebx + bmp.Header.info.Height]
405
	jc	img.decode.bmp._.rgb.error
308
 
406
 
Line 318... Line 416...
318
	mov	ecx, 32 / 1
416
	mov	ecx, 32 / 1
Line 319... Line 417...
319
 
417
 
320
  .next_pixel:
418
  .next_pixel:
321
	rol	edx, 1
419
	rol	edx, 1
322
	mov	al, dl
420
	mov	al, dl
323
	and	eax, 0x00000001
-
 
324
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
421
	and	al, 0x00000001
325
	stosd
422
	stosb
326
	dec	dword[esp]
423
	dec	dword[esp]
327
	jz	@f
424
	jz	@f
328
	dec	ecx
425
	dec	ecx
Line 329... Line 426...
329
	jnz	.next_pixel
426
	jnz	.next_pixel
330
 
427
 
331
    @@: pop	ecx
428
    @@: pop	ecx
Line 332... Line 429...
332
	or	ecx, ecx
429
	or	ecx, ecx
333
	jnz	.next_line_dword
430
	jnz	.next_line_dword
334
 
431
 
Line 335... Line 432...
335
	pop	ecx
432
	pop	edx ecx
Line 345... Line 442...
345
	ret
442
	ret
Line 346... Line 443...
346
 
443
 
347
  img.decode.bmp._.rgb.error:
444
  img.decode.bmp._.rgb.error:
348
	or	eax, -1
445
	or	eax, -1
-
 
446
	ret
-
 
447
 
-
 
448
img.decode.bmp._.rgb.prepare_palette:
-
 
449
	and	eax, not 3
-
 
450
	mov	ecx, [edx + Image.Height]
-
 
451
	imul	eax, ecx
-
 
452
	cmp	esi, eax
-
 
453
	jb	.ret
-
 
454
	mov	esi, [ebx + bmp.Header.info.Size]
-
 
455
	add	esi, sizeof.bmp.FileHeader
-
 
456
	jc	.ret
-
 
457
	mov	eax, [ebx + bmp.Header.file.OffBits]
-
 
458
	sub	eax, esi
-
 
459
	jc	.ret
-
 
460
	push	edi
-
 
461
	mov	edi, [edx + Image.Palette]
-
 
462
	push	ecx
-
 
463
	mov	ecx, 256
-
 
464
	cmp	esi, sizeof.bmp.FileHeader + 12
-
 
465
	jz	.old
-
 
466
	shr	eax, 2
-
 
467
	add	esi, ebx
-
 
468
	cmp	ecx, eax
-
 
469
	jb	@f
-
 
470
	mov	ecx, eax
-
 
471
@@:
-
 
472
	rep	movsd
-
 
473
	jmp	.common
-
 
474
.old:
-
 
475
	movsd
-
 
476
	dec	esi
-
 
477
	sub	eax, 3
-
 
478
	jbe	@f
-
 
479
	sub	ecx, 1
-
 
480
	jnz	.old
-
 
481
@@:
-
 
482
.common:
-
 
483
	pop	ecx
-
 
484
	pop	edi
-
 
485
	mov	esi, ebx
-
 
486
	add	esi, [ebx + bmp.Header.file.OffBits]
-
 
487
.ret:
349
	ret
488
	ret
Line 350... Line 489...
350
endp
489
endp
351
 
490
 
352
;;================================================================================================;;
491
;;================================================================================================;;
Line 363... Line 502...
363
  scanline_len	dd ?
502
  scanline_len	dd ?
364
  marker_x	dd ?
503
  marker_x	dd ?
365
  marker_y	dd ?
504
  marker_y	dd ?
366
  abs_mode_addr dd ?
505
  abs_mode_addr dd ?
367
  enc_mode_addr dd ?
506
  enc_mode_addr dd ?
-
 
507
  height	dd ?
368
endl
508
endl
Line 369... Line -...
369
 
-
 
370
	mov	edi, [edx + Image.Data]
-
 
371
 
509
 
372
	mov	[abs_mode_addr], .absolute_mode.rle8
510
	mov	[abs_mode_addr], .absolute_mode.rle8
373
	mov	[enc_mode_addr], .encoded_mode.rle8
511
	mov	[enc_mode_addr], .encoded_mode.rle8
374
	cmp	[ebx + bmp.Header.info.Compression], bmp.BI_RLE4
512
	cmp	[ebx + bmp.Header.info.Compression], bmp.BI_RLE4
375
	jne	@f
513
	jne	@f
376
	mov	[abs_mode_addr], .absolute_mode.rle4
514
	mov	[abs_mode_addr], .absolute_mode.rle4
-
 
515
	mov	[enc_mode_addr], .encoded_mode.rle4
-
 
516
    @@:
-
 
517
 
-
 
518
	push	esi
-
 
519
	xor	eax, eax	; do not check file size in .prepare_palette
-
 
520
	call	img.decode.bmp._.rgb.prepare_palette
-
 
521
	pop	ecx	; ecx = rest bytes in file
Line 377... Line -...
377
	mov	[enc_mode_addr], .encoded_mode.rle4
-
 
378
 
-
 
379
    @@: mov	esi, ebx
522
	jc	.error
380
	add	esi, [ebx + bmp.Header.file.OffBits]
-
 
381
	mov	eax, [edx + Image.Width]
523
 
-
 
524
	mov	eax, [edx + Image.Width]
-
 
525
	mov	[scanline_len], eax
382
	shl	eax, 2
526
	mov	eax, [edx + Image.Height]
383
	mov	[scanline_len], eax
527
	mov	[height], eax
384
	xor	eax, eax
528
	xor	eax, eax
-
 
529
	mov	[marker_x], eax
Line 385... Line 530...
385
	mov	[marker_x], eax
530
	mov	[marker_y], eax
-
 
531
	mov	edi, [edx + Image.Data]
-
 
532
 
386
	mov	[marker_y], eax
533
  .next_run:
387
 
534
	sub	ecx, 1
388
  .next_run:
535
	jc	.eof
389
	xor	eax, eax
536
	xor	eax, eax
390
	lodsb
537
	lodsb
Line 391... Line 538...
391
	or	al, al
538
	or	al, al
-
 
539
	jz	.escape_mode
-
 
540
	jmp	[enc_mode_addr]
392
	jz	.escape_mode
541
 
393
	jmp	[enc_mode_addr]
542
  .escape_mode:
394
 
543
	sub	ecx, 1
395
  .escape_mode:
544
	jc	.eof
396
	lodsb
545
	lodsb
397
	cmp	al, 0
546
	cmp	al, 0
398
	je	.end_of_scanline
547
	je	.end_of_scanline
399
	cmp	al, 1
548
	cmp	al, 1
Line 400... Line 549...
400
	je	.exit
549
	je	.exit
401
	cmp	al, 2
550
	cmp	al, 2
402
	je	.offset_marker
-
 
403
	jmp	[abs_mode_addr]
-
 
404
 
551
	je	.offset_marker
405
  .end_of_scanline: ; 0
-
 
406
	mov	eax, [marker_x]
552
	jmp	[abs_mode_addr]
-
 
553
 
-
 
554
  .end_of_scanline: ; 0
407
	shl	eax, 2
555
	sub	edi, [marker_x]
-
 
556
	add	edi, [scanline_len]
408
	neg	eax
557
	mov	[marker_x], 0
-
 
558
	mov	eax, [marker_y]
Line 409... Line 559...
409
	add	eax, [scanline_len]
559
	inc	eax
-
 
560
	mov	[marker_y], eax
-
 
561
	cmp	eax, [height]
410
	add	edi, eax
562
	jb	.next_run
411
	mov	[marker_x], 0
563
	jmp	.exit
412
	inc	[marker_y]
564
 
413
	jmp	.next_run
565
  .offset_marker: ; 2: dx, dy
414
 
566
	sub	ecx, 2
415
  .offset_marker: ; 2: dx, dy
567
	jc	.eof
416
	lodsb
-
 
417
	mov	edx, [marker_x]
568
	lodsb
418
	add	edx, eax
569
	mov	edx, [marker_x]
419
	cmp	edx, [ebx + bmp.Header.info.Width]
-
 
420
	jae	.exit
570
	add	edx, eax
421
	mov	[marker_x], edx
571
	cmp	edx, [scanline_len]
422
	shl	eax, 2
572
	jae	.exit
423
	add	edi, eax
573
	mov	[marker_x], edx
424
	lodsb
574
	add	edi, eax
425
	and	eax, 0x0FF
575
	lodsb
426
	mov	edx, [marker_y]
576
	mov	edx, [marker_y]
427
	add	edx, eax
577
	add	edx, eax
Line 428... Line 578...
428
	cmp	edx, [ebx + bmp.Header.info.Height]
578
	cmp	edx, [height]
-
 
579
	jae	.exit
429
	jae	.exit
580
	mov	[marker_y], edx
-
 
581
	imul	eax, [scanline_len]
430
	mov	[marker_y], edx
582
	add	edi, eax
431
	imul	eax, [scanline_len]
-
 
432
	add	edi, eax
583
	jmp	.next_run
433
	jmp	.next_run
584
 
434
 
585
  .encoded_mode.rle8: ; N: b1 * N
435
  .encoded_mode.rle8: ; N: b1 * N
586
	call	.fix_marker
436
	mov	edx, eax
587
	sub	ecx, 1
Line 437... Line 588...
437
	lodsb
588
	jc	.eof
-
 
589
	lodsb
438
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
590
	push	ecx
439
    @@: dec	edx
591
	mov	ecx, edx
440
	js	.fix_marker
592
	rep	stosb
441
	stosd
593
	pop	ecx
442
	inc	[marker_x]
594
	jmp	.check_eoi
443
	jmp	@b
595
 
444
 
596
  .absolute_mode.rle8: ; N: b1 .. bN
445
  .absolute_mode.rle8: ; N: b1 .. bN
597
	call	.fix_marker
446
	mov	edx, eax
598
	cmp	ecx, edx
447
	push	eax
599
	jae	@f
-
 
600
	mov	edx, ecx
448
    @@: dec	edx
601
    @@:
449
	js	@f
602
	push	ecx
450
	lodsb
603
	mov	ecx, edx
451
	and	eax, 0x0FF
604
	rep	movsb
-
 
605
	pop	ecx
-
 
606
	sub	ecx, edx
-
 
607
	jz	.eof
-
 
608
	test	edx, 1
452
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
609
	jz	.check_eoi
Line 453... Line 610...
453
	stosd
610
	sub	ecx, 1
-
 
611
	jc	.eof
454
	inc	[marker_x]
612
	inc	esi
-
 
613
  .check_eoi:
-
 
614
	mov	eax, [marker_y]
455
	jmp	@b
615
	cmp	eax, [height]
-
 
616
	jb	.next_run
456
    @@: pop	eax
617
	jmp	.exit
-
 
618
 
457
	test	eax, 1
619
  .encoded_mode.rle4: ; N: b1 * N
458
	jz	.fix_marker
-
 
459
	inc	esi
-
 
460
	jmp	.fix_marker
-
 
461
 
620
	call	.fix_marker
462
  .encoded_mode.rle4: ; N: b1 * N
-
 
463
	mov	edx, eax
621
	sub	ecx, 1
464
	lodsb
622
	jc	.eof
465
	mov	ecx, eax
623
	movzx	eax, byte [esi]
466
	shr	ecx, 4
624
	inc	esi
467
	mov	ecx, [ebx + ecx * 4 + bmp.Header.info.Palette]
-
 
468
	and	eax, 0x00F
625
	push	ecx
469
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
626
	mov	ecx, eax
470
    @@: dec	edx
627
	and	eax, 0xF
471
	js	.fix_marker
-
 
472
	test	edx, 1
628
	shr	ecx, 4
-
 
629
    @@:
-
 
630
	dec	edx
-
 
631
	js	@f
Line 473... Line 632...
473
	jz	.odd
632
	mov	[edi], cl
-
 
633
	dec	edx
-
 
634
	js	@f
-
 
635
	mov	[edi+1], al
474
	mov	[edi], ecx
636
	add	edi, 2
-
 
637
	jmp	@b
-
 
638
    @@:
-
 
639
	pop	ecx
475
	add	edi, 4
640
	jmp	.check_eoi
476
	inc	[marker_x]
641
 
477
	jmp	@b
642
  .absolute_mode.rle4: ; N: b1 .. bN
478
    .odd:
643
	call	.fix_marker
479
	stosd
-
 
480
	inc	[marker_x]
644
	lea	eax, [edx+1]
481
	jmp	@b
645
	shr	eax, 1
482
 
646
	cmp	ecx, eax
483
  .absolute_mode.rle4: ; N: b1 .. bN
647
	jbe	@f
484
	mov	edx, eax
-
 
485
	push	eax
648
	lea	edx, [ecx*2]
486
    @@: dec	edx
649
    @@:
487
	js	@f
650
	push	ecx edx
488
	lodsb
-
 
489
	and	eax, 0x0FF
-
 
490
	mov	ecx, eax
-
 
491
	shr	eax, 4
651
    @@: dec	edx
492
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
652
	js	@f
493
	stosd
653
	lodsb
494
	inc	[marker_x]
654
	mov	cl, al
495
	dec	edx
655
	shr	al, 4
496
	js	@f
656
	and	cl, 0xF
497
	mov	eax, ecx
657
	stosb
498
	and	eax, 0x00F
658
	dec	edx
499
	mov	eax, [ebx + eax * 4 + bmp.Header.info.Palette]
659
	js	@f
Line 500... Line 660...
500
	stosd
660
	mov	[edi], cl
501
	inc	[marker_x]
661
	inc	edi
502
	jmp	@b
-
 
503
    @@: pop	eax
662
	jmp	@b
504
	and	eax, 0x03
663
    @@: pop	eax ecx
-
 
664
	and	eax, 0x03
-
 
665
	jp	.check_eoi
-
 
666
	sub	ecx, 1
-
 
667
	jc	.eof
-
 
668
	inc	esi
505
	jz	.fix_marker
669
	jmp	.check_eoi
-
 
670
 
-
 
671
  .fix_marker:
-
 
672
	mov	edx, eax
-
 
673
	add	eax, [marker_x]
506
	cmp	eax, 3
674
	mov	[marker_x], eax
-
 
675
    @@:
-
 
676
	sub	eax, [scanline_len]
-
 
677
	jle	@f
Line 507... Line 678...
507
	je	.fix_marker
678
	mov	[marker_x], eax
-
 
679
	push	eax
508
	inc	esi
680
	mov	eax, [marker_y]
509
	jmp	.fix_marker
681
	inc	eax
Line 510... Line 682...
510
 
682
	mov	[marker_y], eax
511
  .fix_marker:
683
	cmp	eax, [height]
Line 540... Line 712...
540
  unshift bmp.RgbByteQuad
712
  unshift bmp.RgbByteQuad
541
  mask	  bmp.RgbQuad
713
  mask	  bmp.RgbQuad
542
  delta   dd ?
714
  delta   dd ?
543
endl
715
endl
Line 544... Line 716...
544
 
716
 
-
 
717
	push	edi
-
 
718
 
545
	push	esi edi
719
	mov	[delta], 4
-
 
720
	mov	eax, [edx + Image.Extended]
-
 
721
	cmp	[eax + bmp.Image.info.BitCount], 32
-
 
722
	je	@f
-
 
723
	cmp	[eax + bmp.Image.info.BitCount], 16
-
 
724
	jne	.error
-
 
725
	mov	[delta], 2
-
 
726
    @@:
-
 
727
	mov	ecx, [edx + Image.Width]
-
 
728
	imul	ecx, [edx + Image.Height]
-
 
729
	imul	ecx, [delta]
-
 
730
	cmp	esi, ecx
-
 
731
	jb	.error
-
 
732
 
Line 546... Line 733...
546
	mov	esi, [edx + Image.Extended]
733
	mov	esi, eax
547
 
734
 
548
	mov	ecx, [esi + bmp.Image.info.RedMask]
735
	mov	ecx, [esi + bmp.Image.info.RedMask]
549
	call	.calc_shift
736
	call	.calc_shift
Line 575... Line 762...
575
 
762
 
576
	mov	edi, [edx + Image.Data]
763
	mov	edi, [edx + Image.Data]
577
	mov	esi, ebx
764
	mov	esi, ebx
Line 578... Line -...
578
	add	esi, [ebx + bmp.Header.file.OffBits]
-
 
579
 
-
 
580
	mov	[delta], 4
-
 
581
	movzx	eax, [ebx + bmp.Header.info.BitCount]
-
 
582
	cmp	eax, 32
-
 
583
	je	@f
-
 
584
	cmp	eax, 16
-
 
585
	jne	.error
-
 
586
	mov	[delta], 2
765
	add	esi, [ebx + bmp.Header.file.OffBits]
Line 587... Line 766...
587
 
766
 
Line 588... Line 767...
588
;;------------------------------------------------------------------------------------------------;;
767
;;------------------------------------------------------------------------------------------------;;
589
 
768
 
590
    @@: mov	ecx, [edx + Image.Height]
769
	mov	ecx, [edx + Image.Height]
Line 640... Line 819...
640
 
819
 
Line 641... Line 820...
641
;;------------------------------------------------------------------------------------------------;;
820
;;------------------------------------------------------------------------------------------------;;
642
 
821
 
643
  .exit:
822
  .exit:
644
	xor	eax, eax
823
	xor	eax, eax
Line 645... Line 824...
645
	pop	edi esi
824
	pop	edi
646
	ret
825
	ret
647
 
826
 
648
  .error:
827
  .error:
Line 649... Line 828...
649
	or	eax, -1
828
	or	eax, -1
650
	pop	edi esi
829
	pop	edi
651
	ret
830
	ret
Line 676... Line 855...
676
    @@: sub	eax, 8
855
    @@: sub	eax, 8
677
	neg	eax
856
	neg	eax
678
	retn
857
	retn
679
endp
858
endp
Line -... Line 859...
-
 
859
 
680
 
860
if 0
681
;;================================================================================================;;
861
;;================================================================================================;;
682
proc img.decode.bmp._.jpeg ;//////////////////////////////////////////////////////////////////////;;
862
proc img.decode.bmp._.jpeg ;//////////////////////////////////////////////////////////////////////;;
683
;;------------------------------------------------------------------------------------------------;;
863
;;------------------------------------------------------------------------------------------------;;
684
;? --- TBD ---                                                                                    ;;
864
;? --- TBD ---                                                                                    ;;
Line 703... Line 883...
703
;< --- TBD ---                                                                                    ;;
883
;< --- TBD ---                                                                                    ;;
704
;;================================================================================================;;
884
;;================================================================================================;;
705
	xor	eax, eax
885
	xor	eax, eax
706
	ret
886
	ret
707
endp
887
endp
708
 
888
end if
Line 709... Line 889...
709
 
889
 
710
;;================================================================================================;;
890
;;================================================================================================;;
711
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
891
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
712
;;================================================================================================;;
892
;;================================================================================================;;