/* This file is part of Netpbm Formats, a File Format plugin for Adobe Photoshop Copyright (C) 2004-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 "entry.h" // must come after Photoshop includes #include "pbm.h" DLLEXPORT MACPASCAL void PluginMain(short selector,FormatRecordPtr pb,intptr_t *data,short *result); int chunk; /* can process this many rows at a time (depends on available memory) */ #define MAXDATA_LIMIT (1L<<20) /* don't ask Photoshop for more than 1MB */ #define SLOP 16384 DLLEXPORT MACPASCAL void PluginMain(short selector,FormatRecordPtr pb,intptr_t *data,short *result){ OSErr e = noErr; long rb; FILECOUNT count; char sig[2]; EnterCodeResource(); if(selector == formatSelectorAbout) DoAbout((AboutRecordPtr)pb); else{ rb = ((long)pb->planes*pb->depth*pb->imageSize.h + 7)/8; switch (selector){ case formatSelectorReadPrepare: #ifdef USEMALLOC /* split memory with Photoshop, but don't ask for a ridiculous amount */ pb->maxData /= 2; if(pb->maxData > MAXDATA_LIMIT) pb->maxData = MAXDATA_LIMIT; #else pb->maxData = 0; // memory will be allocated via Photoshop callback #endif break; case formatSelectorWritePrepare: /* split memory with Photoshop, but don't ask for more than * the entire image would need */ chunk = (pb->maxData/2 - SLOP)/rb; if(chunk > pb->imageSize.v) chunk = pb->imageSize.v; else if(chunk < 1) chunk = 1; pb->maxData = rb*chunk + SLOP; break; case formatSelectorEstimatePrepare: case formatSelectorOptionsPrepare: pb->maxData = 0; break; case formatSelectorReadStart: e = read_start(pb); break; case formatSelectorReadContinue: e = read_continue(pb); break; case formatSelectorReadFinish: e = read_finish(pb); break; case formatSelectorEstimateStart: pb->minDataBytes = pb->maxDataBytes = 3+6+6+6+pb->imageSize.v*rb; case formatSelectorOptionsStart: case formatSelectorEstimateContinue: case formatSelectorOptionsContinue: pb->data = 0; case formatSelectorEstimateFinish: case formatSelectorOptionsFinish: break; case formatSelectorWriteStart: e = write_start(pb); break; case formatSelectorWriteContinue: e = write_continue(pb); break; case formatSelectorWriteFinish: e = write_finish(pb); break; case formatSelectorFilterFile: count = 2; e = !FSREAD(F,&count,sig) && sig[0]=='P' && sig[1]>='1' && sig[1]<='6' ? noErr : formatCannotRead; break; default: e = formatBadParameters; } } *result = e; ExitCodeResource(); }