// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: ReadSFLImageFiles(gaps::R3SurfelScene*, double, double)
static int
ReadSFLImageFiles(R3SurfelScene *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 all images
  for (int i = 0; i < scene->NImages(); i++) {
    R3SurfelImage *image = scene->Image(i);
    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 $0x68, %rsp
movq %rdi, 0x58(%rsp)
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, 0x48(%rsp)
cmpq $0x0, 0x2c79eb(%rip)    # 0x2fef28
jne 0x3754c
movl $0x1, 0x64(%rsp)
jmp 0x37857
leaq 0x38(%rsp), %rdi
callq 0x1c7070
leaq 0x38(%rsp), %rdi
callq 0x38bc0
movl $0x0, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x58(%rsp), %rdi
callq 0x39850
movl %eax, %ecx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x377ac
movq 0x58(%rsp), %rdi
movl 0x20(%rsp), %esi
callq 0x39870
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x3aa10
cmpq $0x0, %rax
jne 0x375d8
jmp 0x3779c
movq 0x18(%rsp), %rdi
callq 0x3aa10
movq %rax, %rdi
movsd 0x50(%rsp), %xmm0
movsd 0x48(%rsp), %xmm1
callq 0x37f00
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x3762b
movq 0x18(%rsp), %rdi
callq 0x3aa10
movq %rax, %rsi
leaq 0x22f26b(%rip), %rdi    # 0x266882
movb $0x0, %al
callq 0x1cbff0
movl $0x0, 0x64(%rsp)
jmp 0x37857
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq (%rdi), %rax
callq *0xe0(%rax)
movq 0x10(%rsp), %rdi
callq 0x39d10
cmpl $0x0, %eax
jle 0x37658
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movq 0x10(%rsp), %rdi
addq $0x18, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37676
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
movq 0x10(%rsp), %rdi
addq $0xe8, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37697
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movq 0x10(%rsp), %rdi
addq $0x1b8, %rdi            # imm = 0x1B8
callq 0x3aa30
cmpl $0x0, %eax
jle 0x376b8
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
movq 0x10(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
callq 0x3aa30
cmpl $0x0, %eax
jle 0x376d9
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
addq $0xd0, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37701
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
addq $0x288, %rdi            # imm = 0x288
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37729
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
callq 0x3aa30
cmpl $0x0, %eax
jle 0x3774a
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
addq $0xd0, %rdi
callq 0x3aa30
cmpl $0x0, %eax
jle 0x37772
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movq 0x10(%rsp), %rdi
addq $0x4f8, %rdi            # imm = 0x4F8
addq $0x1a0, %rdi            # imm = 0x1A0
callq 0x3aa30
cmpl $0x0, %eax
jle 0x3779a
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x3779c
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x37590
cmpl $0x0, 0x2c7509(%rip)    # 0x2fecbc
je 0x3784f
movq 0x2c7768(%rip), %rsi    # 0x2fef28
leaq 0x22f0d9(%rip), %rdi    # 0x2668a0
movb $0x0, %al
callq 0x290f0
leaq 0x38(%rsp), %rdi
callq 0x1c7130
leaq 0x22ebe9(%rip), %rdi    # 0x2663c8
movb $0x1, %al
callq 0x290f0
movl 0x34(%rsp), %esi
leaq 0x22f0cc(%rip), %rdi    # 0x2668bd
movb $0x0, %al
callq 0x290f0
movl 0x30(%rsp), %esi
leaq 0x22f0d1(%rip), %rdi    # 0x2668d4
movb $0x0, %al
callq 0x290f0
movl 0x2c(%rsp), %esi
leaq 0x22f0d6(%rip), %rdi    # 0x2668eb
movb $0x0, %al
callq 0x290f0
movl 0x28(%rsp), %esi
leaq 0x22f0de(%rip), %rdi    # 0x266905
movb $0x0, %al
callq 0x290f0
movl 0x24(%rsp), %esi
leaq 0x22f0e6(%rip), %rdi    # 0x26691f
movb $0x0, %al
callq 0x290f0
movq 0x2b7781(%rip), %rax    # 0x2eefc8
movq (%rax), %rdi
callq 0x29910
movl $0x1, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq