// File: iibrahimli[P]adsa_project/src/../include/bmp.hpp
// Function: BMP_image::BMP_image(unsigned int, unsigned int, pixel4, bool)
BMP_image(unsigned int width, unsigned int height, pixel fill_color = WHITE, bool has_alpha = true){

        if (width <= 0 || height <= 0) {
            throw std::runtime_error("The image width and height must be positive numbers");
        }

        info_h.width = width;
        info_h.height = height;

        neg_height = true;

        // don't hold padding bytes
        data = new pixel[width * height];

        // fill pixels array
        for(int i=0; i<width*height; ++i) data[i] = fill_color;

        info_h.size = sizeof(BMP_info_header);
        file_h.pxl_offset = sizeof(BMP_file_header) + sizeof(BMP_info_header);

        if (has_alpha) {
            info_h.bit_count = 32;
            file_h.file_size = file_h.pxl_offset + width * height * info_h.bit_count/8;
        }
        else {
            info_h.bit_count = 24;
            padding = 4 - ((info_h.width * info_h.bit_count/8) % 4);
            file_h.file_size = file_h.pxl_offset + (width * info_h.bit_count/8 + padding) * height;
        }

    }

// Assembly:
subq $0x58, %rsp
movb %r8b, %al
movl %ecx, 0x54(%rsp)
movq %rdi, 0x48(%rsp)
movl %esi, 0x44(%rsp)
movl %edx, 0x40(%rsp)
andb $0x1, %al
movb %al, 0x3f(%rsp)
movq 0x48(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x9330
movq 0x10(%rsp), %rdi
addq $0xe, %rdi
callq 0x9360
movq 0x10(%rsp), %rax
movq $0x0, 0x38(%rax)
addq $0x40, %rax
movq %rax, 0x18(%rsp)
leaq 0x3e(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x3470
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rdx
leaq 0x6417(%rip), %rsi      # 0xe538
callq 0x93c0
jmp 0x8128
leaq 0x3e(%rsp), %rdi
callq 0x32a0
movq 0x10(%rsp), %rax
movl $0x0, 0x60(%rax)
movb $0x0, 0x64(%rax)
cmpl $0x0, 0x44(%rsp)
jbe 0x8154
cmpl $0x0, 0x40(%rsp)
ja 0x81e1
movl $0x10, %edi
callq 0x3150
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x8(%rsp)
leaq 0x63d2(%rip), %rsi      # 0xe542
callq 0x30f0
jmp 0x8177
movq 0x8(%rsp), %rdi
movq 0xbe6d(%rip), %rsi      # 0x13ff0
movq 0xbe36(%rip), %rdx      # 0x13fc0
callq 0x3440
jmp 0x8309
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x3e(%rsp), %rdi
callq 0x32a0
jmp 0x82ff
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
callq 0x31d0
jmp 0x82f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0x82f5
movq 0x10(%rsp), %rax
movl 0x44(%rsp), %ecx
movl %ecx, 0x12(%rax)
movl 0x40(%rsp), %ecx
movl %ecx, 0x16(%rax)
movb $0x1, 0x64(%rax)
movl 0x44(%rsp), %eax
movl 0x40(%rsp), %ecx
imull %ecx, %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x3030
movq %rax, (%rsp)
jmp 0x8214
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, 0x38(%rax)
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
movl 0x44(%rsp), %ecx
imull 0x40(%rsp), %ecx
cmpl %ecx, %eax
jae 0x825c
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
movslq 0x28(%rsp), %rcx
movl 0x54(%rsp), %edx
movl %edx, (%rax,%rcx,4)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x8229
movq 0x10(%rsp), %rax
movl $0x28, 0xe(%rax)
movl $0x36, 0xa(%rax)
testb $0x1, 0x3f(%rsp)
je 0x829e
movq 0x10(%rsp), %rax
movw $0x20, 0x1c(%rax)
movl 0xa(%rax), %ecx
movl 0x44(%rsp), %edx
imull 0x40(%rsp), %edx
movzwl 0x1c(%rax), %esi
imull %esi, %edx
shrl $0x3, %edx
addl %edx, %ecx
movl %ecx, 0x2(%rax)
jmp 0x82f0
movq 0x10(%rsp), %rcx
movw $0x18, 0x1c(%rcx)
movl 0x12(%rcx), %eax
movzwl 0x1c(%rcx), %ecx
imull %ecx, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl $0x4, %ecx
cltd
idivl %ecx
movq 0x10(%rsp), %rax
movl $0x4, %ecx
subl %edx, %ecx
movl %ecx, 0x60(%rax)
movl 0xa(%rax), %ecx
movl 0x44(%rsp), %edx
movzwl 0x1c(%rax), %esi
imull %esi, %edx
shrl $0x3, %edx
addl 0x60(%rax), %edx
imull 0x40(%rsp), %edx
addl %edx, %ecx
movl %ecx, 0x2(%rax)
addq $0x58, %rsp
retq
movq 0x18(%rsp), %rdi
callq 0x3190
movq 0x30(%rsp), %rdi
callq 0x3460
nopl (%rax)