// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcsample.c
// Function: jinit_downsampler
GLOBAL(void)
jinit_downsampler (j_compress_ptr cinfo)
{
  my_downsample_ptr downsample;
  int ci;
  jpeg_component_info * compptr;
  jboolean smoothok = TRUE;

  downsample = (my_downsample_ptr)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				SIZEOF(my_downsampler));
  cinfo->downsample = (struct jpeg_downsampler *) downsample;
  downsample->pub.start_pass = start_pass_downsample;
  downsample->pub.downsample = sep_downsample;
  downsample->pub.need_context_rows = FALSE;

  if (cinfo->CCIR601_sampling)
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);

  /* Verify we can handle the sampling factors, and set up method pointers */
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
       ci++, compptr++) {
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
	compptr->v_samp_factor == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED
      if (cinfo->smoothing_factor) {
	downsample->methods[ci] = fullsize_smooth_downsample;
	downsample->pub.need_context_rows = TRUE;
      } else
#endif
	downsample->methods[ci] = fullsize_downsample;
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
	       compptr->v_samp_factor == cinfo->max_v_samp_factor) {
      smoothok = FALSE;
      downsample->methods[ci] = h2v1_downsample;
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
	       compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
#ifdef INPUT_SMOOTHING_SUPPORTED
      if (cinfo->smoothing_factor) {
	downsample->methods[ci] = h2v2_smooth_downsample;
	downsample->pub.need_context_rows = TRUE;
      } else
#endif
	downsample->methods[ci] = h2v2_downsample;
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
	       (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
      smoothok = FALSE;
      downsample->methods[ci] = int_downsample;
    } else
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  }

#ifdef INPUT_SMOOTHING_SUPPORTED
  if (cinfo->smoothing_factor && !smoothok)
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
#endif
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl $0x1, 0x4(%rsp)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
movl $0x1, %esi
movl $0x68, %edx
callq *%rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x1e0(%rax)
movq 0x18(%rsp), %rax
leaq 0x290(%rip), %rcx       # 0xdc560
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
leaq 0x291(%rip), %rcx       # 0xdc570
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x20(%rsp), %rax
cmpl $0x0, 0x10c(%rax)
je 0xdc31e
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x19, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
movl $0x0, 0x14(%rsp)
movq 0x20(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x14(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x4c(%rcx), %eax
jge 0xdc51d
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x138(%rcx), %eax
jne 0xdc3bd
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x13c(%rcx), %eax
jne 0xdc3bd
movq 0x20(%rsp), %rax
cmpl $0x0, 0x110(%rax)
je 0xdc3a2
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
leaq 0x2d1(%rip), %rdx       # 0xdc660
movq %rdx, 0x18(%rax,%rcx,8)
movq 0x18(%rsp), %rax
movl $0x1, 0x10(%rax)
jmp 0xdc3b8
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
leaq 0x60d(%rip), %rdx       # 0xdc9c0
movq %rdx, 0x18(%rax,%rcx,8)
jmp 0xdc4fd
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
shll %eax
movq 0x20(%rsp), %rcx
cmpl 0x138(%rcx), %eax
jne 0xdc40c
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x13c(%rcx), %eax
jne 0xdc40c
movl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
leaq 0x62e(%rip), %rdx       # 0xdca30
movq %rdx, 0x18(%rax,%rcx,8)
jmp 0xdc4fb
movq 0x8(%rsp), %rax
movl 0x8(%rax), %eax
shll %eax
movq 0x20(%rsp), %rcx
cmpl 0x138(%rcx), %eax
jne 0xdc484
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
shll %eax
movq 0x20(%rsp), %rcx
cmpl 0x13c(%rcx), %eax
jne 0xdc484
movq 0x20(%rsp), %rax
cmpl $0x0, 0x110(%rax)
je 0xdc46c
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
leaq 0x6e7(%rip), %rdx       # 0xdcb40
movq %rdx, 0x18(%rax,%rcx,8)
movq 0x18(%rsp), %rax
movl $0x1, 0x10(%rax)
jmp 0xdc482
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
leaq 0xbb3(%rip), %rdx       # 0xdd030
movq %rdx, 0x18(%rax,%rcx,8)
jmp 0xdc4f9
movq 0x20(%rsp), %rax
movl 0x138(%rax), %eax
movq 0x8(%rsp), %rcx
cltd
idivl 0x8(%rcx)
cmpl $0x0, %edx
jne 0xdc4d6
movq 0x20(%rsp), %rax
movl 0x13c(%rax), %eax
movq 0x8(%rsp), %rcx
cltd
idivl 0xc(%rcx)
cmpl $0x0, %edx
jne 0xdc4d6
movl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
leaq 0xcc1(%rip), %rdx       # 0xdd190
movq %rdx, 0x18(%rax,%rcx,8)
jmp 0xdc4f7
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x26, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
callq *%rax
jmp 0xdc4f9
jmp 0xdc4fb
jmp 0xdc4fd
jmp 0xdc4ff
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movq 0x8(%rsp), %rax
addq $0x60, %rax
movq %rax, 0x8(%rsp)
jmp 0xdc334
movq 0x20(%rsp), %rax
cmpl $0x0, 0x110(%rax)
je 0xdc556
cmpl $0x0, 0x4(%rsp)
jne 0xdc556
movq 0x20(%rsp), %rax
movq (%rax), %rax
movl $0x63, 0x28(%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq *%rax
addq $0x28, %rsp
retq
nopl (%rax,%rax)