// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x8(%rdi), %rax
pushq $0x1
popq %rsi
pushq $0x18
popq %rdx
callq *(%rax)
movq %rax, %rbx
movq %rax, 0x1d8(%r14)
leaq 0x1cc(%rip), %rax       # 0x6b7a4
movq %rax, (%rbx)
movl 0x3c(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jb 0x6b5f8
leal -0x4(%rax), %ecx
cmpl $0x2, %ecx
jae 0x6b66b
cmpl $0x4, 0x38(%r14)
jne 0x6b5ff
jmp 0x6b60e
cmpl $0x3, 0x38(%r14)
je 0x6b60e
movq (%r14), %rax
movl $0x9, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x50(%r14), %ecx
leal -0x1(%rcx), %eax
cmpl $0x4, %eax
ja 0x6b75f
leaq 0x2fe1b(%rip), %rcx     # 0x9b440
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x4c(%r14)
je 0x6b644
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x3, %eax
je 0x6b65f
cmpl $0x2, %eax
je 0x6b791
cmpl $0x1, %eax
jne 0x6b749
leaq 0x13f(%rip), %rax       # 0x6b7a5
jmp 0x6b785
cmpl $0x1, %eax
jne 0x6b71c
cmpl $0x1, 0x38(%r14)
jne 0x6b5ff
jmp 0x6b60e
cmpl $0x4, 0x4c(%r14)
je 0x6b693
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x5, %eax
je 0x6b77e
cmpl $0x4, %eax
jne 0x6b749
leaq 0x133(%rip), %rax       # 0x6b7e3
movq %rax, (%rbx)
leaq 0x381(%rip), %rax       # 0x6ba3b
jmp 0x6b785
cmpl $0x3, 0x4c(%r14)
je 0x6b6d5
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
movl 0x3c(%r14), %eax
cmpl $0x3, %eax
je 0x6b77e
cmpl $0x2, %eax
jne 0x6b749
leaq 0xf5(%rip), %rax        # 0x6b7e3
movq %rax, (%rbx)
leaq 0x275(%rip), %rax       # 0x6b96d
jmp 0x6b785
cmpl $0x4, 0x4c(%r14)
je 0x6b713
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
cmpl $0x4, 0x3c(%r14)
jne 0x6b749
jmp 0x6b77e
cmpl $0x0, 0x38(%r14)
jg 0x6b60e
jmp 0x6b5ff
cmpl $0x3, 0x4c(%r14)
je 0x6b742
movq (%r14), %rax
movl $0xa, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
cmpl $0x2, 0x3c(%r14)
je 0x6b77e
movq (%r14), %rax
movl $0x1b, 0x28(%rax)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *(%rax)
cmpl 0x3c(%r14), %ecx
jne 0x6b76f
movl 0x4c(%r14), %eax
cmpl 0x38(%r14), %eax
je 0x6b77e
movq (%r14), %rax
movl $0x1b, 0x28(%rax)
movq %r14, %rdi
callq *(%rax)
leaq 0x186(%rip), %rax       # 0x6b90b
movq %rax, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x4b(%rip), %rax        # 0x6b7e3
movq %rax, (%rbx)
leaq 0xf8(%rip), %rax        # 0x6b89a
jmp 0x6b785