void Mgr_skip_input_data_fcn(j_decompress_ptr cinfo, long num_bytes) { // Cannot skip negative or 0 bytes. if (num_bytes <= 0) { LOGW("skipping 0 bytes in InputStream"); return; } SourceManager *src = reinterpret_cast<SourceManager*>(cinfo->src); if (src->mgr.bytes_in_buffer >= num_bytes) { src->mgr.bytes_in_buffer -= num_bytes; src->mgr.next_input_byte += num_bytes; } else { // if skipping more bytes than remain in buffer, set skip_bytes int64_t skip = num_bytes - src->mgr.bytes_in_buffer; src->mgr.next_input_byte += src->mgr.bytes_in_buffer; src->mgr.bytes_in_buffer = 0; int64_t actual = src->inStream->skip(skip); if (actual < 0) { ERREXIT(cinfo, JERR_FILE_READ); } skip -= actual; while (skip > 0) { actual = src->inStream->skip(skip); if (actual < 0) { ERREXIT(cinfo, JERR_FILE_READ); } skip -= actual; if (actual == 0) { // Multiple zero byte skips, likely EOF WARNMS(cinfo, JWRN_JPEG_EOF); return; } } } }
static boolean my_fill_input_buffer (j_decompress_ptr cinfo) { my_src_ptr src = (my_src_ptr) cinfo->src; size_t nbytes; if (src->src_size > INPUT_BUF_SIZE) nbytes = INPUT_BUF_SIZE; else nbytes = src->src_size; memcpy (src->buffer, src->src_buffer, nbytes); src->src_buffer += nbytes; src->src_size -= nbytes; if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ ERREXIT(cinfo, JERR_INPUT_EMPTY); WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; return TRUE; }
static boolean stdio_fill_input_buffer (j_decompress_ptr cinfo) { stdio_src_ptr src = (stdio_src_ptr) cinfo->src; size_t nbytes; nbytes = fread (src->buffer, 1, JPEG_PROG_BUF_SIZE, src->infile); if (nbytes <= 0) { #if 0 if (src->start_of_file) /* Treat empty input file as fatal error */ ERREXIT(cinfo, JERR_INPUT_EMPTY); WARNMS(cinfo, JWRN_JPEG_EOF); #endif /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; return TRUE; }
fill_input_buffer (j_decompress_ptr cinfo) { #ifndef USE_SYMBIAN my_src_ptr src = (my_src_ptr) cinfo->src; int nbytes; nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ ERREXIT(cinfo, JERR_INPUT_EMPTY); WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; #endif return TRUE; }
fill_input_buffer (j_decompress_ptr cinfo) { freeimage_src_ptr src = (freeimage_src_ptr) cinfo->src; size_t nbytes = src->m_io->read_proc(src->buffer, 1, INPUT_BUF_SIZE, src->infile); if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ throw(cinfo, JERR_INPUT_EMPTY); WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; return TRUE; }
jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines) { JDIMENSION lines_per_iMCU_row; if (cinfo->global_state != DSTATE_RAW_OK) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); if (cinfo->output_scanline >= cinfo->output_height) { WARNMS(cinfo, JWRN_TOO_MUCH_DATA); return 0; } /* Call progress monitor hook if present */ if (cinfo->progress != NULL) { cinfo->progress->pass_counter = (long) cinfo->output_scanline; cinfo->progress->pass_limit = (long) cinfo->output_height; (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); } /* Verify that at least one iMCU row can be returned. */ lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size; if (max_lines < lines_per_iMCU_row) ERREXIT(cinfo, JERR_BUFFER_SIZE); /* Decompress directly into user's buffer. */ if (! (*cinfo->coef->decompress_data) (cinfo, data)) return 0; /* suspension forced, can do nothing more */ /* OK, we processed one iMCU row. */ cinfo->output_scanline += lines_per_iMCU_row; return lines_per_iMCU_row; }
static boolean bmJpegFillInputBuffer( j_decompress_ptr cinfo ) { BmJpegInputSource * bjis= (BmJpegInputSource *)cinfo->src; size_t nbytes; nbytes= sioInReadBytes( bjis->bjisSis, bjis->bjisReadBuffer, INPUT_BUF_SIZE ); if ( nbytes <= 0 ) { if ( bjis->bjisAtBeginOfInput ) /* Treat empty input */ /* file as fatal error */ { ERREXIT( cinfo, JERR_INPUT_EMPTY ); } WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ bjis->bjisReadBuffer[0] = (JOCTET) 0xFF; bjis->bjisReadBuffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } bjis->pub.next_input_byte= bjis->bjisReadBuffer; bjis->pub.bytes_in_buffer= nbytes; bjis->bjisAtBeginOfInput= FALSE; return TRUE; }
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines) { JDIMENSION row_ctr, rows_left; if (cinfo->global_state != CSTATE_SCANNING) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); if (cinfo->next_scanline >= cinfo->image_height) WARNMS(cinfo, JWRN_TOO_MUCH_DATA); /* Call progress monitor hook if present */ if (cinfo->progress != NULL) { cinfo->progress->pass_counter = (long) cinfo->next_scanline; cinfo->progress->pass_limit = (long) cinfo->image_height; (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); } /* Give master control module another chance if this is first call to * jpeg_write_scanlines. This lets output of the frame/scan headers be * delayed so that application can write COM, etc, markers between * jpeg_start_compress and jpeg_write_scanlines. */ if (cinfo->master->call_pass_startup) (*cinfo->master->pass_startup) (cinfo); /* Ignore any extra scanlines at bottom of image. */ rows_left = cinfo->image_height - cinfo->next_scanline; if (num_lines > rows_left) num_lines = rows_left; row_ctr = 0; (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); cinfo->next_scanline += row_ctr; return row_ctr; }
fill_input_buffer (j_decompress_ptr cinfo) { stream_source_mgr* src = (stream_source_mgr*) cinfo->src; size_t nbytes; nbytes = stream_get_callbacks(src->stream) ->read(src->buffer, 1, INPUT_BUF_SIZE, src->stream); if (nbytes <= 0) { /* original: Treat empty input file as fatal error if (src->start_of_file_p) ERREXIT(cinfo, JERR_INPUT_EMPTY); */ ERREXIT(cinfo, JERR_INPUT_EOF); WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file_p = FALSE; return TRUE; }
jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines) { JDIMENSION row_ctr; if (cinfo->global_state != DSTATE_SCANNING) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); if (cinfo->output_scanline >= cinfo->output_height) { WARNMS(cinfo, JWRN_TOO_MUCH_DATA); return 0; } /* Call progress monitor hook if present */ if (cinfo->progress != NULL) { cinfo->progress->pass_counter = (long) cinfo->output_scanline; cinfo->progress->pass_limit = (long) cinfo->output_height; (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); } /* Process some data */ row_ctr = 0; (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines); cinfo->output_scanline += row_ctr; return row_ctr; }
sun_jpeg_fill_input_buffer(j_decompress_ptr cinfo) { sun_jpeg_source_ptr src = (sun_jpeg_source_ptr) cinfo->src; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); int ret, buflen; if (src->suspendable) { return FALSE; } if (src->remaining_skip) { src->pub.skip_input_data(cinfo, 0); } RELEASE_ARRAYS(env, src); buflen = (*env)->GetArrayLength(env, src->hInputBuffer); ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, 0, buflen); if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret <= 0) { /* Silently accept truncated JPEG files */ WARNMS(cinfo, JWRN_JPEG_EOF); src->inbuf[0] = (JOCTET) 0xFF; src->inbuf[1] = (JOCTET) JPEG_EOI; ret = 2; } src->pub.next_input_byte = src->inbuf; src->pub.bytes_in_buffer = ret; return TRUE; }
_jpeg_fill_input_buffer(j_decompress_ptr cinfo) { WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ cinfo->src->next_input_byte = fake_EOI; cinfo->src->bytes_in_buffer = sizeof(fake_EOI); return TRUE; }
boolean pgui_jpeg_fill_input_buffer (j_decompress_ptr cinfo) { pgui_jpeg_src_ptr src = (pgui_jpeg_src_ptr) cinfo->src; size_t nbytes; int size=INPUT_BUF_SIZE; // make sure we don't read past "size".. since we kept that in the jpeg_data structure, // artifically increment nbytes to look like it incremented the right size. (BUF_SIZE, // or remaining bytes left from jpeg_data->size size = ((g_jpeg_data.size-g_jpeg_data.copied_size) > INPUT_BUF_SIZE) ? INPUT_BUF_SIZE : (g_jpeg_data.size - g_jpeg_data.copied_size); memcpy(src->buffer, g_jpeg_data.lastptr, size); if(g_jpeg_data.copied_size < (g_jpeg_data.size - INPUT_BUF_SIZE)) { nbytes=INPUT_BUF_SIZE; g_jpeg_data.lastptr+=nbytes; } else { nbytes=(g_jpeg_data.size - g_jpeg_data.copied_size); } g_jpeg_data.copied_size+=nbytes; // if there is no data, and we have just started, mark an exit if (nbytes <= 0) { if (src->start_of_file){ /* Treat empty input file as fatal error */ printf("error: no data!\n"); WARNMS(cinfo, JERR_INPUT_EMPTY); return FALSE; } WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; return TRUE; }
safeboolean fill_input_buffer (j_decompress_ptr cinfo) { my_src_ptr src = (my_src_ptr) cinfo->src; /* 2.0.12: signed size. Thanks to Geert Jansen */ /* 2.0.14: some platforms (mingw-msys) don't have ssize_t. Call an int an int. */ int nbytes = 0; memset (src->buffer, 0, INPUT_BUF_SIZE); while (nbytes < INPUT_BUF_SIZE) { int got = gdGetBuf (src->buffer + nbytes, INPUT_BUF_SIZE - nbytes, src->infile); if ((got == EOF) || (got == 0)) { /* EOF or error. If we got any data, don't worry about it. If we didn't, then this is unexpected. */ if (!nbytes) { nbytes = -1; } break; } nbytes += got; } if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ ERREXIT (cinfo, JERR_INPUT_EMPTY); WARNMS (cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (unsigned char) 0xFF; src->buffer[1] = (unsigned char) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; return TRUE; }
METHODDEF void start_pass_huff_decoder(j_decompress_ptr cinfo) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; int ci, dctbl, actbl; jpeg_component_info *compptr; /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. * This ought to be an error condition, but we make it a warning because * there are some baseline files out there with all zeroes in these bytes. */ if(cinfo->Ss != 0 || cinfo->Se != DCTSIZE2 - 1 || cinfo->Ah != 0 || cinfo->Al != 0) { WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); } for(ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; dctbl = compptr->dc_tbl_no; actbl = compptr->ac_tbl_no; /* Make sure requested tables are present */ if(dctbl < 0 || dctbl >= NUM_HUFF_TBLS || cinfo->dc_huff_tbl_ptrs[dctbl] == NULL) { ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); } if(actbl < 0 || actbl >= NUM_HUFF_TBLS || cinfo->ac_huff_tbl_ptrs[actbl] == NULL) { ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); } /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[dctbl], &entropy->dc_derived_tbls[dctbl]); jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[actbl], &entropy->ac_derived_tbls[actbl]); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->bitstate.printed_eod = FALSE; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
start_pass_huff_decoder (j_decompress_ptr cinfo) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; int ci, blkn, dctbl, actbl; d_derived_tbl **pdtbl; jpeg_component_info * compptr; /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. * This ought to be an error condition, but we make it a warning because * there are some baseline files out there with all zeroes in these bytes. */ if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || cinfo->Ah != 0 || cinfo->Al != 0) WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[ci]; dctbl = compptr->dc_tbl_no; actbl = compptr->ac_tbl_no; /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ pdtbl = entropy->dc_derived_tbls + dctbl; jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, pdtbl); pdtbl = entropy->ac_derived_tbls + actbl; jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, pdtbl); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } /* Precalculate decoding info for each block in an MCU of this scan */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { ci = cinfo->MCU_membership[blkn]; compptr = cinfo->cur_comp_info[ci]; /* Precalculate which table to use for each block */ entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no]; entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no]; /* Decide whether we really care about the coefficient values */ if (compptr->component_needed) { entropy->dc_needed[blkn] = TRUE; /* we don't need the ACs if producing a 1/8th-size image */ entropy->ac_needed[blkn] = (compptr->_DCT_scaled_size > 1); } else { entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE; } } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->pub.insufficient_data = FALSE; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
start_pass_huff_decoder (j_decompress_ptr cinfo) { huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy; __boundcheck_metadata_store((void *)(&entropy),(void *)((size_t)(&entropy)+sizeof(entropy)*8-1)); int ci; __boundcheck_metadata_store((void *)(&ci),(void *)((size_t)(&ci)+sizeof(ci)*8-1)); int dctbl; __boundcheck_metadata_store((void *)(&dctbl),(void *)((size_t)(&dctbl)+sizeof(dctbl)*8-1)); int actbl; __boundcheck_metadata_store((void *)(&actbl),(void *)((size_t)(&actbl)+sizeof(actbl)*8-1)); jpeg_component_info * compptr; __boundcheck_metadata_store((void *)(&compptr),(void *)((size_t)(&compptr)+sizeof(compptr)*8-1)); /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG. * This ought to be an error condition, but we make it a warning because * there are some baseline files out there with all zeroes in these bytes. */ if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 || cinfo->Ah != 0 || cinfo->Al != 0) WARNMS(cinfo, JWRN_NOT_SEQUENTIAL); for (ci = 0; ci < cinfo->comps_in_scan; ci++) { compptr = cinfo->cur_comp_info[_RV_insert_check(0,4,92,15,"start_pass_huff_decoder",ci)]; dctbl = compptr->dc_tbl_no; actbl = compptr->ac_tbl_no; /* Make sure requested tables are present */ if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS || cinfo->dc_huff_tbl_ptrs[_RV_insert_check(0,4,97,2,"start_pass_huff_decoder",dctbl)] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl); if (actbl < 0 || actbl >= NUM_HUFF_TBLS || cinfo->ac_huff_tbl_ptrs[_RV_insert_check(0,4,100,2,"start_pass_huff_decoder",actbl)] == NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl); /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_d_derived_tbl(cinfo, cinfo->dc_huff_tbl_ptrs[_RV_insert_check(0,4,104,36,"start_pass_huff_decoder",dctbl)], & entropy->dc_derived_tbls[_RV_insert_check(0,4,105,10,"start_pass_huff_decoder",dctbl)]); jpeg_make_d_derived_tbl(cinfo, cinfo->ac_huff_tbl_ptrs[_RV_insert_check(0,4,106,36,"start_pass_huff_decoder",actbl)], & entropy->ac_derived_tbls[_RV_insert_check(0,4,107,10,"start_pass_huff_decoder",actbl)]); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[_RV_insert_check(0,4,109,5,"start_pass_huff_decoder",ci)] = 0; } /* Initialize bitread state variables */ entropy->bitstate.bits_left = 0; entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */ entropy->bitstate.printed_eod = FALSE; /* Initialize restart counter */ entropy->restarts_to_go = cinfo->restart_interval; }
sun_jpeg_fill_suspended_buffer(j_decompress_ptr cinfo) { sun_jpeg_source_ptr src = (sun_jpeg_source_ptr) cinfo->src; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); size_t offset, buflen; int ret; RELEASE_ARRAYS(env, src); ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_availableID); if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret < 0 || (unsigned int)ret <= src->remaining_skip) { return; } if (src->remaining_skip) { src->pub.skip_input_data(cinfo, 0); } /* Save the data currently in the buffer */ offset = src->pub.bytes_in_buffer; if (src->pub.next_input_byte > src->inbuf) { memmove(src->inbuf, src->pub.next_input_byte, offset); } RELEASE_ARRAYS(env, src); buflen = (*env)->GetArrayLength(env, src->hInputBuffer) - offset; if (buflen <= 0) { if (!GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } return; } ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, offset, buflen); if ((ret > 0) && ((unsigned int)ret > buflen)) ret = (int)buflen; if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret <= 0) { /* Silently accept truncated JPEG files */ WARNMS(cinfo, JWRN_JPEG_EOF); src->inbuf[offset] = (JOCTET) 0xFF; src->inbuf[offset + 1] = (JOCTET) JPEG_EOI; ret = 2; } src->pub.next_input_byte = src->inbuf; src->pub.bytes_in_buffer = ret + offset; return; }
jpeg_write_raw_data( j_compress_ptr cinfo, JSAMPIMAGE data, JDIMENSION num_lines ) { JDIMENSION lines_per_iMCU_row; if( cinfo->global_state != CSTATE_RAW_OK ) { ERREXIT1( cinfo, JERR_BAD_STATE, cinfo->global_state ); } if( cinfo->next_scanline >= cinfo->image_height ) { WARNMS( cinfo, JWRN_TOO_MUCH_DATA ); return 0; } /* Call progress monitor hook if present */ if( cinfo->progress != NULL ) { cinfo->progress->pass_counter = ( long ) cinfo->next_scanline; cinfo->progress->pass_limit = ( long ) cinfo->image_height; ( *cinfo->progress->progress_monitor )( ( j_common_ptr ) cinfo ); } /* Give master control module another chance if this is first call to * jpeg_write_raw_data. This lets output of the frame/scan headers be * delayed so that application can write COM, etc, markers between * jpeg_start_compress and jpeg_write_raw_data. */ if( cinfo->master->call_pass_startup ) { ( *cinfo->master->pass_startup )( cinfo ); } /* Verify that at least one iMCU row has been passed. */ lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size; if( num_lines < lines_per_iMCU_row ) { ERREXIT( cinfo, JERR_BUFFER_SIZE ); } /* Directly compress the row. */ if( !( *cinfo->coef->compress_data )( cinfo, data ) ) { /* If compressor did not consume the whole row, suspend processing. */ return 0; } /* OK, we processed one iMCU row. */ cinfo->next_scanline += lines_per_iMCU_row; return lines_per_iMCU_row; }
boolean ImageFormatJPG::file_fill_input_buffer(j_decompress_ptr decompress) { FileSource *source = (FileSource*)decompress->src; size_t bytes = fread(source->buffer,sizeof(char),sizeof(source->buffer),source->file); if(bytes <= 0) { if(ftell(source->file) == 0) ERREXIT(decompress,JERR_INPUT_EMPTY); WARNMS(decompress,JWRN_JPEG_EOF); source->buffer[0] = (JOCTET)0xff; source->buffer[1] = (JOCTET)JPEG_EOI; bytes = 2; } source->pub.next_input_byte = source->buffer; source->pub.bytes_in_buffer = bytes; return true; }
static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo) { unsigned char *buf= (unsigned char*) dinfo->src->next_input_byte-2; /* if we get called, must have run out of data */ WARNMS(dinfo, JWRN_JPEG_EOF); buf[0]= (JOCTET) 0xFF; buf[1]= (JOCTET) JPEG_EOI; dinfo->src->next_input_byte= buf; dinfo->src->bytes_in_buffer= 2; return TRUE; }
fill_input_buffer (j_decompress_ptr cinfo) { my_src_ptr src = (my_src_ptr) cinfo->src; WARNMS(cinfo, JWRN_JPEG_EOF); /* Create a fake EOI marker */ src->eoi_buffer[0] = (JOCTET) 0xFF; src->eoi_buffer[1] = (JOCTET) JPEG_EOI; src->pub.next_input_byte = src->eoi_buffer; src->pub.bytes_in_buffer = 2; return TRUE; }
fill_input_buffer_ipp (j_decompress_ptr cinfo) { my_src_ptr src = (my_src_ptr) cinfo->src; size_t bytes_left = src->pub.bytes_in_buffer; size_t bytes_to_read = INPUT_BUF_SIZE - bytes_left; if(src->start_of_file || cinfo->progressive_mode) { return fill_input_buffer(cinfo); } memmove(src->buffer,src->pub.next_input_byte,bytes_left); size_t nbytes = VSIFReadL(src->buffer + bytes_left, 1, bytes_to_read, src->infile); if(nbytes <= 0) { if(src->start_of_file) { /* Treat empty input file as fatal error */ ERREXIT(cinfo, JERR_INPUT_EMPTY); } if(src->pub.bytes_in_buffer == 0 && cinfo->unread_marker == 0) { WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET)0xFF; src->buffer[1] = (JOCTET)JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = bytes_left + nbytes; src->start_of_file = FALSE; return TRUE; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = bytes_left + nbytes; src->start_of_file = FALSE; return TRUE; }
jpeg_undifference6(j_decompress_ptr cinfo, int comp_index, JDIFFROW diff_buf, JDIFFROW prev_row, JDIFFROW undiff_buf, JDIMENSION width) { #ifdef SUPPORT_DICOMOBJECTS_BUG unsigned int xindex; int Ra, Rb, Rc; int min, max, temp; SHIFT_TEMPS if( dicomobjectsbug == -1 ) { dicomobjectsbug = 0; /* no bug by default */ Rb = GETJSAMPLE(prev_row[0]); Ra = (diff_buf[0] + PREDICTOR2) & 0xFFFF; undiff_buf[0] = Ra; temp = min = max = undiff_buf[0]; for (xindex = 1; xindex < width; xindex++) { Rc = Rb; Rb = GETJSAMPLE(prev_row[xindex]); Ra = (diff_buf[xindex] + PREDICTOR6) & 0xFFFF; temp = Ra; min = temp < min ? temp : min; max = temp > max ? temp : max; } if( (max - min) > 50000) /* magic number */ { dicomobjectsbug = 1; WARNMS(cinfo, JWRN_SIGNED_ARITH); } } if(dicomobjectsbug) { UNDIFFERENCE_2D_BUG(PREDICTOR6_BUG); } else { UNDIFFERENCE_2D_BUG(PREDICTOR6); } #else SHIFT_TEMPS UNDIFFERENCE_2D(PREDICTOR6); #endif (void)comp_index;(void)cinfo; }
METHODDEF(boolean) src_fill_buffer(j_decompress_ptr cinfo) { SrcPtr src = (SrcPtr)cinfo->src; static const JOCTET eoi[2] = { 0xFF, JPEG_EOI }; /* * since jpeg_mem_src fills the buffer with everything we've got, * jpeg is trying to read beyond end of buffer. return a fake EOI marker. * note: don't modify input buffer: it might be read-only. */ WARNMS(cinfo, JWRN_JPEG_EOF); src->pub.next_input_byte = eoi; src->pub.bytes_in_buffer = 2; return TRUE; }
static boolean dctd_fill_input_buffer(j_decompress_ptr dinfo) { jpeg_decompress_data *jddp = (jpeg_decompress_data *) ((char *)dinfo - offset_of(jpeg_decompress_data, dinfo)); if (!jddp->input_eod) return FALSE; /* normal case: suspend processing */ /* Reached end of source data without finding EOI */ WARNMS(dinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ dinfo->src->next_input_byte = fake_eoi; dinfo->src->bytes_in_buffer = 2; jddp->faked_eoi = true; /* so process routine doesn't use next_input_byte */ return TRUE; }
fill_input_buffer (j_decompress_ptr cinfo) { // since the initial buffer contains all the data that we have, // if this method is called, it means we're out of data already // so we make up fake data to keep the decoder alive my_src_ptr src = (my_src_ptr) cinfo->src; WARNMS(cinfo, JWRN_JPEG_EOF); // Insert a fake EOI marker src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = 2; return TRUE; }
static boolean fill_mem_input_buffer (j_decompress_ptr cinfo) { static const JOCTET mybuffer[4] = { (JOCTET) 0xFF, (JOCTET) JPEG_EOI, 0, 0 }; /* The whole JPEG data is expected to reside in the supplied memory * buffer, so any request for more data beyond the given buffer size * is treated as an error. */ WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ cinfo->src->next_input_byte = mybuffer; cinfo->src->bytes_in_buffer = 2; return true; }
//------------------------------------------------------------------------- boolean CFKFileJpg::FillInputBuffer( j_decompress_ptr p_pInfo ) { size_t nBytes = 0; CFKFileJpg* pSource = (CFKFileJpg*)p_pInfo->src; nBytes = pSource->m_pFile->Read( pSource->m_pBuffer, 1, JEPG_FILE_BUF_SIZE ); if( nBytes <= 0 ) { if( pSource->m_bIsStartOfFile ) ERREXIT( p_pInfo, JERR_INPUT_EMPTY ); WARNMS( p_pInfo, JWRN_JPEG_EOF ); pSource->m_pBuffer[0] = (JOCTET)0xFF; pSource->m_pBuffer[1] = (JOCTET)JPEG_EOI; nBytes = 2; } pSource->next_input_byte = pSource->m_pBuffer; pSource->bytes_in_buffer = nBytes; pSource->m_bIsStartOfFile = false; return true; }
/****************************************************************************** * * Function fill_input_buffer * * This is the custom source manager's fill input buffer routine, called by * the JPEG library whenever it has finished processing the data in the * source buffer and needs it to be refilled with the next chunk of data. * *****************************************************************************/ static boolean fill_input_buffer ( j_decompress_ptr cinfo) { stream_src_ptr src = (stream_src_ptr) cinfo->src; size_t nbytes; /* ** Since we always process buffer-based streams in a single chunk, the ** only reason read_input_buffer should be called for one is if the data ** in the buffer was truncated or otherwise bogus. If this is the case ** we set nbytes to zero, allocate a new buffer to hold a fake EOI marker ** so the stream buffer isn't overwritten, and let the error-handling ** code below take care of things. */ if (src->stream->type == _DtGrBUFFER) { nbytes = 0; src->buffer = (JOCTET *) (*cinfo->mem->alloc_small) ( (j_common_ptr) cinfo, JPOOL_IMAGE, 2 * SIZEOF(JOCTET)); } else /* _DtGrFILE, read the next chunk of data */ nbytes = _DtGrRead (src->buffer, 1, src->input_buf_size, src->stream); if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ ERREXIT(cinfo, JERR_INPUT_EMPTY); WARNMS(cinfo, JWRN_JPEG_EOF); /* Insert a fake EOI marker */ src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; nbytes = 2; } src->pub.next_input_byte = src->buffer; src->pub.bytes_in_buffer = nbytes; src->start_of_file = FALSE; return TRUE; }