// File: OpenFirework[P]MyJPEG_Decoder/./jpeg/jpeg_decoder.cpp
// Function: readDQT(unsigned char*&)
void readDQT(byte *&jpegdata) {
    std::cout<<"\n************DQT INFO*******************\n";
    int length = readSectionLength(jpegdata);
    std::cout<<"本数据段的长度为："<<length<<"\n";
    byte *dqtdata = new byte[length-2];  //length 包括前面的长度信息数据所占的2个字节
    memcpy(dqtdata, jpegdata, length-2);
    jpegdata = jpegdata + (length-2);
    int dataindex = 0;
    int Precision = ((dqtdata[dataindex]&0xF0)>>4);
    int tableid = (dqtdata[dataindex]&0x0F);
    dataindex++;

    if(Precision == 0) {
        std::cout<<"精度:8位,量化表ID:"<<tableid<<"\n";
        int count = 0;
        for(int i=dataindex;i<dataindex+64;i++) {
            //printf(" %2d",dqtdata[i]);
            std::cout<<" "<<std::setw(2)<<static_cast<int>(dqtdata[i]);
            quantTable[tableid][count] = dqtdata[i];
            count++;
            if(count%8==0) {
                std::cout<<"\n";
            }          
        }
    } else {
        std::cout<<"精度:16位,量化表ID:"<<tableid<<"\n";
        //待补充16位时候的情况
    }

    if(dqtdata != nullptr) {
        delete[] dqtdata;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq 0x841d(%rip), %rdi      # 0xafd0
leaq 0x577d(%rip), %rsi      # 0x8337
callq 0x2130
movq -0x8(%rbp), %rdi
callq 0x3d40
movl %eax, -0xc(%rbp)
movq 0x83fe(%rip), %rdi      # 0xafd0
leaq 0x5613(%rip), %rsi      # 0x81ec
callq 0x2130
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5db7(%rip), %rsi      # 0x89aa
callq 0x2130
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdi
callq 0x2030
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdx
callq 0x2110
movq -0x8(%rbp), %rax
movq (%rax), %rcx
movl -0xc(%rbp), %eax
subl $0x2, %eax
cltq
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0xf0, %eax
sarl $0x4, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
andl $0xf, %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x2d71
movq 0x834a(%rip), %rdi      # 0xafd0
leaq 0x56d4(%rip), %rsi      # 0x8361
callq 0x2130
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5d03(%rip), %rsi      # 0x89aa
callq 0x2130
movl $0x0, -0x28(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x40, %ecx
cmpl %ecx, %eax
jge 0x2d6f
movq 0x82ff(%rip), %rdi      # 0xafd0
leaq 0x5564(%rip), %rsi      # 0x823c
callq 0x2130
movq %rax, -0x38(%rbp)
movl $0x2, %edi
callq 0x4a90
movq -0x38(%rbp), %rdi
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %esi
callq 0x2180
movq %rax, %rdi
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %esi
callq 0x2250
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
movslq -0x24(%rbp), %rcx
leaq 0x8b3b(%rip), %rax      # 0xb860
shlq $0x9, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x2d5f
movq 0x827d(%rip), %rdi      # 0xafd0
leaq 0x5c50(%rip), %rsi      # 0x89aa
callq 0x2130
jmp 0x2d61
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2cb9
jmp 0x2d9e
movq 0x8258(%rip), %rdi      # 0xafd0
leaq 0x55fb(%rip), %rsi      # 0x837a
callq 0x2130
movq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x2250
movq %rax, %rdi
leaq 0x5c11(%rip), %rsi      # 0x89aa
callq 0x2130
cmpq $0x0, -0x18(%rbp)
je 0x2dbe
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x2dbc
movq -0x40(%rbp), %rdi
callq 0x21a0
jmp 0x2dbe
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)