1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <stdio.h> #include <stdlib.h> #include <string.h> #include <setjmp.h> #include "jpeg-utils.h" // jpeg库头文件必须放到stdio.h后面 #include "libjpeg/include/turbojpeg.h" int tjpeg_header(unsigned char* jpeg_buffer, int jpeg_size, int* width, int* height, int* subsample, int* colorspace) { tjhandle handle = NULL; handle = tjInitDecompress(); tjDecompressHeader3(handle, jpeg_buffer, jpeg_size, width, height, subsample, colorspace); tjDestroy(handle); return 0; } int tjpeg2rgb(unsigned char* jpeg_buffer, int jpeg_size, unsigned char* rgb_buffer, int* size) { tjhandle handle = NULL; int width, height, subsample, colorspace; int flags = 0; int pixelfmt = TJPF_RGB; handle = tjInitDecompress(); tjDecompressHeader3(handle, jpeg_buffer, jpeg_size, &width, &height, &subsample, &colorspace); flags |= 0; tjDecompress2(handle, jpeg_buffer, jpeg_size, rgb_buffer, width, 0, height, pixelfmt, flags); tjDestroy(handle); return 0; } int trgb2jpeg(unsigned char* rgb_buffer, int width, int height, int quality, unsigned char** jpeg_buffer, unsigned long* jpeg_size) { tjhandle handle = NULL; //unsigned long size=0; int flags = 0; int subsamp = TJSAMP_422; int pixelfmt = TJPF_RGB; handle=tjInitCompress(); //size=tjBufSize(width, height, subsamp); tjCompress2(handle, rgb_buffer, width, 0, height, pixelfmt, jpeg_buffer, jpeg_size, subsamp, quality, flags); tjDestroy(handle); return 0; }
|