// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movsd %xmm0, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0xedd0
movl %eax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0xedf0
movq -0xa0(%rbp), %rdi
movl -0x98(%rbp), %esi
movl %eax, %edx
movq (%rdi), %rax
callq *0x28(%rax)
movq -0x10(%rbp), %rdi
callq 0xf200
movl %eax, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x1f812
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x25920
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0x25950
movsd (%rax), %xmm0
divsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x25920
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0x25950
movsd (%rax), %xmm0
divsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x25920
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0x25950
movsd (%rax), %xmm0
divsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x28(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x1df20
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x48(%rbp), %xmm2
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x1e2b0
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0xef40
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0xef70
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0xef40
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0xef70
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
movl $0x2, %esi
callq 0xef40
movq %rax, %rdi
movl -0x68(%rbp), %esi
callq 0xef70
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x1f6b3
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0xf090
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x154b0
jmp 0x1f849
leaq -0x88(%rbp), %rdi
callq 0x46c8
movq -0x18(%rbp), %rdi
leaq 0x2a30b(%rip), %rsi     # 0x49b6b
callq 0xf220
addq $0xd0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x46c8
movq -0x90(%rbp), %rdi
callq 0x4620
nopl (%rax,%rax)