// File: /workspace/github_cpp_makefile_star2_O1/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 0x7c0ae
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 0x7c0e3
leal (,%rax,4), %edx
cmpl %ecx, %edx
jbe 0x7c10a
addl %eax, %eax
movl 0x30(%rbx), %edi
cmpl %ecx, %eax
jbe 0x7c131
movl %edi, 0x88(%rbx)
movl 0x34(%rbx), %eax
movl $0x8, %ecx
jmp 0x7c153
movl 0x30(%rbx), %edi
movl $0x8, %esi
callq 0x86a9c
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movl $0x8, %esi
callq 0x86a9c
movl $0x1, %ecx
jmp 0x7c153
movl 0x30(%rbx), %edi
movl $0x4, %esi
callq 0x86a9c
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movl $0x4, %esi
callq 0x86a9c
movl $0x2, %ecx
jmp 0x7c153
movl $0x2, %esi
callq 0x86a9c
movl %eax, 0x88(%rbx)
movl 0x34(%rbx), %edi
movl $0x2, %esi
callq 0x86a9c
movl $0x4, %ecx
movl %eax, 0x8c(%rbx)
movl %ecx, 0x1a0(%rbx)
movq 0x130(%rbx), %r14
movl 0x38(%rbx), %eax
testl %eax, %eax
jle 0x7c1da
movl 0x1a0(%rbx), %ecx
xorl %edx, %edx
movq %r14, %rsi
movl %ecx, %r10d
cmpl $0x7, %ecx
jg 0x7c1cc
movl 0x8(%rsi), %edi
addl %edi, %edi
movl 0x198(%rbx), %r8d
imull %ecx, %r8d
movl %ecx, %r9d
movl %r9d, %r10d
imull %edi, %r10d
cmpl %r8d, %r10d
jg 0x7c1c9
movl 0xc(%rsi), %r10d
imull %r9d, %r10d
addl %r10d, %r10d
movl 0x19c(%rbx), %r11d
imull %ecx, %r11d
cmpl %r11d, %r10d
jg 0x7c1c9
leal (%r9,%r9), %r10d
cmpl $0x4, %r9d
movl %r10d, %r9d
jl 0x7c193
jmp 0x7c1cc
movl %r9d, %r10d
movl %r10d, 0x24(%rsi)
incl %edx
addq $0x60, %rsi
cmpl %eax, %edx
jne 0x7c178
movl 0x38(%rbx), %eax
testl %eax, %eax
jle 0x7c241
addq $0x2c, %r14
xorl %ebp, %ebp
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 0x86a9c
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 0x86a9c
movl %eax, (%r14)
incl %ebp
movl 0x38(%rbx), %eax
addq $0x60, %r14
cmpl %eax, %ebp
jl 0x7c1e7
movl 0x40(%rbx), %ecx
decl %ecx
cmpl $0x4, %ecx
ja 0x7c257
movl %ecx, %eax
leaq 0x2e5dc(%rip), %rcx     # 0xaa830
movl (%rcx,%rax,4), %eax
movl %eax, 0x90(%rbx)
movl $0x1, %ebp
cmpl $0x0, 0x6c(%rbx)
movl $0x1, %eax
jne 0x7c273
movl 0x90(%rbx), %eax
movl %eax, 0x94(%rbx)
movq %rbx, %rdi
callq 0x7c296
testl %eax, %eax
je 0x7c28b
movl 0x19c(%rbx), %ebp
movl %ebp, 0x98(%rbx)
popq %rbx
popq %r14
popq %rbp
retq