/* This file is part of icoformat, a Windows Icon (ICO) File Format plugin for Adobe Photoshop Copyright (C) 2002-2010 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 "icoformat.h" #include "PIAbout.h" #include "entry.h" // must come after Photoshop includes #include "ui.h" enum{ // estimate the largest total of memory allocations we might need MAX_MEM = 4*256 /* 4 x 256 = size of largest colour table */ + 4*256L*256L /* size of largest icon image */ + 32*256L /* largest transparency mask */ + (64L<<10) /* slop */ }; // 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; BufferID tempId; // Need this global data to pass data between phases (Estimate/Write). // Was using malloc(), but that's rather dangerous, as it's supposed // to survive invocations of the plugin. if(selector != formatSelectorAbout && !*data){ if( (*result = PS_BUFFER_ALLOC(sizeof(struct globals), &tempId)) ) return; *data = (intptr_t)PS_BUFFER_LOCK(tempId, true); } EnterCodeResource(); /* Perform the requested operation */ switch (selector){ case formatSelectorAbout: DoAbout((AboutRecordPtr)pb); break; case formatSelectorEstimatePrepare: case formatSelectorWritePrepare: case formatSelectorReadPrepare: /* estimate memory requirements */ pb->maxData /= 2; // take half of available if(pb->maxData > MAX_MEM) pb->maxData = MAX_MEM; break; case formatSelectorReadStart: e = read_start(pb); break; case formatSelectorReadContinue: e = read_continue(pb); break; case formatSelectorReadFinish: e = read_finish(pb); break; case formatSelectorOptionsPrepare: pb->maxData = 0; // no buffers are allocated in Options break; case formatSelectorOptionsStart: // ask user whether to use standard ICO or Vista (PNG) format if(!formatdialog(pb)) e = userCanceledErr; else G(usepng) = usepng; // pass this value to next phase 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); break; case formatSelectorFilterFile: break; default: e = formatBadParameters; } *result = e; ExitCodeResource(); }