how to detect PC or MAC byte order?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
markzman
Posts: 20
Joined: 2010-02-25T00:43:45-07:00
Authentication code: 8675308

how to detect PC or MAC byte order?

Post by markzman »

can imagemagick detect whether a tiff file has a PC or Mac byte order?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to detect PC or MAC byte order?

Post by fmw42 »

use identify -verbose image

and look at the ENDIANESS: value

identify -verbose logo2.tif

logo2.tif
Image: logo2.tif
Format: TIFF (Tagged Image File Format)
Class: PseudoClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: PixelsPerCentimeter
Type: Palette
Base type: Palette
Endianess: MSB
...
markzman
Posts: 20
Joined: 2010-02-25T00:43:45-07:00
Authentication code: 8675308

Re: how to detect PC or MAC byte order?

Post by markzman »

Thanks for the reply.
I think there's a bug with the new release, the Endianess value are the same see below report from PC and MAC sample tif.
Running ImageMagick-6.6.2-7-Q16-windows-dll.exe

1. PC byte order
Image: sample_PC.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 1907x1053+0+0
Resolution: 300x300
Print size: 6.35667x3.51
Units: PixelsPerInch
Type: TrueColorMatte
Base type: TrueColor
Endianess: MSB
Colorspace: RGB
Depth: 8-bit

2. MAC byte order
Image: sample_MAC.tif
Format: TIFF (Tagged Image File Format)
Class: DirectClass
Geometry: 1907x1053+0+0
Resolution: 300x300
Print size: 6.35667x3.51
Units: PixelsPerInch
Type: TrueColorMatte
Base type: TrueColor
Endianess: MSB
Colorspace: RGB
Depth: 8-bit
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to detect PC or MAC byte order?

Post by fmw42 »

How do you know your two files were not written with the same byte order? Often software on various systems allow one to choose or has a default as one or other if you don't specify. How did you create the two images?

Endian reporting seems fine.


convert logo2.tif -endian LSB logo2_lsb.tif
identify -verbose logo2_lsb.tif


Format: TIFF (Tagged Image File Format)
Class: PseudoClass
Geometry: 640x480+0+0
Resolution: 72x72
Print size: 8.88889x6.66667
Units: PixelsPerCentimeter
Type: Palette
Base type: Palette
Endianess: LSB

This is from IM 6.6.2-7 Q16 Mac OSX Tiger

By the way, Mac uses both: Intel-based is little endian and PowerPC-based is big endian.

Also see http://en.wikipedia.org/wiki/Tagged_Image_File_Format where it says:


"Every TIFF begins with a 2-byte indicator of byte order: "II" for little endian and "MM" for big endian byte ordering. ... The TIFF 6.0 specification says that compliant TIFF readers must support both byte orders (II and MM), however, TIFF writers may choose the byte order convenient for their image.[8] This gave rise to the image-processing community's joke that TIFF is an acronym for Thousands of Incompatible File Formats.[9]"
markzman
Posts: 20
Joined: 2010-02-25T00:43:45-07:00
Authentication code: 8675308

Re: how to detect PC or MAC byte order?

Post by markzman »

I'm using Photoshop CS3 on Windows XP.
The sample tiffs do have the "MM" indicator for MAC and "II" for the PC byte order but when I use the -verbose command i only get MSB for both.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to detect PC or MAC byte order?

Post by fmw42 »

perhaps photoshop has a bug and only writes it one way. have you tried verifying the endian with some other third party tool to verify which is in error photoshop or IM?

Why don't you post a link to two small example of writing out from PS both ways. So others can check it out also directly from your images.
markzman
Posts: 20
Joined: 2010-02-25T00:43:45-07:00
Authentication code: 8675308

Re: how to detect PC or MAC byte order?

Post by markzman »

i tried re-saving them on other pc still the same output, see below sample tiff files.

sample PC byte order
http://www.clipartof.com/images/free_ho ... le_pc.tiff

sample MAC byte order
http://www.clipartof.com/images/free_ho ... e_mac.tiff
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to detect PC or MAC byte order?

Post by fmw42 »

I opened both your files in Mac GraphicConverter and it said one was big endian (mac) and the other little endian (pc).

IM tells me both are MSB.

So perhaps there may be a bug in IM or your files are not written according to spec. There were some oddities, such as multiple alpha channels and multiple IPTC sets of data.

I am certainly no expert on tiff format. So you will need one of the IM experts on format to investigate further.

Perhaps you should open a post on the bugs forum and put a link back to this topic.
markzman
Posts: 20
Joined: 2010-02-25T00:43:45-07:00
Authentication code: 8675308

Re: how to detect PC or MAC byte order?

Post by markzman »

The files were re-saved a couple of times while troubleshooting if Photoshop or IM was the problem.
I'll post this on bugs section and see what comes out.
markzman
Posts: 20
Joined: 2010-02-25T00:43:45-07:00
Authentication code: 8675308

Re: how to detect PC or MAC byte order?

Post by markzman »

Now works on IM 6.6.2-10 Q16
See related post - viewtopic.php?f=3&t=16524
Post Reply