home *** CD-ROM | disk | FTP | other *** search
- /
- / Copyright (C) 1992-1993 Michael Davidson.
- / All rights reserved.
- /
- / Permission to use, copy, modify, and distribute this software
- / and its documentation for any purpose and without fee is hereby
- / granted, provided that the above copyright notice appear in all
- / copies and that both that copyright notice and this permission
- / notice appear in supporting documentation.
- /
- / This software is provided "as is" without express or implied warranty.
- /
- .data
-
- zigzag: .byte 0, 1, 8, 16, 9, 2, 3, 10
- .byte 17, 24, 32, 25, 18, 11, 4, 5
- .byte 12, 19, 26, 33, 40, 48, 41, 34
- .byte 27, 20, 13, 6, 7, 14, 21, 28
- .byte 35, 42, 49, 56, 57, 50, 43, 36
- .byte 29, 22, 15, 23, 30, 37, 44, 51
- .byte 58, 59, 52, 45, 38, 31, 39, 46
- .byte 53, 60, 61, 54, 47, 55, 62, 63
- .byte 0, 0, 0, 0, 0, 0, 0, 0
- .byte 0, 0, 0, 0, 0, 0, 0, 0
-
- .text
- /
- / jpegHuffDecode(fp, bptr, dc_tbl, ac_tbl, dc_pred, quant_tbl)
- /
- FP = 8
- DBLOCK = 12
- DC_TBL = 16
- AC_TBL = 20
- DC_PRED = 24
- QUANT_TBL = 28
-
- RET_CODE = -4
- QUANT_0 = -8
- DB_PTR = -12
- .globl jpegHuffDecode
-
- jpegHuffDecode:
- pushl %ebp
- movl %esp, %ebp
- subl $12, %esp
- pushl %ebx
- pushl %edi
- pushl %esi
-
- xorl %eax, %eax
- movl %eax, RET_CODE(%ebp)
- /
- / Save the first entry in the quant table and set the table
- / entry to 1. This allows us to fix up the DC coefficient later
- /
- movl QUANT_TBL(%ebp), %esi
- movb $0x1, %al
- xchgl (%esi), %eax
- movl %eax, QUANT_0(%ebp)
- /
- / load bits_left and get_buffer into registers and make a local copy of db_ptr
- /
- movl db_ptr, %eax
- movb bits_left, %bl
- movl get_buffer, %esi
- movl %eax, DB_PTR(%ebp)
- /
- / for (k = 0; hc = dc; k < DCTSIZE2; k++, hc = ac)
- /
- xorb %bh, %bh
- movl DC_TBL(%ebp), %edi
- xchgl %ebx,%ebx
- .align 4
- L05:
- /
- / if (bits_left < 16)
- / MORE_BITS(fp);
- /
- cmpb $16, %bl
- jge L25
- call more_bits
-
- / for (code = 0; code > hc->maxcode; hc++)
- / {
- / code += code + (get_buffer >> 31);
- / get_buffer <<= 1;
- / --bits_left;
- / }
-
- L25:
- xorl %eax, %eax
- .align 8
- L30:
- addl %esi, %esi
- leal 8(%edi), %edi
- adcl %eax, %eax
- decb %bl
- cmpl (%edi), %eax
- jg L30
-
- / if (hc->codeptr == NULL || bits_left < 0)
- / JPEGError("Corrupted data in JPEG file");
- /
- / r = hc->codeptr[code];
- / s = r & 15;
- / r = r >> 4;
- / if (s)
- / {
- / k += r;
- / if (get_buffer & 0x80000000)
- / s = get_buffer >> (32 - s);
- / else
- / s = (get_buffer >> (32 - s)) + (-1 << s) + 1;
- / get_buffer <<= s;
- / bits_left -= s;
- / (*block)[ZAG[k]] = (JCOEF) (((JCOEF) s) * quanttbl[k]);
- / }
-
- movl 4(%edi), %edi
- orl %edi, %edi
- je corrupt_file
-
- orb %bl, %bl
- jl corrupt_file
-
- movb (%edi,%eax,1), %ch
- movb %ch, %cl
- shrb $4, %ch
- andb $0xf, %cl
- je L35
-
- addb %ch, %bh / k += r
- cmpb %bl, %cl
- jle L32
-
- pushl %ecx / save %cl over call
- call more_bits
- popl %ecx
-
- L32:
- subb %cl, %bl
- cmpl $0x80000000, %esi
- sbbl %eax, %eax
- shldl %esi, %eax
- / adcl $0, %eax
- .byte 0x83, 0xd0, 0x00 / temp kludge to match masm output
- shll %cl, %esi
-
- xorl %edx,%edx
- xorl %ecx,%ecx
-
- movb %bh, %dl / edx = k
- movb zigzag(%edx), %cl
- leal (,%ecx,4), %ecx
- addl DBLOCK(%ebp), %ecx
-
- movl QUANT_TBL(%ebp),%edi
- imull (%edi,%edx,4), %eax
-
- movl %eax, (%ecx)
-
- incb %bh
- movl AC_TBL(%ebp), %edi / hc = ac
- cmpb $64, %bh
- jl L05
-
- done:
- /
- / store updated values in bits_left, get_buffer and db_ptr
- /
- movb %bl, bits_left
- movl %esi, get_buffer
- movl DB_PTR(%ebp), %eax
- movl %eax, db_ptr
- /
- / fix quant table and DC coefficient
- /
- movl QUANT_0(%ebp), %eax
- movl QUANT_TBL(%ebp), %edi
- movl DBLOCK(%ebp), %ecx
- movl DC_PRED(%ebp), %edx
- movl %eax, (%edi) / quanttbl[0] = q0
- movl (%ecx), %edi / s = (*block)[0]
- addl (%edx), %edi
- movl %edi, (%edx)
- imull %edi, %eax
- movl %eax, (%ecx)
-
- movl RET_CODE(%ebp), %eax
-
- popl %esi
- popl %edi
- popl %ebx
- movl %ebp, %esp
- popl %ebp
- ret
-
- / else if (k != 0)
- / {
- / if (r != 15)
- / break;
- / k += 15;
- / }
- L35:
- orb %bh, %bh
- je L36
- cmpb $15, %ch
- jne done
- addb $16, %bh
- movl AC_TBL(%ebp), %edi / hc = ac
- cmpb $64, %bh
- jl L05
- jmp done
-
- L36:
- incb %bh
- movl AC_TBL(%ebp), %edi / hc = ac
- jmp L05
-
- corrupt_file:
- movl $-1, RET_CODE(%ebp)
- jmp done
-
- /
- / need to refill buffer
- /
- .align 8
- refill:
- pushl FP(%ebp)
- call fill_decode_buf
- addl $0x4, %esp
- movl db_ptr, %edx
- movl %edx, DB_PTR(%ebp)
-
- .align 8
- more_bits:
- movl DB_PTR(%ebp), %edx
- .M10:
- xorl %eax, %eax
- movb (%edx), %al
- incl %edx
- cmpb $0xff, %al / check marker
- je .M40
- .M20:
- addb $8, %bl
- movb $32, %cl
- subb %bl, %cl
- shll %cl, %eax
- orl %eax, %esi
- cmpb $24, %bl
- jle .M10
- movl %edx, DB_PTR(%ebp)
- .M30:
- ret
-
- .M40:
- movb (%edx), %ah
- incl %edx
- orb %ah, %ah / if next byte is 0 it's not a marker
- je .M20
- /
- / got some kind of marker
- /
- cmpl db_end, %edx / if we are at the end of the buffer
- je refill / try to refill it
- ret / otherwise bail out
-