【发布时间】:2012-10-03 16:29:35
【问题描述】:
我有下一个基于libjpeg的JPEG图像解压标准代码。
jpeg_decompress_struct cinfo;
// ...Set error manager and data source...
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
while (cinfo.output_scanline < cinfo.output_height) {
JSAMPLE* scanlines[1];
// ...Set target pointer for scanline...
jpeg_read_scanlines(&cinfo, scanlines, 1);
}
jpeg_destroy_decompress(&cinfo);
我想读取图像的一部分,被一个矩形裁剪:
// struct RECT {
// int left;
// int top;
// int right;
// int bottom;
// };
RECT cropRect; // Coordinates of the crop rectangle relative to the output image size
我应该在下面的代码中修改什么来告诉libjpeg立即裁剪图像?
我可以这样实现它:
- 忽略第一行
top - 1; - 对于接下来的每一行
bottom - top: 1) 读取扫描线到临时缓冲区; 2) 将列范围[left, right)中的像素从临时缓冲区复制到目标缓冲区。 - 中止解压。
但是这段代码是多余的。
【问题讨论】:
-
它是多余的,但很简单。除非你真的需要更好的东西,否则我会坚持下去。