/****************************************************************************** File: ModuleFunctions.c Contains: This file contains the the code to perform the actions of the External Module. Written by: Brian Powell Copyright: © 1994 by Brian Powell, all rights reserved. ******************************************************************************/ // Include Files #include "WorkshopModule.h" #include #include /****************************************************************************** * ModuleInit * * Image Workshop is initializing. This is your chance to initialize your * module for anything you may need. * * data1: NULL * data2: NULL ******************************************************************************/ short ModuleInit(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; return (error); } /****************************************************************************** * ModuleRead * * If your module is a reader, then this code is called to read and create the * new image. * * data1: StandardFileReply *, This is the file to load * data2: Boolean *, Whether or not you should create a new image, or merely a * new layer. ******************************************************************************/ short ModuleRead(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; return (error); } /****************************************************************************** * ModuleSave * * If your module saves files, then this code is called to save the image. * * data1: SFReply *, File to save into * data2: NULL ******************************************************************************/ short ModuleSave(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; return (error); } /****************************************************************************** * ModuleExecute * * If you have a general module, whenever your module is selected by the user, * this code is called to execute. * * data1: NULL * data2: NULL ******************************************************************************/ short ModuleExecute(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; StandardFileReply reply; OSType list[1]; short image; Str255 name; FILE *input; char line[80]; short r, g, b, count=0; RGBColor color; float scale = 65535.0/255.0; // Set up the file parameters list[0] = (OSType)'TEXT'; // Let the user choose a file to open StandardGetFile(NULL, 1, list, &reply); if (reply.sfGood) { CTabHandle cTable; // Set up the name BlockMove(reply.sfFile.name, name, reply.sfFile.name[0]+1); name[name[0]+1] = '\0'; // Create a standard 8-bit color table, then hold it down cTable = GetCTable(8); MoveHHi((Handle)cTable); HLock((Handle)cTable); // Open the file, bringing in the color table input = fopen((char *)&(name[1]), "r"); while (!feof(input)) { fscanf(input, "%d %d %d\n", &r, &g, &b); color.red = (float)r*scale; color.green = (float)g*scale; color.blue = (float)b*scale; (*cTable)->ctTable[count++].rgb = color; if (count > 255) break; } fclose(input); // Clean things up HUnlock((Handle)cTable); // Get a file to save into StandardPutFile("\pSave Color Table:", name, &reply); if (reply.sfGood) { short refNum; // Save it out FSpCreateResFile(&(reply.sfFile), kIWSignature, kIWCTableType, smSystemScript); refNum = FSpOpenResFile(&(reply.sfFile), fsRdWrShPerm); AddResource((Handle)cTable, 'clut', 128, reply.sfFile.name); ReleaseResource((Handle)cTable); CloseResFile(refNum); // Tell the user image = functions->GetTopImage(); if (image) { functions->SetColorTable(image, cTable); } Alert(128, NULL); } } return (error); } /****************************************************************************** * ModuleDispose * * Image Workshop is quitting. Do any disposal items you need to. * * data1: NULL * data2: NULL ******************************************************************************/ short ModuleDispose(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; return (error); } /****************************************************************************** * ModuleProcessTask * * Your task needs processing. Do an iteration, and let control back. * * data1: long*. Return the percentage complete your function is (0-100). * data2: long*. The maximum number of ticks you'll allow between calls. ******************************************************************************/ short ModuleProcessTask(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; return (error); } /****************************************************************************** * ModuleCancelTask * * The user canceled your task. * * data1: NULL * data2: NULL ******************************************************************************/ short ModuleCancelTask(ExternalProcPtrs functions, Ptr data1, Ptr data2, Handle *myData) { short error = 0; return (error); }