// File: /workspace/github_cpp_makefile_star2_O1/mhe[P]raytracerframework_cpp/image.cpp
// Function: Image::read_png(char*)
void Image::read_png(char* filename)
{
	std::vector<unsigned char> buffer, image;
	 //load the image file with given filename
	LodePNG::loadFile(buffer, filename);
	
	 //decode the png
	LodePNG::Decoder decoder;
	decoder.decode(image, buffer.empty() ? 0 : &buffer[0], (unsigned)buffer.size());
	cout << decoder.getChannels() << endl;
	cout << decoder.getBpp() << endl;
	
	if (decoder.getChannels()<3 || decoder.getBpp()<24) {
		cerr << "Error: only color (RGBA), 8 bit per channel png images are supported." << endl;
		cerr << "Either convert your image or change the sourcecode." << endl;
		exit(1);
	}
	int w = decoder.getWidth();
	int h = decoder.getHeight();
	set_extent(w,h);
	
	// now convert the image data
	std::vector<unsigned char>::iterator imageIterator = image.begin();
	Color *currentPixel = _pixel;
	while (imageIterator != image.end()) {
		currentPixel->r = (*imageIterator)/255.0;
		imageIterator++;
		currentPixel->g = (*imageIterator)/255.0;
		imageIterator++;
		currentPixel->b = (*imageIterator)/255.0;
		imageIterator++;
		// Let's just ignore the alpha channel
		imageIterator++; 
		currentPixel++;
	}	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
xorl %eax, %eax
movq %rax, -0x40(%rbp)
movq %rax, -0x20(%rbp)
movapd %xmm0, -0x30(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x11(%rbp), %rdx
callq 0x1ae58
leaq -0x50(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x22ef4
leaq -0x168(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1abbc
movq -0x168(%rbp), %rsi
incq %rsi
callq 0x52e0
leaq -0x178(%rbp), %rdi
callq 0x22a58
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
cmovneq %rax, %rdx
subl %eax, %ecx
leaq -0x178(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x22b06
leaq -0x178(%rbp), %rdi
callq 0x22ac8
movl %eax, %esi
movq 0x213d0(%rip), %rdi     # 0x3bfd0
callq 0x51d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51e0
leaq -0x178(%rbp), %rdi
callq 0x22aa6
movl %eax, %esi
movq 0x2138c(%rip), %rdi     # 0x3bfd0
callq 0x51d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x5050
movq %rax, %rdi
callq 0x51e0
leaq -0x178(%rbp), %rdi
callq 0x22ac8
cmpl $0x3, %eax
jb 0x1ad64
leaq -0x178(%rbp), %rdi
callq 0x22aa6
cmpl $0x17, %eax
jbe 0x1ad64
leaq -0x178(%rbp), %rdi
callq 0x22a92
movl %eax, %r14d
leaq -0x178(%rbp), %rdi
callq 0x22a9c
movq %rbx, %rdi
movl %r14d, %esi
movl %eax, %edx
callq 0x1a99c
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x1ad22
movq (%rbx), %rcx
movsd 0x16a3e(%rip), %xmm0    # 0x31718
movzbl (%rax), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx)
movzbl 0x1(%rax), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rcx)
movzbl 0x2(%rax), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rcx)
addq $0x4, %rax
addq $0x18, %rcx
cmpq -0x28(%rbp), %rax
jne 0x1acda
leaq -0x178(%rbp), %rdi
callq 0x22a62
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x1ad43
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x52e0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1ad58
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x52e0
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r14
popq %rbp
retq
movq 0x21285(%rip), %rdi     # 0x3bff0
leaq 0x169ae(%rip), %rsi     # 0x31720
movl $0x45, %edx
callq 0x5360
movq 0x2126d(%rip), %rdi     # 0x3bff0
callq 0x5130
movq 0x21261(%rip), %rdi     # 0x3bff0
leaq 0x169d0(%rip), %rsi     # 0x31766
movl $0x33, %edx
callq 0x5360
movq 0x21249(%rip), %rdi     # 0x3bff0
callq 0x5130
movl $0x1, %edi
callq 0x53b0
jmp 0x1ade5
jmp 0x1adde
movq %rax, %rbx
leaq -0x168(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1adf4
movq -0x168(%rbp), %rsi
incq %rsi
callq 0x52e0
jmp 0x1adf4
movq %rax, %rbx
jmp 0x1adf4
jmp 0x1ade5
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x22a62
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x1ae09
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x52e0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x1ae1e
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x52e0
movq %rbx, %rdi
callq 0x5560