home *** CD-ROM | disk | FTP | other *** search
- #include "classbase.h"
- #include "TIFF.h"
- #include "TIFFTags.h"
-
- #define DB(x) ;
-
- #define SWAPW(a) (Rev ? (WORD)(((UWORD)a>>8)+((((UWORD)a&0xff)<<8))) : a)
- #define SWAPU(a) (Rev ? (UWORD)(((UWORD)a>>8)+((((UWORD)a&0xff)<<8))) : a)
- #define SWAPL(a) (Rev ? (LONG)(((ULONG)a>>24)+(((ULONG)a&0xff0000)>>8)+(((ULONG)a&0xff00)<<8)+(((ULONG)a&0xff)<<24)): a)
-
- #define TAGVAL(a,b) (SWAPW(a->Type)==TT_BYTE ? a->CValue[b] : \
- (SWAPW(a->Type)==TT_SHORT ? SWAPW(a->SValue[b]) : \
- (SWAPW(a->Type)==TT_LONG ? SWAPL(a->LValue) : \
- ~0)))
-
- extern char Rev;
- BOOL ReadError=FALSE;
-
- ULONG ASM ReadData(REG (a0) BPTR fh, register __d0 USHORT type,REG (a6) struct ClassBase *cb)
-
- {
- UBYTE Byte;
- USHORT Short;
- ULONG Long;
-
- switch(type)
- {
- case TT_BYTE:
- if( Read(fh, &Byte,1) !=1)
- ReadError=TRUE;
- return Byte;
- break;
- case TT_SHORT:
- if( Read(fh, &Short,2) !=2)
- ReadError=TRUE;
- return SWAPW(Short);
- break;
- case TT_LONG:
- if( Read(fh, &Long,4) !=4)
- ReadError=TRUE;
- return SWAPL(Long);
- break;
- }
- }/*************************** ReadData ************************/
-
- void ASM ReadShorts(REG (a0) BPTR fh, REG (a1) USHORT *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
-
- {
- int i,oldpos;
-
- DB (KPrintF ("Read Shorts %ld off %ld\n",(long)tag->Count,(long)SWAPL(tag->LValue)));
- oldpos=Seek(fh, SWAPL(tag->LValue), OFFSET_BEGINNING);
- DB (KPrintF ("Seek %ld\n",(long)SWAPL (tag->LValue)));
- for(i=0;i<tag->Count;i++)
- *buffer++=ReadData(fh,tag->Type,cb);
- DB (KPrintF ("Read %ld\n",(long)tag->Count));
- Seek(fh, oldpos, OFFSET_BEGINNING);
- DB (KPrintF ("Seek %ld\n",(long)oldpos));
- }/*************************** ReadShorts ************************/
-
- void ASM ReadLongs(REG (a0) BPTR fh, REG (a1) ULONG *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
-
- {
- int i,oldpos;
-
- DB (KPrintF ("Read Longs %ld\n", (long)tag->Count));
-
- if(tag->Count==1)
- {
- *buffer=TAGVAL(tag,0);
- return;
- }
-
- oldpos=Seek(fh, tag->LValue, OFFSET_BEGINNING);
- for(i=0;i<tag->Count;i++)
- *buffer++=ReadData(fh,SWAPW(tag->Type),cb);
- Seek(fh, oldpos, OFFSET_BEGINNING);
- }/*************************** ReadLongs ************************/
-
- void ASM ReadRational(REG (a0) BPTR fh, REG (a1) ULONG *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
-
- {
- int i,oldpos;
-
- DB (KPrintF ("Read Rationals %ld\n", (long)tag->Count));
- oldpos=Seek(fh, tag->LValue, OFFSET_BEGINNING);
- for(i=0;i<tag->Count;i++)
- {
- *buffer++=ReadData(fh,tag->Type,cb);
- *buffer++=ReadData(fh,tag->Type,cb);
- }
- Seek(fh, oldpos, OFFSET_BEGINNING);
- }/*************************** ReadRational ************************/
-
- void ASM ReadBytes(REG (a0) BPTR fh, REG (a1) UBYTE *buffer, REG (a2) TIFFTagItem *tag,REG (a6) struct ClassBase *cb)
-
- {
- int i,oldpos;
-
- DB (KPrintF ("Read Bytes %ld\n", (long)tag->Count));
- oldpos=Seek(fh, tag->LValue, OFFSET_BEGINNING);
- for(i=0;i<tag->Count;i++)
- *buffer++=ReadData(fh,tag->Type,cb);
- Seek(fh, oldpos, OFFSET_BEGINNING);
- }/*************************** ReadBytes ************************/
-