home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
365.lha
/
MapCol_v1.4
/
MapCol.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-10
|
7KB
|
208 lines
/**********************************************************************
M A P C O L - Change workbench object colors
Copyright (C) 1990, John Adam Thywissen
$Header: Rockie:Projects/Programs/Utils/RCS/MapCol.c,v 1.4 90/03/21 14:48:42 thywiss Exp $
**********************************************************************
* Description And History
*
* DESCRIPTION:
* This program changes the colors of an Amiga Workbench Object.
* It is intended to run from the CLI only.
*
* ENVIRONMENT:
* Programming Language: ANSI C
* Operating System: Amiga System Software Release 1.3.2
* Compiler: Lattice AmigaDOS C v5.05
*
* AUTHOR:
* John A. Thywissen
*
* 4205 Tuckerman Street 7 Stonegate
* University Pk, MD 20782-2144 Houston, TX 77024-2703
*
* Amiga Certified Developer bix: thywiss
*
* DATE CREATED: 3 Mar 1990
*
* REVISION HISTORY:
* $Log: MapCol.c,v $
* Revision 1.4 90/03/21 14:48:42 thywiss
* Forgot to change rev # in introductory message. (Bother!)
*
* Revision 1.3 90/03/21 14:35:39 thywiss
* Was freeing a DiskObject I didn't have (yet)
*
* Revision 1.2 90/03/21 13:11:39 thywiss
* Made suitable for human consumption
* Added command line color option
*
* Revision 1.1 90/03/04 00:00:41 thywiss
* Initial Revision
*
* AVAILABILITY:
* COPYRIGHT 1990, JOHN ADAM THYWISSEN
* This program may be freely distributed under certain conditions:
* 1. This program must be distributed in a completely UNMODIFIED
* form.
* 2. This program shall not be sold. However, public domain
* librarians may charge a small fee for distribution not exceeding
* the cost of duplication, materials, and handling.
* 3. This program may be incorporated into another program or
* package. However, the notice of copyright should be made
* visible to the user of such program or package. (Simply stating
* "MapCol ©1990, John A. Thywissen" in the documentation is
* sufficient.)
* 4. The source need not be distributed with the binary, however,
* this availabilty statement must always accompany the binary and
* source code.
**********************************************************************/
/**********************************************************************
Global Declarations
**********************************************************************/
/* Included Files */
#include <exec/types.h>
#include <proto/exec.h>
#include <intuition/intuition.h>
#include <workbench/workbench.h>
#include <workbench/icon.h>
#include <proto/icon.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
/**********************************************************************
Main Routine
**********************************************************************/
void main(argc,argv) /* void due to Lattice Dain-Bramage */
int argc;
char *argv[];
{
/* main Storage */
struct DiskObject *DO;
struct Image *theimage;
int i,j,nw,planesize,map[4],old,new;
char inbuf[255]; /* KNOWN BUG: lines > 255 char will trash stack */
/* main Statements */
printf("MapCol 1.4 (21 Mar 1990) ©1990, John A. Thywissen\n");
if ((argc != 2) && (argc != 6))
{
printf("Usage: MapCol objectname [color0 color1 color2 color3]\n");
exit(20);
}
IconBase = OpenLibrary(ICONNAME,LIBRARY_VERSION);
if (IconBase == NULL)
{
printf("MapCol: Cannot open the icon library\n");
exit(21);
}
DO = GetDiskObject(argv[1]);
if (DO == NULL)
{
printf("MapCol: Cannot open workbench object %s\n",argv[1]);
CloseLibrary(IconBase);
exit(10);
}
if (DO->do_Version != WB_DISKVERSION)
{
printf("MapCol does not understand this Disk Object version.\n");
FreeDiskObject(DO);
CloseLibrary(IconBase);
exit(5);
}
for (i = 0; i <= 3; i++)
{
if (argc != 6)
{
printf("Map color %d to ",i);
gets(inbuf);
}
if (sscanf(((argc!=6)?inbuf:argv[i+2]),"%d",&(map[i])) != 1)
{
printf("MapCol expects an integer for color %d, but it \
found \"%s\".\n",i,((argc!=6)?inbuf:argv[i+2]));
FreeDiskObject(DO);
CloseLibrary(IconBase);
exit(10);
}
}
theimage = (struct Image *)DO->do_Gadget.GadgetRender;
printf("Height = %d\n",theimage->Height);
printf("Width = %d\n",theimage->Width);
if (theimage->Depth != 2)
{
printf("MapCol: Image Depth is not 2 bitplanes!!\n");
FreeDiskObject(DO);
CloseLibrary(IconBase);
exit(5);
}
nw = (theimage->Width % 16)==0?theimage->Width/16:theimage->Width/16+1;
planesize = theimage->Height * nw;
for (i = 0; i < theimage->Height; i++)
{
for (j = 0; j < theimage->Width; j++)
{
old = (((theimage->ImageData)[i*nw+j/16] & (1<<(15-j%16)))?1:0)+
(((theimage->ImageData)[i*nw+j/16+planesize] & (1<<(15-j%16)))?2:0);
new = map[old];
(theimage->ImageData)[i*nw+j/16] &= ~(1<<(15-j%16));
(theimage->ImageData)[i*nw+j/16] |= (new & 1)<<(15-j%16);
(theimage->ImageData)[i*nw+j/16+planesize] &= ~(1<<(15-j%16));
(theimage->ImageData)[i*nw+j/16+planesize] |=
((new>>1) & 1)<<(15-j%16);
}
}
if (DO->do_Gadget.SelectRender != NULL)
{
theimage = (struct Image *)DO->do_Gadget.SelectRender;
nw = (theimage->Width % 16)==0?theimage->Width/16:theimage->Width/16+1;
planesize = theimage->Height * nw;
for (i = 0; i < theimage->Height; i++)
{
for (j = 0; j < theimage->Width; j++)
{ /* Yes, it's slow, but it was free, no? */
/* Actually, next rev I will not address */
/* every byte 24 times. Besides, what */
/* the Global Pessamizer (oops--Optimizer) */
/* do without this kind of stuff? */
old =
(((theimage->ImageData)[i*nw+j/16] &
(1<<(15-j%16)))?1:0) +
(((theimage->ImageData)[i*nw+j/16+planesize] &
(1<<(15-j%16)))?2:0);
new = map[old];
(theimage->ImageData)[i*nw+j/16] &= ~(1<<(15-j%16));
(theimage->ImageData)[i*nw+j/16] |= (new & 1)<<(15-j%16);
(theimage->ImageData)[i*nw+j/16+planesize] &=
~(1<<(15-j%16));
(theimage->ImageData)[i*nw+j/16+planesize] |=
((new>>1) & 1)<<(15-j%16);
}
}
}
PutDiskObject(argv[1],DO);
FreeDiskObject(DO);
CloseLibrary(IconBase);
}