dsjbest2015 2018-02-26 15:10
浏览 207

与cjpeg一起使用mozjpeg具有优于将其用作库的质量

I have been trying to use mozjpeg in my Go application for JPEG compression, since it seems to have very good quality when used through the cjpeg command-line utility it provides.

However, pictures compressed with my application have inferior quality - a lot more JPEG artefacts with the same quality level.

I am using go bindings for libjpeg-turbo / mozjpeg from https://github.com/subuk/go-mozjpeg/blob/master/jpeg/compress.go

My own code does not seem to be too complex:

    libjpegOptions := jpeg.EncoderOptions{
        Quality:         92,
        OptimizeCoding:  true,
        ProgressiveMode: true,
    }

    err = jpeg.Encode(buf, m, &libjpegOptions)
    if err != nil {
        return nil, err
    }

Both applications seem to link to the same version of mozjpeg library, installed with Homebrew:

$ otool -L /opt/mozjpeg/bin/cjpeg
/opt/mozjpeg/bin/cjpeg:
    /opt/mozjpeg/lib/libjpeg.62.dylib (compatibility version 65.0.0, current version 65.0.0)
    /usr/local/opt/libpng/lib/libpng16.16.dylib (compatibility version 51.0.0, current version 51.0.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)

$ otool -L /Users/fabio/Code/go/bin/imageproxy
/Users/fabio/Code/go/bin/imageproxy:
    /opt/mozjpeg/lib/libjpeg.62.dylib (compatibility version 65.0.0, current version 65.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1451.0.0)
    /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 58286.41.2)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)

What could I try next to ensure that my application is using the same settings as cjpeg?

  • 写回答

1条回答 默认 最新

  • dongtuo0828 2018-02-27 10:20
    关注

    Got to answer my own question, since I found a fix to the issue by going through mozjpeg's commit history. cjpeg has an implicit default for chroma subsampling on JPEG quality ratings above 80 in its argument parsing code, and boundaries of solid areas of certain colour look quite bad with the library default for chroma subsampling.

    /*
        Disable chroma subsampling for good quality ratings, that's what cjpeg command does as well.
        That seems to cause some issues with red color.
    */
    if opt.Quality >= 80 {
        compInfo := (*[3]C.jpeg_component_info)(unsafe.Pointer(cinfo.comp_info))
        compInfo[Y].h_samp_factor, compInfo[Y].v_samp_factor = 1, 1
        compInfo[Cb].h_samp_factor, compInfo[Cb].v_samp_factor = 1, 1
        compInfo[Cr].h_samp_factor, compInfo[Cr].v_samp_factor = 1, 1
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记