// File: tomfunkhouser[P]gaps/pkgs/RGBD/RGBDImage.cpp
// Function: gaps::RGBDImage::WriteDepthChannel()
int RGBDImage::
WriteDepthChannel(void)
{
  // Check filename
  if (!depth_filename) return 0;
  if (NChannels() <= RGBD_DEPTH_CHANNEL) return 0;

  // Get full filename
  char full_filename[4096];
  const char *dirname = (configuration) ? configuration->DepthDirectory() : NULL;
  if (dirname) sprintf(full_filename, "%s/%s", dirname, depth_filename);
  else sprintf(full_filename, "%s", depth_filename);
  
  // Get depth image  
  R2Grid depth_image(*(channels[RGBD_DEPTH_CHANNEL]));
  if (strstr(depth_filename, ".png")) {
    depth_image.Multiply(1000.0);
    if (configuration && configuration->DatasetFormat()) {
      if (!strcmp(configuration->DatasetFormat(), "matterport")) {
        depth_image.Multiply(4);
      }
      else if (!strcmp(configuration->DatasetFormat(), "tum")) {
        depth_image.Multiply(5);
      }
    }
  }
    
  // Write depth image  
  if (!depth_image.WriteFile(depth_filename)) return 0;

  // Return success
  return 1;
}

// Assembly:
subq $0x1138, %rsp           # imm = 0x1138
movq %rdi, 0x1128(%rsp)
movq 0x1128(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x1e0(%rax)
jne 0x2e706
movl $0x0, 0x1134(%rsp)
jmp 0x2e93b
movq 0x30(%rsp), %rdi
callq 0x30430
cmpl $0x3, %eax
jg 0x2e725
movl $0x0, 0x1134(%rsp)
jmp 0x2e93b
movq 0x30(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2e746
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x30730
movq %rax, 0x28(%rsp)
jmp 0x2e74f
xorl %eax, %eax
movq %rax, 0x28(%rsp)
jmp 0x2e74f
movq 0x28(%rsp), %rax
movq %rax, 0x118(%rsp)
cmpq $0x0, 0x118(%rsp)
je 0x2e793
movq 0x30(%rsp), %rax
leaq 0x120(%rsp), %rdi
movq 0x118(%rsp), %rdx
movq 0x1e0(%rax), %rcx
leaq 0x1387d9(%rip), %rsi    # 0x166f63
movb $0x0, %al
callq 0x12130
jmp 0x2e7b5
movq 0x30(%rsp), %rax
leaq 0x120(%rsp), %rdi
movq 0x1e0(%rax), %rdx
leaq 0x13a95d(%rip), %rsi    # 0x16910b
movb $0x0, %al
callq 0x12130
movq 0x30(%rsp), %rdi
addq $0x18, %rdi
movl $0x3, %esi
callq 0x277c0
movq (%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0xb30a0
movq 0x30(%rsp), %rax
movq 0x1e0(%rax), %rdi
leaq 0x13843c(%rip), %rsi    # 0x166c24
callq 0x12160
cmpq $0x0, %rax
je 0x2e8e4
leaq 0x48(%rsp), %rdi
movsd 0x13882c(%rip), %xmm0   # 0x167030
callq 0xba480
jmp 0x2e80b
movq 0x30(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x2e8e2
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x225c0
movq %rax, 0x20(%rsp)
jmp 0x2e830
movq 0x20(%rsp), %rax
cmpq $0x0, %rax
je 0x2e8e2
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x225c0
movq %rax, 0x18(%rsp)
jmp 0x2e854
movq 0x18(%rsp), %rdi
leaq 0x137ede(%rip), %rsi    # 0x16673e
callq 0x12a00
cmpl $0x0, %eax
jne 0x2e89d
leaq 0x48(%rsp), %rdi
movsd 0x1387c1(%rip), %xmm0   # 0x167038
callq 0xba480
jmp 0x2e87e
jmp 0x2e8e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xb3390
jmp 0x2e94a
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x225c0
movq %rax, 0x10(%rsp)
jmp 0x2e8b2
movq 0x10(%rsp), %rdi
leaq 0x1388c0(%rip), %rsi    # 0x16717e
callq 0x12a00
cmpl $0x0, %eax
jne 0x2e8de
leaq 0x48(%rsp), %rdi
movsd 0x13876b(%rip), %xmm0   # 0x167040
callq 0xba480
jmp 0x2e8dc
jmp 0x2e8de
jmp 0x2e8e0
jmp 0x2e8e2
jmp 0x2e8e4
movq 0x30(%rsp), %rax
movq 0x1e0(%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0xc33a0
movl %eax, 0xc(%rsp)
jmp 0x2e900
movl 0xc(%rsp), %eax
cmpl $0x0, %eax
jne 0x2e91e
movl $0x0, 0x1134(%rsp)
movl $0x1, 0x38(%rsp)
jmp 0x2e931
movl $0x1, 0x1134(%rsp)
movl $0x1, 0x38(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xb3390
movl 0x1134(%rsp), %eax
addq $0x1138, %rsp           # imm = 0x1138
retq
movq 0x40(%rsp), %rdi
callq 0x12c20
nopw %cs:(%rax,%rax)