⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libjpeg.doc

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 DOC
📖 第 1 页 / 共 5 页
字号:
	struct jpeg_error_mgr jerr;	...	cinfo.err = jpeg_std_error(&jerr);	jpeg_create_compress(&cinfo);jpeg_create_compress allocates a small amount of memory, so it could failif you are out of memory.  In that case it will exit via the error handler;that's why the error handler must be initialized first.2. Specify the destination for the compressed data (eg, a file).As previously mentioned, the JPEG library delivers compressed data to a"data destination" module.  The library includes one data destinationmodule which knows how to write to a stdio stream.  You can use your owndestination module if you want to do something else, as discussed later.If you use the standard destination module, you must open the target stdiostream beforehand.  Typical code for this step looks like:	FILE * outfile;	...	if ((outfile = fopen(filename, "wb")) == NULL) {	    fprintf(stderr, "can't open %s\n", filename);	    exit(1);	}	jpeg_stdio_dest(&cinfo, outfile);where the last line invokes the standard destination module.WARNING: it is critical that the binary compressed data be delivered to theoutput file unchanged.  On non-Unix systems the stdio library may performnewline translation or otherwise corrupt binary data.  To suppress thisbehavior, you may need to use a "b" option to fopen (as shown above), or usesetmode() or another routine to put the stdio stream in binary mode.  Seecjpeg.c and djpeg.c for code that has been found to work on many systems.You can select the data destination after setting other parameters (step 3),if that's more convenient.  You may not change the destination betweencalling jpeg_start_compress() and jpeg_finish_compress().3. Set parameters for compression, including image size & colorspace.You must supply information about the source image by setting the followingfields in the JPEG object (cinfo structure):	image_width		Width of image, in pixels	image_height		Height of image, in pixels	input_components	Number of color channels (samples per pixel)	in_color_space		Color space of source imageThe image dimensions are, hopefully, obvious.  JPEG supports image dimensionsof 1 to 64K pixels in either direction.  The input color space is typicallyRGB or grayscale, and input_components is 3 or 1 accordingly.  (See "Specialcolor spaces", later, for more info.)  The in_color_space field must beassigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB orJCS_GRAYSCALE.JPEG has a large number of compression parameters that determine how theimage is encoded.  Most applications don't need or want to know about allthese parameters.  You can set all the parameters to reasonable defaults bycalling jpeg_set_defaults(); then, if there are particular values you wantto change, you can do so after that.  The "Compression parameter selection"section tells about all the parameters.You must set in_color_space correctly before calling jpeg_set_defaults(),because the defaults depend on the source image colorspace.  However theother three source image parameters need not be valid until you calljpeg_start_compress().  There's no harm in calling jpeg_set_defaults() morethan once, if that happens to be convenient.Typical code for a 24-bit RGB source image is	cinfo.image_width = Width; 	/* image width and height, in pixels */	cinfo.image_height = Height;	cinfo.input_components = 3;	/* # of color components per pixel */	cinfo.in_color_space = JCS_RGB; /* colorspace of input image */	jpeg_set_defaults(&cinfo);	/* Make optional parameter settings here */4. jpeg_start_compress(...);After you have established the data destination and set all the necessarysource image info and other parameters, call jpeg_start_compress() to begina compression cycle.  This will initialize internal state, allocate workingstorage, and emit the first few bytes of the JPEG datastream header.Typical code:	jpeg_start_compress(&cinfo, TRUE);The "TRUE" parameter ensures that a complete JPEG interchange datastreamwill be written.  This is appropriate in most cases.  If you think you mightwant to use an abbreviated datastream, read the section on abbreviateddatastreams, below.Once you have called jpeg_start_compress(), you may not alter any JPEGparameters or other fields of the JPEG object until you have completedthe compression cycle.5. while (scan lines remain to be written)	jpeg_write_scanlines(...);Now write all the required image data by calling jpeg_write_scanlines()one or more times.  You can pass one or more scanlines in each call, upto the total image height.  In most applications it is convenient to passjust one or a few scanlines at a time.  The expected format for the passeddata is discussed under "Data formats", above.Image data should be written in top-to-bottom scanline order.  The JPEG speccontains some weasel wording about how top and bottom are application-definedterms (a curious interpretation of the English language...) but if you wantyour files to be compatible with everyone else's, you WILL use top-to-bottomorder.  If the source data must be read in bottom-to-top order, you can usethe JPEG library's virtual array mechanism to invert the data efficiently.Examples of this can be found in the sample application cjpeg.The library maintains a count of the number of scanlines written so farin the next_scanline field of the JPEG object.  Usually you can just usethis variable as the loop counter, so that the loop test looks like"while (cinfo.next_scanline < cinfo.image_height)".Code for this step depends heavily on the way that you store the source data.example.c shows the following code for the case of a full-size 2-D sourcearray containing 3-byte RGB pixels:	JSAMPROW row_pointer[1];	/* pointer to a single row */	int row_stride;			/* physical row width in buffer */	row_stride = image_width * 3;	/* JSAMPLEs per row in image_buffer */	while (cinfo.next_scanline < cinfo.image_height) {	    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];	    jpeg_write_scanlines(&cinfo, row_pointer, 1);	}jpeg_write_scanlines() returns the number of scanlines actually written.This will normally be equal to the number passed in, so you can usuallyignore the return value.  It is different in just two cases:  * If you try to write more scanlines than the declared image height,    the additional scanlines are ignored.  * If you use a suspending data destination manager, output buffer overrun    will cause the compressor to return before accepting all the passed lines.    This feature is discussed under "I/O suspension", below.  The normal    stdio destination manager will NOT cause this to happen.In any case, the return value is the same as the change in the value ofnext_scanline.6. jpeg_finish_compress(...);After all the image data has been written, call jpeg_finish_compress() tocomplete the compression cycle.  This step is ESSENTIAL to ensure that thelast bufferload of data is written to the data destination.jpeg_finish_compress() also releases working memory associated with the JPEGobject.Typical code:	jpeg_finish_compress(&cinfo);If using the stdio destination manager, don't forget to close the outputstdio stream (if necessary) afterwards.If you have requested a multi-pass operating mode, such as Huffman codeoptimization, jpeg_finish_compress() will perform the additional passes usingdata buffered by the first pass.  In this case jpeg_finish_compress() may takequite a while to complete.  With the default compression parameters, this willnot happen.It is an error to call jpeg_finish_compress() before writing the necessarytotal number of scanlines.  If you wish to abort compression, calljpeg_abort() as discussed below.After completing a compression cycle, you may dispose of the JPEG objectas discussed next, or you may use it to compress another image.  In that casereturn to step 2, 3, or 4 as appropriate.  If you do not change thedestination manager, the new datastream will be written to the same target.If you do not change any JPEG parameters, the new datastream will be writtenwith the same parameters as before.  Note that you can change the input imagedimensions freely between cycles, but if you change the input colorspace, youshould call jpeg_set_defaults() to adjust for the new colorspace; and thenyou'll need to repeat all of step 3.7. Release the JPEG compression object.When you are done with a JPEG compression object, destroy it by callingjpeg_destroy_compress().  This will free all subsidiary memory (regardless ofthe previous state of the object).  Or you can call jpeg_destroy(), whichworks for either compression or decompression objects --- this may be moreconvenient if you are sharing code between compression and decompressioncases.  (Actually, these routines are equivalent except for the declared typeof the passed pointer.  To avoid gripes from ANSI C compilers, jpeg_destroy()should be passed a j_common_ptr.)If you allocated the jpeg_compress_struct structure from malloc(), freeingit is your responsibility --- jpeg_destroy() won't.  Ditto for the errorhandler structure.Typical code:	jpeg_destroy_compress(&cinfo);8. Aborting.If you decide to abort a compression cycle before finishing, you can clean upin either of two ways:* If you don't need the JPEG object any more, just call  jpeg_destroy_compress() or jpeg_destroy() to release memory.  This is  legitimate at any point after calling jpeg_create_compress() --- in fact,  it's safe even if jpeg_create_compress() fails.* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call  jpeg_abort() which works on both compression and decompression objects.  This will return the object to an idle state, releasing any working memory.  jpeg_abort() is allowed at any time after successful object creation.Note that cleaning up the data destination, if required, is yourresponsibility; neither of these routines will call term_destination().(See "Compressed data handling", below, for more about that.)jpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEGobject that has reported an error by calling error_exit (see "Error handling"for more info).  The internal state of such an object is likely to be out ofwhack.  Either of these two routines will return the object to a known state.Decompression details---------------------Here we revisit the JPEG decompression outline given in the overview.1. Allocate and initialize a JPEG decompression object.This is just like initialization for compression, as discussed above,except that the object is a "struct jpeg_decompress_struct" and youcall jpeg_create_decompress().  Error handling is exactly the same.Typical code:	struct jpeg_decompress_struct cinfo;	struct jpeg_error_mgr jerr;	...	cinfo.err = jpeg_std_error(&jerr);	jpeg_create_decompress(&cinfo);(Both here and in the IJG code, we usually use variable name "cinfo" forboth compression and decompression objects.)2. Specify the source of the compressed data (eg, a file).As previously mentioned, the JPEG library reads compressed data from a "datasource" module.  The library includes one data source module which knows howto read from a stdio stream.  You can use your own source module if you wantto do something else, as discussed later.If you use the standard source module, you must open the source stdio streambeforehand.  Typical code for this step looks like:	FILE * infile;	...	if ((infile = fopen(filename, "rb")) == NULL) {	    fprintf(stderr, "can't open %s\n", filename);	    exit(1);	}	jpeg_stdio_src(&cinfo, infile);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -