// File: /workspace/github_c_makefile_star2_O3/hfiguiere[P]exifprobe/maker_nikon.c
// Function: nikon_colorbalance
void
nikon_colorbalance(FILE *inptr,struct ifd_entry *entry_ptr,unsigned short byteorder,
                                            unsigned long fileoffset_base,int indent)
{
    unsigned long offset;
    unsigned short numerator,denominator;
    double value;
    int chpr = 0;
    int unknown = 0;
    char *id;

    if(entry_ptr && (PRINT_VALUE))
    {
        offset = entry_ptr->value + fileoffset_base;
#if 1
        id = read_string(inptr,offset,4);
        chpr += printf("'ID:");
        show_string(id,4,1);
        if(strncmp(id,"0100",4) == 0)
            offset += 72;
        else if(strncmp(id,"0102",4) == 0)
            offset += 10;
        else if(strncmp(id,"0103",4) == 0)
            offset += 20;
        else
            ++unknown;
        if(!unknown)
        {
            if((PRINT_SECTION))
            {
                indent += MAKERTAGWIDTH + 3;
                chpr += printf("' = {");
                chpr = newline(chpr);
                print_tag_address(ENTRY,offset,indent + MEDIUMINDENT,"?");
                chpr += printf("RedBalance**  = ");
                numerator = read_ushort(inptr,byteorder,offset);
                offset += 2;
                if(strncmp(id,"0100",4))
                {
                    denominator = read_ushort(inptr,byteorder,offset);
                    offset += 2;
                }
                else
                    denominator = 256;
                value = (double)numerator / (double)denominator;
                chpr += printf("%.6f (%u/%u)",value,numerator,denominator);
                chpr = newline(chpr);

                print_tag_address(ENTRY,offset,indent + MEDIUMINDENT,"?");
                chpr += printf("BlueBalance** = ");
                numerator = read_ushort(inptr,byteorder,offset);
                offset += 2;
                if(strncmp(id,"0100",4))
                {
                    denominator = read_ushort(inptr,byteorder,offset);
                    offset += 2;
                }
                else
                    denominator = 256;
                value = (double)numerator / (double)denominator;
                chpr += printf("%.6f (%u/%u)",value,numerator,denominator);
                chpr = newline(chpr);
                print_tag_address(ENTRY,offset + entry_ptr->count - 1,indent,"?");
                chpr += printf("} = {");
                indent -= MAKERTAGWIDTH + 3;
            }
            chpr = newline(chpr);
        }
        else
        {
            chpr += printf(" = unknown = {");
            chpr = newline(chpr);
        }
        offset = entry_ptr->value + fileoffset_base;
        PUSHCOLOR(RED);
        dumpsection(inptr,offset,entry_ptr->count,indent);
        POPCOLOR();
        print_tag_address(ENTRY,offset + entry_ptr->count - 1,indent,"?");
        chpr += printf("}");
    }
#else
/* This just prints everything after the idstring as short rationals, */
/* in the same fashion as print_ushort();                             */
        count = entry_ptr->count / 4;   /* two unsigned shorts        */
        print_ascii(inptr,4,offset);
        count--;
        offset += 4;
        chpr = newline(chpr);
        for(i = 0; i < count; ++i)
        {
            int rowlength;
            if((count -i) >= 4)
                rowlength = 4;
            else
                rowlength = count - i;
            print_tag_address(ENTRY,offset,indent,"?");
            for(j = 0; j < rowlength; ++j,++i)
            {
                numerator = read_ushort(inptr,byteorder,offset);
                denominator = read_ushort(inptr,byteorder,HERE);
                offset += 4;
                if(j)
                    chpr += printf(", ");
                if(j == 2)
                    chpr += printf("    ");
                if(numerator == 0)
                    chpr += printf("0     ");
                else if(denominator == 0)
                    chpr += printf("Inf   ");
                else
                {
                    value = (double)numerator / (double)denominator;
                    chpr += printf("%.4f",value);
                }
            }
            chpr = newline(chpr);
        }
    }
    if(Max_undefined > 0)
    {
        unsigned long dumplength;

        offset = entry_ptr->value + fileoffset_base;
        if((Max_undefined == DUMPALL) || (Max_undefined > entry_ptr->count))
            dumplength = entry_ptr->count;
        else 
            dumplength = Max_undefined;
        chpr = newline(chpr);
        hexdump(inptr,offset,entry_ptr->count,dumplength,16,
                    4,SUBINDENT);
        chpr = newline(1);
    }
#endif
    setcharsprinted(chpr);
}

/* Mark items (usually LONG) which should be treated as offsets.      */

int
maker_nikon_value_is_offset(struct ifd_entry *entry_ptr,int model)
{
    int is_offset = 0;

    /* There is currently no need for a switch on noteversion         */
    if(entry_ptr)
    {
        switch(entry_ptr->tag)
        {
            case 0x0011: is_offset = 1; break; 
            case 0x0097: is_offset = 1; break; 
            case 0x0100: is_offset = 1; break; 
            default: break;
        }
    }
    return(is_offset);
}

// Assembly:
movq %rdi, %rax
xorl %edi, %edi
testq %rsi, %rsi
je 0x17a82
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
leaq 0x2aa2a(%rip), %rcx     # 0x58180
testb $0x30, (%rcx)
je 0x2da3c
movl %edx, %ebx
movq %rsi, %r15
movq %r8, 0x18(%rsp)
movq 0x10(%rsi), %rbp
addq %r14, %rbp
movl $0x4, %edx
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4a17
movq %rax, %r13
leaq 0x1cdf2(%rip), %rdi     # 0x4a581
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
movq %r13, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x957f
leaq 0x1cdd4(%rip), %rsi     # 0x4a586
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d7ff
leaq 0x1cdc1(%rip), %rsi     # 0x4a58b
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d805
leaq 0x1cdae(%rip), %rsi     # 0x4a590
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d80b
leaq 0x1cdd6(%rip), %rdi     # 0x4a5d0
jmp 0x2d9da
addq $0x48, %rbp
jmp 0x2d80f
addq $0xa, %rbp
jmp 0x2d80f
addq $0x14, %rbp
leaq 0x2a96a(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x2d9e4
leaq 0x1cd6e(%rip), %rdi     # 0x4a595
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x1707a
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rax
leal 0x20(%rax), %edx
leaq 0x1cc0a(%rip), %rcx     # 0x4a456
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl %edx, 0x8(%rsp)
callq 0x55eb
leaq 0x1cd37(%rip), %rdi     # 0x4a59b
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
addl 0x4(%rsp), %r12d
movzwl %bx, %esi
movq 0x10(%rsp), %rdi
movl %esi, 0x4(%rsp)
movq %rbp, %rdx
callq 0x45af
movw %ax, 0xe(%rsp)
leaq 0x2(%rbp), %rbx
leaq 0x1ccef(%rip), %rsi     # 0x4a586
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d8c2
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbx, %rdx
callq 0x45af
addq $0x4, %rbp
movq %rbp, %rbx
jmp 0x2d8c6
movw $0x100, %ax             # imm = 0x100
movq 0x18(%rsp), %rcx
addl $0x1c, %ecx
movl %ecx, 0x24(%rsp)
movzwl 0xe(%rsp), %esi
cvtsi2sd %esi, %xmm0
movzwl %ax, %edx
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
leaq 0x1ccbf(%rip), %rdi     # 0x4a5ac
movb $0x1, %al
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x1707a
movl %eax, %ebp
leaq 0x1cb4e(%rip), %rcx     # 0x4a456
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbx, %rsi
movl 0x8(%rsp), %edx
callq 0x55eb
leaq 0x1cc99(%rip), %rdi     # 0x4a5b9
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
addl %ebp, %r12d
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbx, %rdx
callq 0x45af
movw %ax, 0x8(%rsp)
leaq 0x2(%rbx), %rbp
leaq 0x1cc38(%rip), %rsi     # 0x4a586
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d979
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbp, %rdx
callq 0x45af
addq $0x4, %rbx
movq %rbx, %rbp
jmp 0x2d97d
movw $0x100, %ax             # imm = 0x100
movzwl 0x8(%rsp), %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movzwl %ax, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
leaq 0x1cc0e(%rip), %rdi     # 0x4a5ac
movb $0x1, %al
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x1707a
movl %eax, %r12d
movq 0x8(%r15), %rax
leaq (%rax,%rbp), %rsi
decq %rsi
leaq 0x1ca91(%rip), %rcx     # 0x4a456
movl $0x4003333, %edi        # imm = 0x4003333
movl 0x24(%rsp), %edx
callq 0x55eb
leaq 0x1cbf0(%rip), %rdi     # 0x4a5ca
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x1707a
movl %eax, %ebx
addq 0x10(%r15), %r14
movq 0x8(%r15), %rdx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movq 0x18(%rsp), %r12
movl %r12d, %ecx
callq 0x9870
movq 0x8(%r15), %rax
leaq (%rax,%r14), %rsi
decq %rsi
leaq 0x1ca39(%rip), %rcx     # 0x4a456
movl $0x4003333, %edi        # imm = 0x4003333
movl %r12d, %edx
callq 0x55eb
leaq 0x1ba0e(%rip), %rdi     # 0x4943f
xorl %eax, %eax
callq 0x3120
movl %eax, %edi
addl %ebx, %edi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17a82