// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jcparam.c
// Function: jpeg_set_colorspace
GLOBAL(void)
jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
{
  jpeg_component_info * compptr;
  int ci;

#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl)  \
  (compptr = &cinfo->comp_info[index], \
   compptr->component_id = (id), \
   compptr->h_samp_factor = (hsamp), \
   compptr->v_samp_factor = (vsamp), \
   compptr->quant_tbl_no = (quant), \
   compptr->dc_tbl_no = (dctbl), \
   compptr->ac_tbl_no = (actbl) )

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
   * tables 1 for chrominance components.
   */

  cinfo->jpeg_color_space = colorspace;

  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */

  switch (colorspace) {
  case JCS_GRAYSCALE:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 1;
    /* JFIF specifies component ID 1 */
    SET_COMP(0, 1, 1,1, 0, 0,0);
    break;
  case JCS_RGB:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
    cinfo->num_components = 3;
    SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
    break;
  case JCS_YCbCr:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 3;
    /* JFIF specifies component IDs 1,2,3 */
    /* We default to 2x2 subsamples of chrominance */
    SET_COMP(0, 1, 2,2, 0, 0,0);
    SET_COMP(1, 2, 1,1, 1, 1,1);
    SET_COMP(2, 3, 1,1, 1, 1,1);
    break;
  case JCS_CMYK:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
    cinfo->num_components = 4;
    SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
    SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
    break;
  case JCS_YCCK:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
    cinfo->num_components = 4;
    SET_COMP(0, 1, 2,2, 0, 0,0);
    SET_COMP(1, 2, 1,1, 1, 1,1);
    SET_COMP(2, 3, 1,1, 1, 1,1);
    SET_COMP(3, 4, 2,2, 0, 0,0);
    break;
  case JCS_UNKNOWN:
    cinfo->num_components = cinfo->input_components;
    if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
	       MAX_COMPONENTS);
    for (ci = 0; ci < cinfo->num_components; ci++) {
      SET_COMP(ci, ci, 1,1, 0, 0,0);
    }
    break;
  default:
    ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  }
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movl 0x24(%rdi), %eax
cmpl $0x64, %eax
je 0x68ba6
movq (%rbx), %rcx
movl $0x14, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl %ebp, 0x50(%rbx)
andl $0x0, 0x120(%rbx)
andl $0x0, 0x12c(%rbx)
cmpl $0x5, %ebp
ja 0x68dde
movl %ebp, %eax
leaq 0x323ff(%rip), %rcx     # 0x9afc8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x38(%rbx), %eax
movl %eax, 0x4c(%rbx)
leal -0xb(%rax), %ecx
cmpl $-0xb, %ecx
ja 0x68c02
movq (%rbx), %rcx
movl $0x1a, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%rbx), %rax
movl $0xa, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl 0x4c(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movsd 0x327af(%rip), %xmm0    # 0x9b3c0
xorl %edx, %edx
cmpq %rdx, %rax
je 0x68dd7
movq 0x58(%rbx), %rsi
movl %edx, (%rsi,%rcx)
movups %xmm0, 0x8(%rsi,%rcx)
andl $0x0, 0x18(%rsi,%rcx)
incq %rdx
addq $0x60, %rcx
jmp 0x68c13
movl $0x1, 0x12c(%rbx)
movl $0x4, 0x4c(%rbx)
movq 0x58(%rbx), %rax
movl $0x43, (%rax)
movsd 0x32767(%rip), %xmm0    # 0x9b3c0
movups %xmm0, 0x8(%rax)
andl $0x0, 0x18(%rax)
movl $0x4d, 0x60(%rax)
movups %xmm0, 0x68(%rax)
andl $0x0, 0x78(%rax)
movl $0x59, 0xc0(%rax)
movups %xmm0, 0xc8(%rax)
andl $0x0, 0xd8(%rax)
movl $0x4b, 0x120(%rax)
movups %xmm0, 0x128(%rax)
andl $0x0, 0x138(%rax)
jmp 0x68dd7
movl $0x1, 0x12c(%rbx)
movl $0x3, 0x4c(%rbx)
movq 0x58(%rbx), %rax
movl $0x52, (%rax)
movsd 0x326f8(%rip), %xmm0    # 0x9b3c0
movups %xmm0, 0x8(%rax)
andl $0x0, 0x18(%rax)
movl $0x47, 0x60(%rax)
movups %xmm0, 0x68(%rax)
andl $0x0, 0x78(%rax)
movl $0x42, 0xc0(%rax)
movups %xmm0, 0xc8(%rax)
andl $0x0, 0xd8(%rax)
jmp 0x68dd7
pushq $0x1
popq %rax
movl %eax, 0x120(%rbx)
pushq $0x3
popq %rcx
movl %ecx, 0x4c(%rbx)
movq 0x58(%rbx), %rdx
movl %eax, (%rdx)
movsd 0x326b7(%rip), %xmm0    # 0x9b3d0
movups %xmm0, 0x8(%rdx)
andl $0x0, 0x18(%rdx)
movl $0x2, 0x60(%rdx)
movaps 0x31b51(%rip), %xmm0    # 0x9a880
movups %xmm0, 0x68(%rdx)
movl %eax, 0x78(%rdx)
movl %ecx, 0xc0(%rdx)
movups %xmm0, 0xc8(%rdx)
movl %eax, 0xd8(%rdx)
jmp 0x68dd7
pushq $0x1
popq %rax
movl %eax, 0x120(%rbx)
movl %eax, 0x4c(%rbx)
movq 0x58(%rbx), %rcx
movl %eax, (%rcx)
movsd 0x32658(%rip), %xmm0    # 0x9b3c0
movups %xmm0, 0x8(%rcx)
andl $0x0, 0x18(%rcx)
jmp 0x68dd7
pushq $0x1
popq %rax
movl %eax, 0x12c(%rbx)
pushq $0x4
popq %rcx
movl %ecx, 0x4c(%rbx)
movq 0x58(%rbx), %rdx
movl %eax, (%rdx)
movsd 0x32641(%rip), %xmm0    # 0x9b3d0
movups %xmm0, 0x8(%rdx)
andl $0x0, 0x18(%rdx)
movl $0x2, 0x60(%rdx)
movaps 0x31adb(%rip), %xmm1    # 0x9a880
movups %xmm1, 0x68(%rdx)
movl %eax, 0x78(%rdx)
movl $0x3, 0xc0(%rdx)
movups %xmm1, 0xc8(%rdx)
movl %eax, 0xd8(%rdx)
movl %ecx, 0x120(%rdx)
movups %xmm0, 0x128(%rdx)
andl $0x0, 0x138(%rdx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movq (%rbx), %rax
movl $0xa, 0x28(%rax)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmpq *(%rax)