내가 파일에 쓸 libjpeg을 사용하여이 기능을 발견했다 :libjpeg로 파일 대신 메모리 버퍼에 씁니까?
int write_jpeg_file(char *filename)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
/* this is a pointer to one row of image data */
JSAMPROW row_pointer[1];
FILE *outfile = fopen(filename, "wb");
if (!outfile)
{
printf("Error opening output jpeg file %s\n!", filename);
return -1;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outfile);
/* Setting the parameters of the output file here */
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = bytes_per_pixel;
cinfo.in_color_space = color_space;
/* default compression parameters, we shouldn't be worried about these */
jpeg_set_defaults(&cinfo);
/* Now do the compression .. */
jpeg_start_compress(&cinfo, TRUE);
/* like reading a file, this time write one row at a time */
while(cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = &raw_image[ cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
/* similar to read file, clean up after we're done compressing */
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
fclose(outfile);
/* success code is 1! */
return 1;
}
실제로 파일에 저장하지 않고, 단지 메모리 버퍼에 JPEG 압축 된 이미지를 작성해야 시간을 절약하는 것입니다. 누군가 그것을 어떻게 할 수 있는지 예를 들어 줄 수 있습니까?
나는 잠시 동안 웹을 검색해 왔지만, 문서가 매우 희귀하고 어떤 예제도 나오기가 어렵다면 매우 드뭅니다.
나는이 함수 포인터가'jpeg_stdio_dest'가 영향을 줄 것이라고 생각합니까? –
@Ben Voigt, 정확히 무엇을하는지'jpeg_stdio_dest'에 대한 소스를보고 있습니다. 구조체를 할당하고'cinfo-> dest'에 설정 한 다음 포인터를 설정합니다.내 자신의 샘플 코드는'jpeg_destination_mgr' 구조체를 생성하지 않기 때문에 약간 불완전하다고 생각합니다.하지만 나중에 살펴 보겠습니다. –
아 물론. 함수 포인터 바로 다음에 전역 변수가 필요없는 [자신의 데이터 ('std :: vector')를 저장할 수 있습니다.] (http://blogs.msdn.com/b/oldnewthing/archive/2010/12/20/ 10107027.aspx). –