home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
datafiles
/
text
/
c_manual
/
amiga
/
tools
/
swapcols
/
swapcols.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-27
|
10KB
|
235 lines
/****************************************************/
/* */
/* (C) - Wheelbarrow Software Ltd 1991 */
/* */
/* Program - SwapCols */
/* Description - This program swaps colours 1 & 2 */
/* of any icons that are passed in */
/* as workbench parameters */
/* Purpose - With the advent of WB2.0 the */
/* system colours changed from */
/* orange/black/white/blue to */
/* grey/black/white/blue. Icons of */
/* the old type appeared weird */
/* under the new colour scheme. */
/* After changing colours 1 & 2 */
/* things look normal again. */
/* Programmer - Paul Hammant */
/* (Wheelbarrow Software) */
/* Date - 03/11/91 */
/* Notes - This is my first useful program */
/* Everything else to date has been */
/* of the "Hello World" type. */
/****************************************************/
/* ** Changes ** */
/* */
/* Programmer - */
/* Date/Time - */
/* Changes - */
/* */
/****************************************************/
#include <exec/types.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include <intuition/intuition.h>
#include <stdio.h>
#include <libraries/dos.h>
#include <exec/memory.h>
extern struct WBStartup *WBenchMsg;
struct IconBase *IconBase;
/****************************************************/
/* */
/* Function - SwapCols */
/* Description - Colours 1 & 2 of a two bitplane */
/* image are swapped. The image is */
/* passed in as a parameter. */
/* Used by - DoSwap */
/* */
/****************************************************/
void SwapCols(Img)
struct Image *Img;
{
UWORD widint, widmod, h, w;
WORDBITS mmask, *plane0, *plane1;
if(Img){
/* round image width up to whole number of words (16bits) */
/* ------------------------------------------------------ */
widint = Img->Width / 16;
widmod = Img->Width % 16;
if(widmod) widint = widint +1;
/* point to the beginning of each plane */
/* ------------------------------------ */
plane0 = Img->ImageData;
plane1 = plane0 + (Img->Height * widint);
/* Loop through all the lines of the image */
/* --------------------------------------- */
for(h = 0; h < Img->Height; h += 1)
{
/* and all of the pixels across the image (16 at time) */
/* --------------------------------------------------- */
for(w = 0; w < widint; w += 1)
{
/* the bits in the 16bit work variable mmask will have a */
/* 1 to represent where the image colour was either 1 or 2 */
/* and a 0 to represent either 0 or 3. When this is */
/* exclusive-ORed (^) back onto the bitplane again it */
/* essentially flips the bits of the colours 1 & 2. */
/* ------------------------------------------------------- */
mmask = *plane0 ^ *plane1;
*plane0 = *plane0 ^ mmask;
*plane1 = *plane1 ^ mmask;
plane0 += 1;
plane1 += 1;
}
}
}
}
/****************************************************/
/* */
/* Function - DoSwap */
/* Description - Initiate the colour swap for */
/* both the normal image and the */
/* selected image (not always */
/* present). */
/* Used by - ProcessArg */
/* */
/****************************************************/
void DoSwap(GadG)
struct Gadget GadG;
{
SwapCols(GadG.GadgetRender);
SwapCols(GadG.SelectRender);
}
/****************************************************/
/* */
/* Function - ProcessArg */
/* Description - This function processes a WB */
/* argument passed in as a parm */
/* and read the relevent .info */
/* file (Icon) off disk. This is */
/* then processed and written back */
/* to disk. */
/* Used by - ProcessWBArgs */
/* */
/****************************************************/
void ProcessArg(ArgLock,ArgName)
struct FileLock *ArgLock;
STRPTR ArgName;
{
BOOL Written;
struct FileLock *ParLock, *OurLock;
STRPTR OurName;
struct DiskObject *DObj;
struct FileInfoBlock *fib_ptr;
fib_ptr = ParLock = NULL;
OurLock = ArgLock;
OurName = ArgName;
/* if no name passed in as parm then it must be a drawer or disk icon */
/* ------------------------------------------------------------------ */
if(! *OurName){
/* Get enough memory for a File Info Block structure */
/* ------------------------------------------------- */
fib_ptr = (struct FileInfoBlock *)
AllocMem( sizeof(struct FileInfoBlock),
MEMF_PUBLIC|MEMF_CLEAR);
/* Examine the lock ( results are now at fib_ptr ) */
/* ----------------------------------------------- */
Examine( OurLock, fib_ptr );
/* The file name ( without path ) is in the fileinfoblock */
/* ------------------------------------------------------ */
OurName = fib_ptr->fib_FileName;
/* As the file is without path we will have to get the lock */
/* for the parent directory */
/* ---------------------------------------------------------*/
if(ParLock = (struct FileLock *) ParentDir(OurLock)){
OurLock = ParLock;
}
else
{
/* no parent dir exists so we must be dealing with the disk icon*/
/* so leave the lock where it is and "hardcode" the name */
OurName = (STRPTR)"Disk";
}
}
printf("%s .",OurName);
/* Set the current dir ( All our file names don't have full paths */
/* -------------------------------------------------------------- */
CurrentDir(OurLock);
/* Get the DiskObjectstructure for our object */
/* ------------------------------------------ */
if(!(DObj = (struct DiskObject *) GetDiskObject(OurName))){
printf("\10not retrieved for some reason.\n");
}
else
{
/* Process the disk object */
/* ----------------------- */
DoSwap(DObj->do_Gadget);
/* Put it back */
/* ----------- */
Written = PutDiskObject(OurName,DObj);
/* Free up the memory that GetDiskObject Allocated */
/* ----------------------------------------------- */
FreeDiskObject(DObj);
if(!Written) printf("\10not updated.\n");
else printf("\10changed.\n");
}
/* If we had a parent lock the unlock it */
/* ------------------------------------- */
if(ParLock) UnLock(ParLock);
/* If we had a file info block then free the memory */
/* ------------------------------------------------ */
if(fib_ptr) FreeMem(fib_ptr, sizeof(struct FileInfoBlock));
}
/****************************************************/
/* */
/* Function - ProcessWBArgs */
/* Description - This function loops through all */
/* the workbench args passed in. */
/* Used by - main */
/* */
/****************************************************/
void ProcessWBArgs(msg)
struct WBStartup *msg;
{
struct WBArg *arg;
UWORD i;
IconBase = (struct IconBase *) OpenLibrary("icon.library",0);
for(i=0,arg=msg->sm_ArgList;i<msg->sm_NumArgs;i++,arg++){
if(i!=0) {
ProcessArg(arg->wa_Lock,arg->wa_Name);
}
}
if(msg->sm_NumArgs == 1){
printf("To Use:\n1. Click once on this tool.\n2. Press (and hold down) the shift key.\n3. Click once on each icon to change.\n4. Double click on the last icon.\n5. Close & reopen the affected windows.");
Delay(3*50);
}
CloseLibrary(IconBase);
}
/****************************************************/
/* */
/* Function - main */
/* Description - This returns an error message */
/* if invoked from the CLI or */
/* process the WB arguments. */
/* */
/****************************************************/
main(argc,argv)
int argc;
char **argv;
{
if(argc>0){
printf("Sorry Folks This Is a WorkBench Only Tool\n");
exit(10);
}
else{
ProcessWBArgs(WBenchMsg);
Delay(2*50);
}
}
/****************** End Of Source ***********************/