Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;405 412 586
2
;
3
;
4
bufer_size=1024*16+2
5
fichero=4
6
mcu_ptr=8
7
color_ptr=12
8
estado=16
9
color_c=17
10
nbits=color_c
11
idct=20
12
tmp_bits=24
13
actable=28
14
matriz_limit=32
15
sourcebits=36
16
sourcebits_index=40
17
sourcebits_limit=44
18
qt_ptrs=48
19
ht_dc_ptrs=64
20
ht_ac_ptrs=80
21
matrices=96
22
tmp_bufer=100
23
x_org=104
24
y_org=108
25
x_mcu=112
26
y_mcu=116
27
x_size=120
28
y_size=124
29
x_org2=128
30
y_org2=132
31
x_mcu2=136
32
y_mcu2=140
33
x_size2=144
34
y_size2=148
35
q_ptr=152
36
dc=164
37
position=204
38
draw_ptr=208
39
struct_size=212
40
 
41
jpeg_info:  ;fichero en eax
42
            ;retorna ebp
43
        xor ebp,ebp
44
        pushad
45
        mov ebp,esp
46
        mov ecx,6
47
        sub esp,ecx
48
        mov edi,esp
49
        call read
50
        pop dx
51
        cmp dx,0d8ffh
52
        je .l1
53
        mov esp,ebp
54
        popad
55
        ret
56
   .l1: push eax
57
        mov ecx,struct_size
58
        call mallocz
59
        mov [edi],ebp
60
        mov ebp,edi
61
        pop dword [ebp+fichero]
62
        pop ax
63
        pop cx
64
        jmp .l3
65
   .l2: mov ebx,[ebp+tmp_bufer]
66
        add ebx,[ebx-4]
67
        mov cx,[ebx-2]
68
        mov ax,[ebx-4]
69
   .l3: push .l2
70
        xchg cl,ch
71
        add cx,2
72
        cmp ch,3
73
        jnc .l4
74
        cmp al,0ffh
75
        jne eoi
76
        cmp ah,0dbh
77
        je dqt
78
        cmp ah,0c4h
79
        je dht
80
        cmp ah,0c0h
81
        je sof0
82
        cmp ah,0dah
83
        je sos
84
        cmp ah,0c2h
85
        je eoi
86
        cmp ah,0c9h
87
        je eoi
88
        cmp ah,0d9h
89
        je eoi
90
   .l4: lea edx,[ecx-4]
91
        xor ecx,ecx
92
        mov eax,[ebp+fichero]
93
        call skip
94
        mov ecx,4
95
        call READ
96
        cmp ecx,[edi-4]
97
        jne eoi
98
        ret
99
 
100
eoi:
101
      mov esp,[ebp]
135 diamond 102
; do not close file - this will be done by caller
103
        and       dword [ebp+fichero], 0
31 halyavin 104
      call jpeg_close
105
      popad
106
      xor ebp,ebp
107
      ret
108
 
109
jpeg_close:
110
      test ebp,ebp
111
      jz .l2
112
      pushad
113
      mov eax,[ebp+fichero]
114
      call close
115
      mov edi,[ebp+sourcebits]
116
      call free
117
      lea esi,[ebp+qt_ptrs]
118
      mov ecx,14
119
 .l1: mov edi,[esi]
120
      add esi,4
121
      call free
122
      loop .l1
123
      mov edi,ebp
124
      call free
125
      popad
126
 .l2: ret
127
 
128
dqt:  call READ
129
      mov esi,edi
130
      lea eax,[edi+ecx]
131
      push eax
132
 .l1: xor eax,eax
133
      lodsb
134
      cmp al,4
135
      jnc eoi
136
      lea ebx,[ebp+qt_ptrs+eax*4]
137
      test dword [ebx],-1
138
      jnz eoi
139
      mov ecx,64
140
      xor eax,eax
141
      sub esp,128
142
      mov edi,esp
143
 .l2: lodsb
144
      stosw
145
      loop .l2
146
      mov ecx,256
147
      call malloc
148
      mov [ebx],edi
149
      mov eax,esi
150
      mov esi,esp
151
      pushad
152
      mov ebp,zigzag
153
      fninit
154
      mov cl,64
155
      xor eax,eax
156
  .l3: fild word[esi]
157
      mov al,[ebp]
158
      and al,-2
159
      add ebp,2
160
      add esi,2
161
      mov ebx,eax
162
      and ebx,28
163
      fmul dword [ebx+k2]
164
      mov ebx,eax
165
      shr ebx,3
166
      and ebx,4+8+16
167
      fmul dword [ebx+k2]
168
      fstp dword [edi+eax]
169
      dec cl
170
      jnz .l3
171
      popad
172
      mov esi,eax
173
      add esp,128
174
      mov eax,[esp]
175
      sub eax,esi
176
      jc eoi
177
      cmp eax,4
178
      ja .l1
179
      jne eoi
180
      pop eax
181
      ret
182
 
183
sof0:  call READ
184
       cmp byte [edi],8
185
       jne eoi  ;precision
186
       mov ax,[edi+1]
187
       xchg al,ah
188
       mov [ebp+y_size],ax
189
       mov ax,[edi+3]
190
       xchg al,ah
191
       mov [ebp+x_size],ax
192
       mov al,[edi+5] ;ncomponentes
193
       mov cl,al
194
       mov [ebp+color_c],al
195
       mov edx,modes
196
       dec al
197
       jz .l1
198
       dec al
199
       dec al
200
       jnz eoi
201
       mov al,[edi+10]
202
       mov ah,[edi+13]
203
       cmp ax,1111h
204
       jne eoi
205
       mov al,[edi+7]
206
       add edx,16
207
       cmp al,11h
208
       je .l1
209
       add edx,16
210
       cmp al,21h
211
       je .l1
212
       add edx,16
213
       cmp al,22h
214
       jne eoi
215
  .l1: lea ebx,[ebp+q_ptr]
216
       lea esi,[ebp+qt_ptrs]
217
       mov [ebp+mcu_ptr],edx
218
  .l2: movzx eax,byte [edi+8]
219
       add edi,3
220
       cmp al,4
221
       jnc eoi
222
       lea eax,[eax*4+esi]
223
       mov [ebx],eax
224
       add ebx,16
225
       dec cl
226
       jnz .l2
227
       ret
228
 
229
READ:  mov eax,[ebp+fichero]
230
       mov edi,[ebp+tmp_bufer]
231
       movzx ecx,cx
232
       call mresize
233
       mov [ebp+tmp_bufer],edi
234
       jmp read
235
 
236
dht:    call READ
237
        mov esi,edi
238
        lea eax,[edi+ecx]
239
        push eax
240
   .l1: lodsb
241
        mov edi,esi
242
        mov ebx,3+16
243
        and bl,al
244
        cmp bl,al
245
        jne eoi
246
        shr bl,2
247
        and al,3
248
        or bl,al
249
        lea ebx,[ebp+ht_dc_ptrs+ebx*4]
250
        test dword [ebx],-1
251
        jnz eoi
252
        mov cl,15
253
        mov al,[edi]
254
   .l2: inc edi  ;calcular numero de codigos
255
        add al,[edi]
256
        jc eoi
257
        dec cl
258
        jnz .l2
259
        movzx ecx,al
260
        lea ecx,[ecx*4+2]
261
        call malloc
262
        mov [ebx],edi
263
        call arbol_hf
264
        mov eax,[esp]
265
        sub eax,ebx
266
        jc eoi
267
        mov esi,ebx
268
        cmp eax,4
269
        ja .l1
270
        jne eoi
271
        pop eax
272
        ret
273
 
274
arbol_hf:   ;esi=ht edi=memoria para el arbol
275
            ;retorna en ebx  el final de ht
276
            ;codigos: bits 0-3=nbits del siguiente numero
277
            ;         bits 4-7=numero de zeros
278
            ;         bits 8-14=longitud de este codigo o error si =127
279
            ;         bit 15=codigo/puntero
280
        push ebp
281
        lea ebx,[edi-2]
282
        add ebx,[ebx-2]
283
        mov word [ebx],-1 ;codigo de error si encontrado
284
        push ebx
285
        push esi
286
        lea ebx,[esi+16]
287
        mov ebp,esp
288
        xor ecx,ecx
289
        push edi
290
        push ecx
291
        add edi,2
292
        mov dx,1
293
        add dh,[esi]
294
        jz .l3
295
        jmp .l2
296
  .l1:  push edi
297
        push ecx
298
        add edi,2
299
  .l2:  inc cl
300
        cmp cl,dl
301
        jc .l1
302
        mov al,[ebx]
303
        inc ebx
304
        mov ah,128 ;marca de codigo
305
        or ah,dl
306
        cmp edi,[ebp+4]
307
        jnc .l5
308
        stosw
309
        cmp esp,ebp
310
        jnc .l5
311
        pop ecx
312
        pop esi
313
        lea eax,[edi-2]
314
        sub eax,esi
315
        mov [esi],ax
316
        dec dh
317
        jnz .l2 ;ncodigos
318
        mov esi,[ebp]
319
   .l3: inc esi
320
        inc dl
321
        cmp dl,17
322
        jnc .l4
323
        add dh,[esi]
324
        jz .l3
325
        mov [ebp],esi
326
        jmp .l2
327
   .l4: lea esp,[ebp+8]
328
        pop ebp
329
        ret
330
   .l5: mov ebp,[ebp+8]
331
        jmp eoi
332
 
333
sos:   sub ecx,4  ;a continuacion vienen los datos de la imagen
334
       call READ
335
       mov eax,[ebp+fichero]
336
       call ftell
337
       mov [ebp+position],edx
338
       mov esi,edi
339
       lea edi,[ebp+q_ptr]
340
       lodsb ;numero de componentes
341
       sub [ebp+color_c],al
342
       jnz eoi
343
       mov dh,al
344
  .l1: mov ebx,[edi]
345
       mov eax,[ebx]
346
       stosd
347
       lodsw
348
       mov cl,ah
349
       and eax,0f00h
350
       and ecx,0f0h
351
       shr eax,6
352
       shr ecx,2
353
       lea ebx,[ebp+ht_ac_ptrs+eax]
354
       mov eax,[ebx]
355
       lea ebx,[ebp+ht_dc_ptrs+ecx]
356
       mov ecx,[ebx]
357
       test eax,eax
358
       jz eoi
359
       test ecx,ecx
360
       jz eoi
361
       stosd
362
       mov eax,ecx
363
       stosd
364
       add edi,4
365
       dec dh
366
       jnz .l1
367
       mov edx,[ebp+mcu_ptr]
368
       cmp edx,modes
369
       jne .l2
370
       lea esi,[ebp+q_ptr]
371
       lea edi,[ebp+q_ptr+32]
372
       movsd
373
       movsd
374
       movsd
375
   .l2:
376
       mov esi,edx
377
       push dword [esi]
378
       pop dword [ebp+mcu_ptr]
379
       push dword [esi+4]
380
       pop dword[ebp+color_ptr]
381
       push dword [esi+12]
382
       pop dword [ebp+y_mcu]
383
       push dword [esi+8]
384
       pop dword [ebp+x_mcu]
385
       mov ecx,64*18
386
       call malloc
387
       mov [ebp+matrices],edi
388
       mov ecx,bufer_size
389
       call malloc
390
       mov [ebp+sourcebits],edi
391
       mov esp,[ebp]
392
       mov [esp+8],ebp
393
       popad
394
       ret
395
 
396
jpeg_display:
397
       test ebp,ebp
398
       jnz .inicio
399
       ret
400
      .inicio:
401
       pushad
402
       mov [ebp],esp
403
       mov eax,[ebp+fichero]
404
       mov edx,[ebp+position]
405
       call lseek
406
       mov edi,[ebp+sourcebits]
407
       add edi,bufer_size
408
       mov [ebp+sourcebits_index],edi
409
       sub edi,2
410
       mov [ebp+sourcebits_limit],edi
411
       mov edi,[ebp+matrices]
412
       mov [ebp+matriz_limit],edi
413
       xor eax,eax
414
       mov [esp+8],eax
415
       mov [ebp+estado],eax
416
       mov [ebp+tmp_bits],eax
417
       mov [ebp+dc],eax
418
       mov [ebp+dc+16],eax
419
       mov [ebp+dc+32],eax
420
 
421
       mov eax,[ebp+y_mcu]
422
       mov ecx,[ebp+y_org]
423
       sub ecx,eax
424
       mov [ebp+y_org2],ecx
425
       mov [ebp+y_mcu2],eax
426
       push dword [ebp+y_size]
427
       pop dword [ebp+y_size2]
428
  .l3: push dword [ebp+x_org]
429
       pop dword [ebp+x_org2]
430
       push dword [ebp+x_mcu]
431
       pop dword [ebp+x_mcu2]
432
       push dword [ebp+x_size]
433
       pop dword [ebp+x_size2]
434
       mov eax,[ebp+y_mcu2]
435
       add [ebp+y_org2],eax
436
       sub [ebp+y_size2],eax
437
       jnc .l4
438
       add eax,[ebp+y_size2]
439
       jnz .cont
440
       mov [esp+8],ebp
441
       popad
442
       ret
443
     .cont:
444
       mov dword [ebp+y_size2],0
445
       mov [ebp+y_mcu2],eax
446
      .l4:
447
        mov eax,[ebp+x_mcu2]
448
        sub [ebp+x_size2],eax
449
        jnc .l5
450
        add eax,[ebp+x_size2]
451
        jz .l3
452
        mov dword [ebp+x_size2],0
453
        mov [ebp+x_mcu2],eax
454
        call dword [ebp+mcu_ptr]
455
        mov eax,[ebp+x_mcu]
456
        mov ecx,[ebp+x_mcu2]
457
        mov edx,[ebp+y_mcu2]
458
        call recortar
459
        jmp .l6
460
      .l5:
461
        call dword [ebp+mcu_ptr]
462
        mov ecx,[ebp+x_mcu2]
463
        mov edx,[ebp+y_mcu2]
464
      .l6:
465
        mov eax,[ebp+x_org2]
466
        mov ebx,[ebp+y_org2]
467
        call dword [ebp+draw_ptr]
468
        add [ebp+x_org2],ecx
469
        mov ax,[ebp+estado]
470
        test al,15
471
        jz .l4
472
        cmp ah,8
473
        jnc .l4
474
        xor edx,edx
475
        mov [ebp+tmp_bits],edx
476
        mov [ebp+dc],edx
477
        mov [ebp+dc+16],edx
478
        mov [ebp+dc+32],edx
479
        add dword [ebp+sourcebits_index],2
480
        and word [ebp+estado],0c0h
481
        test al,32
482
        jz .l4
483
        jmp .l3
484
 
485
color100:
486
        push edi
487
    .l1: lodsw
488
        mov dl,ah
489
        mov ah,al
490
        stosw
491
        mov ah,dl
492
        stosb
493
        mov al,dl
494
        stosb
495
        stosw
496
        dec cl
497
        jnz .l1
498
        pop edi
499
        ret
500
 
501
color111:
502
        push edi
503
   .l1: lodsw
504
        mov bx,[esi+62]
505
        mov dx,[esi+126]
506
        xchg ah,bh
507
        xchg ah,dl
508
        xchg ah,bl
509
        stosw
510
        mov ax,bx
511
        stosw
512
        mov ax,dx
513
        stosw
514
        dec cl
515
        jnz .l1
516
        pop edi
517
        mov ecx,64*3
518
        jmp ybr_bgr
519
 
520
color411:
521
        push ebp
522
        push edi
523
        lea ebp,[esi+ecx*8]
524
     .l1: push ecx
525
        mov ax,[esi]
526
        mov cx,[ebp]
527
        mov dx,[ebp+64]
528
        add ebp,2
529
        xchg ch,dl
530
        mov bx,ax
531
        mov ah,cl
532
        mov bl,ch
533
        mov [edi],ax
534
        mov [edi+2],bx
535
        mov [edi+4],cx
536
        mov ax,[esi+8]
537
        mov bh,ah
538
        mov ah,cl
539
        mov [edi+48],ax
540
        mov [edi+48+2],bx
541
        mov [edi+48+4],cx
542
        mov ax,[esi+2]
543
        mov bx,ax
544
        mov ah,dl
545
        mov bl,dh
546
        mov [edi+6],ax
547
        mov [edi+2+6],bx
548
        mov [edi+4+6],dx
549
        mov ax,[esi+8+2]
550
        mov bh,ah
551
        mov ah,dl
552
        mov [edi+48+6],ax
553
        mov [edi+48+2+6],bx
554
        mov [edi+48+4+6],dx
555
        pop ecx
556
        add edi,12
557
        dec ecx
558
        add esi,4
559
        test cl,1
560
        jnz .l1
561
        add esi,64-8
562
        test cl,2
563
        jnz .l1
564
        sub esi,128-16
565
        add edi,48
566
        test cl,15
567
        jnz .l1
568
        add esi,64
569
        test cl,cl
570
        jnz .l1
571
        pop edi
572
        pop ebp
573
        mov ecx,64*4*3
574
        jmp ybr_bgr
575
 
576
color211:
577
        push ebp
578
        push edi
579
        lea ebp,[esi+ecx*4]
580
    .l1: push ecx
581
        mov ax,[esi]
582
        mov cx,[ebp]
583
        mov dx,[ebp+64]
584
        add ebp,2
585
        xchg ch,dl
586
        mov bx,ax
587
        mov ah,cl
588
        mov bl,ch
589
        mov [edi],ax
590
        mov [edi+2],bx
591
        mov [edi+4],cx
592
        mov ax,[esi+2]
593
        mov bx,ax
594
        mov ah,dl
595
        mov bl,dh
596
        mov [edi+6],ax
597
        mov [edi+2+6],bx
598
        mov [edi+4+6],dx
599
        pop ecx
600
        add edi,12
601
        dec cl
602
        add esi,4
603
        test cl,1
604
        jnz .l1
605
        add esi,64-8
606
        test cl,2
607
        jnz .l1
608
        sub esi,128-8
609
        test cl,cl
610
        jnz .l1
611
        pop edi
612
        pop ebp
613
        mov ecx,64*3*2
614
        jmp ybr_bgr
615
 
616
 
617
mcu411: lea ebx,[ebp+q_ptr]
618
        call hufdecode
619
        lea ebx,[ebp+q_ptr]
620
        call hufdecode
621
mcu211: lea ebx,[ebp+q_ptr]
622
        call hufdecode
623
mcu111: lea ebx,[ebp+q_ptr]
624
        call hufdecode
625
        lea ebx,[ebp+q_ptr+16]
626
        call hufdecode
627
mcu100: lea ebx,[ebp+q_ptr+32]
628
        call hufdecode
629
        mov esi,[ebp+matrices]
630
        mov dword [ebp+matriz_limit],esi
631
        mov ecx,32
632
        lea edi,[esi+64*6]
633
        jmp dword [ebp+color_ptr]
634
 
635
cargar_bits: ;edx=bits,cl=nbits,
636
             ;bp=data struct
637
             ;cr: cl,edx,eax,si
638
             ;ncr bx,bp,di,ch
639
 
640
        mov esi,[ebp+sourcebits_index]
641
        cmp esi,[ebp+sourcebits_limit]
642
        jnc .l6
643
        movzx eax,byte [esi]
644
        inc esi
645
        add cl,8
646
        cmp al,-1
647
        je .l2
648
        mov ah,al
649
        lodsb
650
        add cl,8
651
        cmp al,-1
652
        je .l2
653
   .l1: ror eax,cl
654
        or edx,eax
655
        mov [ebp+sourcebits_index],esi
656
        ret
657
   .l2: lodsb
658
        test al,al
659
        jnz .l3
660
        mov al,-1
661
        call .l1
662
        cmp cl,16
663
        jc cargar_bits
664
        ret
665
   .l3: sub esi,2
666
        sub cl,8
667
        sub al,0d0h
668
        cmp al,8
669
        jc .l4
670
        sub al,9
671
        mov al,63
672
        jz .l4
673
        mov al,127
674
    .l4: inc al
675
        or [ebp+estado],al
676
        movzx eax,ah
677
        jmp .l1
678
    .l5: mov [ebp+sourcebits_limit],edi
679
        mov word [edi],0d9ffh
680
        popad
681
        jmp cargar_bits
682
   .l6: ;read file
683
        pushad
684
        mov ecx,bufer_size-2
685
        mov edx,[ebp+sourcebits_limit]
686
        mov edi,[ebp+sourcebits]
687
        mov ax,[edx]
688
        sub edx,edi
689
        stosw
690
        sub esi,edx
691
        mov [ebp+sourcebits_index],esi
692
        cmp edx,ecx
693
        jne .l5
694
        mov eax,[ebp+fichero]
695
        call read
696
        lea ecx,[edi+ecx-2]
697
        mov [ebp+sourcebits_limit],ecx
698
        popad
699
        jmp cargar_bits
700
 
701
 
702
hufdecode:  ;si->dctable [bp+20]->actable di->outbufer edx->bits cl->bits en edx
703
 
704
 
705
            ;[bp+24]->sourcebits
706
            ;[bp+22]=outbufer+128
707
            ;[bx]       q ptr para aa&n
708
            ;[bx+2]     a ptr
709
            ;[bx+4]     d ptr
710
            ;[bx+8]     dc componente
711
        fninit
712
        push dword [ebx]
713
        mov cl,[ebp+nbits]
714
        mov edx,[ebp+tmp_bits]
715
        cmp cl,16
716
        jnc .l1
717
        call cargar_bits
718
    .l1: mov eax,[ebx+4]
719
        mov esi,[ebx+8]
720
        mov [ebp+actable],eax
721
        movzx eax,word [esi]
722
        add esi,2
723
   .l2: add edx,edx
724
        jnc .l3
725
        add esi,eax
726
   .l3: lodsw
727
        test ax,ax
728
        jns .l2
729
        ;codigo encontrado
730
        and ax,7f0fh
731
        mov edi,[ebp+matriz_limit] ;arrays
732
        sub cl,ah
733
        jns .l4
734
        fldz
735
   .error:
736
        xor ecx,ecx
737
        or byte [ebp+estado],32
738
        jmp .l12
739
   .l4: cmp cl,al
740
        jnc .l5
741
        push eax
742
        call cargar_bits
743
        pop eax
744
   .l5: sub cl,al
745
        mov ch,cl
746
        mov cl,al
747
        mov eax,edx
748
        shl edx,cl
749
        sar eax,17
750
        xor ax,8000h
751
        xor cl,15
752
        sar ax,cl
753
        mov cl,ch
754
        mov ch,2
755
        add ax,8000h ;incrementar si negativo
756
        adc ax,8000h
757
        add [ebx+12],ax
758
        fild word [ebx+12]
759
        push ecx
760
        mov ecx,64
761
        xor eax,eax
762
        add [ebp+matriz_limit],ecx
763
        rep stosd
764
        pop ecx
765
        sub edi,64*4
766
        mov ebx,[esp]
767
        fmul dword [ebx]
768
    .l6: cmp cl,16
769
        jnc .l7
770
        call cargar_bits
771
   .l7: mov esi,[ebp+actable]
772
        movzx eax,word[esi]
773
        add esi,2
774
   .l8: add edx,edx
775
        jnc .l9
776
        add esi,eax
777
   .l9: lodsw
778
        test ax,ax
779
        jns .l8
780
        ;codigo encontrado
781
        and ah,127
782
        xor ebx,ebx
783
        sub cl,ah
784
        js .error
785
        or bl,al
786
        jz .l12
787
        and al,0f0h
788
        shr al,3
789
        add ch,al
790
        js .error
791
        and bl,0fh
792
        jz .l11
793
        cmp cl,bl
794
        jnc .l10
795
        call cargar_bits
796
    .l10: sub cl,bl
797
        xchg bl,cl
798
        mov eax,edx
799
        shl edx,cl
800
        sar eax,17
801
        xor cl,15
802
        xor ax,8000h
803
        sar ax,cl
804
        add ax,8000h ;incrementar si negativo
805
        adc ax,8000h
806
        mov cl,bl
807
        mov bl,ch
808
        mov [ebp+tmp_bits],ax
809
        mov ax,[ebx+zigzag]
810
        mov ebx,[esp]
811
        fild word [ebp+tmp_bits]
812
        or [ebp+idct],ax
813
        and eax,11111100b
814
        fmul dword [ebx+eax]
815
        fstp dword [edi+eax]
816
  .l11: add ch,2
817
        jns .l6
818
  .l12: mov [ebp+nbits],cl
819
        mov [ebp+tmp_bits],edx
820
        xor ebx,ebx
821
        add esp,4
822
        xchg ebx,[ebp+idct]
823
        cmp ch,2
824
        je idctf1
825
        fstp dword [edi]
826
        test bh,0feh
827
        jnz idctf3
828
idctf2a: test bh,1
829
        mov esi,edi
830
        jz .l1
831
        test bl,1
832
        jnz idctf3
833
        push idctf2b
834
        jmp idctf3b
835
   .l1: call idctf3a
836
        mov cl,4
837
        call limit
838
        mov eax,[edi-8]
839
        mov edx,[edi-4]
840
        mov cl,7
841
   .l2: mov [edi],eax
842
        mov [edi+4],edx
843
        add edi,8
844
        dec cl
845
        jnz .l2
846
        ret
847
 
848
idctf1: fistp word[edi+64]
849
        mov ax,128
850
        add ax,[edi+64]
851
        jz .l2
852
        test ah,ah
853
        jz .l1
854
        mov al,-1
855
        js .l2
856
   .l1: mov ah,al
857
        stosw
858
        stosw
859
        mov eax,[edi-4]
860
        mov ecx,15
861
        rep stosd
862
   .l2: ret
863
 
864
idctf3: mov bl,8
865
        mov esi,edi
866
    .l1: rcr bh,1
867
        jc .l3
868
        mov eax,[esi]
869
        test eax,eax
870
        jz .l4
871
        mov cl,7
872
    .l2: add esi,32
873
        mov [esi],eax
874
        dec cl
875
        jnz .l2
876
        sub esi,32*7-4
877
        dec bl
878
        jnz .l1
879
        jmp .l5
880
   .l3: call idctf3b
881
   .l4: add esi,4
882
        dec bl
883
        jnz .l1
884
   .l5: mov esi,edi
885
        mov cl,8
886
   .l6: call idctf3a
887
        add esi,32
888
        add edi,16
889
        dec cl
890
        jnz .l6
891
        sub edi,128
892
        mov esi,edi
893
        mov cl,32
894
limit:  mov dx,[esi]
895
        mov bx,[esi+2]
896
        add esi,4
897
        add dx,128
898
        add bx,128
899
        test dh,dh
900
        mov ax,dx
901
        jz .l1
902
        mov al,0
903
        js .l1
904
        mov al,-1
905
   .l1: test bh,bh
906
        mov ah,bl
907
        jz .l2
908
        mov ah,0
909
        js .l2
910
        mov ah,-1
911
   .l2: stosw
912
        dec cl
913
        jnz limit
914
        ret
915
 
916
idctf2b:
917
        mov dl,8
918
  .l1:  fld dword[esi]
919
        add esi,32
920
        mov ax,128
921
        fistp word [edi]
922
        add ax,[edi]
923
        test ah,ah
924
        jz .l2
925
        mov al,0
926
        js .l2
927
        mov al,-1
928
  .l2:  mov ah,al
929
        stosw
930
        stosw
931
        stosw
932
        stosw
933
        dec dl
934
        jnz .l1
935
        ret
936
 
937
idctf3a: ;si(d float),di(w int) ncr
938
fld dword[esi+1*4]      ;f1                ;t21=f1+f7
939
fld st0
940
fld dword[esi+7*4]          ;f7
941
fadd st2,st0
942
fsubp st1,st0          ;t22=f1-f7
943
fld dword[esi+5*4]
944
fld st0           ;f5       ;t23=f5+f3
945
fld dword[esi+3*4]                   ;f3
946
fadd st2,st0
947
fsubp st1,st0          ;t20=f5-f3
948
fld st0
949
fadd st0,st3                ;t25=(t20+t22)*k2
950
fmul dword[k+4]                 ;k2 ;t25,t20,t23,t22,t21
951
fld st4                         ;t7=t21+t23
952
fadd st0,st3                        ;t7,t25,t20,t23,t22,t21
953
fld dword[k+12]                 ;k4     ;t6=k4*t20+t25-t7
954
fmulp st3,st0
955
fsub st2,st0
956
fld st1
957
faddp st3,st0                   ;t7,t25,t6,t23,t22,t21
958
fld st5                         ;t5=(t21-t23)*k1-t6
959
fsub st0,st4
960
fmul dword[k]          ;k1
961
fsub st0,st3
962
fstp st6               ;t7,t25,t6,t23,t22,t5
963
fstp st3                        ;t25,t6,t7,t22,t5
964
fxch st3
965
fmul dword[k+8]    ;k3      ;t4=k3*t22-t25+t5
966
fadd st0,st4                        ;t22*k3+t5,t6,t7,t25,t5
967
fsubrp st3,st0                  ;t6,t7,t4,t5
968
fld dword[esi]                       ;f0           ;t10=f0+f4
969
fst st5                         ;f0,t4,t5,t6,t7,f0
970
fld dword[esi+4*4]                   ;f4
971
fsub st6,st0                    ;t11=f0-f4
972
faddp st1,st0
973
fld st0               ;t10,t10,t6,t7,t4,t5,t11
974
fld dword[esi+2*4]                   ;f2      ;t13=f2+f6
975
fadd dword[esi+6*4]                  ;f6      ;t13,t10,t10,t6,t7,t4,t5,t11
976
fadd st2,st0                    ;t13,t10,t0,t6,t7,t4,t5,t11 ;t0=t10+t13
977
fsubp st1,st0                      ;t3,t0,t6,t7,t4,t5,t11 ;t3=t10-t13
978
fld st0                         ;p3=t3-t4
979
fsub st0,st5
980
fistp word [edi+3*2]        ;p3
981
fadd st0,st4                        ;p4=t3+t4
982
fld dword[esi+2*4]                   ;f2
983
fstp st5
984
fistp word [edi+4*2]        ;p4 ;t0,t6,t7,f2,t5,t11
985
fld st0                         ;p0=t0+t7
986
fsub st0,st3
987
fistp word [edi+7*2]        ;p7
988
fadd st0,st2                        ;p7=t0-t7
989
fistp word [edi]                     ;p0 ;t6,t7,f2,t5,t11
990
fld st2                         ;f2  ;f2,t6,t7,f2,t5,t11  ;t12=(f2-f6)*k1-t13
991
fld dword[esi+6*4]                   ;f6
992
fadd st4,st0                    ;f6,f2,t6,t7,t13,t5,t11
993
fsubp st1,st0
994
fmul dword[k]         ;k1
995
fsub st0,st3
996
fst st3                ;t12,t6,t7,t12,t5,t11
997
fadd st0,st5                        ;t1=t11+t12
998
fst st2                         ;t1,t6,t1,t12,t5,t11
999
fadd st0,st1                        ;p1=t1+t6
1000
fistp word [edi+2]                   ;p1    ;t6,t1,t12,t5,t11
1001
fsubp st1,st0                       ;p6=t1-t6
1002
fistp word [edi+6*2]                 ;p6  ;t12,t5,t11
1003
fsubp st2,st0                   ;t2=t11-t12  ;t5,t2
1004
fld st0
1005
fadd st0,st2                ;p2=t2+t5
1006
fistp word [edi+2*2]                 ;p2
1007
fsubp st1,st0                       ;p5=t2-t5   ;t5,t2
1008
fistp word [edi+5*2]
1009
ret             ;p5
1010
 
1011
 
1012
 
1013
 
1014
idctf3b: ;si ncr
1015
fld dword[esi+1*32]
1016
fld st0          ;f1       ;t21=f1+f7
1017
fld dword[esi+7*32]
1018
fadd st2,st0     ;f7
1019
fsubp st1,st0                       ;t22=f1-f7
1020
fld dword[esi+5*32]
1021
fld st0          ;f5       ;t23=f5+f3
1022
fld dword[esi+3*32]                  ;f3
1023
fadd st2,st0
1024
fsubp st1,st0
1025
fld st0  ;t20=f5-f3
1026
fadd st0,st3                        ;t25=(t20+t22)*k2
1027
fmul dword[k+4]                 ;k2 ;t25,t20,t23,t22,t21
1028
fld st4                         ;t7=t21+t23
1029
fadd st0,st3                        ;t7,t25,t20,t23,t22,t21
1030
fld dword[k+12]                 ;k4     ;t6=k4*t20+t25-t7
1031
fmulp st3,st0
1032
fsub st2,st0
1033
fld st1
1034
faddp st3,st0                   ;t7,t25,t6,t23,t22,t21
1035
fld st5                         ;t5=(t21-t23)*k1-t6
1036
fsub st0,st4
1037
fmul dword[k]          ;k1
1038
fsub st0,st3
1039
fstp st6               ;t7,t25,t6,t23,t22,t5
1040
fstp st3
1041
fxch st3               ;t25,t6,t7,t22,t5
1042
fmul dword[k+8]                 ;k3      ;t4=k3*t22-t25+t5
1043
fadd st0,st4                        ;t22*k3+t5,t6,t7,t25,t5
1044
fsubrp st3,st0                  ;t6,t7,t4,t5
1045
fld dword[esi]                       ;f0           ;t10=f0+f4
1046
fst st5                         ;f0,t4,t5,t6,t7,f0
1047
fld dword[esi+4*32]                  ;f4
1048
fsub st6,st0                    ;t11=f0-f4
1049
faddp st1,st0
1050
fld st0               ;t10,t10,t6,t7,t4,t5,t11
1051
fld dword[esi+2*32]                  ;f2      ;t13=f2+f6
1052
fadd dword[esi+6*32]                 ;f6      ;t13,t10,t10,t6,t7,t4,t5,t11
1053
fadd st2,st0                    ;t13,t10,t0,t6,t7,t4,t5,t11 ;t0=t10+t13
1054
fsubp st1,st0                       ;t3,t0,t6,t7,t4,t5,t11 ;t3=t10-t13
1055
fld st0                         ;p3=t3-t4
1056
fsub st0,st5
1057
fstp dword[esi+3*32]        ;p3
1058
fadd st0,st4                        ;p4=t3+t4
1059
fld dword[esi+2*32]                  ;f2
1060
fstp st5
1061
fstp dword[esi+4*32]        ;p4 ;t0,t6,t7,f2,t5,t11
1062
fld st0
1063
fsub st0,st3                ;p0=t0+t7
1064
fstp dword[esi+7*32]                 ;p7
1065
fadd st0,st2                        ;p7=t0-t7
1066
fstp dword[esi]                      ;p0 ;t6,t7,f2,t5,t11
1067
fld st2                         ;f2  ;f2,t6,t7,f2,t5,t11  ;t12=(f2-f6)*k1-t13
1068
fld dword[esi+6*32]                  ;f6
1069
fadd st4,st0                    ;f6,f2,t6,t7,t13,t5,t11
1070
fsubp st1,st0
1071
fmul dword[k]         ;k1
1072
fsub st0,st3
1073
fst st3                ;t12,t6,t7,t12,t5,t11
1074
fadd st0,st5                        ;t1=t11+t12
1075
fst st2                         ;t1,t6,t1,t12,t5,t11
1076
fadd st0,st1                        ;p1=t1+t6
1077
fstp dword[esi+1*32]                 ;p1    ;t6,t1,t12,t5,t11
1078
fsubp st1,st0                       ;p6=t1-t6
1079
fstp dword[esi+6*32]                 ;p6  ;t12,t5,t11
1080
fsubp st2,st0
1081
fld st0           ;t2=t11-t12  ;t5,t2
1082
fadd st0,st2                        ;p2=t2+t5
1083
fstp dword[esi+2*32]                 ;p2
1084
fsubp st1,st0                       ;p5=t2-t5   ;t5,t2
1085
fstp dword[esi+5*32]
1086
ret             ;p5
1087
 
1088
ybr_bgr:  ;edi=bmp ecx=n_BYTES
1089
	  ;retorna edi+=ecx
1090
	pushad
1091
	mov esi,edi
1092
	add edi,ecx
1093
	push edi
1094
	mov edi,[colortabla]
1095
   .l1: lodsw
1096
	movzx ebx,ah
1097
	movzx ebp,al
1098
	movzx eax,al
1099
	movzx ecx,byte[esi]
1100
	lea ebx,[ebx*4+edi+1024]
1101
	lea ecx,[ecx*4+edi]
1102
	add eax,[ebx] ;cb   ;solo se usan 16 bits
1103
	mov edx,[ebx+2]     ;pero el codigo de 32 bits es mas rapido
1104
	mov ebx,[ecx] ;cr
1105
	add eax,[ecx+2]
1106
	add ebx,ebp ;b
1107
	add edx,ebp ;r
1108
	test ah,ah
1109
	jz .l2
1110
	mov al,0
1111
	js .l2
1112
	mov al,-1
1113
   .l2: test dh,dh
1114
	jz .l3
1115
	mov dl,0
1116
	js .l3
1117
	mov dl,-1
1118
   .l3: test bh,bh
1119
	mov dh,al
1120
	jz .l4
1121
	mov bl,0
1122
	js .l4
1123
	mov bl,-1
1124
   .l4: mov [esi-2],dx
1125
	mov [esi],bl
1126
	inc esi
1127
	cmp esi,[esp]
1128
	jc .l1
1129
	pop edi
1130
	popad
1131
	ret
1132
 
1133
recortar:  ;edi=bufer eax=ancho en pixels (ecx,edx)tama¤o deseado
1134
        pushad
1135
        dec edx
1136
        jz .l2
1137
        lea ebx,[ecx*3]
1138
        lea eax,[eax*3]
1139
        lea esi,[edi+eax]
1140
        add edi,ebx
1141
        sub eax,ebx
1142
  .l1:  mov ecx,ebx
1143
        call movedata
1144
        add esi,eax
1145
        dec edx
1146
        jnz .l1
1147
   .l2: popad
1148
        ret
1149
 
1150
;R = Y                    + 1.402  *(Cr-128)
1151
;G = Y - 0.34414*(Cb-128) - 0.71414*(Cr-128)
1152
;B = Y + 1.772  *(Cb-128)
1153
 
1154
colortabla: dd 0
1155
 
1156
colorprecalc: ;prepara la tabla para convertir ycb a rgb
1157
	 mov ecx,1024*2
1158
	 call malloc
1159
	 mov [colortabla],edi
1160
	 fninit
1161
	 fld dword [.k+4]
1162
	 fld dword [.k]
1163
	 mov dl,0
1164
	 call .l1
1165
	 fld dword [.k+12]
1166
	 fld dword[.k+8]
1167
    .l1: mov cx,-128
1168
    .l2: mov [edi],ecx
1169
	 inc ecx
1170
	 fild word[edi]
1171
	 fld st0
1172
	 fmul st0,st2
1173
	 fistp word[edi]
1174
	 fmul st0,st2
1175
	 fistp word[edi+2]
1176
	 add edi,4
1177
	 inc dl
1178
	 jnz .l2
1179
	 ret
1180
 
1181
     .k: dd 1.402,-0.71414,-0.34414,+1.772