jpeg代码,buffer是传入的位图,每个点一个字节的亮度,顺序排列
/*
for(long y=min(m_lt.y,m_rt.y);y<=max(m_lb.y,m_rb.y);y++)
{
for(long x=lx;x<=rx;x++)
{
if(m_cmp_rbuffer[GET_RBUFFER_POS(x,y)] == 0) continue;
long _x=x,_y=y;
_GetRealPT(_x,_y);
_x = _x /4;
_y = _y /4;
int _pos = _y * m_screen_size.cx / 4 + _x;
m_real_buffer[_y * size.cx + _x] = '\255';
}
}
m_real_size = m_screen_size.cx * m_screen_size.cy / 16;
*/
int mkjpeg(int width,int height,char *buffer,char *filename) { struct jpeg_compress_struct jcs; struct jpeg_error_mgr jem; FILE *fp; JSAMPROW row_pointer[1]; // 一行位图 int row_stride; // 每一行的字节数 jcs.err = jpeg_std_error(&jem); jpeg_create_compress(&jcs); fp = fopen(filename,"wb"); if (f==NULL) { return FALSE; } jpeg_stdio_dest(&jcs, fp); jcs.image_width = width; // 位图的宽和高,单位为像素 jcs.image_height = height; jcs.input_components = 1; // 在此为1,表示灰度图, 如果是彩色位图,则为3 jcs.in_color_space = JCS_GRAYSCALE; //JCS_GRAYSCALE表示灰度图,JCS_RGB表示彩色图像 jpeg_set_defaults(&jcs); jpeg_set_quality (&jcs, 80, TRUE); jpeg_start_compress(&jcs, TRUE); while (jcs.next_scanline < jcs.image_height) { row_pointer[0] = buffer[jcs.next_scanline * width]; jpeg_write_scanlines(&jcs, row_pointer, 1); } jpeg_finish_compress(&jcs); jpeg_destroy_compress(&jcs); fclose(fp); return TRUE; }