// File: tomfunkhouser[P]gaps/pkgs/jpeg/jccolor.c
// Function: jinit_color_converter
GLOBAL(void)
jinit_color_converter (j_compress_ptr cinfo)
{
  my_cconvert_ptr cconvert;

  cconvert = (my_cconvert_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_color_converter));
  cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  /* set start_pass to null method until we find out differently */
  cconvert->pub.start_pass = null_method;

  /* Make sure input_components agrees with in_color_space */
  switch (cinfo->in_color_space) {
  case JCS_GRAYSCALE:
    if (cinfo->input_components != 1)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;

  case JCS_RGB:
#if RGB_PIXELSIZE != 3
    if (cinfo->input_components != RGB_PIXELSIZE)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;
#endif /* else share code with YCbCr */

  case JCS_YCbCr:
    if (cinfo->input_components != 3)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;

  case JCS_CMYK:
  case JCS_YCCK:
    if (cinfo->input_components != 4)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;

  default:			/* JCS_UNKNOWN can be anything */
    if (cinfo->input_components < 1)
      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
    break;
  }

  /* Check num_components, set conversion method based on requested space */
  switch (cinfo->jpeg_color_space) {
  case JCS_GRAYSCALE:
    if (cinfo->num_components != 1)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_GRAYSCALE)
      cconvert->pub.color_convert = grayscale_convert;
    else if (cinfo->in_color_space == JCS_RGB) {
      cconvert->pub.start_pass = rgb_ycc_start;
      cconvert->pub.color_convert = rgb_gray_convert;
    } else if (cinfo->in_color_space == JCS_YCbCr)
      cconvert->pub.color_convert = grayscale_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_RGB:
    if (cinfo->num_components != 3)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_YCbCr:
    if (cinfo->num_components != 3)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_RGB) {
      cconvert->pub.start_pass = rgb_ycc_start;
      cconvert->pub.color_convert = rgb_ycc_convert;
    } else if (cinfo->in_color_space == JCS_YCbCr)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_CMYK:
    if (cinfo->num_components != 4)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_CMYK)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_YCCK:
    if (cinfo->num_components != 4)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    if (cinfo->in_color_space == JCS_CMYK) {
      cconvert->pub.start_pass = rgb_ycc_start;
      cconvert->pub.color_convert = cmyk_ycck_convert;
    } else if (cinfo->in_color_space == JCS_YCCK)
      cconvert->pub.color_convert = null_convert;
    else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  default:			/* allow null conversion of JCS_UNKNOWN */
    if (cinfo->jpeg_color_space != cinfo->in_color_space ||
	cinfo->num_components != cinfo->input_components)
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    cconvert->pub.color_convert = null_convert;
    break;
  }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rax
movq (%rax), %rax
movl $0x1, %esi
movl $0x18, %edx
callq *%rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x1d8(%rax)
movq 0x18(%rsp), %rax
leaq 0x44d(%rip), %rcx       # 0xdb960
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x14(%rsp)
subl $0x1, %eax
je 0xdb548
jmp 0xdb529
movl 0x14(%rsp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0xdb579
jmp 0xdb537
movl 0x14(%rsp), %eax
addl $-0x4, %eax
subl $0x2, %eax
jb 0xdb5a7
jmp 0xdb5d5
movq 0x20(%rsp), %rax
cmpl $0x1, 0x38(%rax)
je 0xdb574
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x9, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb603
movq 0x20(%rsp), %rax
cmpl $0x3, 0x38(%rax)
je 0xdb5a5
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x9, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb603
movq 0x20(%rsp), %rax
cmpl $0x4, 0x38(%rax)
je 0xdb5d3
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x9, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb603
movq 0x20(%rsp), %rax
cmpl $0x1, 0x38(%rax)
jge 0xdb601
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x9, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb603
movq 0x20(%rsp), %rax
movl 0x50(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x4, %eax
ja 0xdb903
movq 0x8(%rsp), %rax
leaq 0x5b71b(%rip), %rcx     # 0x136d44
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %rax
cmpl $0x1, 0x4c(%rax)
je 0xdb65e
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xa, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0xdb67b
movq 0x18(%rsp), %rax
leaq 0x2fb(%rip), %rcx       # 0xdb970
movq %rcx, 0x8(%rax)
jmp 0xdb6e9
movq 0x20(%rsp), %rax
cmpl $0x2, 0x3c(%rax)
jne 0xdb6a7
movq 0x18(%rsp), %rax
leaq 0x3ae(%rip), %rcx       # 0xdba40
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
leaq 0x50f(%rip), %rcx       # 0xdbbb0
movq %rcx, 0x8(%rax)
jmp 0xdb6e7
movq 0x20(%rsp), %rax
cmpl $0x3, 0x3c(%rax)
jne 0xdb6c4
movq 0x18(%rsp), %rax
leaq 0x2b2(%rip), %rcx       # 0xdb970
movq %rcx, 0x8(%rax)
jmp 0xdb6e5
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb6e7
jmp 0xdb6e9
jmp 0xdb958
movq 0x20(%rsp), %rax
cmpl $0x3, 0x4c(%rax)
je 0xdb71a
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xa, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0x2, 0x3c(%rax)
jne 0xdb737
movq 0x18(%rsp), %rax
leaq 0x5cf(%rip), %rcx       # 0xdbd00
movq %rcx, 0x8(%rax)
jmp 0xdb758
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb958
movq 0x20(%rsp), %rax
cmpl $0x3, 0x4c(%rax)
je 0xdb789
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xa, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0x2, 0x3c(%rax)
jne 0xdb7b5
movq 0x18(%rsp), %rax
leaq 0x2a0(%rip), %rcx       # 0xdba40
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
leaq 0x651(%rip), %rcx       # 0xdbe00
movq %rcx, 0x8(%rax)
jmp 0xdb7f5
movq 0x20(%rsp), %rax
cmpl $0x3, 0x3c(%rax)
jne 0xdb7d2
movq 0x18(%rsp), %rax
leaq 0x534(%rip), %rcx       # 0xdbd00
movq %rcx, 0x8(%rax)
jmp 0xdb7f3
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb7f5
jmp 0xdb958
movq 0x20(%rsp), %rax
cmpl $0x4, 0x4c(%rax)
je 0xdb826
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xa, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0x4, 0x3c(%rax)
jne 0xdb843
movq 0x18(%rsp), %rax
leaq 0x4c3(%rip), %rcx       # 0xdbd00
movq %rcx, 0x8(%rax)
jmp 0xdb864
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb958
movq 0x20(%rsp), %rax
cmpl $0x4, 0x4c(%rax)
je 0xdb895
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0xa, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x20(%rsp), %rax
cmpl $0x4, 0x3c(%rax)
jne 0xdb8c1
movq 0x18(%rsp), %rax
leaq 0x194(%rip), %rcx       # 0xdba40
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
leaq 0x765(%rip), %rcx       # 0xdc020
movq %rcx, 0x8(%rax)
jmp 0xdb901
movq 0x20(%rsp), %rax
cmpl $0x5, 0x3c(%rax)
jne 0xdb8de
movq 0x18(%rsp), %rax
leaq 0x428(%rip), %rcx       # 0xdbd00
movq %rcx, 0x8(%rax)
jmp 0xdb8ff
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdb901
jmp 0xdb958
movq 0x20(%rsp), %rax
movl 0x50(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x3c(%rcx), %eax
jne 0xdb927
movq 0x20(%rsp), %rax
movl 0x4c(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x38(%rcx), %eax
je 0xdb948
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x1b, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movq 0x18(%rsp), %rax
leaq 0x3ac(%rip), %rcx       # 0xdbd00
movq %rcx, 0x8(%rax)
addq $0x28, %rsp
retq
nopl (%rax)