【问题标题】:libjpeg jpeg_write_coefficientslibjpeg jpeg_write_coefficients
【发布时间】:2011-10-31 03:04:44
【问题描述】:

我创建了自己的 DCT 计算。

如何使用jpeg_write_coefficients 将我的 64 个 DCT 值写入使用 jpeg_write_coefficients 的 JPEG 文件(它需要 jvirt_barray_ptr * coef_arrays)?

如何创建?

【问题讨论】:

  • 这个问题有没有得到解决?互联网上几乎没有一个例子说明如何从原始数据中创建这些数组结构之一,而不是仅仅使用我们从“读取系数”函数中获得的结构??

标签: c++ image-processing libjpeg


【解决方案1】:

四处寻找request_virt_barray 函数(在jmemmgr.c 中)。

也看看这个question。它正在读取 DCT 系数而不是写入它们,但它应该让您了解系数数组的存储方式。除了系数之外,您还需要传入量化表(通过j_compress_ptr cinfo 结构)。这是因为在 libjpeg 库中,前向 DCT 和量化是一步完成的。如果你想自己做正向DCT,你也必须自己做量化。

libjpeg 文档也值得一读。它很长,但实际上可读性很强,并且会大大提高您对库的理解。最有用的文件是structure.txt。它包含有关内存管理和编码器结构的部分,可能会对您有所帮助。

【讨论】:

  • 这些方法需要依次request -> alloc -> 自己实现吗?
【解决方案2】:

您需要系数数组作为输入,以将文件写入变量类型 jvirt_barray_ptr 。您可以通过从图像中读取来填充它,然后

jvirt_barray_ptr *coeffs_array = jpeg_read_coefficients(&cinfo);

或自己填写。然后你必须像这样写你的 dct 输入数据。在以下函数中,我使用jpeg_decompress_struct 作为输入,将我的第一个图像标题用于输出图像标题

int write_jpeg_file_dct(std::string outname,jpeg_decompress_struct in_cinfo, jvirt_barray_ptr *coeffs_array ){

    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE * infile;

    if ((infile = fopen(outname.c_str(), "wb")) == NULL) {
      fprintf(stderr, "can't open %s\n", outname.c_str());
      return 0;
    }

    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_compress(&cinfo);
    jpeg_stdio_dest(&cinfo, infile);

    j_compress_ptr cinfo_ptr = &cinfo;
    jpeg_copy_critical_parameters((j_decompress_ptr)&in_cinfo,cinfo_ptr);
    jpeg_write_coefficients(cinfo_ptr, coeffs_array);

    jpeg_finish_compress( &cinfo );
    jpeg_destroy_compress( &cinfo );
    fclose( infile );

    return 1;
}

【讨论】:

    【解决方案3】:

    您可以关注jpeg_read_coefficients创建dct系数管理器的结构,如

    :dstInfo->mem->alloc_small,dstInfo->mem->request_virt_barray,dstInfo->mem->realize_virt_arrays

    并使用virt_barray_list 获取 dst 目标以将新的 dct 系数/quantyTableQ 放入其中。然后调用 jpeg_write_coefficients 生成 JPEG 文件。

    【讨论】:

      猜你喜欢
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 2016-11-18
      • 2012-10-19
      相关资源
      最近更新 更多