📄 jpeg3.c
字号:
#include <stdio.h>#include <setjmp.h>#include "jpeglib.h"#include "cdjpeg.h"#include "jversion.h"struct my_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */};typedef struct my_error_mgr * my_error_ptr;METHODDEF(void)my_error_exit (j_common_ptr cinfo){ my_error_ptr myerr = (my_error_ptr) cinfo->err; (*cinfo->err->output_message) (cinfo); longjmp(myerr->setjmp_buffer, 1);}GLOBAL(int)read_JPEG_file (char * infn,char *outfn){ struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; FILE * infile, *outfile; /* source file */ djpeg_dest_ptr dest_mgr = NULL; JDIMENSION num_scanlines; if ((infile = fopen(infn, "rb")) == NULL) { fprintf(stderr, "can't open %s\n", infn); return 0; } if ((outfile = fopen(outfn, "wb+")) == NULL) { fprintf(stderr, "can't open %s\n", outfn); return 0; } /* Step 1: allocate and initialize JPEG decompression object */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); fclose(infile); return 0; } 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); dest_mgr = jinit_write_bmp(&cinfo, FALSE); dest_mgr->output_file = outfile; /* 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); (*dest_mgr->start_output) (&cinfo, dest_mgr); /* Step 6: while (scan lines remain to be read) */ while (cinfo.output_scanline < cinfo.output_height) { num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer, dest_mgr->buffer_height); (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines); } (*dest_mgr->finish_output) (&cinfo, dest_mgr); /* Step 7: Finish decompression */ (void) jpeg_finish_decompress(&cinfo); /* Step 8: Release JPEG decompression object */ jpeg_destroy_decompress(&cinfo); fclose(infile); fclose(outfile); return 1;}int main(int argc,char *argv[]){ int suc=0; if((suc=read_JPEG_file(argv[1],argv[2]))!=1){ printf("Usage:%s jpegfilename bmpfilename\n",argv[0]); printf("Failed to read JPEG...\n"); return 1; } else{ printf("\nSuccessfully read JPEG image!!\n"); return 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -