Вот код:
C++ (Qt)
static void error_exit (j_common_ptr cinfo)
{
Q_UNUSED (cinfo)
qDebug() << Q_FUNC_INFO;
}
static void output_message (j_common_ptr cinfo)
{
Q_UNUSED (cinfo)
qDebug() << Q_FUNC_INFO;
}
static void emit_message (j_common_ptr cinfo, int msg_level)
{
Q_UNUSED (cinfo)
Q_UNUSED (msg_level)
qDebug() << Q_FUNC_INFO;
}
static void format_message (j_common_ptr cinfo, char *buffer)
{
Q_UNUSED (cinfo)
Q_UNUSED (buffer)
qDebug() << Q_FUNC_INFO;
}
static void reset_error_mgr (j_common_ptr cinfo)
{
qDebug() << Q_FUNC_INFO;
cinfo->err->num_warnings = 0;
cinfo->err->msg_code = 0;
}
C++ (Qt)
bool JpegFormat::load (const QByteArray &data, const QSize &size)
{
Q_UNUSED (size)
qDebug() << Q_FUNC_INFO;
jpeg_decompress_struct decompressStruct;
jpeg_error_mgr error;
decompressStruct.err = jpeg_std_error (&error);
jpeg_CreateDecompress (&decompressStruct,
JPEG_LIB_VERSION,
sizeof (decompressStruct));
error.error_exit = error_exit;
error.emit_message = emit_message;
error.output_message = output_message;
error.format_message = format_message;
error.reset_error_mgr = reset_error_mgr;
auto inBuf = reinterpret_cast<const unsigned char *> (data.constData());
jpeg_mem_src (&decompressStruct,
const_cast<unsigned char *> (inBuf),
data.size());
if (jpeg_read_header (&decompressStruct, true) != JPEG_HEADER_OK) {
jpeg_destroy_decompress (&decompressStruct);
return false;
}
decompressStruct.out_color_space = JCS_GRAYSCALE;
jpeg_start_decompress (&decompressStruct);
size_ = QSize (decompressStruct.image_width, decompressStruct.image_height);
data_.fill (0,
decompressStruct.image_width * decompressStruct.image_height
);
auto outBuf = reinterpret_cast<unsigned char *> (data_.data());
while (decompressStruct.output_scanline < decompressStruct.image_height) {
jpeg_read_scanlines (&decompressStruct, &outBuf, 1);
outBuf += decompressStruct.image_width;
}
jpeg_finish_decompress (&decompressStruct);
jpeg_destroy_decompress (&decompressStruct);
return true;
}
В jpeg_start_decompress происходит падение, как этого избежать? Файл во вложении.