Solid Fluid System Solutions  
Home Software About Hardware Firmware
Document Icon LibJPEG
Document Icon Modifications
Document Icon Mods - jbufferdst.cpp
Document Icon Mods - jbuffersrc.cpp
Current Document Icon ToJPEG
Document Icon FromJPEG

The ToJPEG function

#include <stdio.h>
#include "ImgJPEG.h"
#include "ImgAlloc.h"
#include ".\JPEG\jpeglib.h"

void jpeg_ToJPEG(void*& pBuf,unsigned long& BufSz,ImgJPEGInfo& Info)
{
	jpeg_compress_struct cinfo;
	jpeg_error_mgr jerr;

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_compress(&cinfo);

	unsigned long OutBufSz = 0;
	unsigned char* pOutBuf = NULL;

	jpeg_buffer_dest(&cinfo,&pOutBuf,&OutBufSz);

	cinfo.image_width = Info.XDim;
	cinfo.image_height = Info.YDim;
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;
	jpeg_set_defaults(&cinfo);

	jpeg_set_quality(&cinfo,Info.Quality,TRUE);

	jpeg_start_compress(&cinfo, TRUE);

	JSAMPROW row_pointer[1];
	while(cinfo.next_scanline < cinfo.image_height)
	{
		row_pointer[0] = &(((unsigned char*)(pBuf))[((cinfo.image_height) - (cinfo.next_scanline + 1)) * Info.LineSize]);
		jpeg_write_scanlines(&cinfo, row_pointer, 1);
	}

	jpeg_finish_compress(&cinfo);

	img_free(pBuf);
	BufSz = OutBufSz;
	pBuf = pOutBuf;
	pOutBuf = NULL;

	jpeg_destroy_compress(&cinfo);
}
Copyright © Solid Fluid 2007-2015
Last modified: SolFlu  Mon, 15 Jun 2009 13:09:59 GMT