// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVImage.cpp
// Function: gaps::GSVImage::DistortedImage() const
R2Image *GSVImage::
DistortedImage(void) const
{
  // Get convenient variables
  int image_index = PanoramaIndex();
  GSVPanorama *panorama = Panorama();
  if (!panorama) return NULL;
  int panorama_index = panorama->RunIndex();
  GSVSegment *segment = panorama->Segment();
  if (!segment) return NULL;
  int segment_index = segment->RunIndex();
  GSVRun *run = segment->Run();
  if (!run) return NULL;
  GSVScene *scene = run->Scene();
  if (!scene) return NULL;
  char run_name[1024];
  if (run->Name()) sprintf(run_name, "%s", run->Name());
  else sprintf(run_name, "Run%d", run->SceneIndex());
  const char *raw_data_directory = scene->RawDataDirectoryName();
  if (!raw_data_directory) return NULL;
  
  // Construct distorted image name
  char distorted_image_name[4096];
  sprintf(distorted_image_name, "%s/%s/segment_%02d/unstitched_%06d_%02d.jpg", 
    raw_data_directory, run_name, segment_index, panorama_index, image_index);
    
  // Allocate distorted image
  R2Image *distorted_image = new R2Image();
  if (!distorted_image) {
    RNFail("Unable to allocate image for %s\n", distorted_image_name);
    return NULL;
  }

  // Read distorted image
  if (!distorted_image->Read(distorted_image_name)) {
    RNFail("Unable to read distorted image %s\n", distorted_image_name);
    delete distorted_image;
    return NULL;
  }

  // Return distorted image
  return distorted_image;
}

// Assembly:
subq $0x14a8, %rsp           # imm = 0x14A8
movq %rdi, 0x1498(%rsp)
movq 0x1498(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x51890
movq 0x30(%rsp), %rdi
movl %eax, 0x1494(%rsp)
callq 0x518a0
movq %rax, 0x1488(%rsp)
cmpq $0x0, 0x1488(%rsp)
jne 0x4fd96
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x1488(%rsp), %rdi
callq 0x4e7b0
movl %eax, 0x1484(%rsp)
movq 0x1488(%rsp), %rdi
callq 0x47d30
movq %rax, 0x1478(%rsp)
cmpq $0x0, 0x1478(%rsp)
jne 0x4fddb
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x1478(%rsp), %rdi
callq 0x4a640
movl %eax, 0x1474(%rsp)
movq 0x1478(%rsp), %rdi
callq 0x4f380
movq %rax, 0x1468(%rsp)
cmpq $0x0, 0x1468(%rsp)
jne 0x4fe20
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x1468(%rsp), %rdi
callq 0x4a630
movq %rax, 0x1460(%rsp)
cmpq $0x0, 0x1460(%rsp)
jne 0x4fe51
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x1468(%rsp), %rdi
callq 0x44310
cmpq $0x0, %rax
je 0x4fe96
leaq 0x1060(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x1468(%rsp), %rdi
callq 0x44310
movq 0x28(%rsp), %rdi
movq %rax, %rdx
leaq 0x23039a(%rip), %rsi    # 0x280227
movb $0x0, %al
callq 0x2a280
jmp 0x4fec5
leaq 0x1060(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x1468(%rsp), %rdi
callq 0x443f0
movq 0x20(%rsp), %rdi
movl %eax, %edx
leaq 0x216c91(%rip), %rsi    # 0x266b4f
movb $0x0, %al
callq 0x2a280
movq 0x1460(%rsp), %rdi
callq 0x47cf0
movq %rax, 0x1058(%rsp)
cmpq $0x0, 0x1058(%rsp)
jne 0x4fef6
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x1058(%rsp), %rdx
movl 0x1474(%rsp), %r8d
movl 0x1484(%rsp), %r9d
movl 0x1494(%rsp), %ecx
movq %rsp, %rax
movl %ecx, (%rax)
leaq 0x217170(%rip), %rsi    # 0x267091
xorl %eax, %eax
leaq 0x50(%rsp), %rdi
leaq 0x1060(%rsp), %rcx
callq 0x2a280
movl $0x18, %edi
callq 0x292e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x1bb3c0
jmp 0x4ff51
movq 0x18(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x4ffa6
leaq 0x50(%rsp), %rsi
leaq 0x21714e(%rip), %rdi    # 0x2670bd
movb $0x0, %al
callq 0x1cbff0
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl $0x18, %esi
callq 0x291f0
jmp 0x50021
movq 0x48(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x518b0
cmpl $0x0, %eax
jne 0x50004
leaq 0x50(%rsp), %rsi
leaq 0x217118(%rip), %rdi    # 0x2670de
movb $0x0, %al
callq 0x1cbff0
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x4fff6
movq 0x10(%rsp), %rdi
callq 0x1bbe10
movq 0x10(%rsp), %rdi
movl $0x18, %esi
callq 0x291f0
movq $0x0, 0x14a0(%rsp)
jmp 0x50011
movq 0x48(%rsp), %rax
movq %rax, 0x14a0(%rsp)
movq 0x14a0(%rsp), %rax
addq $0x14a8, %rsp           # imm = 0x14A8
retq
movq 0x40(%rsp), %rdi
callq 0x29c10
nopl (%rax,%rax)