1

I am reading a CG4 (CALS Group IV bitmap) file and extracted the image data as an array of bytes. The image data is compressed using CCITT Group 4 (T.6) compression.

I don't believe libtiff.net has methods to just un-compress a set of compressed bytes. Is there a way to build a tiff header specifying CCITT Group 4 compression, and then slot in my existing compressed image data, to produce a valid tiff file?

David James Ball
  • 903
  • 10
  • 26
  • One last FYI...The type 2 and JEDMICS variants of CALS images are made up of tiles (not strips) and will need different treatment than the much simpler type 1 files. – BitBank Nov 27 '14 at 08:45
  • Thanks, I'm aware the type 1 is a much simpler format. Do you know of any public type 2 sample files? – David James Ball Nov 27 '14 at 10:41
  • This is the only type 2 sample I've found: http://www.fileformat.info/format/cals/sample/index.htm I wrote support for reading JEDMICS C4 files in my imaging library and want to add CALS type 2, but with only a single sample, I haven't added it. I've never found anyone really using type 2 files. – BitBank Nov 27 '14 at 13:05
  • Thanks for the link. Yes, with very few samples and not enough detailed information about the byte structure, I don't think we will support type 2 after all. – David James Ball Nov 28 '14 at 10:41

1 Answers1

0

Here is a sample that shows how to create black-and-white TIFF from your bytes

using (Tiff output = Tiff.Open(fileName, "w"))
{
    output.SetField(TiffTag.IMAGEWIDTH, width);
    output.SetField(TiffTag.IMAGELENGTH, height);
    output.SetField(TiffTag.SAMPLESPERPIXEL, 1);
    output.SetField(TiffTag.BITSPERSAMPLE, 8);
    output.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);
    output.SetField(TiffTag.ROWSPERSTRIP, height);
    output.SetField(TiffTag.XRESOLUTION, 88.0);
    output.SetField(TiffTag.YRESOLUTION, 88.0);
    output.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);
    output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
    output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
    output.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
    output.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);

    output.WriteRawStrip(0, compressedData, compressedData.Length);
}

Please note that you must provide correct width, height, resolution and other values. And ROWSPERSTRIP must be correct too.

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130