// File: /workspace/github_cpp_makefile_star2_O3/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 0x7246f
movq (%rbx), %rcx
movl $0x14, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl %ebp, 0x50(%rbx)
xorl %eax, %eax
movl %eax, 0x120(%rbx)
movl %eax, 0x12c(%rbx)
cmpl $0x5, %ebp
ja 0x726b6
movl %ebp, %eax
leaq 0x37c46(%rip), %rcx     # 0xaa0d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x38(%rbx), %ecx
movl %ecx, 0x4c(%rbx)
leal -0xb(%rcx), %eax
cmpl $-0xb, %eax
ja 0x724d3
movq (%rbx), %rax
movl $0x1a, 0x28(%rax)
movl %ecx, 0x2c(%rax)
movq (%rbx), %rax
movl $0xa, 0x30(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl 0x4c(%rbx), %ecx
testl %ecx, %ecx
jle 0x726af
movq 0x58(%rbx), %rax
movl %ecx, %ecx
xorl %edx, %edx
movsd 0x2fded(%rip), %xmm0    # 0xa22d0
movl %edx, (%rax)
movups %xmm0, 0x8(%rax)
movl $0x0, 0x18(%rax)
incq %rdx
addq $0x60, %rax
cmpq %rdx, %rcx
jne 0x724e3
jmp 0x726af
movl $0x1, 0x12c(%rbx)
movl $0x4, 0x4c(%rbx)
movq 0x58(%rbx), %rax
movl $0x43, (%rax)
movsd 0x2fdac(%rip), %xmm0    # 0xa22d0
movups %xmm0, 0x8(%rax)
xorl %ecx, %ecx
movl %ecx, 0x18(%rax)
movl $0x4d, 0x60(%rax)
movups %xmm0, 0x68(%rax)
movl %ecx, 0x78(%rax)
movl $0x59, 0xc0(%rax)
movups %xmm0, 0xc8(%rax)
movl %ecx, 0xd8(%rax)
movl $0x4b, 0x120(%rax)
movups %xmm0, 0x128(%rax)
movl %ecx, 0x138(%rax)
jmp 0x726af
movl $0x1, 0x12c(%rbx)
movl $0x3, 0x4c(%rbx)
movq 0x58(%rbx), %rax
movl $0x52, (%rax)
movsd 0x2fd3f(%rip), %xmm0    # 0xa22d0
movups %xmm0, 0x8(%rax)
xorl %ecx, %ecx
movl %ecx, 0x18(%rax)
movl $0x47, 0x60(%rax)
movups %xmm0, 0x68(%rax)
movl %ecx, 0x78(%rax)
movl $0x42, 0xc0(%rax)
movups %xmm0, 0xc8(%rax)
movl %ecx, 0xd8(%rax)
jmp 0x726af
movl $0x1, %eax
movl %eax, 0x120(%rbx)
movl $0x3, %ecx
movl %ecx, 0x4c(%rbx)
movq 0x58(%rbx), %rdx
movl %eax, (%rdx)
movsd 0x36dab(%rip), %xmm0    # 0xa9390
movups %xmm0, 0x8(%rdx)
movl $0x0, 0x18(%rdx)
movl $0x2, 0x60(%rdx)
movaps 0x372f2(%rip), %xmm0    # 0xa98f0
movups %xmm0, 0x68(%rdx)
movl %eax, 0x78(%rdx)
movl %ecx, 0xc0(%rdx)
movups %xmm0, 0xc8(%rdx)
movl %eax, 0xd8(%rdx)
jmp 0x726af
movl $0x1, %eax
movl %eax, 0x120(%rbx)
movl %eax, 0x4c(%rbx)
movq 0x58(%rbx), %rcx
movl %eax, (%rcx)
movsd 0x2fc97(%rip), %xmm0    # 0xa22d0
movups %xmm0, 0x8(%rcx)
movl $0x0, 0x18(%rcx)
jmp 0x726af
movl $0x1, %eax
movl %eax, 0x12c(%rbx)
movl $0x4, %ecx
movl %ecx, 0x4c(%rbx)
movq 0x58(%rbx), %rdx
movl %eax, (%rdx)
movsd 0x36d29(%rip), %xmm0    # 0xa9390
movups %xmm0, 0x8(%rdx)
xorl %esi, %esi
movl %esi, 0x18(%rdx)
movl $0x2, 0x60(%rdx)
movaps 0x37272(%rip), %xmm1    # 0xa98f0
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)
movl %esi, 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)