// File: /workspace/github_cpp_makefile_star2_O3/kebwi[P]Trifid/src/ImageProcs.cpp
// Function: rgbImgToLabImg(double, Image3ChnlReal const&, Image3ChnlReal&)
void rgbImgToLabImg(Float_t maxVal, const Image3ChnlReal &rgbImg, Image3ChnlReal &labImg)
{
	labImg.resize(rgbImg.width(), rgbImg.height());
	
	Float_t r, g, b;
	Float_t x, y, z;
	Float_t l, a, b2;
	int totalPixels = rgbImg.totalPixels();
	for (int i = 0; i < totalPixels; i++)
	{
		r = (*rgbImg[0])[i] / maxVal;
		g = (*rgbImg[1])[i] / maxVal;
		b = (*rgbImg[2])[i] / maxVal;
		
		rgb2xyz(r, g, b, x, y, z);
		xyz2cielab(x, y, z, l, a, b2);
		/*
		if (l < 0 || a < 0 || b2 < 0)
			cout << setw(10) << r
				<< setw(10) << g
				<< setw(10) << b
				<< setw(15) << x
				<< setw(10) << y
				<< setw(10) << z
				<< setw(15) << l
				<< setw(10) << a
				<< setw(10) << b2 << endl;
		*/
		(*labImg[0])[i] = l;
		(*labImg[1])[i] = a;
		(*labImg[2])[i] = b2;
		/*
		if (i % 128 == 0)
		{
			cout << "RGB:";
			cout << setw(15) << r;
			cout << setw(15) << g;
			cout << setw(15) << b << endl;
			cout << "XYZ:";
			cout << setw(15) << x;
			cout << setw(15) << y;
			cout << setw(15) << z << endl;
			cout << "LAB:";
			cout << setw(15) << l;
			cout << setw(15) << a;
			cout << setw(15) << b2 << endl << endl;
		}
		*/
	}
	
	labImg.setFilename(rgbImg.filename());
	labImg.appendFilename("_lab");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movsd %xmm0, (%rsp)
movl 0x28(%rdi), %esi
movl 0x2c(%rdi), %edx
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x28(%rax)
movslq 0x30(%r14), %r13
testq %r13, %r13
jle 0x13607
xorl %ebp, %ebp
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %r12
movq 0x38(%r14), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rdx
movq 0x38(%rcx), %rcx
movsd (%rcx,%rbp,8), %xmm0
movsd (%rsp), %xmm3
divsd %xmm3, %xmm0
movq 0x38(%rdx), %rcx
movsd (%rcx,%rbp,8), %xmm1
divsd %xmm3, %xmm1
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movsd (%rax,%rbp,8), %xmm2
divsd %xmm3, %xmm2
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x121d0
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x123e5
movsd 0x18(%rsp), %xmm0
movq 0x38(%rbx), %rax
movq (%rax), %rcx
movq 0x38(%rcx), %rcx
movsd %xmm0, (%rcx,%rbp,8)
movsd 0x10(%rsp), %xmm0
movq 0x8(%rax), %rcx
movq 0x38(%rcx), %rcx
movsd %xmm0, (%rcx,%rbp,8)
movsd 0x8(%rsp), %xmm0
movq 0x10(%rax), %rax
movq 0x38(%rax), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
cmpq %rbp, %r13
jne 0x1354e
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0xa92c
movq %rbx, %rdi
movq %r14, %rsi
callq 0xce40
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x1364a
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3310
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1743b(%rip), %rsi     # 0x2aa95
leaq 0x17438(%rip), %rdx     # 0x2aa99
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xa9c2
movq %rbx, %rdi
movq %r14, %rsi
callq 0xce5a
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x13690
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3310
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x136cd
movq 0x68(%rsp), %rsi
jmp 0x136c5
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x136cd
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3310
movq %rbx, %rdi
callq 0x3500