/* This file is part of "scramble", a filter plugin for Adobe Photoshop Copyright (C) 2006-9 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 */ /* Photoshop filter which chops an image into blocks, then shuffles them */ #include "world.h" #include "scramble.h" #include "entry.h" #include "ui.h" struct params *lockparams(FilterRecordPtr pb); void unlockparams(FilterRecordPtr pb); DLLEXPORT MACPASCAL void ENTRYPOINT(short selector, FilterRecordPtr epb, long *data, short *result); DLLEXPORT MACPASCAL void ENTRYPOINT(short selector, FilterRecordPtr pb, long *data, short *result){ OSErr e = noErr; struct params *pparam; switch (selector){ case filterSelectorAbout: DoAbout((AboutRecordPtr)pb); break; case filterSelectorParameters: if( (pparam = lockparams(pb)) ){ if(!tile_dialog(pb, pparam)) e = userCanceledErr; unlockparams(pb); }else e = nilHandleErr; /* right error? */ break; case filterSelectorPrepare: break; case filterSelectorStart: // request entire selection, all planes pb->inLoPlane = pb->outLoPlane = 0; pb->inHiPlane = pb->outHiPlane = pb->planes-1; pb->inRect = pb->outRect = pb->filterRect; break; case filterSelectorContinue: // called once (for entire image) if( (pparam = lockparams(pb)) ){ e = process(pb, pparam); unlockparams(pb); }else e = nilHandleErr; /* right error? */ // inform Photoshop that we are quite finished. pb->inRect.left = pb->inRect.right = pb->inRect.top = pb->inRect.bottom = 0; pb->outRect = pb->maskRect = pb->inRect; break; case filterSelectorFinish: break; default: e = filterBadParameters; } *result = e; } struct params *lockparams(FilterRecordPtr pb){ // validate parameter storage if(!pb->parameters){ // not allocated yet if( (pb->parameters = pb->handleProcs->newProc(sizeof(struct params))) ){ struct params* p = (struct params*) pb->handleProcs->lockProc(pb->parameters, true); // set defaults p->tilew = p->tileh = 20; return p; }else return NULL; } return (struct params*) pb->handleProcs->lockProc(pb->parameters, true); } void unlockparams(FilterRecordPtr pb){ if(pb->parameters) pb->handleProcs->unlockProc(pb->parameters); }