// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: ReadGSVImageFiles(gaps::GSVScene*, double, double)
static int
ReadGSVImageFiles(GSVScene *scene,
  double depth_scale, double depth_exponent)
{
  // Check image directory
  if (!image_directory) return 1;

  // Start statistics
  RNTime start_time;
  start_time.Read();
  int color_image_count = 0;
  int depth_image_count = 0;
  int category_image_count = 0;
  int instance_image_count = 0;
  int ray_image_count = 0;
  
  // Read data for all images
  for (int ir = 0; ir < scene->NRuns(); ir++) {
    GSVRun *run = scene->Run(ir);
    for (int is = 0; is < run->NSegments(); is++) {
      GSVSegment *segment = run->Segment(is);
      for (int ip = 0; ip < segment->NPanoramas(); ip++) {
        GSVPanorama *panorama = segment->Panorama(ip);
        for (int ii = 0; ii < panorama->NImages(); ii++) {
          GSVImage *image = panorama->Image(ii);
          if (!image->Name()) continue;

          // Read images
          ImageData *data = ReadImageFiles(image->Name(), depth_scale, depth_exponent);
          if (!data) {
            RNFail("Unable to read images for %s\n", image->Name());
            return 0;
          }

          // Associate data with image
          image->SetData(data);

          // Update statistics
          if (data->color_image.Width() > 0) color_image_count++;
          if (data->depth_image.NEntries() > 0) depth_image_count++;
          if (data->category_image.NEntries() > 0) category_image_count++;
          if (data->instance_image.NEntries() > 0) instance_image_count++;
          if (data->ray_origin_images[0].NEntries() > 0) ray_image_count++;
          if (data->ray_origin_images[1].NEntries() > 0) ray_image_count++;
          if (data->ray_origin_images[2].NEntries() > 0) ray_image_count++;
          if (data->ray_direction_images[0].NEntries() > 0) ray_image_count++;
          if (data->ray_direction_images[1].NEntries() > 0) ray_image_count++;
          if (data->ray_direction_images[2].NEntries() > 0) ray_image_count++;
        }
      }
    }
  }

  // Print statistics
  if (print_verbose) {
    printf("Read GSV images from %s ...\n", image_directory);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Color Images = %d\n", color_image_count);
    printf("  # Depth Images = %d\n", depth_image_count);
    printf("  # Category Images = %d\n", category_image_count);
    printf("  # Instance Images = %d\n", instance_image_count);
    printf("  # Ray Images = %d\n", ray_image_count);
    fflush(stdout);
  }

  // Return success
  return 1;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movsd %xmm0, 0x80(%rsp)
movsd %xmm1, 0x78(%rsp)
cmpq $0x0, 0x2c7452(%rip)    # 0x2fef28
jne 0x37ae8
movl $0x1, 0x94(%rsp)
jmp 0x37ee3
leaq 0x68(%rsp), %rdi
callq 0x1c7070
leaq 0x68(%rsp), %rdi
callq 0x38bc0
movl $0x0, 0x64(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x88(%rsp), %rdi
callq 0x39f90
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x37e35
movq 0x88(%rsp), %rdi
movl 0x50(%rsp), %esi
callq 0x39fb0
movq %rax, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x48(%rsp), %rdi
callq 0x39fe0
movl %eax, %ecx
movl 0x8(%rsp), %eax
cmpl %ecx, %eax
jge 0x37e23
movq 0x48(%rsp), %rdi
movl 0x44(%rsp), %esi
callq 0x3a000
movq %rax, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x38(%rsp), %rdi
callq 0x3a290
movl %eax, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x37e11
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x3a2b0
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movl %eax, (%rsp)
movq 0x28(%rsp), %rdi
callq 0x3a2e0
movl %eax, %ecx
movl (%rsp), %eax
cmpl %ecx, %eax
jge 0x37dff
movq 0x28(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x3a300
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x3ae10
cmpq $0x0, %rax
jne 0x37c29
jmp 0x37def
movq 0x18(%rsp), %rdi
callq 0x3ae10
movq %rax, %rdi
movsd 0x80(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
callq 0x37f00
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x37c82
movq 0x18(%rsp), %rdi
callq 0x3ae10
movq %rax, %rsi
leaq 0x22ec17(%rip), %rdi    # 0x266882
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x94(%rsp)
jmp 0x37ee3
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3ae30
movq 0x10(%rsp), %rdi
callq 0x39d10
cmpl $0x0, %eax
jle 0x37cab
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
movq 0x10(%rsp), %rdi
addq $0x18, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37cc9
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
movq 0x10(%rsp), %rdi
addq $0xe8, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37cea
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movq 0x10(%rsp), %rdi
addq $0x1b8, %rdi            # imm = 0x1B8
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37d0b
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
movq 0x10(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37d2c
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x10(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
addq $0xd0, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37d54
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x10(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37d7c
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x10(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37d9d
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x10(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
addq $0xd0, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37dc5
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
movq 0x10(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37ded
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x37def
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x37be3
jmp 0x37e01
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x37ba8
jmp 0x37e13
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x37b6d
jmp 0x37e25
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x37b2c
cmpl $0x0, 0x2c6e80(%rip)    # 0x2fecbc
je 0x37ed8
movq 0x2c70df(%rip), %rsi    # 0x2fef28
leaq 0x22ea50(%rip), %rdi    # 0x2668a0
movb $0x0, %al
callq 0x290f0
leaq 0x68(%rsp), %rdi
callq 0x1c7130
leaq 0x22e560(%rip), %rdi    # 0x2663c8
movb $0x1, %al
callq 0x290f0
movl 0x64(%rsp), %esi
leaq 0x22ea43(%rip), %rdi    # 0x2668bd
movb $0x0, %al
callq 0x290f0
movl 0x60(%rsp), %esi
leaq 0x22ea48(%rip), %rdi    # 0x2668d4
movb $0x0, %al
callq 0x290f0
movl 0x5c(%rsp), %esi
leaq 0x22ea4d(%rip), %rdi    # 0x2668eb
movb $0x0, %al
callq 0x290f0
movl 0x58(%rsp), %esi
leaq 0x22ea55(%rip), %rdi    # 0x266905
movb $0x0, %al
callq 0x290f0
movl 0x54(%rsp), %esi
leaq 0x22ea5d(%rip), %rdi    # 0x26691f
movb $0x0, %al
callq 0x290f0
movq 0x2b70f8(%rip), %rax    # 0x2eefc8
movq (%rax), %rdi
callq 0x29910
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)