/* This file is part of 8XI (TI-83 Plus) Format, a File Format plugin for Adobe Photoshop Copyright (C) 2006 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 #include #include #include "ti8xi.h" Handle outdata; OSErr write_start(FormatRecordPtr pb,long *data){ OSErr e = noErr; long count; int descbytes,rb; char header[TI_HEADER_BYTES],*p; Handle titleprop; memset(header,0,TI_HEADER_BYTES); strcpy(header,TI8XI_SIG); // get document title property for TI header description if( !pb->propertyProcs->getPropertyProc(kPhotoshopSignature,propTitle,0,NULL,&titleprop) && ( descbytes = pb->handleProcs->getSizeProc(titleprop) ) ){ p = pb->handleProcs->lockProc(titleprop,false); if(descbytes > TI_DESC_BYTES) descbytes = TI_DESC_BYTES; memcpy(header+TI_DESC_OFFSET,p,descbytes); pb->handleProcs->disposeProc(titleprop); }else descbytes = 0; // pad description out with spaces for(p = header+TI_DESC_OFFSET; descbytes < TI_DESC_BYTES; ++descbytes) p[descbytes] = ' '; count = TI_HEADER_BYTES; if(!(e = FSWRITE((FILEREF)pb->dataFork,&count,header))){ pb->theRect.left = pb->theRect.top = 0; pb->theRect.right = pb->imageSize.h < TI8XI_COLS ? pb->imageSize.h : TI8XI_COLS; pb->theRect.bottom = pb->imageSize.v < TI8XI_ROWS ? pb->imageSize.v : TI8XI_ROWS; pb->loPlane = pb->hiPlane = 0; pb->colBytes = 1; pb->rowBytes = rb = TI8XI_COLS/8; /* FIXME: this allocation should be done using Handle suite, since it was not allowed for in Prepare call (maxData). */ if(!(outdata = pb->handleProcs->newProc((long)TI8XI_ROWS*rb))) e = memFullErr; else pb->data = pb->handleProcs->lockProc(outdata,false); } return e; } OSErr write_continue(FormatRecordPtr pb,long *data){ OSErr e; long count; char *row, zeroes[TI8XI_COLS/8]; int j, mask = pb->imageSize.h%8 ? ~((1<<(8-(pb->imageSize.h%8)))-1) : ~0, rb = (pb->imageSize.h+7)/8; memset(zeroes, 0, sizeof(zeroes)); count = TI8XI_COLS/8; for(j = 0, row = pb->data; j < TI8XI_ROWS; ++j, row += pb->rowBytes){ if(j < pb->imageSize.v){ row[rb-1] &= mask; // blank rest of partial byte at end of row if(rb < TI8XI_COLS/8) // blank rest of row after image data memset(row+rb, 0, TI8XI_COLS/8-rb); e = FSWRITE((FILEREF)pb->dataFork,&count,row); }else // write blank rows after supplied image data e = FSWRITE((FILEREF)pb->dataFork,&count,zeroes); if(e) break; } pb->data = NULL; return e; } OSErr write_finish(FormatRecordPtr pb,long *data){ short zeroes = 0; long count = 2; pb->handleProcs->disposeProc(outdata); // not sure what these 2 bytes at the end of the file mean... return FSWRITE((FILEREF)pb->dataFork,&count,&zeroes); }