/* 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 "entry.h" #include "PIAbout.h" #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 */ }; FormatRecordPtr gpb; // MPW MrC requires a prototype static void PluginMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result, int idType); DLLEXPORT MACPASCAL void IcoMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result); DLLEXPORT MACPASCAL void CurMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result); DLLEXPORT MACPASCAL void IcoMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result) { PluginMain(selector, pb, data, result, IDTYPE_ICON); } DLLEXPORT MACPASCAL void CurMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result) { PluginMain(selector, pb, data, result, IDTYPE_CUR); } static void PluginMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result, int idType) { OSErr e = noErr; struct revert_info *rev; EnterCodeResource(); /* Perform the requested operation */ if(selector == formatSelectorAbout){ DoAbout((AboutRecordPtr)pb); }else{ gpb = pb; // 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(!*data){ BufferID tempId; if( (*result = PS_BUFFER_ALLOC(sizeof(struct globals), &tempId)) ) return; *data = (intptr_t)PS_BUFFER_LOCK(tempId, true); } switch (selector){ 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: if(idType == IDTYPE_ICON){ // ask user whether to use standard ICO or Vista (PNG) format if(pb->revertInfo){ dbg("formatSelectorOptionsStart: have revertInfo"); rev = (struct revert_info*)PS_LOCKHANDLE(pb->revertInfo, false); usepng = rev->png; PS_UNLOCKHANDLE(pb->revertInfo); } if(formatdialog(pb)) G(usepng) = usepng; // pass this value to next phase else e = userCanceledErr; } else G(usepng) = 0; 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, idType); break; case formatSelectorWriteContinue: e = write_continue(pb, data); break; case formatSelectorWriteFinish: e = write_finish(pb); break; case formatSelectorFilterFile: break; default: e = formatBadParameters; } } #ifdef __SPBasic__ //PIUSuitesRelease(); #endif *result = e; ExitCodeResource(); }