Search code examples
tiffcodeccompressionimage-compression

Group 4 decompression - does a Pass Mode code the color of the reference line or coding line?


I have been implementing the Group 4 image compression algorithm in an attempt to convert some files (not TIFFs), similar to the person in this question: Algorithm issue with TIFF CCITT Group 4 decompression (T.6)

I have found a number of great resources for doing this, but one question I have. I have found that when a Pass Mode is encountered, the next bits will be an encoding of the run-length b1b2. Is this going to be in the color of the reference line, or the coding line? They will be opposite, so I'm not sure how to treat it. I would naturally assume the color you are encoding is the coding line, so that would be what you take, but also the run-length will be a normal length for the color of the reference line, which means it should be better compressed to use the reference line's color's codes.

So which is it?

Here are some links that I have used for reference:

https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.6-198811-I!!PDF-E&type=items http://www.fileformat.info/format/cals/egff.htm http://www.fileformat.info/mirror/egff/ch09_05.htm

https://books.google.com.au/books?id=LHCY4VbiFqAC&lpg=PA253&ots=N3w5NkHek8&dq=group%204%20two%20dimensional%20bit&pg=PA254#v=onepage&q=group%204%20two%20dimensional%20bit&f=false

https://books.google.com.au/books?id=c9OoCAAAQBAJ&lpg=PA96&ots=sGKb9m76a0&dq=group%204%20two%20dimensional%20bit&pg=PA98#v=onepage&q=group%204%20two%20dimensional%20bit&f=false


Solution

  • The pass code doesn't have any encoded bits following it, it simply means to advance the current X position to the next reference position of the same color. In terms of the G4 standard variable names, this is how to handle the pass code:

    < switch statement on G4 code >
    ...
    case PASS_CODE: // A0 = B2, iRef+=2 
       iReference++; // skip B1
       a0 = pRefLine[iReference++]; // B2 - next reference pos of the same color
       break;