// File: /workspace/github_cpp_makefile_star2_O1/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 0x1366c
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 0x12234
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x12449
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 0x135b3
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 0xa97e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xcf04
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x136af
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3310
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x183f8(%rip), %rsi     # 0x2bab7
leaq 0x183f5(%rip), %rdx     # 0x2babb
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xaa0e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xcf1e
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x136f5
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 0x13732
movq 0x68(%rsp), %rsi
jmp 0x1372a
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x13732
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3310
movq %rbx, %rdi
callq 0x3500