/********************************************************************* File saving exercise *********************************************************************/ #include "LYNXX.h" #include "LYNXXfiles.h" extern SFReply reply; extern TPermanent gPermanent; extern AcquireRecordPtr gStuff; static Point SFGwhere = { 90, 82 }; static Point SFPwhere = { 106, 104 }; int GetRawImage (short_H TheImage) { int vRef,refNum,io; Str255 fn; if (OldFile(fn, &vRef )) if (FSOpen(fn, vRef, &refNum)==noErr) { if (ReadFile(refNum)==noErr) { pStrCopy(reply.fName,gStuff->filename); gStuff->vRefNum = vRef; } } if (FSClose(refNum)==noErr) ; else FileError("\pError opening ", fn); } int OldFile (Str255 fn, int *vRef) { SFTypeList myTypes; extern SFReply reply; myTypes[0]='TEXT'; SFGetFile(SFGwhere, "\p", 0L, 1, myTypes, 0L, &reply ); if (!reply.good) return (0); else { pStrCopy(reply.fName, fn); *vRef = reply.vRefNum; return(1); } } int ReadFile (int refNum) { long DATASize; long j,k; int ioerror; unsigned char tempdata[288],rawbyte1,rawbyte2,rawbyte3; short MinData,MaxData; short tempshort; short **TheImage; DATASize = 288; MaxData = 0; MinData = 4096; TheImage = gPermanent.MyImageHandle; for (j=0;j=MaxData) MaxData = tempshort; if (tempshort<=MinData) MinData = tempshort; tempshort = ((rawbyte2 & 0x00F0)<<4)+rawbyte3; *((*TheImage)+j*NUMCOL+2*k+1) = tempshort; if (tempshort>=MaxData) MaxData = tempshort; if (tempshort<=MinData) MinData = tempshort; } } } if (ioerror !=1) { gPermanent.maxImageValue = MaxData; gPermanent.minImageValue = MinData; } return ioerror; } int pStrCopy (StringPtr p1, StringPtr p2) /* copies a pascal string from p1 to p2 */ { register int len; len = *p2++ = *p1++; while (--len>=0) *p2++=*p1++; } int FileError(Str255 s, Str255 f) { ParamText(s, f,"\p", "\p"); Alert(256, 0L); }