// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x480, %rsp            # imm = 0x480
cmpl $0x3, %edi
jne 0x3f44
movq %rsi, %rbx
leaq -0x84(%rbp), %r14
movq %r14, %rdi
callq 0x248c
leaq -0x28(%rbp), %r8
andq $0x0, (%r8)
leaq -0x18(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x14(%rbp), %rcx
andl $0x0, (%rcx)
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0x28a0
leaq -0x488(%rbp), %r14
movq %r14, %rdi
callq 0x2200
leaq 0x860(%rip), %rsi       # 0x4595
pushq $0x14
popq %rdx
movq %r14, %rdi
callq 0x2050
movq -0x28(%rbp), %rsi
movl -0x18(%rbp), %eax
imull -0x14(%rbp), %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdx
leaq -0x488(%rbp), %rdi
callq 0x2170
leaq -0x488(%rbp), %rdi
callq 0x2190
movq 0x3260(%rip), %rdi      # 0x6fd0
leaq 0x833(%rip), %rsi       # 0x45aa
callq 0x2110
leaq -0x78(%rbp), %rdi
callq 0x32a4
leaq -0x40(%rbp), %r8
andq $0x0, (%r8)
leaq -0x30(%rbp), %rdx
andl $0x0, (%rdx)
leaq -0x2c(%rbp), %rcx
andl $0x0, (%rcx)
movq 0x10(%rbx), %rsi
leaq -0x78(%rbp), %rdi
callq 0x32aa
leaq -0x288(%rbp), %rdi
callq 0x2200
leaq 0x855(%rip), %rsi       # 0x4610
leaq -0x288(%rbp), %rdi
pushq $0x14
popq %rdx
callq 0x2050
movq -0x40(%rbp), %rsi
movl -0x30(%rbp), %eax
imull -0x2c(%rbp), %eax
leal (%rax,%rax,2), %eax
movslq %eax, %rdx
leaq -0x288(%rbp), %rdi
callq 0x2170
leaq -0x288(%rbp), %rdi
callq 0x2190
movq 0x31d6(%rip), %rdi      # 0x6fd0
leaq 0x823(%rip), %rsi       # 0x4624
callq 0x2110
movl -0x18(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq 0x875(%rip), %rsi       # 0x4688
leaq -0x78(%rbp), %rdi
leaq -0x28(%rbp), %r8
callq 0x368a
movq 0x31a9(%rip), %rdi      # 0x6fd0
leaq 0x86f(%rip), %rsi       # 0x469d
callq 0x2110
leaq -0x38(%rbp), %r8
andq $0x0, (%r8)
leaq -0x20(%rbp), %r9
andl $0x0, (%r9)
leaq -0x1c(%rbp), %rax
andl $0x0, (%rax)
movl -0x18(%rbp), %edx
movl -0x14(%rbp), %ecx
movq %rax, (%rsp)
leaq -0x78(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movss 0x700(%rip), %xmm0      # 0x4564
callq 0x3904
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
leaq 0x8a2(%rip), %rsi       # 0x4718
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %r8
callq 0x368a
movq 0x3146(%rip), %rdi      # 0x6fd0
leaq 0x898(%rip), %rsi       # 0x4729
callq 0x2110
movl -0x18(%rbp), %esi
movq %rax, %rdi
callq 0x2210
leaq 0x8bf(%rip), %rsi       # 0x4767
movq %rax, %rdi
callq 0x2110
movl -0x14(%rbp), %esi
movq %rax, %rdi
callq 0x2210
leaq 0x8a7(%rip), %rsi       # 0x4769
movq %rax, %rdi
callq 0x2110
movl -0x20(%rbp), %esi
movq %rax, %rdi
callq 0x2210
leaq 0x88b(%rip), %rsi       # 0x4767
movq %rax, %rdi
callq 0x2110
movl -0x1c(%rbp), %esi
movq %rax, %rdi
callq 0x2210
leaq 0x88f(%rip), %rsi       # 0x4785
movq %rax, %rdi
callq 0x2110
movq -0x28(%rbp), %rdi
testq %rdi, %rdi
je 0x3f0c
callq 0x2160
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x3f1a
callq 0x2160
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0x3f28
callq 0x2160
leaq -0x288(%rbp), %rdi
callq 0x21a0
leaq -0x488(%rbp), %rdi
callq 0x21a0
xorl %eax, %eax
jmp 0x3f5a
movq 0x3085(%rip), %rdi      # 0x6fd0
leaq 0x616(%rip), %rsi       # 0x4568
callq 0x2110
pushq $-0x1
popq %rax
addq $0x480, %rsp            # imm = 0x480
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x3f6c
jmp 0x3f6c
jmp 0x3f6c
movq %rax, %rbx
jmp 0x3f82
jmp 0x3f73
movq %rax, %rbx
leaq -0x288(%rbp), %rdi
callq 0x21a0
leaq -0x488(%rbp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x2230