TIFF CCITT第4组解压缩(T.6)的算法问题 [英] Algorithm issue with TIFF CCITT Group 4 decompression (T.6)

查看:849
本文介绍了TIFF CCITT第4组解压缩(T.6)的算法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一家工程设计公司工作,我们将黑白设计图以TIFF格式存储,并以CCITT Group 4压缩方式进行压缩。

I work for an engineering design house and we store black and white design drawings in TIFF format compressed with CCITT Group 4 compression.

我正在研究一个项目,以改进用于处理这些工程图的软件。我显然需要能够将原始数据加载到程序中,因此必须对其进行解压缩。

I am working on a project to improve our software for working with these drawings. I need to be able to load the raw data into my program obviously, so I must decompress it.

我尝试使用LibTiff,但很快就放弃了。它无法生成,产生2000多个错误。我在库中发现许多明显的语法错误,并得出结论认为这是垃圾。我花了大约3个小时的时间来查找实现CCITT Group 4编解码器但没有运气的库的一部分,该代码令人难以理解。

I tried using LibTiff but gave up on that rather quickly. It wouldn't build, generating over 2000 errors. I found many obvious syntax errors in the library and concluded it was junk. I spent about 3 hours trying to find the part of the library that implements the CCITT Group 4 codec but no luck, that code is an incomprehensible mess.

所以我正在为程序编写自己的编解码器。我大部分都能正常工作,但是我遇到了问题。我找不到这种格式的优质文档。有很多很好的概述可以大致描述2D Modified Huffman压缩的工作原理,但是我找不到任何具有特定实现级别细节的信息。因此,我尝试通过使用一些工程图文件作为示例来解决这个问题。

So it is that I am writing my own codec for the program. I have it mostly working well, but I am stuck on a problem. I cannot find good documentation on this format. There are a lot of good overviews that describe generally how 2D Modified Huffman compression works, but I cant find any that have specific, implementation level details. So I am trying to work it out by using some of the drawing files as examples.

我的垂直和通过模式工作得很好,我的算法解压缩了大约三分之一的在进入向导并产生垃圾之前正确映像。

I have vertical and pass modes working well and my algorithm decompresses about a third of the image properly before it goes off to the wizard and produces garbage.

我将问题追溯到水平模式。我的水平模式算法期望看到水平模式代码001,然后是当前笔颜色的一组化妆代码(可选)和终止代码,然后是另一组化妆代码(可选)和终止代码。相反的颜色。

I traced the problem to the horizontal mode. My algorithm for the horizontal mode expects to see the horizontal mode code 001 followed by a set of makeup codes (optional) and a termination code in the the current pen color, followed by another set of makeup codes (optional) and a termination code in the opposite color.

此算法在整个图像的三分之一过程中都很好用,但是突然我遇到了水平模式运行,其中相反的颜色位于当前笔的颜色之前。

This algorithm worked well for a third of the way through the image, but suddenly I encountered a horizontal mode run where the opposite color comes before the current pen color.

图像部分是12个黑色像素,然后是22个白色像素。

该部分的代码位是00100000110000111解码为水平(001)22白色(0000011)12黑色(0000111),正如您所看到的,它与像素在图像中出现的顺序相反。

The section of the image is a run of 12 black pixels followed by a run of 22 white pixels.
The code bits from that section are 00100000110000111 which decodes to Horizontal (001) 22 White (0000011) 12 Black (0000111 ) which as you can see is opposite of the order in which the pixels appear in the image.

由于我的算法要求列出图像顺序,因此会崩溃。但是在同一图像文件中,以前的307个水平模式实例全部按图像顺序排列。这是我到目前为止发现的唯一逆向词。

Since my algorithm expects image order listing, it crashes. But the previous 307 instances of horizontal mode in this same image file were all in image order. This is the only reversed one I have found (so far).

其他映像程序可以很好地显示此文件。我尝试手动编辑图像文件中的位,以进行测试以按顺序排列图像顺序,这会导致其他图像处理程序在解码图像时崩溃。这使我相信他们有某种方式知道在这种情况下它会被逆转。

Other imaging programs display this file just fine. I tried manually editing the bits in the image file just as a test to put the order in image order and that causes other imaging programs to crash when decoding the image. This leads me to believe they have some way of knowing that it is reversed in that instance.

任何人都知道有关此TIFF CCITT G4编码的具体实现级别的详细信息,这可能对我有帮助了解运行代码有时如何以及为什么会被反向?

Anyone know specific implementation level details about this TIFF CCITT G4 encoding which could help me understand how and why the run codes are sometimes reversed?

感谢
Josh

Thanks Josh

推荐答案

CCITT G4水平代码始终编码为一对(黑/白)或(白/黑)。这取决于当前的笔颜色。垂直代码将翻转颜色,而水平代码将使颜色保持不变。如果当前的笔颜色为黑色,则先解码白色水平代码,再解码黑色。如果当前的笔颜色为白色,则您将相反。

CCITT G4 horizontal codes are always encoded as a pair (black/white) or (white/black). It depends on the current pen color. A vertical code will flip the color, but a horizontal code will leave the color unchanged. If the current pen color is black, then you decode a white horizontal code followed by a black. If the current pen color is white, then you will do the opposite.

这篇关于TIFF CCITT第4组解压缩(T.6)的算法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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