// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdapimin.c
// Function: default_decompress_parms
LOCAL(void)
default_decompress_parms (j_decompress_ptr cinfo)
{
  /* Guess the input colorspace, and set output colorspace accordingly. */
  /* (Wish JPEG committee had provided a real way to specify this...) */
  /* Note application may override our guesses. */
  switch (cinfo->num_components) {
  case 1:
    cinfo->jpeg_color_space = JCS_GRAYSCALE;
    cinfo->out_color_space = JCS_GRAYSCALE;
    break;
    
  case 3:
    if (cinfo->saw_JFIF_marker) {
      cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
    } else if (cinfo->saw_Adobe_marker) {
      switch (cinfo->Adobe_transform) {
      case 0:
	cinfo->jpeg_color_space = JCS_RGB;
	break;
      case 1:
	cinfo->jpeg_color_space = JCS_YCbCr;
	break;
      default:
	WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
	cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
	break;
      }
    } else {
      /* Saw no special markers, try to guess from the component IDs */
      int cid0 = cinfo->comp_info[0].component_id;
      int cid1 = cinfo->comp_info[1].component_id;
      int cid2 = cinfo->comp_info[2].component_id;

      if (cid0 == 1 && cid1 == 2 && cid2 == 3)
	cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
      else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
	cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
      else {
	TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
	cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
      }
    }
    /* Always guess RGB is proper output colorspace. */
    cinfo->out_color_space = JCS_RGB;
    break;
    
  case 4:
    if (cinfo->saw_Adobe_marker) {
      switch (cinfo->Adobe_transform) {
      case 0:
	cinfo->jpeg_color_space = JCS_CMYK;
	break;
      case 2:
	cinfo->jpeg_color_space = JCS_YCCK;
	break;
      default:
	WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
	cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
	break;
      }
    } else {
      /* No special markers, assume straight CMYK. */
      cinfo->jpeg_color_space = JCS_CMYK;
    }
    cinfo->out_color_space = JCS_CMYK;
    break;
    
  default:
    cinfo->jpeg_color_space = JCS_UNKNOWN;
    cinfo->out_color_space = JCS_UNKNOWN;
    break;
  }

  /* Set defaults for other decompression parameters. */
  cinfo->scale_num = 1;		/* 1:1 scaling */
  cinfo->scale_denom = 1;
  cinfo->output_gamma = 1.0;
  cinfo->buffered_image = FALSE;
  cinfo->raw_data_out = FALSE;
  cinfo->dct_method = JDCT_DEFAULT;
  cinfo->do_fancy_upsampling = TRUE;
  cinfo->do_block_smoothing = TRUE;
  cinfo->quantize_colors = FALSE;
  /* We set these in case application only sets quantize_colors. */
  cinfo->dither_mode = JDITHER_FS;
#ifdef QUANT_2PASS_SUPPORTED
  cinfo->two_pass_quantize = TRUE;
#else
  cinfo->two_pass_quantize = FALSE;
#endif
  cinfo->desired_number_of_colors = 256;
  cinfo->colormap = NULL;
  /* Initialize for no mode change in buffered-image mode. */
  cinfo->enable_1pass_quant = FALSE;
  cinfo->enable_external_quant = FALSE;
  cinfo->enable_2pass_quant = FALSE;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movl 0x38(%rax), %eax
movl %eax, 0x14(%rsp)
subl $0x1, %eax
je 0xe2789
jmp 0xe276c
movl 0x14(%rsp), %eax
subl $0x3, %eax
je 0xe27a6
jmp 0xe2777
movl 0x14(%rsp), %eax
subl $0x4, %eax
je 0xe2967
jmp 0xe2a1c
movq 0x30(%rsp), %rax
movl $0x1, 0x3c(%rax)
movq 0x30(%rsp), %rax
movl $0x1, 0x40(%rax)
jmp 0xe2a34
movq 0x30(%rsp), %rax
cmpl $0x0, 0x174(%rax)
je 0xe27c5
movq 0x30(%rsp), %rax
movl $0x3, 0x3c(%rax)
jmp 0xe2956
movq 0x30(%rsp), %rax
cmpl $0x0, 0x180(%rax)
je 0xe2863
movq 0x30(%rsp), %rax
movzbl 0x184(%rax), %eax
movl %eax, 0x10(%rsp)
testl %eax, %eax
je 0xe27f8
jmp 0xe27ed
movl 0x10(%rsp), %eax
subl $0x1, %eax
je 0xe2806
jmp 0xe2814
movq 0x30(%rsp), %rax
movl $0x2, 0x3c(%rax)
jmp 0xe285e
movq 0x30(%rsp), %rax
movl $0x3, 0x3c(%rax)
jmp 0xe285e
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x72, 0x28(%rax)
movq 0x30(%rsp), %rax
movzbl 0x184(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
movq 0x30(%rsp), %rax
movl $0x3, 0x3c(%rax)
jmp 0xe2954
movq 0x30(%rsp), %rax
movq 0x130(%rax), %rax
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0x30(%rsp), %rax
movq 0x130(%rax), %rax
movl 0x60(%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq 0x130(%rax), %rax
movl 0xc0(%rax), %eax
movl %eax, 0x24(%rsp)
cmpl $0x1, 0x2c(%rsp)
jne 0xe28c4
cmpl $0x2, 0x28(%rsp)
jne 0xe28c4
cmpl $0x3, 0x24(%rsp)
jne 0xe28c4
movq 0x30(%rsp), %rax
movl $0x3, 0x3c(%rax)
jmp 0xe2952
cmpl $0x52, 0x2c(%rsp)
jne 0xe28e7
cmpl $0x47, 0x28(%rsp)
jne 0xe28e7
cmpl $0x42, 0x24(%rsp)
jne 0xe28e7
movq 0x30(%rsp), %rax
movl $0x2, 0x3c(%rax)
jmp 0xe2950
jmp 0xe28e9
movq 0x30(%rsp), %rax
movq (%rax), %rax
addq $0x2c, %rax
movq %rax, 0x18(%rsp)
movl 0x2c(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, (%rax)
movl 0x28(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0x24(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x6f, 0x28(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0x1, %esi
callq *%rax
movq 0x30(%rsp), %rax
movl $0x3, 0x3c(%rax)
jmp 0xe2952
jmp 0xe2954
jmp 0xe2956
movq 0x30(%rsp), %rax
movl $0x2, 0x40(%rax)
jmp 0xe2a34
movq 0x30(%rsp), %rax
cmpl $0x0, 0x180(%rax)
je 0xe2a02
movq 0x30(%rsp), %rax
movzbl 0x184(%rax), %eax
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0xe299a
jmp 0xe298f
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0xe29a8
jmp 0xe29b6
movq 0x30(%rsp), %rax
movl $0x4, 0x3c(%rax)
jmp 0xe2a00
movq 0x30(%rsp), %rax
movl $0x5, 0x3c(%rax)
jmp 0xe2a00
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl $0x72, 0x28(%rax)
movq 0x30(%rsp), %rax
movzbl 0x184(%rax), %ecx
movq 0x30(%rsp), %rax
movq (%rax), %rax
movl %ecx, 0x2c(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x30(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq *%rax
movq 0x30(%rsp), %rax
movl $0x5, 0x3c(%rax)
jmp 0xe2a0e
movq 0x30(%rsp), %rax
movl $0x4, 0x3c(%rax)
movq 0x30(%rsp), %rax
movl $0x4, 0x40(%rax)
jmp 0xe2a34
movq 0x30(%rsp), %rax
movl $0x0, 0x3c(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x40(%rax)
movq 0x30(%rsp), %rax
movl $0x1, 0x44(%rax)
movq 0x30(%rsp), %rax
movl $0x1, 0x48(%rax)
movq 0x30(%rsp), %rax
movsd 0x505af(%rip), %xmm0    # 0x133008
movsd %xmm0, 0x50(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x58(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x5c(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x60(%rax)
movq 0x30(%rsp), %rax
movl $0x1, 0x64(%rax)
movq 0x30(%rsp), %rax
movl $0x1, 0x68(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x6c(%rax)
movq 0x30(%rsp), %rax
movl $0x2, 0x70(%rax)
movq 0x30(%rsp), %rax
movl $0x1, 0x74(%rax)
movq 0x30(%rsp), %rax
movl $0x100, 0x78(%rax)      # imm = 0x100
movq 0x30(%rsp), %rax
movq $0x0, 0xa0(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x7c(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x80(%rax)
movq 0x30(%rsp), %rax
movl $0x0, 0x84(%rax)
addq $0x38, %rsp
retq
nopl (%rax)