// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::R2Grid(gaps::R2Image const&, int)
R2Grid::
R2Grid(const R2Image& image, int dummy)
  : grid_values(NULL)
{
  // Determine grid resolution
  grid_resolution[0] = image.Width();
  grid_resolution[1] = image.Height();
  grid_row_size = grid_resolution[0];
  grid_size = grid_row_size * grid_resolution[1];

  // Allocate grid values
  if (grid_size <= 0) grid_values = NULL;
  else grid_values = new RNScalar [ grid_size ];
  assert(!grid_size || grid_values);

  // Copy grid values
  for (int j = 0; j < grid_resolution[1]; j++) {
    for (int i = 0; i < grid_resolution[0]; i++) {
      RNRgb rgb = image.PixelRGB(i, j);
      SetGridValue(i, j, rgb.Luminance());
    }
  }

  // Set transformations
  grid_to_world_transform = R2identity_affine;
  world_to_grid_transform = R2identity_affine;
  world_to_grid_scale_factor = 1.0;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl %edx, 0x74(%rsp)
movq 0x80(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq %rdi, %rax
movq %rax, 0x28(%rsp)
callq 0xbed00
movq 0x30(%rsp), %rdi
addq $0x58, %rdi
movq %rdi, 0x38(%rsp)
callq 0xbed00
jmp 0xa7487
movq 0x28(%rsp), %rax
movq $0x0, 0xb8(%rax)
movq 0x78(%rsp), %rdi
callq 0xb93b0
movl %eax, 0x24(%rsp)
jmp 0xa74a7
movq 0x28(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, 0xc0(%rax)
movq 0x78(%rsp), %rdi
callq 0xb93c0
movl %eax, 0x20(%rsp)
jmp 0xa74c6
movq 0x28(%rsp), %rax
movl 0x20(%rsp), %ecx
movl %ecx, 0xc4(%rax)
movl 0xc0(%rax), %ecx
movl %ecx, 0xc8(%rax)
movl 0xc8(%rax), %ecx
imull 0xc4(%rax), %ecx
movl %ecx, 0xcc(%rax)
cmpl $0x0, 0xcc(%rax)
jg 0xa753f
movq 0x28(%rsp), %rax
movq $0x0, 0xb8(%rax)
jmp 0xa757e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
jmp 0xa7671
movq 0x38(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
callq 0xb9250
jmp 0xa7671
movq 0x28(%rsp), %rax
movslq 0xcc(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0xf030
movq %rax, 0x18(%rsp)
jmp 0xa756d
movq 0x28(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0xb8(%rax)
movl $0x0, 0x60(%rsp)
movq 0x28(%rsp), %rcx
movl 0x60(%rsp), %eax
cmpl 0xc4(%rcx), %eax
jge 0xa762a
movl $0x0, 0x5c(%rsp)
movq 0x28(%rsp), %rcx
movl 0x5c(%rsp), %eax
cmpl 0xc0(%rcx), %eax
jge 0xa7618
movq 0x78(%rsp), %rsi
movl 0x5c(%rsp), %edx
movl 0x60(%rsp), %ecx
leaq 0x40(%rsp), %rdi
callq 0xc5560
jmp 0xa75cd
movl 0x5c(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x40(%rsp), %rdi
callq 0xb93d0
movsd %xmm0, 0x10(%rsp)
jmp 0xa75ef
movsd 0x10(%rsp), %xmm0
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %esi
movq 0x28(%rsp), %rdi
callq 0x6bc00
jmp 0xa7609
jmp 0xa760b
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0xa75a3
jmp 0xa761a
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xa7586
movq 0x28(%rsp), %rdi
leaq 0x4d3432(%rip), %rsi    # 0x57aa68
callq 0xb9200
jmp 0xa763d
movq 0x28(%rsp), %rdi
addq $0x58, %rdi
leaq 0x4d341b(%rip), %rsi    # 0x57aa68
callq 0xb9200
jmp 0xa7654
movq 0x28(%rsp), %rax
movsd 0x8b9a7(%rip), %xmm0    # 0x133008
movsd %xmm0, 0xb0(%rax)
addq $0x88, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0xb9250
movq 0x68(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)