// File: 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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rax
movq (%rax), %rax
movl $0x1, %esi
movl $0x30, %edx
callq *%rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x268(%rax)
movq 0x18(%rsp), %rax
leaq 0x36d(%rip), %rcx       # 0xf3ac0
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movl 0x3c(%rax), %eax
movl %eax, 0x10(%rsp)
subl $0x1, %eax
je 0xf3788
jmp 0xf3769
movl 0x10(%rsp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0xf37b9
jmp 0xf3777
movl 0x10(%rsp), %eax
addl $-0x4, %eax
subl $0x2, %eax
jb 0xf37e7
jmp 0xf3815
movq 0x20(%rsp), %rax
cmpl $0x1, 0x38(%rax)
je 0xf37b4
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
jmp 0xf3843
movq 0x20(%rsp), %rax
cmpl $0x3, 0x38(%rax)
je 0xf37e5
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
jmp 0xf3843
movq 0x20(%rsp), %rax
cmpl $0x4, 0x38(%rax)
je 0xf3813
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
jmp 0xf3843
movq 0x20(%rsp), %rax
cmpl $0x1, 0x38(%rax)
jge 0xf3841
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
jmp 0xf3843
movq 0x20(%rsp), %rax
movl 0x40(%rax), %eax
movl %eax, 0xc(%rsp)
subl $0x1, %eax
je 0xf3877
jmp 0xf3856
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0xf3916
jmp 0xf3865
movl 0xc(%rsp), %eax
subl $0x4, %eax
je 0xf39b0
jmp 0xf3a28
movq 0x20(%rsp), %rax
movl $0x1, 0x90(%rax)
movq 0x20(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
je 0xf389c
movq 0x20(%rsp), %rax
cmpl $0x3, 0x3c(%rax)
jne 0xf38f0
movq 0x18(%rsp), %rax
leaq 0x228(%rip), %rcx       # 0xf3ad0
movq %rcx, 0x8(%rax)
movl $0x1, 0x14(%rsp)
movl 0x14(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xf38ee
movq 0x20(%rsp), %rax
movq 0x130(%rax), %rax
movslq 0x14(%rsp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x30(%rax)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xf38b4
jmp 0xf3911
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 0xf3a82
movq 0x20(%rsp), %rax
movl $0x3, 0x90(%rax)
movq 0x20(%rsp), %rax
cmpl $0x3, 0x3c(%rax)
jne 0xf394c
movq 0x18(%rsp), %rax
leaq 0x1e4(%rip), %rcx       # 0xf3b20
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rdi
callq 0xf3d10
jmp 0xf39ab
movq 0x20(%rsp), %rax
cmpl $0x1, 0x3c(%rax)
jne 0xf3969
movq 0x18(%rsp), %rax
leaq 0x53d(%rip), %rcx       # 0xf3ea0
movq %rcx, 0x8(%rax)
jmp 0xf39a9
movq 0x20(%rsp), %rax
cmpl $0x2, 0x3c(%rax)
jne 0xf3986
movq 0x18(%rsp), %rax
leaq 0x5f0(%rip), %rcx       # 0xf3f70
movq %rcx, 0x8(%rax)
jmp 0xf39a7
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 0xf39a9
jmp 0xf39ab
jmp 0xf3a82
movq 0x20(%rsp), %rax
movl $0x4, 0x90(%rax)
movq 0x20(%rsp), %rax
cmpl $0x5, 0x3c(%rax)
jne 0xf39e6
movq 0x18(%rsp), %rax
leaq 0x6aa(%rip), %rcx       # 0xf4080
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rdi
callq 0xf3d10
jmp 0xf3a26
movq 0x20(%rsp), %rax
cmpl $0x4, 0x3c(%rax)
jne 0xf3a03
movq 0x18(%rsp), %rax
leaq 0x573(%rip), %rcx       # 0xf3f70
movq %rcx, 0x8(%rax)
jmp 0xf3a24
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 0xf3a26
jmp 0xf3a82
movq 0x20(%rsp), %rax
movl 0x40(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x3c(%rcx), %eax
jne 0xf3a5f
movq 0x20(%rsp), %rax
movl 0x38(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x90(%rax)
movq 0x18(%rsp), %rax
leaq 0x517(%rip), %rcx       # 0xf3f70
movq %rcx, 0x8(%rax)
jmp 0xf3a80
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 0xf3a82
movq 0x20(%rsp), %rax
cmpl $0x0, 0x6c(%rax)
je 0xf3a9e
movq 0x20(%rsp), %rax
movl $0x1, 0x94(%rax)
jmp 0xf3ab4
movq 0x20(%rsp), %rax
movl 0x90(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x94(%rax)
addq $0x28, %rsp
retq
nopl (%rax)