/* This file is part of WBMP Format, a File Format plugin for Adobe Photoshop Copyright (C) 2004-6 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 "wbmp.h" #include "file_io.h" #include "bufio.h" Handle indata; unsigned long read_varnum(FILEREF r){ int b; unsigned long v = 0; do{ v <<= 7; b = bufgetc(r); v |= b & 0x7f; }while( b & 0x80 ); return v; } OSErr read_start(FormatRecordPtr pb,long *data){ OSErr e = noErr; long count,*p; if(read_varnum((FILEREF)pb->dataFork) == WBMP_TYPE){ bufgetc((FILEREF)pb->dataFork); /* skip FixHeaderField */ pb->imageSize.h = read_varnum((FILEREF)pb->dataFork); pb->imageSize.v = read_varnum((FILEREF)pb->dataFork); pb->rowBytes = (pb->imageSize.h + 7)>>3; count = (long)pb->rowBytes * pb->imageSize.v; /* this allocation must be done using Handle suite, since it was not allowed for in Prepare call (maxData). */ if( (indata = pb->handleProcs->newProc(count + 4)) ){ pb->imageMode = plugInModeBitmap; pb->depth = 1; pb->planes = 1; pb->imageHRes = pb->imageVRes = 72L<<16; pb->theRect.left = pb->theRect.top = 0; pb->theRect.right = pb->imageSize.h; pb->theRect.bottom = pb->imageSize.v; pb->loPlane = pb->hiPlane = 0; pb->colBytes = 1; pb->data = pb->handleProcs->lockProc(indata,false); if(!(e = bufgetbytes((FILEREF)pb->dataFork,count,pb->data))) for( p=(long*)pb->data,count=(count+3)/4 ; count-- ; ) *p++ ^= -1; /* invert data */ }else e = memFullErr; }else e = formatCannotRead; return e; } OSErr read_continue(FormatRecordPtr pb,long *data){ pb->data = 0; return noErr; } OSErr read_finish(FormatRecordPtr pb,long *data){ pb->handleProcs->disposeProc(indata); return noErr; }