tar -xzf jpegsrc.v9b.tar.gz
进如解压好的文件夹 编译
./configure mkdir build make -j32 make install DESTDIR=/XXX/build
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
代码如下
#include "jpeglib.h" // 设置一个足够大的buffer char jpeg[512*1024]; int jpeg_size=512*1024; rgb2jpeg(rgb_buffer, width, height, channel, jpeg, &jpeg_size); int rgb2jpeg(const char *rgb_buffer, int width, int height, int depth, char *jpeg_buffer, int *size) {
jpeg.err = jpeg_std_error(&jerr); jpeg_create_compress(&jpeg); jpeg_mem_dest(&jpeg, (unsigned char **)&jpeg_buffer, (long unsigned int *)size); JSAMPROW row_pointer[1]; jpeg.image_width = width; jpeg.image_height = height; jpeg.input_components = depth; jpeg.in_color_space = JCS_RGB; jpeg_set_defaults(&jpeg); jpeg_start_compress(&jpeg, TRUE); int row_stride = width * depth; while (jpeg.next_scanline < jpeg.image_height) {
row_pointer[0] = (JSAMPROW)(rgb_buffer + jpeg.next_scanline * row_stride); jpeg_write_scanlines(&jpeg, row_pointer, 1); } jpeg_finish_compress(&jpeg); jpeg_destroy_compress(&jpeg); return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/102379.html