// File: olegk0[P]readAVI/ReadAVI.cpp
// Function: ReadAVI::read_stream_format()
int ReadAVI::read_stream_format()
{
    int t, r, g, b;
#ifdef VERBOSE
    long offset = inFile.tellg();
#endif
    stream_format_vid.header_size = read_int();
    stream_format_vid.image_width = read_int();
    stream_format_vid.image_height = read_int();
    stream_format_vid.number_of_planes = read_word();
    stream_format_vid.bits_per_pixel = read_word();
    read_chars(stream_format_vid.compression_type, 4);
    //stream_format_vid.compression_type = read_int();
    stream_format_vid.image_size_in_bytes = read_int();
    stream_format_vid.x_pels_per_meter = read_int();
    stream_format_vid.y_pels_per_meter = read_int();
    stream_format_vid.colors_used = read_int();
    stream_format_vid.colors_important = read_int();
    stream_format_vid.palette = 0;

    if (stream_format_vid.colors_important != 0) {
	stream_format_vid.palette = new int[stream_format_vid.colors_important];
	for (t = 0; t < stream_format_vid.colors_important; t++) {
	    unsigned char buf[3];
	    read_chars_bin(buf, 3);
	    b = buf[0];
	    g = buf[1];
	    r = buf[2];
	    stream_format_vid.palette[t] = (r << 16) + (g << 8) + b;
	}
    }

    MSG_DBG(2, "            offset=0x%lx\n", offset);
    MSG_DBG(2, "                   header_size: %d\n", stream_format_vid.header_size);
    MSG_DBG(2, "                   image_width: %d\n", stream_format_vid.image_width);
    MSG_DBG(2, "                  image_height: %d\n", stream_format_vid.image_height);
    MSG_DBG(2, "              number_of_planes: %d\n", stream_format_vid.number_of_planes);
    MSG_DBG(2, "                bits_per_pixel: %d\n", stream_format_vid.bits_per_pixel);
    MSG_DBG(2, "              compression_type: %s\n", stream_format_vid.compression_type);
    /*    MSG_DBG(2, "              compression_type: %04x (%c%c%c%c)\n", stream_format_vid.compression_type,
     ((stream_format_vid.compression_type) & 255), ((stream_format_vid.compression_type >> 8) & 255),
     ((stream_format_vid.compression_type >> 16) & 255), ((stream_format_vid.compression_type >> 24) & 255));
     */
    MSG_DBG(2, "           image_size_in_bytes: %d\n", stream_format_vid.image_size_in_bytes);
    MSG_DBG(2, "              x_pels_per_meter: %d\n", stream_format_vid.x_pels_per_meter);
    MSG_DBG(2, "              y_pels_per_meter: %d\n", stream_format_vid.y_pels_per_meter);
    MSG_DBG(2, "                   colors_used: %d\n", stream_format_vid.colors_used);
    MSG_DBG(2, "              colors_important: %d\n", stream_format_vid.colors_important);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x40(%rbp)
addq $0x20, %rdi
callq 0x23f0
movq %rax, -0x30(%rbp)
movq %rdx, -0x28(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5350
movq -0x40(%rbp), %rdi
movq %rax, -0x20(%rbp)
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x298(%rdi)
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x29c(%rdi)
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x2a0(%rdi)
callq 0x49e0
movq -0x40(%rbp), %rdi
movl %eax, 0x2a4(%rdi)
callq 0x49e0
movq -0x40(%rbp), %rdi
movl %eax, 0x2a8(%rdi)
movq %rdi, %rsi
addq $0x298, %rsi            # imm = 0x298
addq $0x14, %rsi
movl $0x4, %edx
callq 0x3f20
movq -0x40(%rbp), %rdi
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x2b4(%rdi)
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x2b8(%rdi)
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x2bc(%rdi)
callq 0x3f60
movq -0x40(%rbp), %rdi
movl %eax, 0x2c0(%rdi)
callq 0x3f60
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x2c4(%rax)
movq $0x0, 0x2c8(%rax)
cmpl $0x0, 0x2c4(%rax)
je 0x4839
movq -0x40(%rbp), %rax
movslq 0x2c4(%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x2c8(%rax)
movl $0x0, -0xc(%rbp)
movq -0x40(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0x2c4(%rcx), %eax
jge 0x4837
movq -0x40(%rbp), %rdi
leaq -0x33(%rbp), %rsi
movl $0x3, %edx
callq 0x3b70
movq -0x40(%rbp), %rax
movzbl -0x33(%rbp), %ecx
movl %ecx, -0x18(%rbp)
movzbl -0x32(%rbp), %ecx
movl %ecx, -0x14(%rbp)
movzbl -0x31(%rbp), %ecx
movl %ecx, -0x10(%rbp)
movl -0x10(%rbp), %edx
shll $0x10, %edx
movl -0x14(%rbp), %ecx
shll $0x8, %ecx
addl %ecx, %edx
addl -0x18(%rbp), %edx
movq 0x2c8(%rax), %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x47d3
jmp 0x4839
movq 0x4770(%rip), %rax      # 0x8fb0
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x1be6(%rip), %rsi      # 0x6434
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x4750(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x298(%rax), %edx
leaq 0x1cb3(%rip), %rsi      # 0x6523
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x472e(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x29c(%rax), %edx
leaq 0x1cb5(%rip), %rsi      # 0x6547
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x470c(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2a0(%rax), %edx
leaq 0x1cb7(%rip), %rsi      # 0x656b
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x46ea(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2a4(%rax), %edx
leaq 0x1cb9(%rip), %rsi      # 0x658f
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x46c8(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2a8(%rax), %edx
leaq 0x1cbb(%rip), %rsi      # 0x65b3
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rdx
movq 0x46a6(%rip), %rax      # 0x8fb0
movq (%rax), %rdi
addq $0x298, %rdx            # imm = 0x298
addq $0x14, %rdx
leaq 0x1cb8(%rip), %rsi      # 0x65d7
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x467f(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2b4(%rax), %edx
leaq 0x1cba(%rip), %rsi      # 0x65fb
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x465d(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2b8(%rax), %edx
leaq 0x1cbc(%rip), %rsi      # 0x661f
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x463b(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2bc(%rax), %edx
leaq 0x1cbe(%rip), %rsi      # 0x6643
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x4619(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2c0(%rax), %edx
leaq 0x1cc0(%rip), %rsi      # 0x6667
movb $0x0, %al
callq 0x2360
movq -0x40(%rbp), %rax
movq 0x45f7(%rip), %rcx      # 0x8fb0
movq (%rcx), %rdi
movl 0x2c4(%rax), %edx
leaq 0x1cc2(%rip), %rsi      # 0x668b
movb $0x0, %al
callq 0x2360
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)