// File: /workspace/github_cpp_makefile_star2_O3/OpenFirework[P]MyJPEG_Decoder/test_main.cpp
// Function: main
int main(int argc, char *argv[]) {
    if(argc !=3 ) {
        std::cout<<"please use as test.bin <jpegpath> <bmppath>\n";
        return  -1;
    }

    MyJPEG::jpegDecoder decoder;
    byte *bgrdata = nullptr;
    int imgwidth = 0;
    int imgheidht = 0;

    /*************jpeg文件解码***********/
    decoder.imgread(argv[1], imgwidth, imgheidht, bgrdata);

    /*************将解码后的bgr数据存储，数据内容为[bgr,bgr,bgr,...,bgr]*************/
    std::ofstream outfile;
    outfile.open("jpeg_decoded_bgr.bin",std::ios::out|std::ios::binary);
    outfile.write((char*)bgrdata, imgwidth*imgheidht*3);
    outfile.close();


    std::cout<<"\n*****jpeg图像解码结束，已将bgr数据存储为二进制数据：jpeg_decoded_bgr.bin******\n\n";
    MyBMP::BMP bmpdecoder;

    /*************BMP文件解码***********/
    byte *bgrdata1 = nullptr;
    int imgwidth1 = 0;
    int imgheidht1 = 0;
    bmpdecoder.decode(argv[2], imgwidth1, imgheidht1, bgrdata1);

    /*************存储BMP文件中的图像数据存储位为二进制bgr数据***********/
    std::ofstream outfile1;
    outfile1.open("bmp_decoded_bgr.bin",std::ios::out|std::ios::binary);
    outfile1.write((char*)bgrdata1, imgwidth1*imgheidht1*3);
    outfile1.close();
    std::cout<<"\n*****bmp图像解码结束，已将bgr数据存储为二进制数据：bmp_decoded_bgr.bin******\n\n";

    /*****将前面解码的jpeg数据转换为bmp数据***********/
    bmpdecoder.encode("jpeg_to_bmp_test.bmp",imgwidth, imgheidht, bgrdata);
    std::cout<<"\n*****测试：将jpeg解码的数据存储位bmp图像，验证正确性，存储文件为：jpeg_to_bmp_test.bmp******\n\n";


    /******resize 测试，将图片缩放位任意尺寸********/
    byte *resizedata = nullptr;
    int resizewidth = 0;
    int resizeheight = 0;
    float scale = 1.5;
    bmpdecoder.resize(bgrdata, imgwidth, imgheidht, resizedata, resizewidth, resizeheight, scale);    
    bmpdecoder.encode("jpeg_resized.bmp",resizewidth, resizeheight, resizedata);
    std::cout<<"图像resize测试（双线型插值法）,图像原尺寸（"<<imgwidth<<","<<imgheidht<<"),resize 后的尺寸为（"<<resizewidth<<","<< \
    resizeheight<<"),resize后的图像为：jpeg_resized.bmp\n";

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

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

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

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
cmpl $0x3, %edi
jne 0x42d8
movq %rsi, %r14
leaq -0x9c(%rbp), %rbx
movq %rbx, %rdi
callq 0x25ac
leaq -0x40(%rbp), %r8
movq $0x0, (%r8)
xorl %eax, %eax
leaq -0x30(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x2c(%rbp), %rcx
movl %eax, (%rcx)
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x2ada
leaq -0x4a0(%rbp), %rbx
movq %rbx, %rdi
callq 0x2200
leaq 0x1553(%rip), %rsi      # 0x5585
movq %rbx, %rdi
movl $0x14, %edx
callq 0x2050
movq -0x40(%rbp), %rsi
movl -0x30(%rbp), %eax
imull -0x2c(%rbp), %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdx
leaq -0x4a0(%rbp), %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x2180
movq 0x3f65(%rip), %rdi      # 0x7fd0
leaq 0x1528(%rip), %rsi      # 0x559a
movl $0x65, %edx
callq 0x2130
leaq -0x90(%rbp), %rdi
callq 0x34d0
leaq -0x58(%rbp), %r8
movq $0x0, (%r8)
xorl %eax, %eax
leaq -0x48(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x44(%rbp), %rcx
movl %eax, (%rcx)
movq 0x10(%r14), %rsi
leaq -0x90(%rbp), %rdi
callq 0x34d6
leaq -0x2a0(%rbp), %rdi
callq 0x2200
leaq 0x153c(%rip), %rsi      # 0x5600
leaq -0x2a0(%rbp), %rdi
movl $0x14, %edx
callq 0x2050
movq -0x58(%rbp), %rsi
movl -0x48(%rbp), %eax
imull -0x44(%rbp), %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdx
leaq -0x2a0(%rbp), %rdi
callq 0x2160
leaq -0x2a0(%rbp), %r14
movq %r14, %rdi
callq 0x2180
movq 0x3ec8(%rip), %rdi      # 0x7fd0
leaq 0x1505(%rip), %rsi      # 0x5614
movl $0x63, %edx
callq 0x2130
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq 0x1552(%rip), %rsi      # 0x5678
leaq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %r8
callq 0x38e0
movq 0x3e93(%rip), %rdi      # 0x7fd0
leaq 0x1549(%rip), %rsi      # 0x568d
movl $0x7a, %edx
callq 0x2130
leaq -0x50(%rbp), %r8
movq $0x0, (%r8)
xorl %eax, %eax
leaq -0x38(%rbp), %r9
movl %eax, (%r9)
leaq -0x34(%rbp), %rsi
movl %eax, (%rsi)
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq %rsi, (%rsp)
leaq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movss 0x13cf(%rip), %xmm0     # 0x5554
callq 0x3b66
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
leaq 0x1571(%rip), %rsi      # 0x5708
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %r8
callq 0x38e0
movq 0x3e22(%rip), %rdi      # 0x7fd0
leaq 0x1564(%rip), %rsi      # 0x5719
movl $0x3d, %edx
callq 0x2130
movl -0x30(%rbp), %esi
movq 0x3e07(%rip), %rdi      # 0x7fd0
callq 0x2210
movq %rax, %r15
leaq 0x157f(%rip), %rsi      # 0x5757
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x155f(%rip), %rsi      # 0x5759
movl $0x1b, %edx
movq %rax, %rdi
callq 0x2130
movl -0x38(%rbp), %esi
movq %r15, %rdi
callq 0x2210
movq %rax, %r15
leaq 0x153b(%rip), %rsi      # 0x5757
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movl -0x34(%rbp), %esi
movq %r15, %rdi
callq 0x2210
leaq 0x153a(%rip), %rsi      # 0x5775
movl $0x2b, %edx
movq %rax, %rdi
callq 0x2130
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x4256
callq 0x2150
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x4264
callq 0x2150
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x4272
callq 0x2150
movq 0x3d4f(%rip), %rax      # 0x7fc8
movq (%rax), %r15
movq 0x18(%rax), %r12
leaq -0x298(%rbp), %rdi
movq %r15, -0x8(%rdi)
movq -0x18(%r15), %rax
movq %r12, -0x2a0(%rbp,%rax)
callq 0x20e0
movl $0xf8, %r13d
addq %r13, %r14
movq %r14, %rdi
callq 0x2080
leaq -0x498(%rbp), %rdi
movq %r15, -0x8(%rdi)
movq -0x18(%r15), %rax
movq %r12, -0x4a0(%rbp,%rax)
callq 0x20e0
addq %r13, %rbx
movq %rbx, %rdi
callq 0x2080
xorl %eax, %eax
jmp 0x42f5
movq 0x3cf1(%rip), %rdi      # 0x7fd0
leaq 0x1272(%rip), %rsi      # 0x5558
movl $0x2c, %edx
callq 0x2130
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x430d
jmp 0x430d
jmp 0x430d
movq %rax, %rbx
jmp 0x4323
jmp 0x4314
movq %rax, %rbx
leaq -0x2a0(%rbp), %rdi
callq 0x2190
leaq -0x4a0(%rbp), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2230