AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2000.02.02 17:50 "Microsoft Imaging and Jpeg in TIFF", by Myers, Randall
[...]
2000.02.03 01:55 "Re: Microsoft Imaging and Jpeg in TIFF", by Tom Lane
2000.02.03 11:10 "Re: Microsoft Imaging and Jpeg in TIFF", by Andy
[...]

2000.02.03 11:10 "Re: Microsoft Imaging and Jpeg in TIFF", by Andy

Hello,

These questions I hope you can answer.

Are Wang TIFF strips correlated to JPEG MCU's (minimum coded unit)? That is, for a given strip in the TIFF file,besides the first which is also containing the SOS (Start of scan) marker, is each strip before the last having the same number of MCU's, if so, what is this number? If there is this number, then the DRI (Define restart interval) marker can be set with an Ri parameter of the number of MCU's per strip, with an RST (restart) marker between each strip, thus yielding the JPEG data stream with added DRI marker right before SOS and restart markers after some known number of MCU's.

(DRI marker is 0x FF' DD' 00' 04' (Ri>>8)' (Ri&0xff)', six bytes, where Ri is the restart interval, which is the number of MCU's in an ECS, entropy coded segment.)

For example, what I am having here is the Wang JPEG data stream, with an inserted DRI marker before the first strip's data and incrementing RST's between each strip. So, setting the DRI's Ri parameter to zero, which disables restart, yields that the JPEG stream displays the first strip's worth of data, and no more. So, setting that is not right. Setting Ri to a variety of values (image length, rowsperstrip, number of strips) does not yield correct data. I was hoping there was some constant for these Wang images. Setting DRI marker Ri to (rowsperstrip * width) yields the same image as Ri of zero, strangely enough.

So, what I have stumbled upon for a particular test image is to set Ri to the image width * 3/8. For example, this image with a width of 1272 would have an Ri of 477. However, I do not know if either of these two variables, 3 and 8, are set or if they depend on the image. Having just found this combination, it is a grayscale image. Now I try a color (RGB, or rather HSB) image. This value is not effective. So, I try some more permutations for the numerator of this fraction.

I crop the above grayscale image to 600 x 818. The 600 * 3/8 does not work, but 600 * 6/8 does (450). A previous crop to a width of a non-multiple of 8 is giving me a headache.

The first image has 24 rows per strip, the second 48. Ah ha! A linear coincidence. So, what is being rowsperstrip divided by 8 times image width divided by 8, rowsperstrip * imagewidth/64. This works for both images.

Trying again the image the width of which is not being a multiple of 8, this algorithm does not work. Back to the drawing board, as it were. Rounding up the width variable in the equation to a multiple of 8 is not having the desired effect.

As we are trying to determine how many MCU's are being coded in each of these strips, at this point thinking generally number of components * rowsperstrip * imagewidth /64 is an option. After testing this solution, it is proven ineffective. So, I try rps*w/64/samplesperpixel, which is not right, yet it has many less artifacts.

By the way, the way I am gauging the effectveness of this process is to write each produced JPEG stream to file and viewing it to compare the relative destruction.

Can you explain the absolute measures to make a Wang TIFF/JPEG data stream into a valid one? That is, explain how the DRI Ri (restart interval) is determined? Otherwise, we should endeavor to do so as a group. Has this question come up before?

Here's my algorithm thus far:

  1. Write JPEG headers from JPEGIFOffset.
  2. Write DRI marker with some value for Ri.
  3. Write first strip's raw data.
  4. Write RST marker.
  5. Repeat 3 and 4 for each strip except last.
  6. Write last strip.
  7. So I guess my question is : What should Ri be?

Andy