📄 jdapimin.c
字号:
GLOBAL(int)jpeg_read_header (j_decompress_ptr cinfo, boolean require_image){ int retcode; if (cinfo->global_state != DSTATE_START && cinfo->global_state != DSTATE_INHEADER) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); retcode = jpeg_consume_input(cinfo); switch (retcode) { case JPEG_REACHED_SOS: retcode = JPEG_HEADER_OK; break; case JPEG_REACHED_EOI: if (require_image) /* Complain if application wanted an image */ ERREXIT(cinfo, JERR_NO_IMAGE); /* Reset to start state; it would be safer to require the application to * call jpeg_abort, but we can't change it now for compatibility reasons. * A side effect is to free any temporary memory (there shouldn't be any). */ jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ retcode = JPEG_HEADER_TABLES_ONLY; break; case JPEG_SUSPENDED: /* no work */ break; } return retcode;}/* * Consume data in advance of what the decompressor requires. * This can be called at any time once the decompressor object has * been created and a data source has been set up. * * This routine is essentially a state machine that handles a couple * of critical state-transition actions, namely initial setup and * transition from header scanning to ready-for-start_decompress. * All the actual input is done via the input controller's consume_input * method. */GLOBAL(int)jpeg_consume_input (j_decompress_ptr cinfo){ int retcode = JPEG_SUSPENDED; /* NB: every possible DSTATE value should be listed in this switch */ switch (cinfo->global_state) { case DSTATE_START: /* Start-of-datastream actions: reset appropriate modules */ (*cinfo->inputctl->reset_input_controller) (cinfo); /* Initialize application's data source module */ (*cinfo->src->init_source) (cinfo); cinfo->global_state = DSTATE_INHEADER; /*FALLTHROUGH*/ case DSTATE_INHEADER: retcode = (*cinfo->inputctl->consume_input) (cinfo); if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */ /* Set up default parameters based on header data */ default_decompress_parms(cinfo); /* Set global state: ready for start_decompress */ cinfo->global_state = DSTATE_READY; } break; case DSTATE_READY: /* Can't advance past first SOS until start_decompress is called */ retcode = JPEG_REACHED_SOS; break; case DSTATE_PRELOAD: case DSTATE_PRESCAN: case DSTATE_SCANNING: case DSTATE_RAW_OK: case DSTATE_BUFIMAGE: case DSTATE_BUFPOST: case DSTATE_STOPPING: retcode = (*cinfo->inputctl->consume_input) (cinfo); break; default: ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); } return retcode;}/* * Have we finished reading the input file? */GLOBAL(boolean)jpeg_input_complete (j_decompress_ptr cinfo){ /* Check for valid jpeg object */ if (cinfo->global_state < DSTATE_START || cinfo->global_state > DSTATE_STOPPING) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); return cinfo->inputctl->eoi_reached;}/* * Is there more than one scan? */GLOBAL(boolean)jpeg_has_multiple_scans (j_decompress_ptr cinfo){ /* Only valid after jpeg_read_header completes */ if (cinfo->global_state < DSTATE_READY || cinfo->global_state > DSTATE_STOPPING) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); return cinfo->inputctl->has_multiple_scans;}/* * Finish JPEG decompression. * * This will normally just verify the file trailer and release temp storage. * * Returns FALSE if suspended. The return value need be inspected only if * a suspending data source is used. */GLOBAL(boolean)jpeg_finish_decompress (j_decompress_ptr cinfo){ if ((cinfo->global_state == DSTATE_SCANNING || cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) { /* Terminate final pass of non-buffered mode */ if (cinfo->output_scanline < cinfo->output_height) ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); (*cinfo->master->finish_output_pass) (cinfo); cinfo->global_state = DSTATE_STOPPING; } else if (cinfo->global_state == DSTATE_BUFIMAGE) { /* Finishing after a buffered-image operation */ cinfo->global_state = DSTATE_STOPPING; } else if (cinfo->global_state != DSTATE_STOPPING) { /* STOPPING = repeat call after a suspension, anything else is error */ ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); } /* Read until EOI */ while (! cinfo->inputctl->eoi_reached) { if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) return FALSE; /* Suspend, come back later */ } /* Do final cleanup */ (*cinfo->src->term_source) (cinfo); /* We can use jpeg_abort to release memory and reset global_state */ jpeg_abort((j_common_ptr) cinfo); return TRUE;}int mmxsupport(){ int mmx_supported = 0;#ifdef HAVE_MMX_INTEL_MNEMONICS _asm { pushfd //Save Eflag to stack pop eax //Get Eflag from stack into eax mov ecx, eax //Make another copy of Eflag in ecx xor eax, 0x200000 //Toggle ID bit in Eflag [i.e. bit(21)] push eax //Save modified Eflag back to stack popfd //Restored modified value back to Eflag reg pushfd //Save Eflag to stack pop eax //Get Eflag from stack xor eax, ecx //Compare the new Eflag with the original Eflag jz NOT_SUPPORTED //If the same, CPUID instruction is not supported, //skip following instructions and jump to //NOT_SUPPORTED label xor eax, eax //Set eax to zero _asm _emit 0x0f //CPUID instruction (two bytes opcode) _asm _emit 0xa2 cmp eax, 1 //make sure eax return non-zero value jl NOT_SUPPORTED //If eax is zero, mmx not supported xor eax, eax //set eax to zero inc eax //Now increment eax to 1. This instruction is //faster than the instruction "mov eax, 1" _asm _emit 0x0f //CPUID instruction _asm _emit 0xa2 and edx, 0x00800000 //mask out all bits but mmx bit(24) cmp edx, 0 // 0 = mmx not supported jz NOT_SUPPORTED // non-zero = Yes, mmx IS supported mov mmx_supported, 1 //set return value to 1NOT_SUPPORTED: mov eax, mmx_supported //move return value to eax }#endif#if defined(HAVE_MMX_ATT_MNEMONICS) __asm__ ( "pushl %%ebx \n\t" //Save ebx that can serve as the PIC base "pushfl \n\t" //Save Eflag to stack "popl %%eax \n\t" //Get Eflag from stack into eax "movl %%eax,%%ecx \n\t" //Make another copy of Eflag in ecx "xorl $0x200000,%%eax \n\t" //Toggle ID bit in Eflag [i.e. bit(21)] "pushl %%eax \n\t" //Save modified Eflag back to stack "popfl \n\t" //Restored modified value back to Eflag reg "pushfl \n\t" //Save Eflag to stack "popl %%eax \n\t" //Get Eflag from stack "xorl %%ecx,%%eax \n\t" //Compare the new Eflag with the original Eflag "jz NOT_SUPPORTED \n\t" //If the same, CPUID instruction is not supported, //skip following instructions and jump to //NOT_SUPPORTED label "xorl %%eax,%%eax \n\t" //Set eax to zero "cpuid \n\t" //CPUID instruction (two bytes opcode) "orl %%eax,%%eax \n\t" //make sure eax return non-zero value "jz NOT_SUPPORTED \n\t" //If eax is zero, mmx not supported "xorl %%eax,%%eax \n\t" //set eax to zero "incl %%eax \n\t" //Now increment eax to 1. This instruction is //faster than the instruction "mov eax, 1" "cpuid \n\t" "andl $0x00800000,%%edx \n\t" //mask out all bits but mmx bit(24) "jz NOT_SUPPORTED \n\t" // non-zero = Yes, mmx IS supported "movl $1,%0 \n\t" "NOT_SUPPORTED: \n\t" "popl %%ebx \n\t" // restore ebx saved earlier : "=g" (mmx_supported) : // FIXASM: input regs, e.g.: "c" (count), "S" (src), "D" (dest) : "eax", "ecx", "edx", "cc");#endif return mmx_supported; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -