// File: /workspace/github_cpp_makefile_star2_O1/kebwi[P]Trifid/src/Image3ChnlReal.cpp
// Function: Image3ChnlReal::normalize(double, bool, bool)
void Image3ChnlReal::normalize(Float_t maxVal, bool normalizeUpToo, bool independentChannels)
{
	if (independentChannels)
	{
		img_[0]->normalize(maxVal, normalizeUpToo);
		img_[1]->normalize(maxVal, normalizeUpToo);
		img_[2]->normalize(maxVal, normalizeUpToo);
	}
	else
	{
		Float_t maxCurrentVal = 0;
		for (int i = 0; i < totalPixels_; i++)
		{
			if ((*img_[0])[i] > maxCurrentVal)
				maxCurrentVal = (*img_[0])[i];
			if ((*img_[1])[i] > maxCurrentVal)
				maxCurrentVal = (*img_[1])[i];
			if ((*img_[2])[i] > maxCurrentVal)
				maxCurrentVal = (*img_[2])[i];
		}
		//cout << "maxCurrentVal before RGB normalization: " << maxCurrentVal << endl;
		/*
		int minCurrentVal = 999999;
		for (int i = 0; i < totalPixels_; i++)
		{
			if ((*img_[0])[i] < minCurrentVal)
				minCurrentVal = (*img_[0])[i];
			if ((*img_[1])[i] < minCurrentVal)
				minCurrentVal = (*img_[1])[i];
			if ((*img_[2])[i] < minCurrentVal)
				minCurrentVal = (*img_[2])[i];
		}
		cout << "minCurrentVal before RGB normalization: " << minCurrentVal << endl;
		*/
		if (maxCurrentVal < maxVal && !normalizeUpToo)
			return;
		if (maxCurrentVal == 0)
			return;
		
		Float_t scalar = maxVal / maxCurrentVal;
		
		scale(scalar);
		/*
		maxCurrentVal = 0;
		for (int i = 0; i < totalPixels_; i++)
		{
			if ((*img_[0])[i] > maxCurrentVal)
				maxCurrentVal = (*img_[0])[i];
			if ((*img_[1])[i] > maxCurrentVal)
				maxCurrentVal = (*img_[1])[i];
			if ((*img_[2])[i] > maxCurrentVal)
				maxCurrentVal = (*img_[2])[i];
		}
		cout << "maxCurrentVal after RGB normalization: " << maxCurrentVal << endl;
		minCurrentVal = 999999;
		for (int i = 0; i < totalPixels_; i++)
		{
			if ((*img_[0])[i] < minCurrentVal)
				minCurrentVal = (*img_[0])[i];
			if ((*img_[1])[i] < minCurrentVal)
				minCurrentVal = (*img_[1])[i];
			if ((*img_[2])[i] < minCurrentVal)
				minCurrentVal = (*img_[2])[i];
		}
		cout << "minCurrentVal after RGB normalization: " << minCurrentVal << endl;
		*/
	}
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
testl %edx, %edx
je 0xe62f
movq 0x38(%rbx), %rax
movq (%rax), %rdi
movzbl %sil, %ebp
movl %ebp, %esi
movsd %xmm0, (%rsp)
callq 0xd21c
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rdi
movsd (%rsp), %xmm0
movl %ebp, %esi
callq 0xd21c
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdi
movsd (%rsp), %xmm0
movl %ebp, %esi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xd21c
movslq 0x30(%rbx), %rax
xorpd %xmm4, %xmm4
xorpd %xmm1, %xmm1
testq %rax, %rax
jle 0xe684
movq 0x38(%rbx), %rdi
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x38(%rcx), %rcx
movq 0x38(%rdx), %rdx
movq 0x10(%rdi), %rdi
movq 0x38(%rdi), %rdi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm2
maxsd %xmm1, %xmm2
movsd (%rdx,%r8,8), %xmm3
maxsd %xmm2, %xmm3
movsd (%rdi,%r8,8), %xmm1
maxsd %xmm3, %xmm1
incq %r8
cmpq %r8, %rax
jne 0xe65e
ucomisd %xmm1, %xmm0
setbe %al
ucomisd %xmm4, %xmm1
jne 0xe693
jnp 0xe6ae
orb %sil, %al
je 0xe6ae
divsd %xmm1, %xmm0
movq (%rbx), %rax
movq 0x30(%rax), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmpq *%rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop