// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/jpeg/jdmaster.c
// Function: jpeg_calc_output_dimensions
GLOBAL(void)
jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
/* Do computations that are needed before master selection phase */
{
#ifdef IDCT_SCALING_SUPPORTED
  int ci;
  jpeg_component_info *compptr;
#endif

  /* Prevent application from calling me at wrong times */
  if (cinfo->global_state != DSTATE_READY)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

#ifdef IDCT_SCALING_SUPPORTED

  /* Compute actual output image dimensions and DCT scaling choices. */
  if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
    /* Provide 1/8 scaling */
    cinfo->output_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width, 8L);
    cinfo->output_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height, 8L);
    cinfo->min_DCT_scaled_size = 1;
  } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
    /* Provide 1/4 scaling */
    cinfo->output_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width, 4L);
    cinfo->output_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height, 4L);
    cinfo->min_DCT_scaled_size = 2;
  } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
    /* Provide 1/2 scaling */
    cinfo->output_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width, 2L);
    cinfo->output_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height, 2L);
    cinfo->min_DCT_scaled_size = 4;
  } else {
    /* Provide 1/1 scaling */
    cinfo->output_width = cinfo->image_width;
    cinfo->output_height = cinfo->image_height;
    cinfo->min_DCT_scaled_size = DCTSIZE;
  }
  /* In selecting the actual DCT scaling for each component, we try to
   * scale up the chroma components via IDCT scaling rather than upsampling.
   * This saves time if the upsampler gets to use 1:1 scaling.
   * Note this code assumes that the supported DCT scalings are powers of 2.
   */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    int ssize = cinfo->min_DCT_scaled_size;
    while (ssize < DCTSIZE &&
	   (compptr->h_samp_factor * ssize * 2 <=
	    cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
	   (compptr->v_samp_factor * ssize * 2 <=
	    cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
      ssize = ssize * 2;
    }
    compptr->DCT_scaled_size = ssize;
  }

  /* Recompute downsampled dimensions of components;
   * application needs to know these if using raw downsampled data.
   */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    /* Size in samples, after IDCT scaling */
    compptr->downsampled_width = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_width *
		    (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
		    (long) (cinfo->max_h_samp_factor * DCTSIZE));
    compptr->downsampled_height = (JDIMENSION)
      jdiv_round_up((long) cinfo->image_height *
		    (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
		    (long) (cinfo->max_v_samp_factor * DCTSIZE));
  }

#else /* !IDCT_SCALING_SUPPORTED */

  /* Hardwire it to "no scaling" */
  cinfo->output_width = cinfo->image_width;
  cinfo->output_height = cinfo->image_height;
  /* jdinput.c has already initialized DCT_scaled_size to DCTSIZE,
   * and has computed unscaled downsampled_width and downsampled_height.
   */

#endif /* IDCT_SCALING_SUPPORTED */

  /* Report number of components in selected colorspace. */
  /* Probably this should be in the color conversion module... */
  switch (cinfo->out_color_space) {
  case JCS_GRAYSCALE:
    cinfo->out_color_components = 1;
    break;
  case JCS_RGB:
#if RGB_PIXELSIZE != 3
    cinfo->out_color_components = RGB_PIXELSIZE;
    break;
#endif /* else share code with YCbCr */
  case JCS_YCbCr:
    cinfo->out_color_components = 3;
    break;
  case JCS_CMYK:
  case JCS_YCCK:
    cinfo->out_color_components = 4;
    break;
  default:			/* else must be same colorspace as in file */
    cinfo->out_color_components = cinfo->num_components;
    break;
  }
  cinfo->output_components = (cinfo->quantize_colors ? 1 :
			      cinfo->out_color_components);

  /* See if upsampler will want to emit more than one row at a time */
  if (use_merged_upsample(cinfo))
    cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  else
    cinfo->rec_outbuf_height = 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl 0x24(%rdi), %eax
cmpl $0xca, %eax
je 0x6f42a
movq (%rbx), %rcx
movl $0x14, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *(%rax)
movl 0x44(%rbx), %eax
movl 0x48(%rbx), %ecx
leal (,%rax,8), %edx
cmpl %ecx, %edx
jbe 0x6f45c
leal (,%rax,4), %edx
cmpl %ecx, %edx
jbe 0x6f481
addl %eax, %eax
movl 0x30(%rbx), %edi
cmpl %ecx, %eax
jbe 0x6f4a5
movl %edi, 0x88(%rbx)
movl 0x34(%rbx), %eax
pushq $0x8
jmp 0x6f4c4
pushq $0x1
popq %rbp
movl 0x30(%rbx), %edi
pushq $0x8
popq %r14
movq %r14, %rsi
callq 0x79150
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movq %r14, %rsi
callq 0x79150
jmp 0x6f4c5
movl 0x30(%rbx), %edi
pushq $0x4
popq %r14
movq %r14, %rsi
callq 0x79150
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movq %r14, %rsi
callq 0x79150
pushq $0x2
jmp 0x6f4c4
pushq $0x2
popq %r14
movq %r14, %rsi
callq 0x79150
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movq %r14, %rsi
callq 0x79150
pushq $0x4
popq %rbp
movl %eax, 0x8c(%rbx)
movl %ebp, 0x1a0(%rbx)
movq 0x130(%rbx), %r14
movl 0x38(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movq %r14, %rsi
cmpl %edx, %ecx
je 0x6f539
movl %ebp, %r8d
movl %r8d, %edi
cmpl $0x7, %r8d
jg 0x6f52e
leal (%rdi,%rdi), %r8d
movl 0x8(%rsi), %r9d
imull %r8d, %r9d
movl 0x198(%rbx), %r10d
imull %ebp, %r10d
cmpl %r10d, %r9d
jg 0x6f52e
movl 0xc(%rsi), %r9d
imull %r8d, %r9d
movl 0x19c(%rbx), %r10d
imull %ebp, %r10d
cmpl %r10d, %r9d
jle 0x6f4f1
movl %edi, 0x24(%rsi)
incl %ecx
addq $0x60, %rsi
jmp 0x6f4ea
addq $0x2c, %r14
xorl %ebp, %ebp
cmpl %eax, %ebp
jge 0x6f59b
movl 0x30(%rbx), %eax
movslq -0x24(%r14), %rcx
movslq -0x8(%r14), %rdi
imulq %rcx, %rdi
imulq %rax, %rdi
movslq 0x198(%rbx), %rsi
shlq $0x3, %rsi
callq 0x79150
movl %eax, -0x4(%r14)
movl 0x34(%rbx), %eax
movslq -0x20(%r14), %rcx
movslq -0x8(%r14), %rdi
imulq %rcx, %rdi
imulq %rax, %rdi
movslq 0x19c(%rbx), %rsi
shlq $0x3, %rsi
callq 0x79150
movl %eax, (%r14)
incl %ebp
movl 0x38(%rbx), %eax
addq $0x60, %r14
jmp 0x6f53f
movl 0x40(%rbx), %ecx
decl %ecx
cmpl $0x4, %ecx
ja 0x6f5b1
movl %ecx, %eax
leaq 0x2bfe2(%rip), %rcx     # 0x9b590
movl (%rcx,%rax,4), %eax
movl %eax, 0x90(%rbx)
cmpl $0x0, 0x6c(%rbx)
pushq $0x1
popq %rbp
cmovnel %ebp, %eax
movl %eax, 0x94(%rbx)
movq %rbx, %rdi
callq 0x6f5e4
testl %eax, %eax
je 0x6f5d9
movl 0x19c(%rbx), %ebp
movl %ebp, 0x98(%rbx)
popq %rbx
popq %r14
popq %rbp
retq