亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? jpeg.cpp

?? 《精通 vc++ 圖像編程》的源代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
	*/
	struct my_error_mgr jerr;
	/* More stuff */
	FILE * infile;		/* source file */
	JSAMPARRAY buffer;		/* Output row buffer */
	int row_stride;		/* physical row width in output buffer */
	char buf[250];

	/* In this example we want to open the input file before doing anything else,
	* so that the setjmp() error recovery below can assume the file is open.
	* VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
	* requires it in order to read binary files.
	*/

	if ((infile = fopen(lpstrFileName, "rb")) == NULL) 
	{
		sprintf(buf, "JPEG :\nCan't open %s\n", lpstrFileName);
		m_strJPEGError = buf;
		return NULL;
	}

	/* Step 1: allocate and initialize JPEG decompression object */

	/* We set up the normal JPEG error routines, then override error_exit. */
	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = my_error_exit;


	/* Establish the setjmp return context for my_error_exit to use. */
	if (setjmp(jerr.setjmp_buffer)) 
	{
		/* If we get here, the JPEG code has signaled an error.
		 * We need to clean up the JPEG object, close the input file, and return.
		 */

		jpeg_destroy_decompress(&cinfo);
		fclose(infile);
		return NULL;
	}

	/* Now we can initialize the JPEG decompression object. */
	jpeg_create_decompress(&cinfo);

	/* Step 2: specify data source (eg, a file) */

	jpeg_stdio_src(&cinfo, infile);

	/* Step 3: read file parameters with jpeg_read_header() */

	(void) jpeg_read_header(&cinfo, TRUE);
	/* We can ignore the return value from jpeg_read_header since
	*   (a) suspension is not possible with the stdio data source, and
	*   (b) we passed TRUE to reject a tables-only JPEG file as an error.
	* See libjpeg.doc for more info.
	*/

	/* Step 4: set parameters for decompression */

	/* In this example, we don't need to change any of the defaults set by
	* jpeg_read_header(), so we do nothing here.
	*/

	/* Step 5: Start decompressor */

	(void) jpeg_start_decompress(&cinfo);
	/* We can ignore the return value since suspension is not possible
	* with the stdio data source.
	*/

	/* We may need to do some setup of our own at this point before reading
	* the data.  After jpeg_start_decompress() we have the correct scaled
	* output image dimensions available, as well as the output colormap
	* if we asked for color quantization.
	* In this example, we need to make an output work buffer of the right size.
	*/ 

	// get our buffer set to hold data
	BYTE *dataBuf;

	////////////////////////////////////////////////////////////
	// alloc and open our new buffer
	dataBuf=(BYTE *)new BYTE[cinfo.output_width * 3 * cinfo.output_height];
	if (dataBuf==NULL) 
	{

		m_strJPEGError = "JpegFile :\nOut of memory";

		jpeg_destroy_decompress(&cinfo);
		
		fclose(infile);

		return NULL;
	}

	// how big is this thing gonna be?
	*uWidth = cinfo.output_width;
	*uHeight = cinfo.output_height;
	
	/* JSAMPLEs per row in output buffer */
	row_stride = cinfo.output_width * cinfo.output_components;

	/* Make a one-row-high sample array that will go away when done with image */
	buffer = (*cinfo.mem->alloc_sarray)
		((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

	/* Step 6: while (scan lines remain to be read) */
	/*           jpeg_read_scanlines(...); */

	/* Here we use the library's state variable cinfo.output_scanline as the
	* loop counter, so that we don't have to keep track ourselves.
	*/
	while (cinfo.output_scanline < cinfo.output_height) 
	{
		/* jpeg_read_scanlines expects an array of pointers to scanlines.
		 * Here the array is only one element long, but you could ask for
		 * more than one scanline at a time if that's more convenient.
		 */
		(void) jpeg_read_scanlines(&cinfo, buffer, 1);
		/* Assume put_scanline_someplace wants a pointer and sample count. */

		// asuumer all 3-components are RGBs
		if (cinfo.out_color_components==3) 
		{
			
			j_putRGBScanline(buffer[0], 
							*uWidth,
							dataBuf,
							cinfo.output_scanline-1);

		} 
		else if (cinfo.out_color_components==1) 
		{

			// assume all single component images are grayscale
			j_putGrayScanlineToRGB(buffer[0], 
								*uWidth,
								dataBuf,
								cinfo.output_scanline-1);

		}

	}

	/* Step 7: Finish decompression */

	(void) jpeg_finish_decompress(&cinfo);
	/* We can ignore the return value since suspension is not possible
	* with the stdio data source.
	*/

	/* Step 8: Release JPEG decompression object */

	/* This is an important step since it will release a good deal of memory. */
	jpeg_destroy_decompress(&cinfo);

	/* After finish_decompress, we can close the input file.
	* Here we postpone it until after no more JPEG errors are possible,
	* so as to simplify the setjmp error logic above.  (Actually, I don't
	* think that jpeg_destroy can do an error exit, but why assume anything...)
	*/
	fclose(infile);

	/* At this point you may want to check to see whether any corrupt-data
	* warnings occurred (test whether jerr.pub.num_warnings is nonzero).
	*/

	return dataBuf;
}

//
//	write a JPEG file
//
BOOL CJpeg::WriteJPEGFile(LPCSTR lpstrFileName, 
						BYTE *dataBuf,
						UINT widthPix,
						UINT height,
						BOOL color, 
						int quality)
{
	if (dataBuf==NULL)
		return FALSE;
	if (widthPix==0)
		return FALSE;
	if (height==0)
		return FALSE;

	LPBYTE tmp;
	if (!color) 
	{
		tmp = (BYTE*)new BYTE[widthPix*height];
		if (tmp==NULL) 
		{
			m_strJPEGError = "Memory error";
			return FALSE;
		}

		UINT row,col;
		for (row=0;row<height;row++) 
		{
			for (col=0;col<widthPix;col++) 
			{
				LPBYTE pRed, pGrn, pBlu;
				pRed = dataBuf + row * widthPix * 3 + col * 3;
				pGrn = dataBuf + row * widthPix * 3 + col * 3 + 1;
				pBlu = dataBuf + row * widthPix * 3 + col * 3 + 2;

				// luminance
				int lum = (int)(.299 * (double)(*pRed) + .587 * (double)(*pGrn) + .114 * (double)(*pBlu));
				LPBYTE pGray;
				pGray = tmp + row * widthPix + col;
				*pGray = (BYTE)lum;
			}
		}
	}

	struct jpeg_compress_struct cinfo;
	/* More stuff */
	FILE * outfile;			/* target file */
	int row_stride;			/* physical row widthPix in image buffer */

	struct my_error_mgr jerr;

	/* Step 1: allocate and initialize JPEG compression object */
	cinfo.err = jpeg_std_error(&jerr.pub);
	jerr.pub.error_exit = my_error_exit;

	/* Establish the setjmp return context for my_error_exit to use. */
	if (setjmp(jerr.setjmp_buffer)) 
	{
		/* If we get here, the JPEG code has signaled an error.
		 * We need to clean up the JPEG object, close the input file, and return.
		 */

		jpeg_destroy_compress(&cinfo);
		fclose(outfile);

		if (!color) 
		{
			delete [] tmp;
		}
		return FALSE;
	}

	/* Now we can initialize the JPEG compression object. */
	jpeg_create_compress(&cinfo);

	/* Step 2: specify data destination (eg, a file) */
	/* Note: steps 2 and 3 can be done in either order. */

	if ((outfile = fopen(lpstrFileName, "wb")) == NULL) 
	{
		char buf[250];
		sprintf(buf, "JpegFile :\nCan't open %s\n", lpstrFileName);
		m_strJPEGError = buf;
		return FALSE;
	}

	jpeg_stdio_dest(&cinfo, outfile);

	/* Step 3: set parameters for compression */
												    
	/* First we supply a description of the input image.
	* Four fields of the cinfo struct must be filled in:
	*/
	cinfo.image_width = widthPix; 	/* image widthPix and height, in pixels */
	cinfo.image_height = height;
	if (color) 
	{
		cinfo.input_components = 3;		/* # of color components per pixel */
		cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
	} 
	else 
	{
		cinfo.input_components = 1;		/* # of color components per pixel */
		cinfo.in_color_space = JCS_GRAYSCALE; 	/* colorspace of input image */
	}

 
/* Now use the library's routine to set default compression parameters.
   * (You must set at least cinfo.in_color_space before calling this,
   * since the defaults depend on the source color space.)
   */

  jpeg_set_defaults(&cinfo);
  /* Now you can set any non-default parameters you wish to.
   * Here we just illustrate the use of quality (quantization table) scaling:
   */
  jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);

  /* Step 4: Start compressor */

  /* TRUE ensures that we will write a complete interchange-JPEG file.
   * Pass TRUE unless you are very sure of what you're doing.
   */
  jpeg_start_compress(&cinfo, TRUE);

  /* Step 5: while (scan lines remain to be written) */
  /*           jpeg_write_scanlines(...); */

  /* Here we use the library's state variable cinfo.next_scanline as the
   * loop counter, so that we don't have to keep track ourselves.
   * To keep things simple, we pass one scanline per call; you can pass
   * more if you wish, though.
   */
  row_stride = widthPix * 3;	/* JSAMPLEs per row in image_buffer */

  while (cinfo.next_scanline < cinfo.image_height) 
  {
    /* jpeg_write_scanlines expects an array of pointers to scanlines.
     * Here the array is only one element long, but you could pass
     * more than one scanline at a time if that's more convenient.
     */
	LPBYTE outRow;
	if (color) 
	{
		outRow = dataBuf + (cinfo.next_scanline * widthPix * 3);
	} 
	else 
	{
		outRow = tmp + (cinfo.next_scanline * widthPix);
	}

    (void) jpeg_write_scanlines(&cinfo, &outRow, 1);
  }

  /* Step 6: Finish compression */

  jpeg_finish_compress(&cinfo);

  /* After finish_compress, we can close the output file. */
  fclose(outfile);

  /* Step 7: release JPEG compression object */

  /* This is an important step since it will release a good deal of memory. */
  jpeg_destroy_compress(&cinfo);

  if (!color)
	  delete [] tmp;
  /* And we're done! */

  return TRUE;
}

//
//	stash a scanline
//

void j_putRGBScanline(BYTE *jpegline, 
					 int widthPix,
					 BYTE *outBuf,
					 int row)
{
	int offset = row * widthPix * 3;
	int count;
	for (count=0;count<widthPix;count++) {
		BYTE iRed, iBlu, iGrn;
		LPBYTE oRed, oBlu, oGrn;

		iRed = *(jpegline + count * 3 + 0);
		iGrn = *(jpegline + count * 3 + 1);
		iBlu = *(jpegline + count * 3 + 2);

		oRed = outBuf + offset + count * 3 + 0;
		oGrn = outBuf + offset + count * 3 + 1;
		oBlu = outBuf + offset + count * 3 + 2;

		*oRed = iRed;
		*oGrn = iGrn;
		*oBlu = iBlu;
	}
}

//
//	stash a gray scanline
//

void j_putGrayScanlineToRGB(BYTE *jpegline, 
							 int widthPix,
							 BYTE *outBuf,
							 int row)
{
	int offset = row * widthPix * 3;
	int count;
	for (count=0;count<widthPix;count++) 
	{
		BYTE iGray;
		LPBYTE oRed, oBlu, oGrn;

		// get our grayscale value
		iGray = *(jpegline + count);

		oRed = outBuf + offset + count * 3;
		oGrn = outBuf + offset + count * 3 + 1;
		oBlu = outBuf + offset + count * 3 + 2;

		*oRed = iGray;
		*oGrn = iGray;
		*oBlu = iGray;
	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区三区啪啪| 一区二区三区美女视频| 国产精品网站在线观看| 一区二区三区不卡在线观看 | 亚洲一区二区三区四区不卡 | 久久99国产精品麻豆| 国产精品一区二区免费不卡| 成人国产精品免费网站| 欧美在线观看视频在线| 欧美精品一区男女天堂| 一级日本不卡的影视| 老司机一区二区| 日本道色综合久久| 久久久精品蜜桃| 免费看日韩a级影片| 欧美一级片免费看| 国产午夜精品一区二区三区视频| 一区二区成人在线| 成人午夜视频网站| 欧美大片一区二区| 五月天激情综合| 日本二三区不卡| 亚洲视频一区在线| 成人中文字幕合集| 久久久不卡影院| 日韩影院免费视频| 在线观看区一区二| 国产精品久久久久久妇女6080| 精品午夜一区二区三区在线观看| 欧美日韩1区2区| 亚洲高清视频中文字幕| 色婷婷精品大在线视频| 一区免费观看视频| thepron国产精品| 亚洲女同ⅹxx女同tv| 99re66热这里只有精品3直播| 国产欧美日韩精品a在线观看| 国内精品嫩模私拍在线| 欧美成人午夜电影| 久久av资源站| 国产欧美一区二区精品性色 | 91免费观看在线| 一区二区在线观看视频在线观看| 波多野结衣亚洲一区| 中文字幕综合网| 欧美午夜影院一区| 麻豆视频观看网址久久| 久久精品一区二区三区四区| 国产精品一区2区| 亚洲欧美一区二区三区孕妇| 国产欧美精品一区二区色综合朱莉| 久久超碰97人人做人人爱| 国产日韩精品一区二区三区 | 久久99久久99| 国产精品卡一卡二卡三| 欧美视频一区二区| 国产成人啪午夜精品网站男同| 成人免费一区二区三区在线观看| 在线观看日韩国产| 国产乱码精品一区二区三区忘忧草 | 日韩亚洲欧美成人一区| 国产乱子伦视频一区二区三区| 亚洲欧美综合另类在线卡通| 91麻豆精品国产91久久久资源速度| 国产精品99久久久久久有的能看| 亚洲欧美日韩电影| 欧美xxxx在线观看| 色综合中文字幕国产| 另类小说图片综合网| 亚洲精品美腿丝袜| 久久精品视频在线免费观看| 欧美日韩精品一区二区天天拍小说| 国产在线国偷精品免费看| 亚洲综合区在线| 国产精品剧情在线亚洲| 久久久久国产精品人| 欧美成人bangbros| 欧美色综合久久| 91在线观看一区二区| 激情久久五月天| 婷婷成人激情在线网| 一区二区三区在线视频观看 | 久久精品一区二区三区不卡| 精品福利一区二区三区免费视频| 在线观看视频一区| 精品视频在线免费看| 91久久精品一区二区| 91小宝寻花一区二区三区| 国产成人精品免费网站| 国产一区999| 国产成人精品1024| 成人综合婷婷国产精品久久| 日韩精品专区在线影院重磅| 日韩视频一区二区| 精品国产凹凸成av人导航| 欧美一级午夜免费电影| 884aa四虎影成人精品一区| 91麻豆精品国产91久久久资源速度 | 在线观看www91| 欧美日韩不卡一区二区| 欧美一区二区三区四区高清| 欧美疯狂做受xxxx富婆| 日韩欧美国产精品| 久久九九久精品国产免费直播| 国产亚洲短视频| 亚洲人成网站影音先锋播放| 五月天亚洲精品| 国产剧情av麻豆香蕉精品| 成人黄色国产精品网站大全在线免费观看| jiyouzz国产精品久久| 欧美三级电影在线看| 精品人伦一区二区色婷婷| 国产精品国产三级国产aⅴ中文| 一区二区三区免费观看| 裸体歌舞表演一区二区| 成人精品免费视频| 欧美在线你懂得| 久久精品网站免费观看| 亚洲图片欧美色图| 国产精品一区二区三区99| 欧美三级资源在线| 久久久久国产精品人| 五月天亚洲婷婷| 91麻豆蜜桃一区二区三区| 日韩免费观看高清完整版| 亚洲摸摸操操av| 粉嫩aⅴ一区二区三区四区五区| 欧美精品成人一区二区三区四区| 国产精品麻豆欧美日韩ww| 无码av免费一区二区三区试看 | 欧美日韩国产精品成人| 久久精品一区二区三区不卡| 日韩电影网1区2区| 91久久精品一区二区三| 亚洲欧美国产三级| 国产成人av一区二区| 久久久久久一二三区| 久久精品国产一区二区三区免费看| 在线观看不卡视频| 一个色在线综合| 在线观看成人免费视频| 亚洲精品videosex极品| 91香蕉视频黄| 一区二区高清免费观看影视大全| av一区二区三区| 中文字幕在线观看一区| 成人久久久精品乱码一区二区三区| 久久久久国产成人精品亚洲午夜| 黄色成人免费在线| 久久日一线二线三线suv| 国产一区二区毛片| 国产精品乱码久久久久久| 丰满亚洲少妇av| 成人欧美一区二区三区视频网页| 99re在线精品| 亚洲一区二区三区自拍| 欧美日韩五月天| 美女视频一区二区| 国产日产欧美一区二区三区 | 亚洲国产日韩一区二区| 欧美日韩美女一区二区| 久久99最新地址| 中国av一区二区三区| 欧美日韩在线亚洲一区蜜芽| 天堂资源在线中文精品| 日韩三级免费观看| av一区二区三区四区| 婷婷中文字幕一区三区| 国产亚洲短视频| 欧美日韩一区国产| 国产精品66部| 亚洲动漫第一页| 国产人成亚洲第一网站在线播放 | 日韩欧美亚洲国产另类| 99久久婷婷国产综合精品| 夜夜爽夜夜爽精品视频| 精品播放一区二区| 91浏览器打开| 国产乱码一区二区三区| 首页综合国产亚洲丝袜| 国产精品免费视频一区| 欧美视频在线播放| 91网页版在线| 国产剧情av麻豆香蕉精品| 日本亚洲免费观看| 亚洲成人免费av| 国产精品色呦呦| 欧美成人国产一区二区| 在线观看91精品国产入口| 精品午夜一区二区三区在线观看| 五月天精品一区二区三区| 国产精品理伦片| 久久久精品2019中文字幕之3| 在线播放欧美女士性生活| 91婷婷韩国欧美一区二区| 高清beeg欧美| 国产91精品一区二区麻豆网站| 蜜臀99久久精品久久久久久软件| 日产欧产美韩系列久久99| 亚洲国产精品久久一线不卡|