// File: /workspace/github_c_makefile_star2_O2/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 0x16a4f
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
leaq 0x2b111(%rip), %rcx     # 0x57180
testb $0x30, (%rcx)
je 0x2c342
movq %rsi, %r15
movl %edx, 0x4(%rsp)
movq %r8, 0x18(%rsp)
movq 0x10(%rsi), %rbp
addq %r14, %rbp
pushq $0x4
popq %rbx
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x45bd
movq %rax, %r13
leaq 0x1c486(%rip), %rdi     # 0x48531
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r13, %rdi
callq 0x8e0f
leaq 0x1c46c(%rip), %rsi     # 0x48536
movq %r13, %rdi
movq %rbx, %rdx
callq 0x3090
testl %eax, %eax
je 0x2c111
leaq 0x1c45b(%rip), %rsi     # 0x4853b
pushq $0x4
popq %rdx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2c117
leaq 0x1c44a(%rip), %rsi     # 0x48540
pushq $0x4
popq %rdx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2c11d
leaq 0x1c474(%rip), %rdi     # 0x48580
jmp 0x2c2e0
addq $0x48, %rbp
jmp 0x2c121
addq $0xa, %rbp
jmp 0x2c121
addq $0x14, %rbp
leaq 0x2b058(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x2c2ea
leaq 0x1c40c(%rip), %rdi     # 0x48545
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x160f7
movl %eax, %ebx
movq 0x18(%rsp), %rax
leal 0x20(%rax), %edx
leaq 0x1c2aa(%rip), %rcx     # 0x48406
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbp, %rsi
movl %edx, 0x8(%rsp)
callq 0x5100
leaq 0x1c3d7(%rip), %rdi     # 0x4854b
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
addl %ebx, %r12d
movzwl 0x4(%rsp), %esi
movq 0x10(%rsp), %rdi
movl %esi, 0x4(%rsp)
movq %rbp, %rdx
callq 0x416a
movw %ax, 0xe(%rsp)
leaq 0x2(%rbp), %rbx
leaq 0x1c38f(%rip), %rsi     # 0x48536
pushq $0x4
popq %rdx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2c1d0
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbx, %rdx
callq 0x416a
addq $0x4, %rbp
movq %rbp, %rbx
jmp 0x2c1d4
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 0x1c361(%rip), %rdi     # 0x4855c
movb $0x1, %al
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x160f7
movl %eax, %ebp
leaq 0x1c1f0(%rip), %rcx     # 0x48406
movl $0x4003333, %edi        # imm = 0x4003333
movq %rbx, %rsi
movl 0x8(%rsp), %edx
callq 0x5100
leaq 0x1c33b(%rip), %rdi     # 0x48569
xorl %eax, %eax
callq 0x3120
movl %eax, %r12d
addl %ebp, %r12d
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbx, %rdx
callq 0x416a
movw %ax, 0x8(%rsp)
leaq 0x2(%rbx), %rbp
leaq 0x1c2da(%rip), %rsi     # 0x48536
pushq $0x4
popq %rdx
movq %r13, %rdi
callq 0x3090
testl %eax, %eax
je 0x2c285
movq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %rbp, %rdx
callq 0x416a
addq $0x4, %rbx
movq %rbx, %rbp
jmp 0x2c289
movw $0x100, %ax             # imm = 0x100
movzwl 0x8(%rsp), %esi
cvtsi2sd %esi, %xmm0
movzwl %ax, %edx
cvtsi2sd %edx, %xmm1
divsd %xmm1, %xmm0
leaq 0x1c2b8(%rip), %rdi     # 0x4855c
movb $0x1, %al
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x160f7
movl %eax, %r12d
movq 0x8(%r15), %rax
leaq (%rax,%rbp), %rsi
decq %rsi
leaq 0x1c13b(%rip), %rcx     # 0x48406
movl $0x4003333, %edi        # imm = 0x4003333
movl 0x24(%rsp), %edx
callq 0x5100
leaq 0x1c29a(%rip), %rdi     # 0x4857a
xorl %eax, %eax
callq 0x3120
addl %eax, %r12d
movl %r12d, %edi
callq 0x160f7
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 0x90de
movq 0x8(%r15), %rax
leaq (%rax,%r14), %rsi
decq %rsi
leaq 0x1c0e3(%rip), %rcx     # 0x48406
movl $0x4003333, %edi        # imm = 0x4003333
movl %r12d, %edx
callq 0x5100
leaq 0x1b0b8(%rip), %rdi     # 0x473ef
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 0x16a4f