⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpeg.inc

📁 这是一个JPEG解码器,里面使用了MMX,SSE等汇编指令集
💻 INC
字号:
;// JPEG constants and structures

INCLUDE jpeg_dec.inc

;// markers
mSOF0 = 0C0h  ;// Baseline DCT
mSOF1 = 0C1h  ;// Extended sequential DCT
mSOF2 = 0C2h  ;// Progressive DCT
mSOF3 = 0C3h  ;// Lossless (sequential)
mSOF5 = 0C5h  ;// Differential sequential DCT       
mSOF6 = 0C6h  ;// Differential progressive DCT      
mSOF7 = 0C7h  ;// Differential lossless (sequential)
mJPG  = 0C8h  ;// Reserved for JPEG extensions
mSOF9 = 0C9h  ;// Extended sequential DCT   
mSOF10= 0CAh  ;// Progressive DCT             
mSOF11= 0CBh  ;// Lossless (sequential)       
mSOF13= 0CDh  ;// Differential sequential DCT       
mSOF14= 0CEh  ;// Differential progressive DCT      
mSOF15= 0CFh  ;// Differential lossless (sequential)
mDHT  = 0C4h  ;// Define Huffman table(s)
mDAC  = 0CCh  ;// Define arithmetic coding conditioning(s)
mRST  = 0D0h  ;// Restart
mRST0 = 0D0h
mRST1 = 0D1h
mRST2 = 0D2h
mRST3 = 0D3h
mRST4 = 0D4h
mRST5 = 0D5h
mRST6 = 0D6h
mRST7 = 0D7h
mSOI  = 0D8h  ;// Start of image                            
mEOI  = 0D9h  ;// End of image                              
mSOS  = 0DAh  ;// Start of scan                             
mDQT  = 0DBh  ;// Define quantization table(s)              
mDNL  = 0DCh  ;// Define number of lines                    
mDRI  = 0DDh  ;// Define restart interval                   
mDHP  = 0DEh  ;// Define hierarchical progression           
mEXP  = 0DFh  ;// Expand reference component(s)
mAPPs = 0E0h  ;// Reserved for application segments
mAPPe = 0EFh  ;// Reserved for application segments
mJPGs = 0F0h  ;// Reserved for JPEG extensions              
mJPGe = 0FDh  ;// Reserved for JPEG extensions              
mCOM  = 0FEh  ;// Comment                                   
mTEM  = 001h  ;// Reserved
mRESs = 002h
mRESe = 0BFh

;// max. number of components
MAX_COMP = 3
;// max. number of huffman tables
MAX_HUFF_TABLE = 4
;// max. number of quantization tables
MAX_QUANT_TABLE = 4
;// max. sampling factor
MAX_SAMPLEFACTOR = 4

;// idct type
IDCT_8x8 = 3
IDCT_16x16 = 2
IDCT_16x8 = 1
IDCT_8x16 = 0

;// instruction set supported by cpu
CPU_NONE = 0
CPU_MMX  = (CPU_NONE+1)
CPU_SSE  = (CPU_NONE+2)
CPU_SSE2 = (CPU_NONE+3)
CPU_SSE3 = (CPU_NONE+4)

;// SSE needed
CPU_MIN = CPU_SSE

;// magic
MAGIC = 0ABCDDCBAh

;// sample row size
ROWSIZE = 8*4

;// Bitstream
BITSTREAM STRUCT 8
    ;// temporary qword  
    Temp qword ?
    ;// number of bits in the bit buffer (mm0)
    Bits dword ?
    ;// unused
    _ dword ?
    ;// pointer to the next unread byte
    CurrentPtr dword ?
    ;// number of bytes left in the bitstream
    NbLeft dword ?
    ;// points one byte after the end of the bitstream
    Limit dword ?
BITSTREAM ENDS

;// Huffman table
HUFFTABLE STRUCT 4
    ;// pointer to value
    ValPtr dword 16 dup (?)
    ;// MinCode[i] = min code of length i
    MinCode dword 16 dup (?)
    ;// MaxCode[i] = max code of length i
    MaxCode dword 16 dup (?)
    ;// number of bytes in a lookup table
    LOOKUP_SIZE = 256*2
    ;// lookup table for code length <= 8
    Lookup word  LOOKUP_SIZE/2 dup (?)
HUFFTABLE ENDS

;// Component information
COMPINFO STRUCT 4
    ;// horizontal sampling factor
    H dword ?
    ;// vertical sampling factor
    V dword ?
    ;// number of data unit in a MCU (H*V)
    NbDU dword ?
    ;// pointer to DC table
    DCTable dword ?
    ;// pointer to AC table
    ACTable dword ?
    ;// pointer to quantization table
    QuantTable dword ?
    ;// DC prediction
    DCPred dword ?
    ;// pointer to idct function
    Idct dword ?
COMPINFO ENDS

;// Frame information
FRAMEINFO STRUCT 16
    ;// component info
    CompInfo COMPINFO MAX_COMP dup (<>)
    ;// max. horizontal sampling factor
    Hmax dword ?
    ;// max. vertical sampling factor
    Vmax dword ?
    ;// 4*64*Hmax*Vmax
    HmaxVmax64 dword ?
    ;// number of MCU in entropy-coded segment
    NbMCU dword ?
    ;// number of MCU in restart interval
    Ri dword ?
    ;// pointer to rgb conversion function
    RGBConv dword ?
    ;// current pointer in rgb buffer
    cRGB dword ?
    ;// Width / 8*Hmax
    NbHmaxRow dword ?
    ;// counts from NbHmaxRow-1 to -1
    HmaxCount dword ?
    ;// pointer to pointers table used in RGB conversion
    PointerTable dword (?)
    ;// delta in RGB buffer after converting 8*Vmax*Xr pixels
    DeltaRGB dword (?)
    ALIGN 16
    ;// sample shift
    S real4 4 dup (?)
FRAMEINFO ENDS


;// Decoder data
DECODER STRUCT 16
    ;// returned by the decoder
    Image JPEGIMAGE <>
    ;// magic
    Magic dword ?
    ;// last error
    LastError dword ?
    ;// decoder state
    State dword ?
    ;// current marker
    CurrentMarker dword ?
    ;// decoding options
    Options dword ?
    ;// cpu support
    CpuSupport dword ?
    ;// bitstream
    ALIGN 8
    Bs BITSTREAM <>
    ;// frame info
    ALIGN 16
    FrameInfo FRAMEINFO <>
    ;// memory block used to store resampling and RGB buffers
    AllocMem dword ?
    ;// aligned AllocMem
    Mem dword ?
    ;// array of IDCT function pointers
    Idct dword ?
    ;// return adress from IDCT
    RetIdct dword ?
    ;// array of RGB conversion function pointers
    RGBConv dword ?
    ;// quantization table
    ALIGN 16
    QuantTable0 real4 MAX_QUANT_TABLE*64 dup (?)
    ;// (DC,AC) pairs of huffman tables
    HufTable0 HUFFTABLE MAX_HUFF_TABLE*2 dup (<>)
DECODER ENDS

;// Prototypes

MEM_Alloc PROTO
MEM_Free PROTO
MEM_Set PROTO

BS_Init PROTO
BS_GetBits PROTO
BS_PeekBits PROTO
BS_SkipBits PROTO
BS_GetBitsECS PROTO
BS_SkipBytes PROTO
BS_Test PROTO
BS_Align PROTO
BS_GetPtr PROTO

HUF_Decode PROTO
HUF_GenTable PROTO

IDCT_Init PROTO

CPUID_Init PROTO

JPG_GetMarker PROTO
JPG_InitDecoder PROTO
JPG_ProcessMarker PROTO

RGB_Init PROTO
RGB_GenPointer PROTO
RGB_YCbCrConv_SSE2 PROTO
RGB_YCbCrConv_SSE PROTO
RGB_GrayConv_SSE2 PROTO
RGB_GrayConv_SSE PROTO

IDCT_8x8_SSE2 PROTO
IDCT_16x16_SSE2 PROTO
IDCT_16x8_SSE2 PROTO
IDCT_8x16_SSE2 PROTO
IDCT_8x8_SSE PROTO
IDCT_16x16_SSE PROTO
IDCT_16x8_SSE PROTO
IDCT_8x16_SSE PROTO

;// Macro

;// ebp always points to decoder data
ASSUME ebp:PTR DECODER
Ctx TEXTEQU <ebp>

;// bitstream
BS TEXTEQU <[Ctx].Bs>

;// min
MIN MACRO a,b
sub       b, a
sbb       eax, eax
and       eax, b
add       a, eax
ENDM

;// max
MAX MACRO a,b
sub       b, a
sbb       eax, eax
not       eax
and       eax, b
add       a, eax
ENDM

;// pushad struct by bitRAKE
_PUSHAD STRUCT
    _EDI dword ?
    _ESI dword ?
    _EBP dword ?
    _ESP dword ?	;// not used when POPAD
    _EBX dword ?
    _EDX dword ?
    _ECX dword ?
    _EAX dword ?
_PUSHAD ENDS
SPUSHAD = sizeof(_PUSHAD)

QPTR  TEXTEQU  <qword ptr>
DPTR  TEXTEQU  <dword ptr>
SDPTR TEXTEQU  <sdword ptr>
WPTR  TEXTEQU  <word ptr>
BPTR  TEXTEQU  <byte ptr>

;//=========================================================================
;// Tables
;//=========================================================================

EXTERNDEF TBL_TransList:dword
EXTERNDEF TBL_TransFunc:dword
EXTERNDEF TBL_64:qword
EXTERNDEF TBL_jpeg_natural_order:byte
EXTERNDEF TBL_IDCT:dword
EXTERNDEF TBL_MultRow8x8:dword
EXTERNDEF TBL_MultRow16x16:dword
EXTERNDEF TBL_MultRow8x16:dword
EXTERNDEF TBL_MultRow16x8:dword
EXTERNDEF TBL_tg1_16:real4
EXTERNDEF TBL_tg2_16:real4
EXTERNDEF TBL_tg3_16:real4
EXTERNDEF TBL_tg1_32:real4
EXTERNDEF TBL_tg3_32:real4
EXTERNDEF TBL_tg5_32:real4
EXTERNDEF TBL_tg7_32:real4
EXTERNDEF TBL_cos4_16:real4
EXTERNDEF TBL_cos2_16:real4
EXTERNDEF TBL_MultCB:real4
EXTERNDEF TBL_MultCR:real4
EXTERNDEF TBL_RGBConv:dword
EXTERNDEF TBL_C0:byte
EXTERNDEF TBL_C1:byte

;//=========================================================================
;// Debug
;//=========================================================================
INCLUDE dbg.inc

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -