// File: tomfunkhouser[P]gaps/apps/conf2img/conf2img.cpp
// Function: ReadConfiguration(char const*)
static int
ReadConfiguration(const char *filename) 
{
  // Start statistics
  RNTime start_time;
  start_time.Read();
  if (print_verbose) {
    printf("Reading configuration from %s ...\n", filename);
    fflush(stdout);
  }

  // Read file
  if (!configuration.ReadFile(filename, load_every_kth_image)) {
    RNFail("Unable to read configuration from %s\n", filename);
    return 0;
  }

#if 0
  // Read all channels ... for now
  if (!configuration.ReadChannels()) {
    RNFail("Unable to read channels for %s\n", filename);
    return 0;
  }
#endif

  // Set width and height
  if ((width == 0) || (height == 0)) {
    if (configuration.NImages() > 0) {
      RGBDImage *image0 = configuration.Image(0);
      if ((image0->NPixels(RN_X) == 0) || (image0->NPixels(RN_Y) == 0)) {
        image0->ReadColorChannels();
        image0->ReleaseColorChannels();
      }
      width = image0->NPixels(RN_X);
      height = image0->NPixels(RN_Y);
    }
  }

  // Double-check to make sure width and height are not zero
  if (width == 0) width = 1280;
  if (height == 0) height = 1024;
  
  // Print statistics
  if (print_verbose) {
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Images = %d\n", configuration.NImages());
    printf("  # Surfaces = %d\n", configuration.NSurfaces());
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x13fe80
leaq 0x8(%rsp), %rdi
callq 0x30490
cmpl $0x0, 0x22c224(%rip)    # 0x255d88
je 0x29b88
movq 0x18(%rsp), %rsi
leaq 0x1b5822(%rip), %rdi    # 0x1df394
movb $0x0, %al
callq 0x24090
movq 0x225410(%rip), %rax    # 0x24ef90
movq (%rax), %rdi
callq 0x24c10
movq 0x18(%rsp), %rsi
movl 0x225f1d(%rip), %edx    # 0x24fab0
leaq 0x22bfee(%rip), %rdi    # 0x255b88
callq 0x33f10
cmpl $0x0, %eax
jne 0x29bc4
movq 0x18(%rsp), %rsi
leaq 0x1b5807(%rip), %rdi    # 0x1df3b7
movb $0x0, %al
callq 0x144e00
movl $0x0, 0x24(%rsp)
jmp 0x29cf7
cmpl $0x0, 0x22c1d1(%rip)    # 0x255d9c
je 0x29bda
cmpl $0x0, 0x22c1cc(%rip)    # 0x255da0
jne 0x29c61
leaq 0x22bfa7(%rip), %rdi    # 0x255b88
callq 0x304b0
cmpl $0x0, %eax
jle 0x29c5f
leaq 0x22bf96(%rip), %rdi    # 0x255b88
xorl %esi, %esi
callq 0x304d0
movq %rax, (%rsp)
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x30500
cmpl $0x0, %eax
je 0x29c20
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x30500
cmpl $0x0, %eax
jne 0x29c3a
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x100(%rax)
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x150(%rax)
movq (%rsp), %rdi
xorl %esi, %esi
callq 0x30500
movl %eax, 0x22c151(%rip)    # 0x255d9c
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x30500
movl %eax, 0x22c141(%rip)    # 0x255da0
jmp 0x29c61
cmpl $0x0, 0x22c134(%rip)    # 0x255d9c
jne 0x29c74
movl $0x500, 0x22c128(%rip)  # imm = 0x500
cmpl $0x0, 0x22c125(%rip)    # 0x255da0
jne 0x29c87
movl $0x400, 0x22c119(%rip)  # imm = 0x400
cmpl $0x0, 0x22c0fa(%rip)    # 0x255d88
je 0x29cef
leaq 0x8(%rsp), %rdi
callq 0x13ff40
leaq 0x1b573c(%rip), %rdi    # 0x1df3dd
movb $0x1, %al
callq 0x24090
leaq 0x22bed9(%rip), %rdi    # 0x255b88
callq 0x304b0
movl %eax, %esi
leaq 0x1b5737(%rip), %rdi    # 0x1df3f4
movb $0x0, %al
callq 0x24090
leaq 0x22bebd(%rip), %rdi    # 0x255b88
callq 0x30540
movl %eax, %esi
leaq 0x1b572c(%rip), %rdi    # 0x1df405
movb $0x0, %al
callq 0x24090
movq 0x2252a9(%rip), %rax    # 0x24ef90
movq (%rax), %rdi
callq 0x24c10
movl $0x1, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq