Subversion Repositories Kolibri OS

Rev

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

Rev 1015 Rev 1079
Line 33... Line 33...
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'
36
include 'jpeg/jpeg.asm'
37
include 'png/png.asm'
-
 
38
 
-
 
39
mem.alloc   dd ?
-
 
40
mem.free    dd ?
37
include 'png/png.asm'
41
mem.realloc dd ?
38
include 'tga/tga.asm'
Line 42... Line 39...
42
dll.load    dd ?
39
include 'z80/z80.asm'
43
 
40
 
44
;;================================================================================================;;
41
;;================================================================================================;;
45
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
42
proc lib_init ;///////////////////////////////////////////////////////////////////////////////////;;
Line 58... Line 55...
58
	mov	[mem.realloc], ecx
55
	mov	[mem.realloc], ecx
59
	mov	[dll.load], edx
56
	mov	[dll.load], edx
Line 60... Line 57...
60
 
57
 
Line -... Line 58...
-
 
58
	call	img.initialize.jpeg
-
 
59
 
-
 
60
	xor	eax, eax
-
 
61
	cpuid
-
 
62
	cmp	ecx, 'ntel'
-
 
63
	jnz	@f
-
 
64
	mov	dword [img._.do_rgb.handlers + (Image.bpp15-1)*4], img._.do_rgb.bpp15.intel
-
 
65
	mov	dword [img._.do_rgb.handlers + (Image.bpp16-1)*4], img._.do_rgb.bpp16.intel
61
	call	img.initialize.jpeg
66
  @@:
62
 
67
 
63
  .ok:	xor	eax,eax
68
  .ok:	xor	eax,eax
Line 64... Line 69...
64
	ret
69
	ret
Line 209... Line 214...
209
;< --- TBD ---                                                                                    ;;
214
;< --- TBD ---                                                                                    ;;
210
;;================================================================================================;;
215
;;================================================================================================;;
211
	mov	ecx, [esi + Image.Width]
216
	mov	ecx, [esi + Image.Width]
212
	imul	ecx, [esi + Image.Height]
217
	imul	ecx, [esi + Image.Height]
213
	mov	eax, [esi + Image.Type]
218
	mov	eax, [esi + Image.Type]
214
	dec	eax
-
 
215
	jz	.bpp8
-
 
216
	dec	eax
-
 
217
	jz	.bpp24
-
 
218
; 32 BPP -> 24 BPP
-
 
219
	mov	esi, [esi + Image.Data]
219
	jmp	dword [.handlers + (eax-1)*4]
Line -... Line 220...
-
 
220
 
-
 
221
align 16
-
 
222
.bpp8:
-
 
223
; 8 BPP -> 24 BPP
-
 
224
	push	ebx
-
 
225
	mov	ebx, [esi + Image.Palette]
220
 
226
	mov	esi, [esi + Image.Data]
221
    @@:
227
@@:
-
 
228
	movzx	eax, byte [esi]
-
 
229
	add	esi, 1
222
	mov	eax, [esi]
230
	mov	eax, [ebx + eax*4]
-
 
231
	mov	[edi], eax
223
	mov	[edi], ax
232
	add	edi, 3
-
 
233
	sub	ecx, 1
-
 
234
	jnz	@b
-
 
235
	pop	ebx
-
 
236
	ret
-
 
237
 
-
 
238
; 15 BPP -> 24 BPP
-
 
239
.bpp15.intel:
-
 
240
	push	ebx ebp
-
 
241
	sub	ecx, 4
-
 
242
	jb	.bpp15.tail
-
 
243
align 16
-
 
244
.bpp15.intel.loop:
-
 
245
repeat 2
-
 
246
	mov	ebx, [esi]
224
	shr	eax, 16
247
	mov	al, [esi]
225
	mov	[edi+2], al
248
	mov	ah, [esi+1]
-
 
249
	add	esi, 4
-
 
250
	and	al, 0x1F
-
 
251
	and	ah, 0x1F shl 2
-
 
252
	mov	ebp, ebx
-
 
253
	mov	dl, al
-
 
254
	mov	dh, ah
-
 
255
	shr	al, 2
-
 
256
	shr	ah, 4
-
 
257
	shl	dl, 3
-
 
258
	shl	dh, 1
-
 
259
	and	ebp, 0x1F shl 5
-
 
260
	add	al, dl
-
 
261
	add	ah, dh
-
 
262
	shr	ebp, 2
-
 
263
	mov	[edi], al
-
 
264
	mov	[edi+2], ah
-
 
265
	mov	eax, ebx
-
 
266
	mov	ebx, ebp
-
 
267
	shr	eax, 16
-
 
268
	shr	ebx, 5
-
 
269
	add	ebx, ebp
-
 
270
	mov	ebp, eax
-
 
271
	mov	[edi+1], bl
-
 
272
	and	eax, (0x1F) or (0x1F shl 10)
-
 
273
	and	ebp, 0x1F shl 5
-
 
274
	lea	edx, [eax+eax]
-
 
275
	shr	al, 2
-
 
276
	mov	ebx, ebp
-
 
277
	shr	ah, 4
-
 
278
	shl	dl, 2
-
 
279
	shr	ebx, 2
-
 
280
	shr	ebp, 7
-
 
281
	add	al, dl
-
 
282
	add	ah, dh
-
 
283
	mov	[edi+3], al
-
 
284
	add	ebx, ebp
-
 
285
	mov	[edi+5], ah
-
 
286
	mov	[edi+4], bl
-
 
287
	add	edi, 6
-
 
288
end repeat
-
 
289
	sub	ecx, 4
-
 
290
	jnb	.bpp15.intel.loop
-
 
291
.bpp15.tail:
-
 
292
	add	ecx, 4
-
 
293
	jz	.bpp15.done
-
 
294
@@:
-
 
295
	movzx	eax, word [esi]
-
 
296
	mov	ebx, eax
-
 
297
	add	esi, 2
-
 
298
	and	eax, (0x1F) or (0x1F shl 10)
-
 
299
	and	ebx, 0x1F shl 5
-
 
300
	lea	edx, [eax+eax]
-
 
301
	shr	al, 2
-
 
302
	mov	ebp, ebx
-
 
303
	shr	ebx, 2
-
 
304
	shr	ah, 4
-
 
305
	shl	dl, 2
-
 
306
	shr	ebp, 7
-
 
307
	add	eax, edx
-
 
308
	add	ebx, ebp
-
 
309
	mov	[edi], al
-
 
310
	mov	[edi+1], bl
226
	add	esi, 4
311
	mov	[edi+2], ah
227
	add	edi, 3
312
	add	edi, 3
228
	sub	ecx, 1
313
	sub	ecx, 1
-
 
314
	jnz	@b
-
 
315
.bpp15.done:
-
 
316
	pop	ebp ebx
Line -... Line 317...
-
 
317
	ret
-
 
318
 
-
 
319
.bpp15.amd:
-
 
320
	push	ebx ebp
-
 
321
	sub	ecx, 4
-
 
322
	jb	.bpp15.tail
-
 
323
align 16
-
 
324
.bpp15.amd.loop:
-
 
325
repeat 4
-
 
326
if (% mod 2) = 1
-
 
327
	mov	eax, dword [esi]
-
 
328
	mov	ebx, dword [esi]
-
 
329
else
-
 
330
	movzx	eax, word [esi]
-
 
331
	mov	ebx, eax
-
 
332
end if
-
 
333
	add	esi, 2
-
 
334
	and	eax, (0x1F) or (0x1F shl 10)
-
 
335
	and	ebx, 0x1F shl 5
-
 
336
	lea	edx, [eax+eax]
-
 
337
	shr	al, 2
-
 
338
	mov	ebp, ebx
-
 
339
	shr	ebx, 2
-
 
340
	shr	ah, 4
-
 
341
	shl	dl, 2
-
 
342
	shr	ebp, 7
-
 
343
	add	eax, edx
-
 
344
	add	ebx, ebp
-
 
345
	mov	[edi], al
-
 
346
	mov	[edi+1], bl
-
 
347
	mov	[edi+2], ah
-
 
348
	add	edi, 3
-
 
349
end repeat
-
 
350
	sub	ecx, 4
-
 
351
	jnb	.bpp15.amd.loop
-
 
352
	jmp	.bpp15.tail
-
 
353
 
-
 
354
; 16 BPP -> 24 BPP
-
 
355
.bpp16.intel:
-
 
356
	push	ebx ebp
-
 
357
	sub	ecx, 4
-
 
358
	jb	.bpp16.tail
-
 
359
align 16
-
 
360
.bpp16.intel.loop:
-
 
361
repeat 2
-
 
362
	mov	ebx, [esi]
-
 
363
	mov	al, [esi]
-
 
364
	mov	ah, [esi+1]
-
 
365
	add	esi, 4
-
 
366
	and	al, 0x1F
-
 
367
	and	ah, 0x1F shl 3
-
 
368
	mov	ebp, ebx
-
 
369
	mov	dl, al
-
 
370
	mov	dh, ah
-
 
371
	shr	al, 2
-
 
372
	shr	ah, 5
-
 
373
	shl	dl, 3
-
 
374
	and	ebp, 0x3F shl 5
-
 
375
	add	al, dl
-
 
376
	add	ah, dh
-
 
377
	shr	ebp, 3
-
 
378
	mov	[edi], al
-
 
379
	mov	[edi+2], ah
-
 
380
	mov	eax, ebx
-
 
381
	mov	ebx, ebp
-
 
382
	shr	eax, 16
-
 
383
	shr	ebx, 6
-
 
384
	add	ebx, ebp
-
 
385
	mov	ebp, eax
-
 
386
	mov	[edi+1], bl
-
 
387
	and	eax, (0x1F) or (0x1F shl 11)
-
 
388
	and	ebp, 0x3F shl 5
-
 
389
	mov	edx, eax
-
 
390
	shr	al, 2
-
 
391
	mov	ebx, ebp
-
 
392
	shr	ah, 5
-
 
393
	shl	dl, 3
-
 
394
	shr	ebx, 3
-
 
395
	shr	ebp, 9
-
 
396
	add	al, dl
-
 
397
	add	ah, dh
-
 
398
	mov	[edi+3], al
-
 
399
	add	ebx, ebp
-
 
400
	mov	[edi+5], ah
-
 
401
	mov	[edi+4], bl
-
 
402
	add	edi, 6
-
 
403
end repeat
-
 
404
	sub	ecx, 4
-
 
405
	jnb	.bpp16.intel.loop
-
 
406
.bpp16.tail:
229
	jnz	@b
407
	add	ecx, 4
-
 
408
	jz	.bpp16.done
-
 
409
@@:
-
 
410
	movzx	eax, word [esi]
-
 
411
	mov	ebx, eax
-
 
412
	add	esi, 2
-
 
413
	and	eax, (0x1F) or (0x1F shl 11)
-
 
414
	and	ebx, 0x3F shl 5
-
 
415
	mov	edx, eax
-
 
416
	shr	al, 2
-
 
417
	mov	ebp, ebx
-
 
418
	shr	ebx, 3
-
 
419
	shr	ah, 5
-
 
420
	shl	dl, 3
-
 
421
	shr	ebp, 9
-
 
422
	add	eax, edx
-
 
423
	add	ebx, ebp
-
 
424
	mov	[edi], al
-
 
425
	mov	[edi+1], bl
-
 
426
	mov	[edi+2], ah
-
 
427
	add	edi, 3
-
 
428
	sub	ecx, 1
-
 
429
	jnz	@b
230
 
430
.bpp16.done:
Line -... Line 431...
-
 
431
	pop	ebp ebx
-
 
432
	ret
-
 
433
 
-
 
434
.bpp16.amd:
-
 
435
	push	ebx ebp
-
 
436
	sub	ecx, 4
-
 
437
	jb	.bpp16.tail
-
 
438
align 16
-
 
439
.bpp16.amd.loop:
-
 
440
repeat 4
-
 
441
if (% mod 2) = 1
-
 
442
	mov	eax, dword [esi]
-
 
443
	mov	ebx, dword [esi]
-
 
444
else
-
 
445
	movzx	eax, word [esi]
-
 
446
	mov	ebx, eax
-
 
447
end if
-
 
448
	add	esi, 2
-
 
449
	and	eax, (0x1F) or (0x1F shl 11)
-
 
450
	and	ebx, 0x3F shl 5
-
 
451
	mov	edx, eax
-
 
452
	shr	al, 2
-
 
453
	mov	ebp, ebx
-
 
454
	shr	ebx, 3
-
 
455
	shr	ah, 5
-
 
456
	shl	dl, 3
-
 
457
	shr	ebp, 9
-
 
458
	add	eax, edx
-
 
459
	add	ebx, ebp
-
 
460
	mov	[edi], al
-
 
461
	mov	[edi+1], bl
-
 
462
	mov	[edi+2], ah
-
 
463
	add	edi, 3
-
 
464
end repeat
-
 
465
	sub	ecx, 4
-
 
466
	jnb	.bpp16.amd.loop
231
    @@:
467
	jmp	.bpp16.tail
232
	ret
468
 
233
 
469
align 16
234
.bpp24:
470
.bpp24:
235
; 24 BPP -> 24 BPP
471
; 24 BPP -> 24 BPP
236
	lea	ecx, [ecx*3 + 3]
472
	lea	ecx, [ecx*3 + 3]
237
	mov	esi, [esi + Image.Data]
473
	mov	esi, [esi + Image.Data]
Line -... Line 474...
-
 
474
	shr	ecx, 2
238
	shr	ecx, 2
475
	rep	movsd
239
	rep	movsd
476
	ret
240
	ret
-
 
241
 
-
 
242
.bpp8:
477
 
-
 
478
align 16
243
; 8 BPP -> 24 BPP
479
.bpp32:
244
	push	ebx
480
; 32 BPP -> 24 BPP
245
	mov	ebx, [esi + Image.Palette]
-
 
246
	mov	esi, [esi + Image.Data]
-
 
247
@@:
481
	mov	esi, [esi + Image.Data]
248
	movzx	eax, byte [esi]
482
 
249
	add	esi, 1
483
    @@:
-
 
484
	mov	eax, [esi]
250
	mov	eax, [ebx + eax*4]
485
	mov	[edi], ax
251
	mov	[edi], ax
486
	shr	eax, 16
252
	shr	eax, 16
487
	mov	[edi+2], al
-
 
488
	add	esi, 4
253
	mov	[edi+2], al
489
	add	edi, 3
254
	add	edi, 3
490
	sub	ecx, 1
-
 
491
	jnz	@b
255
	sub	ecx, 1
492
 
Line 256... Line 493...
256
	jnz	@b
493
    @@:
257
	pop	ebx
494
	ret
258
	ret
495
 
Line 333... Line 570...
333
	pop	ecx
570
	pop	ecx
334
	ret
571
	ret
335
endp
572
endp
Line 336... Line 573...
336
 
573
 
-
 
574
;;================================================================================================;;
-
 
575
proc img.destroy.layer _img ;/////////////////////////////////////////////////////////////////////;;
-
 
576
;;------------------------------------------------------------------------------------------------;;
-
 
577
;? --- TBD ---                                                                                    ;;
-
 
578
;;------------------------------------------------------------------------------------------------;;
-
 
579
;> --- TBD ---                                                                                    ;;
-
 
580
;;------------------------------------------------------------------------------------------------;;
-
 
581
;< eax = false / true                                                                             ;;
-
 
582
;;================================================================================================;;
-
 
583
	mov	eax, [_img]
-
 
584
	mov	edx, [eax + Image.Previous]
-
 
585
	test	edx, edx
-
 
586
	jz	@f
-
 
587
	push	[eax + Image.Next]
-
 
588
	pop	[edx + Image.Next]
-
 
589
@@:
-
 
590
	mov	edx, [eax + Image.Next]
-
 
591
	test	edx, edx
-
 
592
	jz	@f
-
 
593
	push	[eax + Image.Previous]
-
 
594
	pop	[edx + Image.Previous]
-
 
595
@@:
-
 
596
	stdcall img._.delete, eax
-
 
597
	ret
-
 
598
endp
-
 
599
 
337
;;================================================================================================;;
600
;;================================================================================================;;
338
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
601
proc img.destroy _img ;///////////////////////////////////////////////////////////////////////////;;
339
;;------------------------------------------------------------------------------------------------;;
602
;;------------------------------------------------------------------------------------------------;;
340
;? --- TBD ---                                                                                    ;;
603
;? --- TBD ---                                                                                    ;;
341
;;------------------------------------------------------------------------------------------------;;
604
;;------------------------------------------------------------------------------------------------;;
342
;> --- TBD ---                                                                                    ;;
605
;> --- TBD ---                                                                                    ;;
343
;;------------------------------------------------------------------------------------------------;;
606
;;------------------------------------------------------------------------------------------------;;
344
;< eax = false / true                                                                             ;;
607
;< eax = false / true                                                                             ;;
-
 
608
;;================================================================================================;;
-
 
609
	push	1
-
 
610
	mov	eax, [_img]
-
 
611
	mov	eax, [eax + Image.Previous]
-
 
612
.destroy_prev_loop:
-
 
613
	test	eax, eax
345
;;================================================================================================;;
614
	jz	.destroy_prev_done
346
	;TODO: link Next and Previous
615
	pushd	[eax + Image.Previous]
-
 
616
	stdcall	img._.delete, eax
-
 
617
	test	eax, eax
-
 
618
	jnz	@f
-
 
619
	mov	byte [esp+4], 0
-
 
620
@@:
-
 
621
	pop	eax
-
 
622
	jmp	.destroy_prev_loop
-
 
623
.destroy_prev_done:
-
 
624
	mov	eax, [_img]
-
 
625
.destroy_next_loop:
-
 
626
	pushd	[eax + Image.Next]
-
 
627
	stdcall	img._.delete, eax
-
 
628
	test	eax, eax
-
 
629
	jnz	@f
-
 
630
	mov	byte [esp+4], 0
-
 
631
@@:
-
 
632
	pop	eax
-
 
633
	test	eax, eax
-
 
634
	jnz	.destroy_next_loop
347
	stdcall img._.delete, [_img]
635
	pop	eax
348
	ret
636
	ret
Line 349... Line 637...
349
endp
637
endp
350
 
638
 
Line 415... Line 703...
415
	xor	eax, eax
703
	xor	eax, eax
416
	ret
704
	ret
417
endp
705
endp
Line 418... Line 706...
418
 
706
 
419
;;================================================================================================;;
707
;;================================================================================================;;
420
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
708
proc img.flip.layer _img, _flip_kind ;////////////////////////////////////////////////////////////;;
421
;;------------------------------------------------------------------------------------------------;;
709
;;------------------------------------------------------------------------------------------------;;
422
;? Flip image                                                                                     ;;
710
;? Flip image layer                                                                               ;;
423
;;------------------------------------------------------------------------------------------------;;
711
;;------------------------------------------------------------------------------------------------;;
424
;> _img = pointer to image                                                                        ;;
712
;> _img = pointer to image                                                                        ;;
425
;> _flip_kind = one of FLIP_* constants                                                           ;;
713
;> _flip_kind = one of FLIP_* constants                                                           ;;
426
;;------------------------------------------------------------------------------------------------;;
714
;;------------------------------------------------------------------------------------------------;;
Line 491... Line 779...
491
	mov	ecx, [ebx + Image.Height]
779
	mov	ecx, [ebx + Image.Height]
492
	mov	eax, [ebx + Image.Type]
780
	mov	eax, [ebx + Image.Type]
493
	mov	esi, [ebx + Image.Data]
781
	mov	esi, [ebx + Image.Data]
494
	mov	edi, [scanline_len]
782
	mov	edi, [scanline_len]
495
	add	edi, esi
783
	add	edi, esi
-
 
784
	jmp	dword [.handlers_horz + (eax-1)*4]
Line 496... Line -...
496
 
-
 
497
	dec	eax
-
 
498
	jz	.bpp8.2
-
 
499
	dec	eax
785
 
500
	jz	.bpp24.2
-
 
501
 
786
.bpp32_horz:
Line 502... Line 787...
502
	sub	edi, 4
787
	sub	edi, 4
503
 
788
 
Line 519... Line 804...
519
	add	edi, [scanline_len]
804
	add	edi, [scanline_len]
520
	dec	ecx
805
	dec	ecx
521
	jnz	.next_line_horz
806
	jnz	.next_line_horz
522
	jmp	.exit
807
	jmp	.exit
Line -... Line 808...
-
 
808
 
-
 
809
.bpp1x_horz:
-
 
810
	sub	edi, 2
-
 
811
  .next_line_horz1x:
-
 
812
	push	ecx esi edi
-
 
813
 
-
 
814
	mov	ecx, [ebx + Image.Width]
-
 
815
    @@: mov	ax, [esi]
-
 
816
	mov	dx, [edi]
-
 
817
	mov	[edi], ax
-
 
818
	mov	[esi], dx
-
 
819
	add	esi, 2
-
 
820
	sub	edi, 2
-
 
821
	sub	ecx, 2
-
 
822
	ja	@b
-
 
823
 
-
 
824
	pop	edi esi ecx
-
 
825
	add	esi, [scanline_len]
-
 
826
	add	edi, [scanline_len]
-
 
827
	dec	ecx
-
 
828
	jnz	.next_line_horz1x
-
 
829
	jmp	.exit
523
 
830
 
524
.bpp8.2:
831
.bpp8_horz:
525
	dec	edi
832
	dec	edi
526
  .next_line_horz8:
833
  .next_line_horz8:
Line 527... Line 834...
527
	push	ecx esi edi
834
	push	ecx esi edi
Line 542... Line 849...
542
	add	edi, [scanline_len]
849
	add	edi, [scanline_len]
543
	dec	ecx
850
	dec	ecx
544
	jnz	.next_line_horz8
851
	jnz	.next_line_horz8
545
	jmp	.exit
852
	jmp	.exit
Line 546... Line 853...
546
 
853
 
547
.bpp24.2:
854
.bpp24_horz:
548
	sub	edi, 3
855
	sub	edi, 3
549
  .next_line_horz32:
856
  .next_line_horz24:
Line 550... Line 857...
550
	push	ecx esi edi
857
	push	ecx esi edi
551
 
-
 
552
	mov	ecx, [ebx + Image.Width]
858
 
553
	shr	ecx, 1
859
	mov	ecx, [ebx + Image.Width]
554
    @@:
860
    @@:
555
	mov	al, [esi]
861
	mov	al, [esi]
556
	mov	dl, [edi]
862
	mov	dl, [edi]
Line 564... Line 870...
564
	mov	dl, [edi+2]
870
	mov	dl, [edi+2]
565
	mov	[edi+2], al
871
	mov	[edi+2], al
566
	mov	[esi+2], dl
872
	mov	[esi+2], dl
567
	add	esi, 3
873
	add	esi, 3
568
	sub	edi, 3
874
	sub	edi, 3
569
	sub	ecx, 1
875
	sub	ecx, 2
570
	jnz	@b
876
	ja	@b
Line 571... Line 877...
571
 
877
 
572
	pop	edi esi ecx
878
	pop	edi esi ecx
573
	add	esi, [scanline_len]
879
	add	esi, [scanline_len]
574
	add	edi, [scanline_len]
880
	add	edi, [scanline_len]
575
	dec	ecx
881
	dec	ecx
Line 576... Line 882...
576
	jnz	.next_line_horz32
882
	jnz	.next_line_horz24
577
 
883
 
578
  .exit:
884
  .exit:
579
	xor	eax, eax
885
	xor	eax, eax
Line 586... Line 892...
586
	pop	edi esi ebx
892
	pop	edi esi ebx
587
	ret
893
	ret
588
endp
894
endp
Line 589... Line 895...
589
 
895
 
-
 
896
;;================================================================================================;;
-
 
897
proc img.flip _img, _flip_kind ;//////////////////////////////////////////////////////////////////;;
-
 
898
;;------------------------------------------------------------------------------------------------;;
-
 
899
;? Flip all layers of image                                                                       ;;
-
 
900
;;------------------------------------------------------------------------------------------------;;
-
 
901
;> _img = pointer to image                                                                        ;;
-
 
902
;> _flip_kind = one of FLIP_* constants                                                           ;;
-
 
903
;;------------------------------------------------------------------------------------------------;;
-
 
904
;< eax = false / true                                                                             ;;
-
 
905
;;================================================================================================;;
-
 
906
	push	1
-
 
907
	mov	ebx, [_img]
-
 
908
@@:
-
 
909
	mov	eax, [ebx + Image.Previous]
-
 
910
	test	eax, eax
-
 
911
	jz	.loop
-
 
912
	mov	ebx, eax
-
 
913
	jmp	@b
-
 
914
.loop:
-
 
915
	stdcall	img.flip.layer, ebx, [_flip_kind]
-
 
916
	test	eax, eax
-
 
917
	jnz	@f
-
 
918
	mov	byte [esp], 0
-
 
919
@@:
-
 
920
	mov	ebx, [ebx + Image.Next]
-
 
921
	test	ebx, ebx
-
 
922
	jnz	.loop
-
 
923
	pop	eax
-
 
924
	ret
-
 
925
endp
-
 
926
 
590
;;================================================================================================;;
927
;;================================================================================================;;
591
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
928
proc img.rotate.layer _img, _rotate_kind ;////////////////////////////////////////////////////////;;
592
;;------------------------------------------------------------------------------------------------;;
929
;;------------------------------------------------------------------------------------------------;;
593
;? Rotate image                                                                                   ;;
930
;? Rotate image layer                                                                             ;;
594
;;------------------------------------------------------------------------------------------------;;
931
;;------------------------------------------------------------------------------------------------;;
595
;> _img = pointer to image                                                                        ;;
932
;> _img = pointer to image                                                                        ;;
596
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
933
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
597
;;------------------------------------------------------------------------------------------------;;
934
;;------------------------------------------------------------------------------------------------;;
Line 644... Line 981...
644
 
981
 
645
	cmp	[ebx + Image.Type], Image.bpp8
982
	cmp	[ebx + Image.Type], Image.bpp8
646
	jz	.rotate_ccw8
983
	jz	.rotate_ccw8
647
	cmp	[ebx + Image.Type], Image.bpp24
984
	cmp	[ebx + Image.Type], Image.bpp24
-
 
985
	jz	.rotate_ccw24
-
 
986
	cmp	[ebx + Image.Type], Image.bpp32
-
 
987
	jz	.rotate_ccw32
-
 
988
 
-
 
989
  .next_column_ccw_low1x:
-
 
990
	dec	ecx
-
 
991
	js	.exchange_dims
-
 
992
	push	ecx
-
 
993
 
-
 
994
	mov	edx, [scanline_len_old]
-
 
995
	add	[scanline_len_old], -2
-
 
996
 
-
 
997
	mov	ecx, [scanline_pixels_new]
-
 
998
	mov	esi, [ebx + Image.Data]
-
 
999
	mov	edi, [line_buffer]
-
 
1000
    @@: mov	ax, [esi]
-
 
1001
	mov	[edi], ax
-
 
1002
	add	esi, edx
-
 
1003
	add	edi, 2
-
 
1004
	sub	ecx, 1
-
 
1005
	jnz	@b
-
 
1006
 
-
 
1007
	mov	eax, [scanline_pixels_new]
-
 
1008
	mov	edi, [ebx + Image.Data]
-
 
1009
	lea	esi, [edi + 2]
-
 
1010
	mov	edx, [scanline_len_old]
-
 
1011
    @@: mov	ecx, edx
-
 
1012
	shr	ecx, 2
-
 
1013
	rep	movsd
-
 
1014
	mov	ecx, edx
-
 
1015
	and	ecx, 3
-
 
1016
	rep	movsb
-
 
1017
	add	esi, 1
-
 
1018
	sub	eax, 1
Line -... Line 1019...
-
 
1019
	jnz	@b
-
 
1020
 
-
 
1021
	mov	eax, [scanline_len_new]
-
 
1022
	sub	[pixels_ptr], eax
-
 
1023
	mov	ecx, [scanline_pixels_new]
-
 
1024
	mov	esi, [line_buffer]
-
 
1025
	mov	edi, [pixels_ptr]
-
 
1026
	mov	edx, ecx
-
 
1027
	shr	ecx, 2
-
 
1028
	rep	movsd
-
 
1029
	mov	ecx, edx
-
 
1030
	and	ecx, 3
-
 
1031
	rep	movsb
-
 
1032
 
-
 
1033
	pop	ecx
-
 
1034
	jmp	.next_column_ccw_low1x
648
	jz	.rotate_ccw24
1035
 
649
 
1036
.rotate_ccw32:
650
  .next_column_ccw_low:
1037
  .next_column_ccw_low:
651
	dec	ecx
1038
	dec	ecx
Line 807... Line 1194...
807
 
1194
 
808
	cmp	[ebx + Image.Type], Image.bpp8
1195
	cmp	[ebx + Image.Type], Image.bpp8
809
	jz	.rotate_cw8
1196
	jz	.rotate_cw8
810
	cmp	[ebx + Image.Type], Image.bpp24
1197
	cmp	[ebx + Image.Type], Image.bpp24
-
 
1198
	jz	.rotate_cw24
-
 
1199
	cmp	[ebx + Image.Type], Image.bpp32
-
 
1200
	jz	.rotate_cw32
-
 
1201
 
-
 
1202
  .next_column_cw_low1x:
-
 
1203
	dec	ecx
-
 
1204
	js	.exchange_dims
-
 
1205
	push	ecx
-
 
1206
 
-
 
1207
	mov	edx, [scanline_len_old]
-
 
1208
	add	[scanline_len_old], -2
-
 
1209
 
-
 
1210
	mov	ecx, [scanline_pixels_new]
-
 
1211
	mov	esi, [pixels_ptr]
-
 
1212
	add	esi, -2
-
 
1213
	mov	edi, [line_buffer]
-
 
1214
    @@: mov	ax, [esi]
-
 
1215
	mov	[edi], ax
-
 
1216
	sub	esi, edx
-
 
1217
	add	edi, 2
-
 
1218
	sub	ecx, 1
-
 
1219
	jnz	@b
-
 
1220
 
-
 
1221
	mov	eax, [scanline_pixels_new]
-
 
1222
	dec	eax
-
 
1223
	mov	edi, [ebx + Image.Data]
-
 
1224
	add	edi, [scanline_len_old]
-
 
1225
	lea	esi, [edi + 2]
-
 
1226
	mov	edx, [scanline_len_old]
-
 
1227
    @@: mov	ecx, edx
-
 
1228
	shr	ecx, 2
-
 
1229
	rep	movsd
-
 
1230
	mov	ecx, edx
-
 
1231
	and	ecx, 3
-
 
1232
	rep	movsb
-
 
1233
	add	esi, 3
-
 
1234
	sub	eax, 1
-
 
1235
	jnz	@b
-
 
1236
 
-
 
1237
	mov	eax, [scanline_len_new]
-
 
1238
	sub	[pixels_ptr], eax
-
 
1239
	mov	ecx, eax
-
 
1240
	mov	esi, [line_buffer]
-
 
1241
	mov	edi, [pixels_ptr]
-
 
1242
	shr	ecx, 2
-
 
1243
	rep	movsd
-
 
1244
	mov	ecx, eax
-
 
1245
	and	ecx, 3
-
 
1246
	rep	movsb
-
 
1247
 
-
 
1248
	pop	ecx
Line -... Line 1249...
-
 
1249
	jmp	.next_column_cw_low1x
811
	jz	.rotate_cw24
1250
 
812
 
1251
.rotate_cw32:
813
  .next_column_cw_low:
1252
  .next_column_cw_low:
814
	dec	ecx
1253
	dec	ecx
Line 974... Line 1413...
974
	xor	eax, eax
1413
	xor	eax, eax
975
	pop	edi esi ebx
1414
	pop	edi esi ebx
976
	ret
1415
	ret
977
endp
1416
endp
Line -... Line 1417...
-
 
1417
 
-
 
1418
;;================================================================================================;;
-
 
1419
proc img.rotate _img, _rotate_kind ;//////////////////////////////////////////////////////////////;;
-
 
1420
;;------------------------------------------------------------------------------------------------;;
-
 
1421
;? Rotate all layers of image                                                                     ;;
-
 
1422
;;------------------------------------------------------------------------------------------------;;
-
 
1423
;> _img = pointer to image                                                                        ;;
-
 
1424
;> _rotate_kind = one of ROTATE_* constants                                                       ;;
-
 
1425
;;------------------------------------------------------------------------------------------------;;
-
 
1426
;< eax = false / true                                                                             ;;
-
 
1427
;;================================================================================================;;
-
 
1428
	push	1
-
 
1429
	mov	ebx, [_img]
-
 
1430
@@:
-
 
1431
	mov	eax, [ebx + Image.Previous]
-
 
1432
	test	eax, eax
-
 
1433
	jz	.loop
-
 
1434
	mov	ebx, eax
-
 
1435
	jmp	@b
-
 
1436
.loop:
-
 
1437
	stdcall	img.rotate.layer, ebx, [_rotate_kind]
-
 
1438
	test	eax, eax
-
 
1439
	jnz	@f
-
 
1440
	mov	byte [esp], 0
-
 
1441
@@:
-
 
1442
	mov	ebx, [ebx + Image.Next]
-
 
1443
	test	ebx, ebx
-
 
1444
	jnz	.loop
-
 
1445
	pop	eax
-
 
1446
	ret
-
 
1447
endp
-
 
1448
 
-
 
1449
;;================================================================================================;;
-
 
1450
proc img.draw _img, _x, _y, _width, _height, _xpos, _ypos ;///////////////////////////////////////;;
-
 
1451
;;------------------------------------------------------------------------------------------------;;
-
 
1452
;? Draw image in the window                                                                       ;;
-
 
1453
;;------------------------------------------------------------------------------------------------;;
-
 
1454
;> _img = pointer to image                                                                        ;;
-
 
1455
;>_x = x-coordinate in the window                                                                 ;;
-
 
1456
;>_y = y-coordinate in the window                                                                 ;;
-
 
1457
;>_width = maximum width to draw                                                                  ;;
-
 
1458
;>_height = maximum height to draw                                                                ;;
-
 
1459
;>_xpos = offset in image by x-axis                                                               ;;
-
 
1460
;>_ypos = offset in image by y-axis                                                               ;;
-
 
1461
;;------------------------------------------------------------------------------------------------;;
-
 
1462
;< no return value                                                                                ;;
-
 
1463
;;================================================================================================;;
-
 
1464
	push	ebx esi edi
-
 
1465
	mov	ebx, [_img]
-
 
1466
	stdcall	img._.validate, ebx
-
 
1467
	test	eax, eax
-
 
1468
	jnz	.done
-
 
1469
	mov	ecx, [ebx + Image.Width]
-
 
1470
	sub	ecx, [_xpos]
-
 
1471
	jbe	.done
-
 
1472
	cmp	ecx, [_width]
-
 
1473
	jb	@f
-
 
1474
	mov	ecx, [_width]
-
 
1475
@@:
-
 
1476
	mov	edx, [ebx + Image.Height]
-
 
1477
	sub	edx, [_ypos]
-
 
1478
	jbe	.done
-
 
1479
	cmp	edx, [_height]
-
 
1480
	jb	@f
-
 
1481
	mov	edx, [_height]
-
 
1482
@@:
-
 
1483
	mov	eax, [ebx + Image.Width]
-
 
1484
	sub	eax, ecx
-
 
1485
	call	img._.get_scanline_len
-
 
1486
	shl	ecx, 16
-
 
1487
	add	ecx, edx
-
 
1488
	mov	edx, [_x - 2]
-
 
1489
	mov	dx, word [_y]
-
 
1490
	mov	esi, [ebx + Image.Type]
-
 
1491
	mov	esi, [type2bpp + (esi-1)*4]
-
 
1492
	mov	edi, [ebx + Image.Palette]
-
 
1493
	mov	ebx, [ebx + Image.Data]
-
 
1494
	push	ebp
-
 
1495
	push	65
-
 
1496
	pop	ebp
-
 
1497
	xchg	eax, ebp
-
 
1498
	int	40h
-
 
1499
	pop	ebp
-
 
1500
.done:
-
 
1501
	pop	edi esi ebx
-
 
1502
	ret
Line 978... Line 1503...
978
 
1503
endp
979
 
1504
 
980
;;================================================================================================;;
1505
;;================================================================================================;;
981
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1506
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
Line 1013... Line 1538...
1013
	jz	@f
1538
	jz	@f
1014
	push	ecx
1539
	push	ecx
1015
	xor	ecx, ecx
1540
	xor	ecx, ecx
1016
	mov	[eax + Image.Data], ecx
1541
	mov	[eax + Image.Data], ecx
1017
	mov	[eax + Image.Type], ecx
1542
	mov	[eax + Image.Type], ecx
-
 
1543
	mov	[eax + Image.Flags], ecx
1018
	mov	[eax + Image.Extended], ecx
1544
	mov	[eax + Image.Extended], ecx
1019
	mov	[eax + Image.Previous], ecx
1545
	mov	[eax + Image.Previous], ecx
1020
	mov	[eax + Image.Next], ecx
1546
	mov	[eax + Image.Next], ecx
1021
	pop	ecx
1547
	pop	ecx
1022
@@:
1548
@@:
Line 1116... Line 1642...
1116
;;================================================================================================;;
1642
;;================================================================================================;;
1117
	cmp	[ebx + Image.Type], Image.bpp8
1643
	cmp	[ebx + Image.Type], Image.bpp8
1118
	jz	.bpp8.1
1644
	jz	.bpp8.1
1119
	cmp	[ebx + Image.Type], Image.bpp24
1645
	cmp	[ebx + Image.Type], Image.bpp24
1120
	jz	.bpp24.1
1646
	jz	.bpp24.1
-
 
1647
	add	eax, eax
-
 
1648
	cmp	[ebx + Image.Type], Image.bpp32
-
 
1649
	jnz	@f
1121
	shl	eax, 2
1650
	add	eax, eax
1122
	jmp	@f
1651
	jmp	@f
1123
.bpp24.1:
1652
.bpp24.1:
1124
	lea	eax, [eax*3]
1653
	lea	eax, [eax*3]
1125
.bpp8.1:
1654
.bpp8.1:
1126
@@:
1655
@@:
Line 1133... Line 1662...
1133
;! Below is private data you should never use directly from your code                             ;;
1662
;! Below is private data you should never use directly from your code                             ;;
1134
;;================================================================================================;;
1663
;;================================================================================================;;
1135
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1664
;;////////////////////////////////////////////////////////////////////////////////////////////////;;
1136
;;================================================================================================;;
1665
;;================================================================================================;;
Line 1137... Line 1666...
1137
 
1666
 
1138
 
1667
align 4
1139
img._.formats_table:
1668
img._.formats_table:
1140
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
1669
  .bmp dd img.is.bmp, img.decode.bmp, img.encode.bmp
1141
; .ico dd img.is.ico, img.decode.ico, img.encode.ico
1670
; .ico dd img.is.ico, img.decode.ico, img.encode.ico
1142
; .cur dd img.is.cur, img.decode.cur, img.encode.cur
1671
; .cur dd img.is.cur, img.decode.cur, img.encode.cur
1143
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
1672
  .gif dd img.is.gif, img.decode.gif, img.encode.gif
1144
  .png dd img.is.png, img.decode.png, img.encode.png
1673
  .png dd img.is.png, img.decode.png, img.encode.png
-
 
1674
  .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
-
 
1675
  .tga dd img.is.tga, img.decode.tga, img.encode.tga
-
 
1676
  .z80 dd img.is.z80, img.decode.z80, img.encode.z80 ;this must be the last entry as there are no
1145
  .jpg dd img.is.jpg, img.decode.jpg, img.encode.jpg
1677
  ;signatures in z80 screens at all
Line -... Line 1678...
-
 
1678
       dd 0
-
 
1679
 
-
 
1680
align 4
-
 
1681
type2bpp	dd	8, 24, 32, 15, 16
-
 
1682
img._.do_rgb.handlers:
-
 
1683
	dd	img._.do_rgb.bpp8
-
 
1684
	dd	img._.do_rgb.bpp24
-
 
1685
	dd	img._.do_rgb.bpp32
-
 
1686
	dd	img._.do_rgb.bpp15.amd	; can be overwritten in lib_init
-
 
1687
	dd	img._.do_rgb.bpp16.amd	; can be overwritten in lib_init
-
 
1688
 
-
 
1689
img.flip.layer.handlers_horz:
-
 
1690
	dd	img.flip.layer.bpp8_horz
-
 
1691
	dd	img.flip.layer.bpp24_horz
-
 
1692
	dd	img.flip.layer.bpp32_horz
Line 1146... Line 1693...
1146
       dd 0
1693
	dd	img.flip.layer.bpp1x_horz
1147
 
1694
	dd	img.flip.layer.bpp1x_horz
1148
 
1695
 
1149
;;================================================================================================;;
1696
;;================================================================================================;;
Line 1158... Line 1705...
1158
align 4
1705
align 4
1159
@EXPORT:
1706
@EXPORT:
Line 1160... Line 1707...
1160
 
1707
 
1161
export					      \
1708
export					      \
1162
	lib_init	, 'lib_init'	    , \
1709
	lib_init	, 'lib_init'	    , \
1163
	0x00010003	, 'version'	    , \
1710
	0x00010004	, 'version'	    , \
1164
	img.is_img	, 'img.is_img'	    , \
1711
	img.is_img	, 'img.is_img'	    , \
1165
	img.info	, 'img.info'	    , \
1712
	img.info	, 'img.info'	    , \
1166
	img.from_file	, 'img.from_file'   , \
1713
	img.from_file	, 'img.from_file'   , \
1167
	img.to_file	, 'img.to_file'     , \
1714
	img.to_file	, 'img.to_file'     , \
Line 1170... Line 1717...
1170
	img.to_rgb2     , 'img.to_rgb2'     , \
1717
	img.to_rgb2	, 'img.to_rgb2'     , \
1171
	img.decode	, 'img.decode'	    , \
1718
	img.decode	, 'img.decode'	    , \
1172
	img.encode	, 'img.encode'	    , \
1719
	img.encode	, 'img.encode'	    , \
1173
	img.create	, 'img.create'	    , \
1720
	img.create	, 'img.create'	    , \
1174
	img.destroy	, 'img.destroy'     , \
1721
	img.destroy	, 'img.destroy'     , \
-
 
1722
	img.destroy.layer, 'img.destroy.layer', \
1175
	img.count	, 'img.count'	    , \
1723
	img.count	, 'img.count'	    , \
1176
	img.lock_bits	, 'img.lock_bits'   , \
1724
	img.lock_bits	, 'img.lock_bits'   , \
1177
	img.unlock_bits , 'img.unlock_bits' , \
1725
	img.unlock_bits , 'img.unlock_bits' , \
1178
	img.flip	, 'img.flip'	    , \
1726
	img.flip	, 'img.flip'	    , \
-
 
1727
	img.flip.layer  , 'img.flip.layer'  , \
1179
	img.rotate	, 'img.rotate'
1728
	img.rotate	, 'img.rotate'      , \
-
 
1729
	img.rotate.layer, 'img.rotate.layer', \
-
 
1730
	img.draw        , 'img.draw'
Line 1180... Line 1731...
1180
 
1731
 
1181
; import from deflate unpacker
1732
; import from deflate unpacker
1182
; is initialized only when PNG loading is requested
1733
; is initialized only when PNG loading is requested
1183
align 4
1734
align 4
Line 1184... Line 1735...
1184
@IMPORT:
1735
@IMPORT:
1185
 
1736
 
1186
library kfar_arc, '../File Managers/kfar_arc.obj'
1737
library kfar_arc, '../File Managers/kfar_arc.obj'
Line -... Line 1738...
-
 
1738
import	kfar_arc, \
1187
import	kfar_arc, \
1739
	deflate_unpack2, 'deflate_unpack2'
1188
	deflate_unpack2, 'deflate_unpack2'
1740
 
Line -... Line 1741...
-
 
1741
align 4
-
 
1742
; mutex for unpacker loading
-
 
1743
deflate_loader_mutex	dd	0
-
 
1744
 
-
 
1745
; default palette for GIF - b&w
1189
 
1746
gif_default_palette:
1190
; mutex for unpacker loading
1747
	db	0, 0, 0
-
 
1748
	db	0xFF, 0xFF, 0xFF
-
 
1749
 
-
 
1750
section '.data' data readable writable align 16
-
 
1751
; uninitialized data - global constant tables
Line 1191... Line 1752...
1191
deflate_loader_mutex	dd	0
1752
mem.alloc   dd ?
1192
 
1753
mem.free    dd ?
1193
section '.data' data readable writable align 16
1754
mem.realloc dd ?
1194
; uninitialized data - global constant tables
1755
dll.load    dd ?