// File: kebwi[P]Trifid/src/ImageProcs.cpp
// Function: addSensorNoise(Image3ChnlReal&, bool, NoiseParam)
void addSensorNoise(Image3ChnlReal &rgbImage, bool applyBayer, NoiseParam noiseParams)
{
	cout << "Adding color sensor noise..." << endl;
	
	//Check to see if the image is normalized
	int totalPixels = rgbImage.totalPixels();
	Float_t maxVal = 0;
	for (int c = 0; c < 3; c++)
		for (int i = 0; i < totalPixels; i++)
		{
			assert((*rgbImage[c])[i] >= 0 && (*rgbImage[c])[i] <= 1.0);
			if ((*rgbImage[c])[i] > maxVal)
				maxVal = (*rgbImage[c])[i];
		}
	if (maxVal != 1.0)
		cout << "***  NOTE  ***  This input image is not normalized yet" << endl;
	
	//Noisify the image
	cout << endl << setw(40) << left << "  Noisifying with ags: " << noiseParams.ampGain_ << endl;
	for (int c = 0; c < 3; c++)
		addSensorNoise(*rgbImage[c], applyBayer, noiseParams);
	
	rgbImage.appendFilename("_n-");
	rgbImage.appendFilename(noiseParams.label_);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdx, -0x120(%rbp)
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq 0x36a97(%rip), %rdi     # 0x59fd0
leaq 0x28404(%rip), %rsi     # 0x4b944
callq 0x4390
movq %rax, %rdi
movq 0x36a69(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq -0x8(%rbp), %rdi
callq 0xf200
movl %eax, -0x1c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jge 0x23673
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x23663
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xef40
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0xef70
movsd (%rax), %xmm0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x121(%rbp)
jb 0x235e4
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xef40
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0xef70
movsd 0x25a49(%rip), %xmm0    # 0x49020
ucomisd (%rax), %xmm0
setae %al
movb %al, -0x121(%rbp)
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x235f0
jmp 0x235f2
jmp 0x23611
leaq 0x28368(%rip), %rdi     # 0x4b961
leaq 0x27731(%rip), %rsi     # 0x4ad31
movl $0x473, %edx            # imm = 0x473
leaq 0x28388(%rip), %rcx     # 0x4b994
callq 0x4240
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xef40
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0xef70
movsd (%rax), %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x23653
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xef40
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0xef70
movsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x23655
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x23580
jmp 0x23665
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2356f
movsd -0x28(%rbp), %xmm0
movsd 0x259a0(%rip), %xmm1    # 0x49020
ucomisd %xmm1, %xmm0
jne 0x2368a
jp 0x2368a
jmp 0x236ac
movq 0x3693f(%rip), %rdi     # 0x59fd0
leaq 0x280a0(%rip), %rsi     # 0x4b738
callq 0x4390
movq %rax, %rdi
movq 0x36911(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq 0x3691d(%rip), %rdi     # 0x59fd0
movq 0x368fe(%rip), %rsi     # 0x59fb8
callq 0x43d0
movq %rax, -0x130(%rbp)
movl $0x28, %edi
callq 0xe410
movq -0x130(%rbp), %rdi
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %esi
callq 0x4430
movq %rax, %rdi
leaq -0x152bc(%rip), %rsi    # 0xe430
callq 0x4110
movq %rax, %rdi
leaq 0x28154(%rip), %rsi     # 0x4b84f
callq 0x4390
movq %rax, %rdi
movq -0x120(%rbp), %rax
movsd 0xa0(%rax), %xmm0
callq 0x4670
movq %rax, %rdi
movq 0x36897(%rip), %rsi     # 0x59fb8
callq 0x43d0
movl $0x0, -0x38(%rbp)
cmpl $0x3, -0x38(%rbp)
jge 0x237c3
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0xef40
movq -0x120(%rbp), %rsi
movq %rax, -0x140(%rbp)
movzbl -0x9(%rbp), %eax
movl %eax, -0x144(%rbp)
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0xec90
movl -0x144(%rbp), %esi
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rdx
andl $0x1, %esi
callq 0x203e0
jmp 0x2378c
leaq -0xe8(%rbp), %rdi
callq 0xe3d0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2372d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0xe3d0
jmp 0x23840
movq -0x8(%rbp), %rdi
leaq 0x27e69(%rip), %rsi     # 0x4b637
callq 0xf220
movq -0x120(%rbp), %rsi
movq -0x8(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x118(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x4180
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x154f0
jmp 0x2380d
leaq -0x118(%rbp), %rdi
callq 0x46c8
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x46c8
movq -0xf0(%rbp), %rdi
callq 0x4620
nopl (%rax)