// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDSurface.cpp
// Function: gaps::RGBDSurface::WriteColorChannels()
int RGBDSurface::
WriteColorChannels(void)
{
  // Check filename
  if (NChannels() <= RGBD_BLUE_CHANNEL) return 0;

  // Create texture filename, if there is none
  if (!texture_filename) {
    char buffer[4096];
    sprintf(buffer, "t%06d.jpg", ConfigurationIndex());
    SetTextureFilename(buffer);
  }

  // Get full filename
  char full_filename[4096];
  const char *dirname = (configuration) ? configuration->TextureDirectory() : NULL;
  if (dirname) sprintf(full_filename, "%s/%s", dirname, texture_filename);
  else sprintf(full_filename, "%s", texture_filename);

  // Compute color image
  R2Image rgb_image(width, height, 3);
  for (int iy = 0; iy < height; iy++) {
    for (int ix = 0; ix < width; ix++) {
      RNRgb rgb = TexelColor(ix, iy);
      rgb_image.SetPixelRGB(ix, iy, rgb);
    }
  }

  // Write color image
  if (!rgb_image.Write(full_filename)) return 0;

  // Return success
  return 1;
}

// Assembly:
subq $0x2088, %rsp           # imm = 0x2088
movq %rdi, 0x2078(%rsp)
movq 0x2078(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x277e0
cmpl $0x2, %eax
jg 0x26546
movl $0x0, 0x2084(%rsp)
jmp 0x26716
movq 0x18(%rsp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x26594
movq 0x18(%rsp), %rdi
leaq 0x1070(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x27ee0
movq 0x10(%rsp), %rdi
movl %eax, %edx
leaq 0x140a29(%rip), %rsi    # 0x166fa0
movb $0x0, %al
callq 0x12130
movq 0x18(%rsp), %rdi
leaq 0x1070(%rsp), %rsi
movq (%rdi), %rax
callq *0xc0(%rax)
movq 0x18(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x265b5
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x19f60
movq %rax, 0x8(%rsp)
jmp 0x265be
xorl %eax, %eax
movq %rax, 0x8(%rsp)
jmp 0x265be
movq 0x8(%rsp), %rax
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x68(%rsp)
je 0x265f3
movq 0x18(%rsp), %rax
leaq 0x70(%rsp), %rdi
movq 0x68(%rsp), %rdx
movq 0x38(%rax), %rcx
leaq 0x140979(%rip), %rsi    # 0x166f63
movb $0x0, %al
callq 0x12130
jmp 0x2660f
movq 0x18(%rsp), %rax
leaq 0x70(%rsp), %rdi
movq 0x38(%rax), %rdx
leaq 0x142b03(%rip), %rsi    # 0x16910b
movb $0x0, %al
callq 0x12130
movq 0x18(%rsp), %rax
movl 0x28(%rax), %esi
movl 0x2c(%rax), %edx
leaq 0x50(%rsp), %rdi
movl $0x3, %ecx
callq 0xd1c40
movl $0x0, 0x4c(%rsp)
movq 0x18(%rsp), %rcx
movl 0x4c(%rsp), %eax
cmpl 0x2c(%rcx), %eax
jge 0x266c6
movl $0x0, 0x48(%rsp)
movq 0x18(%rsp), %rcx
movl 0x48(%rsp), %eax
cmpl 0x28(%rcx), %eax
jge 0x266b4
movq 0x18(%rsp), %rsi
movl 0x48(%rsp), %edx
movl 0x4c(%rsp), %ecx
leaq 0x30(%rsp), %rdi
callq 0x24520
jmp 0x26672
movl 0x48(%rsp), %esi
movl 0x4c(%rsp), %edx
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rcx
callq 0xd2490
jmp 0x2668b
jmp 0x2668d
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x2664b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xd2160
jmp 0x26725
jmp 0x266b6
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x26631
leaq 0x50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x27f80
movl %eax, 0x4(%rsp)
jmp 0x266db
movl 0x4(%rsp), %eax
cmpl $0x0, %eax
jne 0x266f9
movl $0x0, 0x2084(%rsp)
movl $0x1, 0x20(%rsp)
jmp 0x2670c
movl $0x1, 0x2084(%rsp)
movl $0x1, 0x20(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xd2160
movl 0x2084(%rsp), %eax
addq $0x2088, %rsp           # imm = 0x2088
retq
movq 0x28(%rsp), %rdi
callq 0x12c20
nop