Trying to convert a 24 bpp bitmap to black & white TIFF with CCITT group 4 compression. The result is a TIFF 1 bpp image as expected but it is uncompressed.
I'm using FreePascal which has magickwand bindings and the status is never MagickFalse:
MagickWandGenesis;
wand := NewMagickWand;
try
status := MagickReadImage(wand,PChar(InputFile));
if (status = MagickFalse) then HandleError;
status := MagickSetImageFormat(wand,'TIFF');
if (status = MagickFalse) then HandleError;
// convert to black & white/lineart
status := MagickSetImageType(wand,BilevelType);
if (status = MagickFalse) then HandleError;
// Group4Compression seems defined as 4 which
// apparently doesn't match imagemagick source. Bug:
//http://mantis.freepascal.org/view.php?id=26723
status := MagickSetImageCompression(wand,CompressionType(7)); //was Group4Compression
if (status = MagickFalse) then HandleError;
// Apparently set(image)compresionquality and
// stripimage are necessary to actually compress
status := MagickSetImageCompressionQuality(wand,0);
if (status = MagickFalse) then HandleError;
status := MagickStripImage(wand);
if (status = MagickFalse) then HandleError;
status := MagickWriteImage(wand,PChar(OutputFile));
if (status = MagickFalse) then HandleError;
finally
wand := DestroyMagickWand(wand);
end;
MagickWandTerminus;
Source image at http://filehorst.de/d/bmqjzDuB
Original (faulty) program source code at http://filehorst.de/d/bluhjivq
Original (faulty) output image at http://filehorst.de/d/bhlbjHgp
What am I doing wrong?
Edit: solved; got the solution off-site: the CompressionType enum in the FreePascal bindings were probably out of date - Group4Compression was 4 (IIRC) while it should be 7.
I'll give the bounty to Mark Setchell as his answer was a necessary part of the solution. Source code above updated with correct version.