/* This file is part of PSPFormat, a File Format plugin for Adobe Photoshop Copyright (C) 2003-7 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 "pspformat.h" #include "entry.h" // must come after Photoshop includes #include "str.h" #include "ui.h" long prepare(long); int lastsel = -1; FormatRecordPtr gpb; // MPW MrC requires a prototype DLLEXPORT MACPASCAL void PluginMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result); DLLEXPORT MACPASCAL void PluginMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result){ OSErr e = noErr; PSP_file_header h; if(selector != formatSelectorAbout && !*data){ BufferID tempId; if( (*result = PS_BUFFER_ALLOC(sizeof(globals), &tempId)) ) return; *data = (intptr_t)PS_BUFFER_LOCK(tempId, true); } EnterCodeResource(); gpb = pb; /* Perform the requested operation */ switch (selector){ case formatSelectorAbout: DoAbout((AboutRecordPtr)pb); break; case formatSelectorEstimatePrepare: case formatSelectorWritePrepare: case formatSelectorReadPrepare: pb->maxData = prepare(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: e = options_start(pb, data); case formatSelectorOptionsContinue: pb->data = NULL; 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: e = headerok((FILEREF)pb->dataFork, &h); break; default: e = formatBadParameters; } *result = e; ExitCodeResource(); } /* estimate the largest total of memory allocations we might need */ long prepare(long maxData){ //maxData /= 2; // take half of available, up to MAX_MEM //return maxData < MAX_MEM ? maxData : MAX_MEM; return 128L<<10; // nominal } void putrevertinfo(FormatRecordPtr pb, struct revertinfo *p){ /* when plugin entered for the first time for this document, * pb->revertInfo should be NULL */ Handle h = pb->revertInfo ? pb->revertInfo : (pb->hostNewHdl)(sizeof(struct revertinfo)); if(h){ *((struct revertinfo*)*h) = *p; pb->revertInfo = h; } } int getrevertinfo(FormatRecordPtr pb, struct revertinfo *p){ if(pb->revertInfo){ *p = *((struct revertinfo*)*pb->revertInfo); return 1; } return 0; }