// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/exposure.c
// Function: GetRaspistillExpParms
char * GetRaspistillExpParms()
{
    // if ISO min/max are not configured manually, set the according to camera module.
    if (ex.ISOmin == 0 || ex.ISOmax == 0){
        int min, max;
        if (memcmp(ImageInfo.CameraModel, "RP_ov5647",10) == 0){
            //V1 (5 mp) camera module
            min = 100; max = 800;
        }
        if (memcmp(ImageInfo.CameraModel, "RP_imx219",10) == 0){
            // V2 (8 mp) camera module.
            min = 50; max = 1600;
        }
        if (memcmp(ImageInfo.CameraModel, "RP_imx477",10) == 0){
            // HQ (12 mp) camera module.
            min = 40; max = 3200;
        }
        if (ex.ISOmin == 0) ex.ISOmin = min;
        if (ex.ISOmax == 0) ex.ISOmax = max;
    }
    // Set Tmin and max if not configured.
    if (ex.Tmin <= 0.0001)  ex.Tmin = 0.0001;
    if (ex.Tmax == 0) ex.Tmax = 0.25;
    if (ex.Tmax <= 0.001)  ex.Tmax = 0.001;
    if (ex.ISOoverExTime == 0) ex.ISOoverExTime = 32000;



    double ExTime = 1/sqrt(ex.ISOoverExTime/ISOtimesExp);

    if (ExTime < ex.Tmin) ExTime = ex.Tmin;
    if (ExTime > ex.Tmax) ExTime = ex.Tmax;
    double ISO = ISOtimesExp / ExTime;

    // Apply limits to ISO.
    if (ISO > ex.ISOmax) ISO = ex.ISOmax;
    if (ISO < ex.ISOmin) ISO = ex.ISOmin;

    // Re-compute exposure time, in case we hit ISO rails.
    ExTime = ISOtimesExp / ISO;

    // Re-apply limits to exposure time.
    ExMaxLimitHit = ExMinLimitHit = 0;
    if (ExTime < ex.Tmin) {
        ExTime = ex.Tmin;
        ExMinLimitHit = 1;// too much light.  Kind of unlikely.
        fprintf(Log,"Exposure at min ISO and time.\n");
    }
    if (ExTime > ex.Tmax) {
        ExTime = ex.Tmax;
        ExMaxLimitHit = 1;// Dark image, but further exposure increase not possible.
        fprintf(Log,"Exposure at max ISO and time\n");
    }

    fprintf(Log,"New exposure: t=%0.5f ISO=%d ISO*Exp=%5.0f\n",ExTime, (int)ISO,ISOtimesExp);

    static char RaspiParms[50];
    snprintf(RaspiParms, 50, " -ss %d -ISO %d",(int)(ExTime*1000000), (int)ISO);

    //printf("Raspiparms: '%s'\n",RaspiParms);
    return RaspiParms;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
cmpl $0x0, 0xad41(%rip)      # 0x17ba0
je 0xce6e
cmpl $0x0, 0xad3c(%rip)      # 0x17ba4
jne 0xcf2a
leaq 0x8643(%rip), %rdi      # 0x154b8
addq $0x1028, %rdi           # imm = 0x1028
leaq 0x47b9(%rip), %rsi      # 0x1163c
movl $0xa, %edx
callq 0x3210
cmpl $0x0, %eax
jne 0xcea0
movl $0x64, -0x4(%rbp)
movl $0x320, -0x8(%rbp)      # imm = 0x320
leaq 0x8611(%rip), %rdi      # 0x154b8
addq $0x1028, %rdi           # imm = 0x1028
leaq 0x4791(%rip), %rsi      # 0x11646
movl $0xa, %edx
callq 0x3210
cmpl $0x0, %eax
jne 0xced2
movl $0x32, -0x4(%rbp)
movl $0x640, -0x8(%rbp)      # imm = 0x640
leaq 0x85df(%rip), %rdi      # 0x154b8
addq $0x1028, %rdi           # imm = 0x1028
leaq 0x4769(%rip), %rsi      # 0x11650
movl $0xa, %edx
callq 0x3210
cmpl $0x0, %eax
jne 0xcf04
movl $0x28, -0x4(%rbp)
movl $0xc80, -0x8(%rbp)      # imm = 0xC80
cmpl $0x0, 0xac95(%rip)      # 0x17ba0
jne 0xcf16
movl -0x4(%rbp), %eax
movl %eax, 0xac8a(%rip)      # 0x17ba0
cmpl $0x0, 0xac87(%rip)      # 0x17ba4
jne 0xcf28
movl -0x8(%rbp), %eax
movl %eax, 0xac7c(%rip)      # 0x17ba4
jmp 0xcf2a
movss 0xac76(%rip), %xmm0     # 0x17ba8
cvtss2sd %xmm0, %xmm1
movsd 0x4652(%rip), %xmm0     # 0x11590
ucomisd %xmm1, %xmm0
jb 0xcf54
movss 0x46e4(%rip), %xmm0     # 0x11630
movss %xmm0, 0xac54(%rip)     # 0x17ba8
movss 0xac50(%rip), %xmm0     # 0x17bac
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xcf76
jp 0xcf76
movss 0x46c6(%rip), %xmm0     # 0x11634
movss %xmm0, 0xac36(%rip)     # 0x17bac
movss 0xac2e(%rip), %xmm0     # 0x17bac
cvtss2sd %xmm0, %xmm1
movsd 0x2eae(%rip), %xmm0     # 0xfe38
ucomisd %xmm1, %xmm0
jb 0xcfa0
movss 0x46a0(%rip), %xmm0     # 0x11638
movss %xmm0, 0xac0c(%rip)     # 0x17bac
cmpl $0x0, 0xac0d(%rip)      # 0x17bb4
jne 0xcfb3
movl $0x7d00, 0xac01(%rip)   # imm = 0x7D00
cvtsi2sdl 0xabf9(%rip), %xmm0 # 0x17bb4
divsd 0x7365(%rip), %xmm0     # 0x14328
callq 0x34a0
movaps %xmm0, %xmm1
movsd 0x2715(%rip), %xmm0     # 0xf6e8
divsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm1
movss 0xabbf(%rip), %xmm0     # 0x17ba8
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xd004
movss 0xabad(%rip), %xmm0     # 0x17ba8
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movss 0xab9b(%rip), %xmm1     # 0x17bac
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xd02c
movss 0xab89(%rip), %xmm0     # 0x17bac
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd 0x72f4(%rip), %xmm0     # 0x14328
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
cvtsi2sdl 0xab59(%rip), %xmm1 # 0x17ba4
ucomisd %xmm1, %xmm0
jbe 0xd05e
cvtsi2sdl 0xab4b(%rip), %xmm0 # 0x17ba4
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm1
cvtsi2sdl 0xab35(%rip), %xmm0 # 0x17ba0
ucomisd %xmm1, %xmm0
jbe 0xd07e
cvtsi2sdl 0xab27(%rip), %xmm0 # 0x17ba0
movsd %xmm0, -0x18(%rbp)
movsd 0x72a2(%rip), %xmm0     # 0x14328
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x0, 0xab1e(%rip)      # 0x17bb8
movl $0x0, 0xab18(%rip)      # 0x17bbc
movsd -0x10(%rbp), %xmm1
movss 0xaaf7(%rip), %xmm0     # 0x17ba8
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xd0ee
movss 0xaae5(%rip), %xmm0     # 0x17ba8
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x1, 0xaae2(%rip)      # 0x17bb8
leaq 0x7f3b(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq 0x4573(%rip), %rsi      # 0x1165a
movb $0x0, %al
callq 0x3290
movsd -0x10(%rbp), %xmm0
movss 0xaab1(%rip), %xmm1     # 0x17bac
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xd138
movss 0xaa9f(%rip), %xmm0     # 0x17bac
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x1, 0xaa9c(%rip)      # 0x17bbc
leaq 0x7ef1(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq 0x4548(%rip), %rsi      # 0x11679
movb $0x0, %al
callq 0x3290
leaq 0x7ed9(%rip), %rax      # 0x15018
movq (%rax), %rdi
movsd -0x10(%rbp), %xmm0
cvttsd2si -0x18(%rbp), %edx
movsd 0x71d4(%rip), %xmm1     # 0x14328
leaq 0x453c(%rip), %rsi      # 0x11697
movb $0x2, %al
callq 0x3290
movsd 0x442e(%rip), %xmm0     # 0x11598
mulsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
cvttsd2si -0x18(%rbp), %r8d
leaq 0xaa40(%rip), %rdi      # 0x17bc0
movl $0x32, %esi
leaq 0x4537(%rip), %rdx      # 0x116c3
movb $0x0, %al
callq 0x3190
leaq 0xaa26(%rip), %rax      # 0x17bc0
addq $0x20, %rsp
popq %rbp
retq