Subversion Repositories Kolibri OS

Rev

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

Rev 783 Rev 999
Line 1... Line 1...
1
;;================================================================================================;;
1
;;================================================================================================;;
2
;;//// libimg.asm //// (c) mike.dld, 2007-2008 ///////////////////////////////////////////////////;;
2
;;//// libimg.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
;;================================================================================================;;
Line 19... Line 19...
19
 
19
 
Line 23... Line 23...
23
public @EXPORT as 'EXPORTS'
23
public @EXPORT as 'EXPORTS'
Line 24... Line 24...
24
 
24
 
25
include '../../../../struct.inc'
25
include '../../../../struct.inc'
26
include '../../../../proc32.inc'
26
include '../../../../proc32.inc'
27
include '../../../../macros.inc'
27
include '../../../../macros.inc'
Line 28... Line 28...
28
purge section,mov;add,sub
28
purge section,mov,add,sub
Line 29... Line 29...
29
 
29
 
Line 30... Line 30...
30
include 'libimg.inc'
30
include 'libimg.inc'
31
 
31
 
-
 
32
section '.flat' code readable align 16
Line 32... Line 33...
32
section '.flat' code readable align 16
33
 
33
 
34
include 'bmp/bmp.asm'
34
include 'bmp/bmp.asm'
35
include 'gif/gif.asm'
35
include 'gif/gif.asm'
36
include 'jpeg/jpeg.asm'
Line 54... Line 55...
54
	mov	[mem.alloc], eax
55
	mov	[mem.alloc], eax
55
	mov	[mem.free], ebx
56
	mov	[mem.free], ebx
56
	mov	[mem.realloc], ecx
57
	mov	[mem.realloc], ecx
57
	mov	[dll.load], edx
58
	mov	[dll.load], edx
Line -... Line 59...
-
 
59
 
-
 
60
	call	img.initialize.jpeg
58
 
61
 
59
  .ok:	xor	eax,eax
62
  .ok:	xor	eax,eax
60
	ret
63
	ret
Line 61... Line 64...
61
endp
64
endp
Line 160... Line 163...
160
	push	eax
163
	push	eax
161
	mov	eax, [esi + Image.Width]
164
	mov	eax, [esi + Image.Width]
162
	stosd
165
	stosd
163
	mov	eax, [esi + Image.Height]
166
	mov	eax, [esi + Image.Height]
164
	stosd
167
	stosd
-
 
168
	mov	eax, [esi + Image.Type]
-
 
169
	dec	eax
-
 
170
	jz	.bpp8
-
 
171
	dec	eax
-
 
172
	jz	.bpp24
-
 
173
	dec	eax
-
 
174
	jnz	.error_pop
-
 
175
; 32 BPP -> 24 BPP
165
	mov	esi, [esi + Image.Data]
176
	mov	esi, [esi + Image.Data]
Line 166... Line 177...
166
 
177
 
167
    @@: dec	ecx
178
    @@: dec	ecx
168
	js	@f
179
	js	@f
Line 172... Line 183...
172
 
183
 
173
    @@: pop	eax
184
    @@: pop	eax
174
	pop	edi esi
185
	pop	edi esi
Line -... Line 186...
-
 
186
	ret
-
 
187
 
-
 
188
.bpp24:
-
 
189
; 24 BPP -> 24 BPP
-
 
190
	lea	ecx, [ecx*3 + 3]
-
 
191
	mov	esi, [esi + Image.Data]
-
 
192
	shr	ecx, 2
-
 
193
	rep	movsd
-
 
194
	pop	eax
-
 
195
	pop	edi esi
-
 
196
	ret
-
 
197
 
-
 
198
.bpp8:
-
 
199
; 8 BPP -> 24 BPP
-
 
200
	push	ebx
-
 
201
	mov	ebx, [esi + Image.Palette]
-
 
202
	mov	esi, [esi + Image.Data]
-
 
203
@@:
-
 
204
	movzx	eax, byte [esi]
-
 
205
	add	esi, 1
-
 
206
	mov	eax, [ebx + eax*4]
-
 
207
	mov	[edi], eax
-
 
208
	add	edi, 3
-
 
209
	sub	ecx, 1
-
 
210
	jnz	@b
-
 
211
	pop	ebx
-
 
212
	pop	eax
-
 
213
	pop	edi esi
-
 
214
	ret
-
 
215
 
-
 
216
  .error_pop:
175
	ret
217
  	pop	eax
176
 
218
 
177
  .error:
219
  .error:
178
	xor	eax, eax
220
	xor	eax, eax
179
	pop	edi esi
221
	pop	edi esi
Line 194... Line 236...
194
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
236
    @@: stdcall [ebx + FormatsTableEntry.Is], [_data], [_length]
195
	or	eax, eax
237
	or	eax, eax
196
	jnz	@f
238
	jnz	@f
197
	add	ebx, sizeof.FormatsTableEntry
239
	add	ebx, sizeof.FormatsTableEntry
198
	cmp	dword[ebx], 0
240
	cmp	dword[ebx], 0
199
	jnz	@f
241
	jnz	@b
200
	jmp	.error
242
	jmp	.error
201
    @@: stdcall [ebx + FormatsTableEntry.Decode], [_data], [_length]
243
    @@: stdcall [ebx + FormatsTableEntry.Decode], [_data], [_length]
Line 202... Line 244...
202
 
244
 
203
  .error:
245
  .error:
Line 217... Line 259...
217
	xor	eax, eax
259
	xor	eax, eax
218
	ret
260
	ret
219
endp
261
endp
Line 220... Line 262...
220
 
262
 
221
;;================================================================================================;;
263
;;================================================================================================;;
222
proc img.create _width, _height ;/////////////////////////////////////////////////////////////////;;
264
proc img.create _width, _height, _type ;//////////////////////////////////////////////////////////;;
223
;;------------------------------------------------------------------------------------------------;;
265
;;------------------------------------------------------------------------------------------------;;
224
;? --- TBD ---                                                                                    ;;
266
;? --- TBD ---                                                                                    ;;
225
;;------------------------------------------------------------------------------------------------;;
267
;;------------------------------------------------------------------------------------------------;;
226
;> --- TBD ---                                                                                    ;;
268
;> --- TBD ---                                                                                    ;;
Line 231... Line 273...
231
 
273
 
232
	stdcall img._.new
274
	stdcall img._.new
233
	or	eax, eax
275
	or	eax, eax
Line -... Line 276...
-
 
276
	jz	.error
-
 
277
 
-
 
278
	mov	ecx, [_type]
234
	jz	.error
279
	mov	[eax + Image.Type], ecx
Line 235... Line 280...
235
 
280
 
236
	push	eax
281
	push	eax
237
 
282
 
Line 238... Line 283...
238
	stdcall img._.resize_data, eax, [_width], [_height]
283
	stdcall img._.resize_data, eax, [_width], [_height]
239
	or	eax, eax
284
	or	eax, eax
Line 240... Line 285...
240
	jz	.error.2
285
	jz	.error.2
241
 
286
 
242
	pop	eax
287
	pop	eax
243
	ret
288
	jmp	.ret
Line 244... Line 289...
244
 
289
 
-
 
290
  .error.2:
245
  .error.2:
291
;       pop     eax
246
;       pop     eax
292
	stdcall img._.delete; eax
247
	stdcall img._.delete; eax
293
	xor	eax, eax
Line 248... Line 294...
248
	xor	eax, eax
294
 
Line 346... Line 392...
346
;;================================================================================================;;
392
;;================================================================================================;;
347
locals
393
locals
348
  scanline_len dd ?
394
  scanline_len dd ?
349
endl
395
endl
Line 350... Line 396...
350
 
396
 
-
 
397
	push	ebx esi edi
351
	push	esi edi
398
	mov	ebx, [_img]
352
	stdcall img._.validate, [_img]
399
	stdcall img._.validate, ebx
353
	or	eax, eax
400
	or	eax, eax
Line 354... Line -...
354
	jnz	.error
-
 
355
 
401
	jnz	.error
356
	mov	esi, [_img]
402
 
357
	mov	ecx, [esi + Image.Height]
403
	mov	ecx, [ebx + Image.Height]
358
	mov	eax, [esi + Image.Width]
404
	mov	eax, [ebx + Image.Width]
Line 359... Line -...
359
	shl	eax, 2
-
 
360
	mov	[scanline_len], eax
-
 
361
 
405
	call	img._.get_scanline_len
362
	push	esi
406
	mov	[scanline_len], eax
Line 363... Line 407...
363
 
407
 
364
	test	[_flip_kind], FLIP_VERTICAL
408
	test	[_flip_kind], FLIP_VERTICAL
365
	jz	.dont_flip_vert
409
	jz	.dont_flip_vert
366
 
410
 
367
	imul	eax, ecx
411
	imul	eax, ecx
Line 368... Line 412...
368
	sub	eax, [scanline_len]
412
	sub	eax, [scanline_len]
369
	shr	ecx, 1
413
	shr	ecx, 1
Line 370... Line 414...
370
	mov	esi, [esi + Image.Data]
414
	mov	esi, [ebx + Image.Data]
-
 
415
	lea	edi, [esi + eax]
371
	lea	edi, [esi + eax]
416
	
372
	
417
  .next_line_vert:
373
  .next_line_vert:
418
	push	ecx
374
	push	ecx
419
 
-
 
420
	mov	ecx, [scanline_len]
375
 
421
	push	ecx
-
 
422
	shr	ecx, 2
-
 
423
    @@: mov	eax, [esi]
-
 
424
	xchg	eax, [edi]
-
 
425
	mov	[esi], eax
-
 
426
	add	esi, 4
-
 
427
	add	edi, 4
-
 
428
	sub	ecx, 1
-
 
429
	jnz	@b
-
 
430
	pop	ecx
-
 
431
	and	ecx, 3
-
 
432
	jz	.cont_line_vert
376
	mov	ecx, [scanline_len]
433
    @@:
377
	shr	ecx, 2
434
	mov	al, [esi]
-
 
435
	xchg	al, [edi]
Line 378... Line 436...
378
    @@: lodsd
436
	mov	[esi], al
379
	xchg	eax, [edi]
437
	add	esi, 1
380
	mov	[esi - 4], eax
438
	add	edi, 1
381
	add	edi, 4
439
	dec	ecx
382
	dec	ecx
440
	jnz	@b
383
	jnz	@b
441
    .cont_line_vert:
Line 384... Line 442...
384
 
442
 
Line 385... Line -...
385
	pop	ecx
-
 
386
	mov	eax, [scanline_len]
-
 
387
	shl	eax, 1
443
	pop	ecx
388
	sub	edi, eax
444
	mov	eax, [scanline_len]
Line 389... Line 445...
389
	dec	ecx
445
	shl	eax, 1
390
	jnz	.next_line_vert
446
	sub	edi, eax
391
 
447
	dec	ecx
392
  .dont_flip_vert:
448
	jnz	.next_line_vert
-
 
449
 
-
 
450
  .dont_flip_vert:
-
 
451
 
-
 
452
	test	[_flip_kind], FLIP_HORIZONTAL
-
 
453
	jz	.exit
-
 
454
 
-
 
455
	mov	ecx, [ebx + Image.Height]
-
 
456
	mov	eax, [ebx + Image.Type]
Line 393... Line 457...
393
 
457
	mov	esi, [ebx + Image.Data]
394
	pop	esi
458
	mov	edi, [scanline_len]
Line 395... Line 459...
395
 
459
	add	edi, esi
Line 409... Line 473...
409
    @@: mov	eax, [esi]
473
    @@: mov	eax, [esi]
410
	xchg	eax, [edi]
474
	xchg	eax, [edi]
411
	mov	[esi], eax
475
	mov	[esi], eax
412
	add	esi, 4
476
	add	esi, 4
413
	add	edi, -4
477
	add	edi, -4
414
	dec	ecx
478
	sub	ecx, 1
415
	jnz	@b
479
	jnz	@b
Line 416... Line 480...
416
 
480
 
417
	pop	edi esi ecx
481
	pop	edi esi ecx
418
	add	esi, [scanline_len]
482
	add	esi, [scanline_len]
419
	add	edi, [scanline_len]
483
	add	edi, [scanline_len]
420
	dec	ecx
484
	dec	ecx
-
 
485
	jnz	.next_line_horz
-
 
486
	jmp	.exit
-
 
487
 
-
 
488
.bpp8.2:
-
 
489
	dec	edi
-
 
490
  .next_line_horz8:
-
 
491
	push	ecx esi edi
-
 
492
 
-
 
493
	mov	ecx, [scanline_len]
-
 
494
	shr	ecx, 1
-
 
495
    @@: mov	al, [esi]
-
 
496
	mov	dl, [edi]
-
 
497
	mov	[edi], al
-
 
498
	mov	[esi], dl
-
 
499
	add	esi, 1
-
 
500
	sub	edi, 1
-
 
501
	sub	ecx, 1
-
 
502
	jnz	@b
-
 
503
 
-
 
504
	pop	edi esi ecx
-
 
505
	add	esi, [scanline_len]
-
 
506
	add	edi, [scanline_len]
-
 
507
	dec	ecx
-
 
508
	jnz	.next_line_horz8
-
 
509
	jmp	.exit
-
 
510
 
-
 
511
.bpp24.2:
-
 
512
	sub	edi, 3
-
 
513
  .next_line_horz32:
-
 
514
	push	ecx esi edi
-
 
515
 
-
 
516
	mov	ecx, [ebx + Image.Width]
-
 
517
	shr	ecx, 1
-
 
518
    @@:
-
 
519
	mov	al, [esi]
-
 
520
	mov	dl, [edi]
-
 
521
	mov	[edi], al
-
 
522
	mov	[esi], dl
-
 
523
	mov	al, [esi+1]
-
 
524
	mov	dl, [edi+1]
-
 
525
	mov	[edi+1], al
-
 
526
	mov	[esi+1], dl
-
 
527
	mov	al, [esi+2]
-
 
528
	mov	dl, [edi+2]
-
 
529
	mov	[edi+2], al
-
 
530
	mov	[esi+2], dl
-
 
531
	add	esi, 3
-
 
532
	sub	edi, 3
-
 
533
	sub	ecx, 1
-
 
534
	jnz	@b
-
 
535
 
-
 
536
	pop	edi esi ecx
-
 
537
	add	esi, [scanline_len]
-
 
538
	add	edi, [scanline_len]
-
 
539
	dec	ecx
Line 421... Line 540...
421
	jnz	.next_line_horz
540
	jnz	.next_line_horz32
422
 
541
 
423
  .exit:
542
  .exit:
424
	xor	eax, eax
543
	xor	eax, eax
425
	inc	eax
544
	inc	eax
Line 426... Line 545...
426
	pop	edi esi
545
	pop	edi esi ebx
427
	ret
546
	ret
428
 
547
 
429
  .error:
548
  .error:
430
	xor	eax, eax
549
	xor	eax, eax
Line 431... Line 550...
431
	pop	edi esi
550
	pop	edi esi ebx
432
	ret
551
	ret
Line 451... Line 570...
451
endl
570
endl
Line 452... Line 571...
452
 
571
 
Line 453... Line 572...
453
	mov	[line_buffer], 0
572
	mov	[line_buffer], 0
-
 
573
 
454
 
574
	push	ebx esi edi
455
	push	ebx esi edi
575
	mov	ebx, [_img]
456
	stdcall img._.validate, [_img]
576
	stdcall img._.validate, ebx
Line 457... Line 577...
457
	or	eax, eax
577
	or	eax, eax
458
	jnz	.error
578
	jnz	.error
Line 464... Line 584...
464
	cmp	[_rotate_kind], ROTATE_180
584
	cmp	[_rotate_kind], ROTATE_180
465
	je	.flip
585
	je	.flip
466
	jmp	.exit
586
	jmp	.exit
Line 467... Line 587...
467
 
587
 
468
  .rotate_ccw_low:
-
 
469
	mov	ebx, [_img]
588
  .rotate_ccw_low:
470
	mov	eax, [ebx + Image.Height]
589
	mov	eax, [ebx + Image.Height]
471
	mov	[scanline_pixels_new], eax
590
	mov	[scanline_pixels_new], eax
472
	shl	eax, 2
591
	call	img._.get_scanline_len
Line 473... Line 592...
473
	mov	[scanline_len_new], eax
592
	mov	[scanline_len_new], eax
474
 
593
 
475
	invoke	mem.alloc, eax
594
	invoke	mem.alloc, eax
476
	or	eax, eax
595
	or	eax, eax
Line 477... Line 596...
477
	jz	.error
596
	jz	.error
478
	mov	[line_buffer], eax
597
	mov	[line_buffer], eax
-
 
598
 
479
 
599
	mov	eax, [ebx + Image.Width]
Line 480... Line 600...
480
	mov	ecx, [ebx + Image.Width]
600
	mov	ecx, eax
481
	lea	eax, [ecx * 4]
601
	call	img._.get_scanline_len
482
	mov	[scanline_len_old], eax
602
	mov	[scanline_len_old], eax
483
 
603
 
Line -... Line 604...
-
 
604
	mov	eax, [scanline_len_new]
-
 
605
	imul	eax, ecx
-
 
606
	add	eax, [ebx + Image.Data]
-
 
607
	mov	[pixels_ptr], eax
-
 
608
 
484
	mov	eax, [scanline_len_new]
609
	cmp	[ebx + Image.Type], Image.bpp8
485
	imul	eax, ecx
610
	jz	.rotate_ccw8
486
	add	eax, [ebx + Image.Data]
611
	cmp	[ebx + Image.Type], Image.bpp24
487
	mov	[pixels_ptr], eax
612
	jz	.rotate_ccw24
Line 488... Line 613...
488
 
613
 
489
  .next_column_ccw_low:
614
  .next_column_ccw_low:
Line 522... Line 647...
522
	rep	movsd
647
	rep	movsd
Line 523... Line 648...
523
 
648
 
524
	pop	ecx
649
	pop	ecx
Line -... Line 650...
-
 
650
	jmp	.next_column_ccw_low
-
 
651
 
-
 
652
.rotate_ccw8:
-
 
653
  .next_column_ccw_low8:
-
 
654
	dec	ecx
-
 
655
	js	.exchange_dims
-
 
656
	push	ecx
-
 
657
 
-
 
658
	mov	edx, [scanline_len_old]
-
 
659
	add	[scanline_len_old], -1
-
 
660
 
-
 
661
	mov	ecx, [scanline_pixels_new]
-
 
662
	mov	esi, [ebx + Image.Data]
-
 
663
	mov	edi, [line_buffer]
-
 
664
    @@: mov	al, [esi]
-
 
665
	mov	[edi], al
-
 
666
	add	esi, edx
-
 
667
	add	edi, 1
-
 
668
	sub	ecx, 1
-
 
669
	jnz	@b
-
 
670
 
-
 
671
	mov	eax, [scanline_pixels_new]
-
 
672
	mov	edi, [ebx + Image.Data]
-
 
673
	lea	esi, [edi + 1]
-
 
674
	mov	edx, [scanline_len_old]
-
 
675
    @@: mov	ecx, edx
-
 
676
	shr	ecx, 2
-
 
677
	rep	movsd
-
 
678
	mov	ecx, edx
-
 
679
	and	ecx, 3
-
 
680
	rep	movsb
-
 
681
	add	esi, 1
-
 
682
	sub	eax, 1
-
 
683
	jnz	@b
-
 
684
 
-
 
685
	mov	eax, [scanline_len_new]
-
 
686
	sub	[pixels_ptr], eax
-
 
687
	mov	ecx, [scanline_pixels_new]
-
 
688
	mov	esi, [line_buffer]
-
 
689
	mov	edi, [pixels_ptr]
-
 
690
	mov	edx, ecx
-
 
691
	shr	ecx, 2
-
 
692
	rep	movsd
-
 
693
	mov	ecx, edx
-
 
694
	and	ecx, 3
-
 
695
	rep	movsb
-
 
696
 
-
 
697
	pop	ecx
-
 
698
	jmp	.next_column_ccw_low8
-
 
699
 
-
 
700
.rotate_ccw24:
-
 
701
  .next_column_ccw_low24:
-
 
702
	dec	ecx
-
 
703
	js	.exchange_dims
-
 
704
	push	ecx
-
 
705
 
-
 
706
	mov	edx, [scanline_len_old]
-
 
707
	add	[scanline_len_old], -3
-
 
708
 
-
 
709
	mov	ecx, [scanline_pixels_new]
-
 
710
	mov	esi, [ebx + Image.Data]
-
 
711
	mov	edi, [line_buffer]
-
 
712
    @@: mov	al, [esi]
-
 
713
	mov	[edi], al
-
 
714
	mov	al, [esi+1]
-
 
715
	mov	[edi+1], al
-
 
716
	mov	al, [esi+2]
-
 
717
	mov	[edi+2], al
-
 
718
	add	esi, edx
-
 
719
	add	edi, 3
-
 
720
	sub	ecx, 1
-
 
721
	jnz	@b
-
 
722
 
-
 
723
	mov	eax, [scanline_pixels_new]
-
 
724
	mov	edi, [ebx + Image.Data]
-
 
725
	lea	esi, [edi + 3]
-
 
726
	mov	edx, [scanline_len_old]
-
 
727
    @@: mov	ecx, edx
-
 
728
	shr	ecx, 2
-
 
729
	rep	movsd
-
 
730
	mov	ecx, edx
-
 
731
	and	ecx, 3
-
 
732
	rep	movsb
-
 
733
	add	esi, 3
-
 
734
	sub	eax, 1
-
 
735
	jnz	@b
-
 
736
 
-
 
737
	mov	eax, [scanline_len_new]
-
 
738
	sub	[pixels_ptr], eax
-
 
739
	mov	ecx, eax
-
 
740
	mov	esi, [line_buffer]
-
 
741
	mov	edi, [pixels_ptr]
-
 
742
	shr	ecx, 2
-
 
743
	rep	movsd
-
 
744
	mov	ecx, eax
-
 
745
	and	ecx, 3
-
 
746
	rep	movsb
-
 
747
 
-
 
748
	pop	ecx
525
	jmp	.next_column_ccw_low
749
	jmp	.next_column_ccw_low24
526
 
-
 
527
  .rotate_cw_low:
750
 
528
	mov	ebx, [_img]
751
  .rotate_cw_low:
529
	mov	eax, [ebx + Image.Height]
752
	mov	eax, [ebx + Image.Height]
530
	mov	[scanline_pixels_new], eax
753
	mov	[scanline_pixels_new], eax
Line 531... Line 754...
531
	shl	eax, 2
754
	call	img._.get_scanline_len
532
	mov	[scanline_len_new], eax
755
	mov	[scanline_len_new], eax
533
 
756
 
534
	invoke	mem.alloc, eax
757
	invoke	mem.alloc, eax
Line 535... Line 758...
535
	or	eax, eax
758
	or	eax, eax
536
	jz	.error
759
	jz	.error
-
 
760
	mov	[line_buffer], eax
537
	mov	[line_buffer], eax
761
 
Line 538... Line 762...
538
 
762
	mov	eax, [ebx + Image.Width]
539
	mov	ecx, [ebx + Image.Width]
763
	mov	ecx, eax
540
	lea	eax, [ecx * 4]
764
	call	img._.get_scanline_len
541
	mov	[scanline_len_old], eax
765
	mov	[scanline_len_old], eax
Line -... Line 766...
-
 
766
 
-
 
767
	mov	eax, [scanline_len_new]
-
 
768
	imul	eax, ecx
-
 
769
	add	eax, [ebx + Image.Data]
-
 
770
	mov	[pixels_ptr], eax
542
 
771
 
543
	mov	eax, [scanline_len_new]
772
	cmp	[ebx + Image.Type], Image.bpp8
544
	imul	eax, ecx
773
	jz	.rotate_cw8
545
	add	eax, [ebx + Image.Data]
774
	cmp	[ebx + Image.Type], Image.bpp24
Line 584... Line 813...
584
	rep	movsd
813
	rep	movsd
Line 585... Line 814...
585
 
814
 
586
	pop	ecx
815
	pop	ecx
Line -... Line 816...
-
 
816
	jmp	.next_column_cw_low
-
 
817
 
-
 
818
.rotate_cw8:
-
 
819
  .next_column_cw_low8:
-
 
820
	dec	ecx
-
 
821
	js	.exchange_dims
-
 
822
	push	ecx
-
 
823
 
-
 
824
	mov	edx, [scanline_len_old]
-
 
825
	add	[scanline_len_old], -1
-
 
826
 
-
 
827
	mov	ecx, [scanline_pixels_new]
-
 
828
	mov	esi, [pixels_ptr]
-
 
829
	add	esi, -1
-
 
830
	mov	edi, [line_buffer]
-
 
831
    @@: mov	al, [esi]
-
 
832
	mov	[edi], al
-
 
833
	sub	esi, edx
-
 
834
	add	edi, 1
-
 
835
	sub	ecx, 1
-
 
836
	jnz	@b
-
 
837
 
-
 
838
	mov	eax, [scanline_pixels_new]
-
 
839
	dec	eax
-
 
840
	mov	edi, [ebx + Image.Data]
-
 
841
	add	edi, [scanline_len_old]
-
 
842
	lea	esi, [edi + 1]
-
 
843
	mov	edx, [scanline_len_old]
-
 
844
    @@: mov	ecx, edx
-
 
845
	shr	ecx, 2
-
 
846
	rep	movsd
-
 
847
	mov	ecx, edx
-
 
848
	and	ecx, 3
-
 
849
	rep	movsb
-
 
850
	add	esi, 1
-
 
851
	sub	eax, 1
-
 
852
	jnz	@b
-
 
853
 
-
 
854
	mov	eax, [scanline_len_new]
-
 
855
	sub	[pixels_ptr], eax
-
 
856
	mov	ecx, eax
-
 
857
	mov	esi, [line_buffer]
-
 
858
	mov	edi, [pixels_ptr]
-
 
859
	shr	ecx, 2
-
 
860
	rep	movsd
-
 
861
	mov	ecx, eax
-
 
862
	and	ecx, 3
-
 
863
	rep	movsb
-
 
864
 
-
 
865
	pop	ecx
-
 
866
	jmp	.next_column_cw_low8
-
 
867
 
-
 
868
.rotate_cw24:
-
 
869
  .next_column_cw_low24:
-
 
870
	dec	ecx
-
 
871
	js	.exchange_dims
-
 
872
	push	ecx
-
 
873
 
-
 
874
	mov	edx, [scanline_len_old]
-
 
875
	add	[scanline_len_old], -3
-
 
876
 
-
 
877
	mov	ecx, [scanline_pixels_new]
-
 
878
	mov	esi, [pixels_ptr]
-
 
879
	add	esi, -3
-
 
880
	mov	edi, [line_buffer]
-
 
881
    @@: mov	al, [esi]
-
 
882
	mov	[edi], al
-
 
883
	mov	al, [esi+1]
-
 
884
	mov	[edi+1], al
-
 
885
	mov	al, [esi+2]
-
 
886
	mov	[edi+2], al
-
 
887
	sub	esi, edx
-
 
888
	add	edi, 3
-
 
889
	sub	ecx, 1
-
 
890
	jnz	@b
-
 
891
 
-
 
892
	mov	eax, [scanline_pixels_new]
-
 
893
	dec	eax
-
 
894
	mov	edi, [ebx + Image.Data]
-
 
895
	add	edi, [scanline_len_old]
-
 
896
	lea	esi, [edi + 3]
-
 
897
	mov	edx, [scanline_len_old]
-
 
898
    @@: mov	ecx, edx
-
 
899
	shr	ecx, 2
-
 
900
	rep	movsd
-
 
901
	mov	ecx, edx
-
 
902
	and	ecx, 3
-
 
903
	rep	movsb
-
 
904
	add	esi, 3
-
 
905
	sub	eax, 1
-
 
906
	jnz	@b
-
 
907
 
-
 
908
	mov	eax, [scanline_len_new]
-
 
909
	sub	[pixels_ptr], eax
-
 
910
	mov	ecx, eax
-
 
911
	mov	esi, [line_buffer]
-
 
912
	mov	edi, [pixels_ptr]
-
 
913
	shr	ecx, 2
-
 
914
	rep	movsd
-
 
915
	mov	ecx, eax
-
 
916
	and	ecx, 3
-
 
917
	rep	movsb
-
 
918
 
-
 
919
	pop	ecx
587
	jmp	.next_column_cw_low
920
	jmp	.next_column_cw_low24
588
 
921
 
Line 589... Line 922...
589
  .flip:
922
  .flip:
590
	jmp	.exit
923
	jmp	.exit
Line 638... Line 971...
638
;> --- TBD ---                                                                                    ;;
971
;> --- TBD ---                                                                                    ;;
639
;;------------------------------------------------------------------------------------------------;;
972
;;------------------------------------------------------------------------------------------------;;
640
;< eax = 0 / pointer to image                                                                     ;;
973
;< eax = 0 / pointer to image                                                                     ;;
641
;;================================================================================================;;
974
;;================================================================================================;;
642
	invoke	mem.alloc, sizeof.Image
975
	invoke	mem.alloc, sizeof.Image
-
 
976
	test	eax, eax
-
 
977
	jz	@f
-
 
978
	push	ecx
-
 
979
	xor	ecx, ecx
-
 
980
	mov	[eax + Image.Data], ecx
-
 
981
	mov	[eax + Image.Type], ecx
-
 
982
	mov	[eax + Image.Extended], ecx
-
 
983
	mov	[eax + Image.Previous], ecx
-
 
984
	mov	[eax + Image.Next], ecx
-
 
985
	pop	ecx
-
 
986
@@:
643
	ret
987
	ret
644
endp
988
endp
Line 645... Line 989...
645
 
989
 
646
;;================================================================================================;;
990
;;================================================================================================;;
Line 672... Line 1016...
672
;;------------------------------------------------------------------------------------------------;;
1016
;;------------------------------------------------------------------------------------------------;;
673
;> --- TBD ---                                                                                    ;;
1017
;> --- TBD ---                                                                                    ;;
674
;;------------------------------------------------------------------------------------------------;;
1018
;;------------------------------------------------------------------------------------------------;;
675
;< --- TBD ---                                                                                    ;;
1019
;< --- TBD ---                                                                                    ;;
676
;;================================================================================================;;
1020
;;================================================================================================;;
677
	push	ebx
1021
	push	ebx esi
678
	mov	ebx, [_img]
1022
	mov	ebx, [_img]
679
	mov	eax, [_height]
1023
	mov	eax, [_height]
-
 
1024
; our memory is limited, [_width]*[_height] must not overflow
-
 
1025
; image with width or height greater than 65535 is most likely bogus
-
 
1026
	cmp	word [_width+2], 0
-
 
1027
	jnz	.error
-
 
1028
	cmp	word [_height+2], 0
-
 
1029
	jnz	.error
680
	imul	eax, [_width]
1030
	imul	eax, [_width]
-
 
1031
	test	eax, eax
-
 
1032
	jz	.error
-
 
1033
; do not allow images which require too many memory
-
 
1034
	cmp	eax, 4000000h
-
 
1035
	jae	.error
-
 
1036
	cmp	[ebx + Image.Type], Image.bpp8
-
 
1037
	jz	.bpp8
-
 
1038
	cmp	[ebx + Image.Type], Image.bpp24
-
 
1039
	jz	.bpp24
-
 
1040
.bpp32:
681
	shl	eax, 2
1041
	shl	eax, 2
-
 
1042
	jmp	@f
-
 
1043
.bpp24:
-
 
1044
	lea	eax, [eax*3]
-
 
1045
	jmp	@f
-
 
1046
.bpp8:
-
 
1047
	add	eax, 256*4	; for palette
-
 
1048
@@:
-
 
1049
	mov	esi, eax
682
	invoke	mem.realloc, [ebx + Image.Data], eax
1050
	invoke	mem.realloc, [ebx + Image.Data], eax
683
	or	eax, eax
1051
	or	eax, eax
684
	jz	.error
1052
	jz	.error
Line 685... Line 1053...
685
 
1053
 
686
	mov	[ebx + Image.Data], eax
1054
	mov	[ebx + Image.Data], eax
687
	push	[_width]
1055
	push	[_width]
688
	pop	[ebx + Image.Width]
1056
	pop	[ebx + Image.Width]
689
	push	[_height]
1057
	push	[_height]
-
 
1058
	pop	[ebx + Image.Height]
-
 
1059
	cmp	[ebx + Image.Type], Image.bpp8
-
 
1060
	jnz	.ret
-
 
1061
	lea	esi, [eax + esi - 256*4]
-
 
1062
	mov	[ebx + Image.Palette], esi
Line 690... Line 1063...
690
	pop	[ebx + Image.Height]
1063
	jmp	.ret
-
 
1064
 
-
 
1065
  .error:
691
 
1066
	xor	eax, eax
692
  .error:
1067
  .ret:
693
	pop	ebx
1068
	pop	esi ebx
Line -... Line 1069...
-
 
1069
	ret
-
 
1070
endp
-
 
1071
 
-
 
1072
;;================================================================================================;;
-
 
1073
img._.get_scanline_len: ;/////////////////////////////////////////////////////////////////////////;;
-
 
1074
;;------------------------------------------------------------------------------------------------;;
-
 
1075
;? --- TBD ---                                                                                    ;;
-
 
1076
;;------------------------------------------------------------------------------------------------;;
-
 
1077
;> --- TBD ---                                                                                    ;;
-
 
1078
;;------------------------------------------------------------------------------------------------;;
-
 
1079
;< --- TBD ---                                                                                    ;;
-
 
1080
;;================================================================================================;;
-
 
1081
	cmp	[ebx + Image.Type], Image.bpp8
-
 
1082
	jz	.bpp8.1
-
 
1083
	cmp	[ebx + Image.Type], Image.bpp24
-
 
1084
	jz	.bpp24.1
-
 
1085
	shl	eax, 2
-
 
1086
	jmp	@f
-
 
1087
.bpp24.1:
-
 
1088
	lea	eax, [eax*3]
-
 
1089
.bpp8.1:
Line 694... Line 1090...
694
	ret
1090
@@:
695
endp
1091
	ret
696
 
1092
 
697
 
1093
 
Line 708... Line 1104...
708
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
1104
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
709
; .ico dd img.is.ico, img.decode.ico, img.encode.ico
1105
; .ico dd img.is.ico, img.decode.ico, img.encode.ico
710
; .cur dd img.is.cur, img.decode.cur, img.encode.cur
1106
; .cur dd img.is.cur, img.decode.cur, img.encode.cur
711
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
1107
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
712
; .png dd img.is.png, img.decode.png, img.encode.png
1108
; .png dd img.is.png, img.decode.png, img.encode.png
713
; .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
1109
  .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
714
       dd 0
1110
       dd 0
Line 715... Line 1111...
715
 
1111
 
716
 
1112
 
Line 721... Line 1117...
721
;;================================================================================================;;
1117
;;================================================================================================;;
722
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1118
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
723
;;================================================================================================;;
1119
;;================================================================================================;;
Line 724... Line 1120...
724
 
1120
 
725
 
1121
 
Line 726... Line 1122...
726
align 16
1122
align 4
727
@EXPORT:
1123
@EXPORT:
728
 
1124
 
Line 742... Line 1138...
742
	img.count	, 'img.count'	    , \
1138
	img.count	, 'img.count'	    , \
743
	img.lock_bits	, 'img.lock_bits'   , \
1139
	img.lock_bits	, 'img.lock_bits'   , \
744
	img.unlock_bits , 'img.unlock_bits' , \
1140
	img.unlock_bits , 'img.unlock_bits' , \
745
	img.flip	, 'img.flip'	    , \
1141
	img.flip	, 'img.flip'	    , \
746
	img.rotate	, 'img.rotate'
1142
	img.rotate	, 'img.rotate'
-
 
1143
 
-
 
1144
section '.data' data readable writable align 16
-
 
1145
; uninitialized data - global constant tables
-
 
1146
 
-
 
1147
; data for YCbCr -> RGB translation
-
 
1148
color_table_1		rd	256
-
 
1149
color_table_2		rd	256
-
 
1150
color_table_3		rd	256
-
 
1151
color_table_4		rd	256