// File: /workspace/github_c_makefile_star2_O1/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 0x17530
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
leaq 0x2b1e0(%rip), %rcx     # 0x58180
testb $0x30, (%rcx)
je 0x2d295
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 0x49e6
movq %rax, %r13
leaq 0x1d568(%rip), %rdi     # 0x4a541
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
movq %r13, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x9448
leaq 0x1d54a(%rip), %rsi     # 0x4a546
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d048
leaq 0x1d537(%rip), %rsi     # 0x4a54b
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d04e
leaq 0x1d524(%rip), %rsi     # 0x4a550
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
leaq 0x14(%rbp), %rcx
testl %eax, %eax
sete %al
cmoveq %rcx, %rbp
jmp 0x2d054
addq $0x48, %rbp
jmp 0x2d052
addq $0xa, %rbp
movb $0x1, %al
testb %al, %al
je 0x2d10f
leaq 0x2b11d(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x2d23d
leaq 0x1d4e1(%rip), %rdi     # 0x4a555
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x16b56
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rax
leal 0x20(%rax), %edx
leaq 0x1d37d(%rip), %rcx     # 0x4a416
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl %edx, 0x8(%rsp)
callq 0x5605
leaq 0x1d4aa(%rip), %rdi     # 0x4a55b
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 0x4574
movw %ax, 0xe(%rsp)
leaq 0x2(%rbp), %rbx
leaq 0x1d462(%rip), %rsi     # 0x4a546
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d11b
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbx, %rdx
callq 0x4574
addq $0x4, %rbp
movq %rbp, %rbx
jmp 0x2d11f
leaq 0x1d47a(%rip), %rdi     # 0x4a590
jmp 0x2d233
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 0x1d426(%rip), %rdi     # 0x4a56c
movb $0x1, %al
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x16b56
movl %eax, %ebp
leaq 0x1d2b5(%rip), %rcx     # 0x4a416
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbx, %rsi
movl 0x8(%rsp), %edx
callq 0x5605
leaq 0x1d400(%rip), %rdi     # 0x4a579
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
addl %ebp, %r12d
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbx, %rdx
callq 0x4574
movw %ax, 0x8(%rsp)
leaq 0x2(%rbx), %rbp
leaq 0x1d39f(%rip), %rsi     # 0x4a546
movl $0x4, %edx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2d1d2
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbp, %rdx
callq 0x4574
addq $0x4, %rbx
movq %rbx, %rbp
jmp 0x2d1d6
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 0x1d375(%rip), %rdi     # 0x4a56c
movb $0x1, %al
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x16b56
movl %eax, %r12d
movq 0x8(%r15), %rax
leaq (%rax,%rbp), %rsi
decq %rsi
leaq 0x1d1f8(%rip), %rcx     # 0x4a416
movl $0x4003333, %edi        # imm = 0x4003333
movl 0x24(%rsp), %edx
callq 0x5605
leaq 0x1d357(%rip), %rdi     # 0x4a58a
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x16b56
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 0x9745
movq 0x8(%r15), %rax
leaq (%rax,%r14), %rsi
decq %rsi
leaq 0x1d1a0(%rip), %rcx     # 0x4a416
movl $0x4003333, %edi        # imm = 0x4003333
movl %r12d, %edx
callq 0x5605
leaq 0x1c175(%rip), %rdi     # 0x493ff
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 0x17530