写的libjpeg用(赛格故障)JPEG格式 [英] write a jpeg with libjpeg (seg fault)

查看:190
本文介绍了写的libjpeg用(赛格故障)JPEG格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试着写使用的libjpeg一些原始数据的JPEG文件。

Trying to write a jpeg file from some raw data using libjpeg.

这会触发分段错误在 jpeg_start_com $ P $(PSS)

下面是code的相关部分:

Here is the relevant part of the code :

void write_sub_image(char *filename, int start, int end)
{
    struct jpeg_compress_struct cinfo;
    unsigned char *stride;
    JSAMPROW row_pointer[1];
    unsigned long new_width = end-start;
    int i;
    FILE *fp;

    stride = (unsigned char *)malloc( new_width * 3);

    fp = fopen(filename, "w+");

    jpeg_create_compress(&cinfo);

    jpeg_stdio_dest(&cinfo, fp);

    cinfo.image_width = new_width;
    cinfo.image_height = height;
    cinfo.input_components = 3;
    cinfo.in_color_space = JCS_RGB;

    jpeg_set_defaults(&cinfo);

    jpeg_start_compress(&cinfo, FALSE);

    for (i=0; i<height; i++) {
        memcpy (stride, image + (start + i * width) * 3, new_width * 3);
        row_pointer[0] = stride;
        jpeg_write_scanlines(&cinfo, &stride, 1);
    }

    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);

    fclose(fp);
}

问题是不符合的memcpy,它甚至不得到的for循环...只是在崩溃_start_com preSS。

The problem is not with the memcpy, it does not even get to the for loop... just crash at _start_compress.

在与其相关的情况下,该系统是Ubuntu的10.10。

In case that is relevant, the system is Ubuntu 10.10.

推荐答案

您需要设置一个错误管理器:

You need to set an error manager:

struct jpeg_error_mgr jerr; 
....
cinfo.err = jpeg_std_error(&jerr); 
jpeg_set_defaults(&cinfo);
....

这篇关于写的libjpeg用(赛格故障)JPEG格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆