/*
    This file is part of TIFFlib Format, a File Format plugin for Adobe Photoshop
    Copyright (C) 2005-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 "tifflibplugin.h"

int compitem, comptype[8];
char *compstr[8];

void setupcomp(FormatRecordPtr pb){
	int item = 0;
	compstr[item] = "None"; comptype[item++] = COMPRESSION_NONE;
	if(pb->depth == 1){
		compstr[item] = "G3 Fax"; comptype[item++] = COMPRESSION_CCITTFAX3;
		compstr[item] = "G4 Fax"; comptype[item++] = COMPRESSION_CCITTFAX4;
	}else if(pb->imageMode != plugInModeIndexedColor){
		compstr[item] = "JPEG"; comptype[item++] = COMPRESSION_JPEG;
	}
	compstr[item] = "LZW"; comptype[item++] = COMPRESSION_LZW;
	compstr[item] = "PackBits"; comptype[item++] = COMPRESSION_PACKBITS;
	compstr[item] = "AdobeDeflate (ZIP)"; comptype[item++] = COMPRESSION_ADOBE_DEFLATE;
	comptype[item] = 0; // terminate list
}

OSErr options_start(FormatRecordPtr pb,long *data){
	int i, origcomp;
	struct revertinfo rev;
	
	pb->data = NULL; // tell PS we don't need Continue/Finish options phases
	
	setupcomp(pb);
	
	// find menu item corresponding to image's compression type
	compitem = 0;
	if(pb->revertInfo){
		origcomp = ((struct revertinfo*)(*pb->revertInfo))->comptype;
		for(i = 0; comptype[i]; ++i)
			if(comptype[i] == origcomp){
				compitem = i;
				break;
			}
	}
	
	if(compdlg()){
		rev.comptype = comptype[compitem];
		putrevertinfo(pb, &rev);
		return noErr;
	}else
		return userCanceledErr;
}
