// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jdcolor.c
// Function: jinit_color_deconverter
GLOBAL(void)
jinit_color_deconverter (j_decompress_ptr cinfo)
{
  my_cconvert_ptr cconvert;
  int ci;

  cconvert = (my_cconvert_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_color_deconverter));
  cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  cconvert->pub.start_pass = start_pass_dcolor;

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

  case JCS_RGB:
  case JCS_YCbCr:
    if (cinfo->num_components != 3)
      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    break;

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

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

  /* Set out_color_components and conversion method based on requested space.
   * Also clear the component_needed flags for any unused components,
   * so that earlier pipeline stages can avoid useless computation.
   */

  switch (cinfo->out_color_space) {
  case JCS_GRAYSCALE:
    cinfo->out_color_components = 1;
    if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
	cinfo->jpeg_color_space == JCS_YCbCr) {
      cconvert->pub.color_convert = grayscale_convert;
      /* For color->grayscale conversion, only the Y (0) component is needed */
      for (ci = 1; ci < cinfo->num_components; ci++)
	cinfo->comp_info[ci].component_needed = FALSE;
    } else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_RGB:
    cinfo->out_color_components = RGB_PIXELSIZE;
    if (cinfo->jpeg_color_space == JCS_YCbCr) {
      cconvert->pub.color_convert = ycc_rgb_convert;
      build_ycc_rgb_table(cinfo);
    } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
      cconvert->pub.color_convert = gray_rgb_convert;
    } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
      cconvert->pub.color_convert = null_convert;
    } else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  case JCS_CMYK:
    cinfo->out_color_components = 4;
    if (cinfo->jpeg_color_space == JCS_YCCK) {
      cconvert->pub.color_convert = ycck_cmyk_convert;
      build_ycc_rgb_table(cinfo);
    } else if (cinfo->jpeg_color_space == JCS_CMYK) {
      cconvert->pub.color_convert = null_convert;
    } else
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;

  default:
    /* Permit null conversion to same output space */
    if (cinfo->out_color_space == cinfo->jpeg_color_space) {
      cinfo->out_color_components = cinfo->num_components;
      cconvert->pub.color_convert = null_convert;
    } else			/* unsupported non-null conversion */
      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
    break;
  }

  if (cinfo->quantize_colors)
    cinfo->output_components = 1; /* single colormapped output component */
  else
    cinfo->output_components = cinfo->out_color_components;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %rax
pushq $0x1
popq %rbp
pushq $0x30
popq %rdx
movl %ebp, %esi
callq *(%rax)
movq %rax, %r14
movq %rax, 0x268(%rbx)
leaq 0x161(%rip), %rax       # 0x769fb
movq %rax, (%r14)
movl 0x3c(%rbx), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jb 0x768bc
leal -0x4(%rax), %ecx
cmpl $0x2, %ecx
jae 0x76938
cmpl $0x4, 0x38(%rbx)
jne 0x768c2
jmp 0x768d1
cmpl $0x3, 0x38(%rbx)
je 0x768d1
movq (%rbx), %rax
movl $0xa, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
movl 0x40(%rbx), %eax
cmpl $0x4, %eax
je 0x76976
cmpl $0x2, %eax
je 0x7694d
cmpl $0x1, %eax
jne 0x769a2
movl $0x1, 0x90(%rbx)
movl 0x3c(%rbx), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x769bd
leaq 0xf1(%rip), %rax        # 0x769fc
movq %rax, 0x8(%r14)
movslq 0x38(%rbx), %rax
pushq $0x1
popq %rcx
movl $0x90, %edx
cmpq %rax, %rcx
jge 0x769cc
movq 0x130(%rbx), %rsi
andl $0x0, (%rsi,%rdx)
incq %rcx
addq $0x60, %rdx
jmp 0x7691b
cmpl $0x1, %eax
jne 0x769e3
cmpl $0x1, 0x38(%rbx)
jne 0x768c2
jmp 0x768d1
movl $0x3, 0x90(%rbx)
movl 0x3c(%rbx), %eax
cmpl $0x1, %eax
je 0x769f2
cmpl $0x2, %eax
je 0x769b0
cmpl $0x3, %eax
jne 0x769bd
leaq 0xa1(%rip), %rax        # 0x76a15
jmp 0x76994
movl $0x4, 0x90(%rbx)
movl 0x3c(%rbx), %eax
cmpl $0x4, %eax
je 0x769b0
cmpl $0x5, %eax
jne 0x769bd
leaq 0x2ea(%rip), %rax       # 0x76c7e
movq %rax, 0x8(%r14)
movq %rbx, %rdi
callq 0x76afd
jmp 0x769cc
cmpl 0x3c(%rbx), %eax
jne 0x769bd
movl 0x38(%rbx), %eax
movl %eax, 0x90(%rbx)
leaq 0x262(%rip), %rax       # 0x76c19
movq %rax, 0x8(%r14)
jmp 0x769cc
movq (%rbx), %rax
movl $0x1b, 0x28(%rax)
movq %rbx, %rdi
callq *(%rax)
cmpl $0x0, 0x6c(%rbx)
jne 0x769d8
movl 0x90(%rbx), %ebp
movl %ebp, 0x94(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
cmpl $0x0, 0x38(%rbx)
jg 0x768d1
jmp 0x768c2
leaq 0x1d8(%rip), %rax       # 0x76bd1
jmp 0x769b7