// File: /workspace/github_cpp_makefile_star2_O2/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
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
movaps %xmm0, -0x30(%rbp)
andq $0x0, -0x20(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x11(%rbp), %rdx
callq 0xee22
leaq -0x50(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x15f36
leaq -0x178(%rbp), %rdi
callq 0x45d8
leaq -0x178(%rbp), %rdi
callq 0x15ad4
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 0x15b60
leaq -0x178(%rbp), %rdi
callq 0x15b30
movl %eax, %esi
movq 0x1e066(%rip), %rdi     # 0x2dfd0
callq 0x41c0
movq %rax, %rdi
callq 0x4120
leaq -0x178(%rbp), %rdi
callq 0x15b22
movl %eax, %esi
movq 0x1e044(%rip), %rdi     # 0x2dfd0
callq 0x41c0
movq %rax, %rdi
callq 0x4120
leaq -0x178(%rbp), %rdi
callq 0x15b30
cmpl $0x3, %eax
jb 0x10065
leaq -0x178(%rbp), %rdi
callq 0x15b22
cmpl $0x17, %eax
jbe 0x10065
leaq -0x178(%rbp), %rdi
callq 0x15b0e
movl %eax, %r14d
leaq -0x178(%rbp), %rdi
callq 0x15b18
movq %rbx, %rdi
movl %r14d, %esi
movl %eax, %edx
callq 0xfd68
movq -0x30(%rbp), %rax
movq (%rbx), %rcx
movsd 0x12736(%rip), %xmm0    # 0x22730
cmpq -0x28(%rbp), %rax
je 0x1003b
movzbl (%rax), %edx
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx)
movzbl 0x1(%rax), %edx
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rcx)
movzbl 0x2(%rax), %edx
cvtsi2sd %edx, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rcx)
addq $0x4, %rax
addq $0x18, %rcx
jmp 0xfffa
leaq -0x178(%rbp), %rdi
callq 0x15ade
leaq -0x30(%rbp), %rdi
callq 0x1011a
leaq -0x50(%rbp), %rdi
callq 0x1011a
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r14
popq %rbp
retq
movq 0x1df84(%rip), %rdi     # 0x2dff0
leaq 0x126c5(%rip), %rsi     # 0x22738
callq 0x4280
movq %rax, %rdi
callq 0x4120
movq 0x1df69(%rip), %rdi     # 0x2dff0
leaq 0x126f0(%rip), %rsi     # 0x2277e
callq 0x4280
movq %rax, %rdi
callq 0x4120
pushq $0x1
popq %rdi
callq 0x4370
jmp 0x100bf
jmp 0x100b8
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x45d8
jmp 0x100ce
movq %rax, %rbx
jmp 0x100ce
jmp 0x100bf
movq %rax, %rbx
leaq -0x178(%rbp), %rdi
callq 0x15ade
leaq -0x30(%rbp), %rdi
callq 0x1011a
leaq -0x50(%rbp), %rdi
callq 0x1011a
movq %rbx, %rdi
callq 0x4530