/* This file is part of DITABIS, a File Format plugin for Adobe Photoshop Copyright (C) 2003-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 "ditabis.h" #include "entry.h" // must come after Photoshop includes #include "str.h" #include "ui.h" long DoPrepare(long); MACPASCAL void PluginMain(short selector,FormatRecordPtr pb,long *data,short *result); DLLEXPORT MACPASCAL void PluginMain(short selector,FormatRecordPtr pb,long *data,short *result){ OSErr e = noErr; extern long ypixel,xpixel,byteperpixel; EnterCodeResource(); /* Perform the requested operation */ switch (selector){ case formatSelectorAbout: DoAbout((AboutRecordPtr)pb); break; case formatSelectorEstimatePrepare: // case formatSelectorWritePrepare: case formatSelectorReadPrepare: pb->maxData = DoPrepare(pb->maxData); break; case formatSelectorReadStart: e = read_start(pb,data); break; case formatSelectorReadContinue: e = read_continue(pb,data); break; case formatSelectorReadFinish: e = read_finish(pb,data); break; /* case formatSelectorOptionsPrepare: pb->maxData = 0; // no buffers are allocated in Options break; case formatSelectorOptionsStart: pb->data = 0; case formatSelectorOptionsContinue: case formatSelectorOptionsFinish: break; case formatSelectorEstimateStart: e = estimate_start(pb,data); break; case formatSelectorEstimateContinue: e = estimate_continue(pb,data); break; case formatSelectorEstimateFinish: e = estimate_finish(pb,data); break; case formatSelectorWriteStart: e = write_start(pb,data); break; case formatSelectorWriteContinue: e = write_continue(pb,data); break; case formatSelectorWriteFinish: e = write_finish(pb,data); break; */ case formatSelectorFilterFile: readheader((FILEREF)pb->dataFork,false); e = xpixel && ypixel && byteperpixel ? noErr : formatCannotRead; break; default: e = formatBadParameters; } *result = e; ExitCodeResource(); } long DoPrepare(long maxData){ // estimate the largest total of memory allocations we might need enum{ MAX_MEM = (1L<<20) /* 1 megabyte */ }; return lesser(maxData / 2,MAX_MEM); // take half of available } long lesser(long a,long b){ return a < b ? a : b; }