/* This file is part of SGI Format, a File Format plugin for Adobe Photoshop Copyright (C) 2003-9 Toby Thain, toby@telegraphics.com.au This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sgiformat.h" Boolean is_sgi(FILEREF r,struct sgi_header *h){ return ! read_sgi_header(r,h) /* && h->magic == SGI_MAGIC */ ; } OSErr read_sgi_header(FILEREF f,struct sgi_header *h){ FILECOUNT count = SGI_IMAGENAME_SIZE; FILEPOS pos; OSErr e; if( !(e = GETFPOS(f,&pos)) && !(e = read2B(f,(short*)&h->magic)) ){ if( h->magic == SGI_MAGIC ){ /* iris image file magic number */ /* header is BigEndian (normal) */ (e = read1 (f,(unsigned char*)&h->storage)) /* storage format */ || (e = read1 (f,(unsigned char*)&h->bpc)) /* number of bytes per pixel channel */ || (e = read2B(f,(short*)&h->dimension)) /* number of dimensions */ || (e = read2B(f,(short*)&h->xsize)) /* x size in pixels */ || (e = read2B(f,(short*)&h->ysize)) /* y size in pixels */ || (e = read2B(f,(short*)&h->zsize)) /* number of channels */ || (e = read4B(f,&h->pixmin)) /* minimum pixel value */ || (e = read4B(f,&h->pixmax)) /* maximum pixel value */ || (e = read1 (f,(unsigned char*)&h->dummy)) /* ignored */ || (e = FSREAD(f,&count,&h->imagename)) || (e = read4B(f,&h->colormap)); /* colormap id */ }else if( h->magic == SGI_MAGIC_LITTLEENDIAN ){ /* header is LittleEndian (unusual) */ (e = read1 (f,(unsigned char*)&h->storage)) /* storage format */ || (e = read1 (f,(unsigned char*)&h->bpc)) /* number of bytes per pixel channel */ || (e = read2L(f,(short*)&h->dimension)) /* number of dimensions */ || (e = read2L(f,(short*)&h->xsize)) /* x size in pixels */ || (e = read2L(f,(short*)&h->ysize)) /* y size in pixels */ || (e = read2L(f,(short*)&h->zsize)) /* number of channels */ || (e = read4L(f,&h->pixmin)) /* minimum pixel value */ || (e = read4L(f,&h->pixmax)) /* maximum pixel value */ || (e = read1 (f,(unsigned char*)&h->dummy)) /* ignored */ || (e = FSREAD(f,&count,&h->imagename)) || (e = read4L(f,&h->colormap)); /* colormap id */ }else e = formatCannotRead; if(!e) e = SETFPOS(f,fsFromStart,pos+SGI_HEADER_SIZE); } return e; } OSErr write_sgi_header(FILEREF f,struct sgi_header *h){ FILECOUNT count = SGI_IMAGENAME_SIZE; FILEPOS pos; OSErr e; (e = GETFPOS(f,&pos)) || (e = write2B(f,h->magic)) /* iris image file magic number */ || (e = write1 (f,h->storage)) /* storage format */ || (e = write1 (f,h->bpc)) /* number of bytes per pixel channel */ || (e = write2B(f,h->dimension)) /* number of dimensions */ || (e = write2B(f,h->xsize)) /* x size in pixels */ || (e = write2B(f,h->ysize)) /* y size in pixels */ || (e = write2B(f,h->zsize)) /* number of channels */ || (e = write4B(f,h->pixmin)) /* minimum pixel value */ || (e = write4B(f,h->pixmax)) /* maximum pixel value */ || (e = write1 (f,h->dummy)) /* ignored */ || (e = FSWRITE(f,&count,&h->imagename)) || (e = write4B(f,h->colormap)) /* colormap id */ || (e = SETFPOS(f,fsFromStart,pos+SGI_HEADER_SIZE)); return e; }