1

I have a VB6 application (using IMGSCAN and IMGEDIT conrols) to scan images from HP scanner through TWAIN which generates multipage tiff with old jpeg compression. Now When I access the new Kodak scanner i2600 through TWAIN from same VB6 application it hangs.

So now Im trying write an executable which will just scan and create a multi paged Tiff file which can be accessed in my VB6 application (through IMGEDIT conrol) for viewing.

I tried to create multipage tiff file with old JPEG compression using the C# code found on below post:

https://stackoverflow.com/questions/14811496/tiff-with-jpeg-compression-much-larger-than-original-jpeg

I used compression as 6, to achieve old JPEG compression. IFD:

{254, 4, 1, 0}, // NewSubfileType
{256, 4, 1, width}, // ImageWidth
{257, 4, 1, length}, // ImageLength
{258, 3, 3, offset}, // BitsPerSample
{259, 3, 1, 6}, // Compression (Old JPEG)
{262, 3, 1, 6}, //PhotometricInterpretation (YCbCr)
{273, 4, 1, offset + 22}, // StripOffsets (offset IFH + entries + values of BitsPerSample & YResolution & XResolution)
{277, 3, 1, 3}, // SamplesPerPixel
{278, 4, 1, length}, // RowsPerStrip
{279, 4, 1, (uint)jpegs[i].LongLength}, // StripByteCounts
{282, 5, 1, offset + 6}, // XResolution (offset IFH + entries + values of BitsPerSample)
{283, 5, 1, offset + 14}, // YResolution (offset IFH + entries + values of BitsPerSample & YResolution)
{284, 3, 1, 1}, // PlanarConfiguration (chunky)
{296, 3, 1, 2} // ResolutionUnit

I successfully created the multi page TIFF file. But the problem is, IMGEDIT control (in VB6) is not display this images properly. All the images are distorted.

So I analysed IFD's of the old tiff file (created using vb6 application) with the new file (created using c# with above settings).

Old Tiff File

SUBFILETYPE     0
IMAGEWIDTH  826
IMAGELENGTH     1169
BITSPERSAMPLE   8
COMPRESSION      OJPEG
PHOTOMETRIC      YCBCR
FILLORDER    MSB2LSB
STRIPOFFSETS     System.UInt32[]
ORIENTATION      TOPLEFT
SAMPLESPERPIXEL     3
ROWSPERSTRIP    8
STRIPBYTECOUNTS      System.UInt32[]
XRESOLUTION     100
YRESOLUTION     100
PLANARCONFIG     CONTIG
RESOLUTIONUNIT   INCH
SOFTWARE     System.Byte[]
TILEOFFSETS      System.UInt32[]
TILEBYTECOUNTS   System.UInt32[]
JPEGPROC    1
JPEGIFOFFSET    932
JPEGIFBYTECOUNT     601
JPEGRESTARTINTERVAL     0
JPEGQTABLES     3
JPEGDCTABLES    3
JPEGACTABLES    3
YCBCRSUBSAMPLING    2

New Tiff File:

SUBFILETYPE  0
IMAGEWIDTH   830
IMAGELENGTH  1172
BITSPERSAMPLE 8
COMPRESSION     OJPEG
PHOTOMETRIC      YCBCR
**< FILLORDER  field missing when comparing above>**
STRIPOFFSETS     System.UInt32[]
< ORIENTATION  field missing when comparing above>
SAMPLESPERPIXEL 3
ROWSPERSTRIP    1172
STRIPBYTECOUNTS   System.UInt32[]
XRESOLUTION     100
YRESOLUTION     100
PLANARCONFIG     CONTIG
RESOLUTIONUNIT    INCH
< SOFTWARE  field missing when comparing above>
TILEOFFSETS        System.UInt32[]
TILEBYTECOUNTS      System.UInt32[]
< JPEGPROC  field missing when comparing above>
< JPEGIFOFFSET  field missing when comparing above>
< JPEGIFBYTECOUNT  field missing when comparing above>
< JPEGRESTARTINTERVAL  field missing when comparing above>
< JPEGQTABLES  field missing when comparing above>
< JPEGDCTABLES  field missing when comparing above>
< JPEGACTABLES  field missing when comparing above>
YCBCRSUBSAMPLING    2

IFD's like JPEGPROC, JPEGIFOFFSET, JPEGIFBYTECOUNT, JPEGRESTARTINTERVAL, JPEGQTABLES, JPEGDCTABLES, JPEGACTABLES were not available in new file. I guess this might be the reason for IMGEDIT control not displaying image properly. Is anyway to set these properties while we generate the TIFF file ?

Community
  • 1
  • 1
  • Why do you want to use "Old JPEG" compression? It's specification was flawed and it should never be used. Why not use the new, well defined JPEG specification? – Harald K Jan 05 '15 at 10:04
  • @haraldK Client is gonna use this VB6 application for scanning. This IMGEDIT, IMGSCAN controls are old they support only "Old JPEG compression" of multi page Tiff files. If i try to create file with new JPEG compression, this control doesn't recognize it as valid file. – Hari Prasath Jan 05 '15 at 10:10

1 Answers1

0

Most probably you create your TIFF improperly.

Re-check IMAGEWIDTH, SAMPLESPERPIXEL and BITSPERSAMPLE values. Some of them might be wrong and that is why you get distorted image.

You don't get JPEG*** tags in your output image because you can not create OldJPEG-encoded images with libtiff (there is simply no OldJpeg encoder, only decoder is present). And you you shouldn't create such images because OldJPEG is deprecated long long long long long time ago.

Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
  • I have updated the new tiff file's IFD above. As you can see it almost same as old files value except the JPEG Tags. The new tiff is view able on microsoft picture manager, Irfan viwer, etc.,. The problem happens only when we try to view it through IMGEDIT control. I dont know whether its issue with IMGEDIT control (as its very old). Is there any other way we can create OldJPEG-encoded TIFF images ? – Hari Prasath Dec 26 '14 at 16:13