v01i009: palette, a colormix tool, Part 02/02
Charles Mcgrew
mcgrew at dartagnan.rutgers.edu
Fri May 19 07:03:42 AEST 1989
Submitted-by: Wayne Mesard <mesard at bbn.com>
Posting-number: Volume 1, Issue 9
Archive-name: palette/part02
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# Makefile
# canvas.c
# color.icon
# desktop.c
# hash.c
# hash.h
# left_arrow.pr
# right_arrow.pr
# This archive created: Thu May 18 13:59:08 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'Makefile'" '(372 characters)'
if test -f 'Makefile'
then
echo shar: will not over-write existing file "'Makefile'"
else
sed 's/^ X//' << \SHAR_EOF > 'Makefile'
XWINDOW_LIB = -lsuntool -lsunwindow -lpixrect
XBINDIR = ../bin
X
XMANDIR = ../man/manl
XMANEXT = l
X
XCFLAGS = -O -f68881
XLFLAGS = -s
X
Xpalette: palette.o hash.o canvas.o desktop.o
X $(CC) $(CFLAGS) $(LFLAGS) -o palette \
X palette.o hash.o canvas.o desktop.o $(WINDOW_LIB)
X
Xinstall: palette
X mv palette $(BINDIR)
X mv palette.l $(MANDIR)/palette.$(MANEXT)
X
Xclean:
X -rm *.o core
X
SHAR_EOF
if test 372 -ne "`wc -c < 'Makefile'`"
then
echo shar: error transmitting "'Makefile'" '(should have been 372 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'canvas.c'" '(6580 characters)'
if test -f 'canvas.c'
then
echo shar: will not over-write existing file "'canvas.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'canvas.c'
X/*
X * canvas.c - This module implements all the I/O to the palette canvas.
X * This includes the color swatches, highlighting the current
X * color(s), and determining the location of a mouse click.
X *
X * Exported routines:
X * MakePalette
X * SetPaletteSize
X * SavePalette
X * DrawPalette
X * WhichSwatch
X * HighlightSwatch
X * BoxSwatches
X */
X
X/**************************************************************************
X * palette - a colormap editor
X * Copyright (c) 1988 Wayne Mesard *
X * *
X * This is free software. It may be reproduced, retransmitted, *
X * redistributed and otherwise propogated at will, provided that *
X * no monetary profit is realized and that this notice remains *
X * intact and in place. *
X * *
X * Please direct bug reports, code enhancements and comments *
X * to mesard at BBN.COM. *
X * *
X **************************************************************************/
X
X#include <suntool/sunview.h>
X#include <suntool/canvas.h>
X#include <stdio.h>
X
X#define Y_LOC(ENTRY) (y_edge + ((ENTRY)/powx)*edge)
X#define X_LOC(ENTRY) (x_edge + ((ENTRY)%powx)*edge)
X
Xstatic Canvas palette_canvas;
Xstatic Pixwin *palette_pw;
X
Xstatic int palette_width, palette_height, x_edge, y_edge, edge;
Xstatic unsigned int powx, powy;
X
X
X/* MakePalette - Sets module variables and returns the pixwin of the
X * canvas. Must be called once before any other routines
X * in this module.
X */
X
XPixwin *MakePalette(canvas)
XCanvas canvas;
X{
X return(palette_pw = canvas_pixwin(palette_canvas=canvas));
X}
X
X
X
X/*
X * SetPaletteSize - Updates module variables. Must be called when
X * canvas is resized.
X */
X
Xvoid SetPaletteSize()
X{
X palette_width = (int) window_get(palette_canvas, CANVAS_WIDTH);
X palette_height = (int) window_get(palette_canvas, CANVAS_HEIGHT);
X}
X
X
X
X/*
X * SavePalette - Given an open file pointer, creates a rasterfile image
X * of the palette.
X */
X
Xint SavePalette(fp, colormap)
XFILE *fp;
Xcolormap_t *colormap;
X{
X return(pr_dump(palette_pw->pw_prretained, fp, colormap, RT_STANDARD, 0));
X}
X
X
X/*
X * DrawPalette - Given a number of colors, draw a recangle containing a
X * square for each color. The size of the rectangle
X * should be maximal w.r.t. the size of the palette.
X * (This procedure is greatly simplified by the fact that
X * the width:height ratio is always a power of 2 (since
X * the number of colors is always a power of 2.
X */
X
Xvoid DrawPalette(n_colors)
Xint n_colors;
X{
X void DrawRect();
X register int x, y;
X int temp;
X int x_max = palette_width;
X int y_max = palette_height;
X
X edge = 0;
X for (x = n_colors, y = 1; x; x >>= 1, y <<= 1) {
X temp = ((x_max-8)/x < (y_max-8)/y ?
X (x_max-8)/x : (y_max-8)/y);
X if (temp > edge) {
X powx = x;
X powy = y;
X edge = temp;
X }
X }
X /* Note: a non-iterative algorithm for the above procedure exists,
X * but it requires floating point arithmetic and mathlib routines.
X * This is computationally more efficient, although less elegant.
X */
X
X x_edge = (x_max - (powx*edge))/2;
X y_edge = (y_max - (powy*edge))/2;
X
X pw_batch_on(palette_pw);
X pw_writebackground(palette_pw, 0, 0, x_max, y_max, PIX_SRC | PIX_COLOR(0));
X
X x_max = x_edge + powx*edge;
X y_max = y_edge + powy*edge;
X
X n_colors--; /* So we don't have to compare n-1 */
X
X DrawRect(x_edge-2, y_edge-2, x_max, y_max, PIX_SRC, n_colors);
X
X for (temp = -1, y=y_edge; y < y_max; y += edge)
X for (x=x_edge; x < x_max; x += edge) {
X pw_writebackground(palette_pw, x, y, edge-1, edge-1,
X PIX_SRC | PIX_COLOR(++temp));
X }
X pw_batch_off(palette_pw);
X}
X
X
X
X/*
X * WhichSwatch - Find out which color is at specified position. Return
X * -1 if it's outside the rectangle.
X *
X * Can't simply look at the pixel value, since it might be
X * on the border, or adjacent to the currently selected
X * square (and therefore with that color's enlarge square
X */
X
Xint WhichSwatch(x, y)
Xint x, y;
X{
X x = x-x_edge;
X y = y-y_edge;
X if (x < 0 || y < 0 || (x=x/edge) >= powx || (y=y/edge) >= powy)
X return (-1);
X else
X return((y*powx)+x);
X}
X
X
X
X/*
X * HighlightSwatch - Draw a big old square for the specified color.
X */
X
Xvoid HighlightSwatch(num, border_color)
Xint num, border_color;
X{
X void DrawRect();
X int x, y;
X
X if (border_color > 2) {
X y = Y_LOC(num);
X x = X_LOC(num);
X
X pw_batch_on(palette_pw);
X pw_writebackground(palette_pw, x-edge/2, y-edge/2, 2*edge, 2*edge,
X PIX_SRC | PIX_COLOR(num));
X DrawRect(x, y, x+edge, y+edge, PIX_SRC,
X (num == border_color ? 0 : border_color));
X pw_batch_off(palette_pw);
X
X }
X}
X
X
X
X/*
X * BoxSwatches - Draw a border around the specified range of color squares.
X */
X
Xvoid BoxSwatches(e1, e2)
Xint e1, e2;
X{
X void BoxRegion();
X int temp;
X
X pw_batch_on(palette_pw);
X /* Box the first row iff region doesn't start at col 0. */
X if (e1 % powx && ((e2-e1 > powx) || (e2%powx < e1%powx))) {
X temp = e1-(e1%powx)+powx-1;
X BoxRegion(e1, temp);
X e1 = temp+1;
X }
X /* Box the rows between the first and the last, if there are any. */
X if (e2-e1 >= powx) {
X temp = e2-(e2%powx)-1;
X BoxRegion(e1, temp);
X e1 = temp+1;
X }
X /* Box the partial row at the end, if there is one. */
X if (e1 <= e2)
X BoxRegion(e1, e2);
X
X pw_batch_off(palette_pw);
X}
X
X
X
X/*
X * BoxRegion - Draw a rectangle whose upper left corner is at square e1
X * and whose lower right is at e2.
X */
X
Xstatic void BoxRegion(e1, e2)
Xint e1, e2;
X{
X void DrawRect();
X
X DrawRect(X_LOC(e1)-1, Y_LOC(e1)-1, X_LOC(e2)+edge-1, Y_LOC(e2)+edge-1,
X PIX_NOT(PIX_DST), 0);
X}
X
X
Xstatic void DrawRect(x1, y1, x2, y2, op, color)
Xint x1, y1, x2, y2, color;
X{
X pw_vector(palette_pw, x1, y1, x2, y1, op, color);
X pw_vector(palette_pw, x2, y1, x2, y2, op, color);
X pw_vector(palette_pw, x2, y2, x1, y2, op, color);
X pw_vector(palette_pw, x1, y2, x1, y1, op, color);
X}
X
SHAR_EOF
if test 6580 -ne "`wc -c < 'canvas.c'`"
then
echo shar: error transmitting "'canvas.c'" '(should have been 6580 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'color.icon'" '(14926 characters)'
if test -f 'color.icon'
then
echo shar: will not over-write existing file "'color.icon'"
else
sed 's/^ X//' << \SHAR_EOF > 'color.icon'
X/* Format_version=1, Width=64, Height=64, Depth=8, Valid_bits_per_item=16
X */
X 0x0001,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0100,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0100,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0007,0x0707,0x0707,0x0707,
X 0x0707,0x0707,0x0707,0x0707,0x0707,0x0700,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0707,0x0700,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0707,0x0700,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0707,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,
X 0x0700,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0x0200,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0707,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0707,0x0000,0x0002,0x0202,0x0200,0x0002,0x0202,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0007,0x0700,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0707,0x0000,0x0000,0x0202,0x0202,0x0202,0x0202,0x0202,
X 0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0007,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0202,0x0202,0x0202,
X 0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0700,
X 0x0000,0x0000,0x0000,0x0202,0x0202,0x0202,0x0202,0x0202,
X 0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0700,0x0000,
X 0x0000,0x0000,0x0000,0x0002,0x0202,0x0202,0x0202,0x0202,
X 0x0202,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,
X 0x0303,0x0300,0x0000,0x0002,0x0202,0x0202,0x0202,0x0202,
X 0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0707,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,0x0003,
X 0x0303,0x0303,0x0000,0x0002,0x0202,0x0202,0x0202,0x0202,
X 0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0700,0x0000,0x0303,
X 0x0303,0x0303,0x0300,0x0002,0x0202,0x0202,0x0202,0x0202,
X 0x0200,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0007,0x0000,0x0003,0x0303,
X 0x0303,0x0303,0x0303,0x0000,0x0202,0x0202,0x0202,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0007,0x0000,0x0303,0x0303,
X 0x0303,0x0303,0x0303,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0700,0x0000,0x0303,0x0303,
X 0x0303,0x0303,0x0303,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0700,0x0000,0x0003,0x0303,
X 0x0303,0x0303,0x0303,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0707,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0007,0x0000,0x0000,0x0003,0x0303,
X 0x0303,0x0303,0x0303,0x0300,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0007,0x0000,0x0000,0x0003,0x0303,
X 0x0303,0x0303,0x0303,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0303,
X 0x0303,0x0303,0x0300,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0007,0x0700,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0004,0x0000,0x0000,
X 0x0000,0x0303,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,
X 0x0707,0x0700,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0404,0x0404,0x0400,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0707,0x0707,0x0707,0x0000,0x0000,0x0000,0x0000,0x0707,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0004,0x0404,0x0404,0x0404,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0007,0x0700,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0404,0x0404,0x0404,0x0404,
X 0x0400,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0700,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,0x0707,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0004,0x0404,0x0404,0x0404,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0700,0x0000,0x0700,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0404,0x0404,0x0404,0x0404,
X 0x0400,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0700,0x0007,0x0700,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0004,0x0404,0x0404,0x0404,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0700,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0404,0x0404,0x0404,0x0404,
X 0x0400,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0700,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0004,0x0404,0x0404,0x0404,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0700,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0404,0x0404,0x0404,
X 0x0400,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0700,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0004,0x0404,0x0404,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0700,
X 0x0000,0x0000,0x0000,0x0007,0x0000,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0005,0x0500,0x0000,0x0000,0x0000,0x0000,0x0007,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0005,
X 0x0505,0x0505,0x0500,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0707,0x0707,0x0707,0x0000,0x0000,0x0000,0x0700,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0000,0x0005,0x0505,
X 0x0505,0x0505,0x0505,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0707,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0005,0x0505,0x0505,
X 0x0505,0x0505,0x0500,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0700,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0700,0x0000,0x0005,0x0505,0x0505,
X 0x0505,0x0505,0x0505,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0707,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0007,0x0000,0x0000,0x0505,0x0505,
X 0x0505,0x0505,0x0500,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0707,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0007,0x0000,0x0005,0x0505,0x0505,
X 0x0505,0x0505,0x0505,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0007,0x0000,0x0005,0x0505,0x0505,
X 0x0505,0x0505,0x0500,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0007,0x0700,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0700,0x0000,0x0005,0x0505,
X 0x0505,0x0500,0x0000,0x0000,0x0606,0x0600,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0700,0x0000,0x0005,0x0505,
X 0x0505,0x0500,0x0000,0x0006,0x0606,0x0606,0x0600,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0707,0x0000,0x0505,0x0505,
X 0x0505,0x0000,0x0000,0x0606,0x0606,0x0606,0x0606,0x0600,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0700,0x0000,0x0005,
X 0x0000,0x0000,0x0000,0x0606,0x0606,0x0606,0x0606,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0707,0x0000,0x0000,
X 0x0000,0x0000,0x0006,0x0606,0x0606,0x0606,0x0606,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,0x0000,
X 0x0000,0x0000,0x0006,0x0606,0x0606,0x0606,0x0606,0x0606,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0700,0x0000,
X 0x0000,0x0000,0x0000,0x0606,0x0606,0x0606,0x0600,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0707,0x0000,
X 0x0000,0x0000,0x0006,0x0606,0x0606,0x0606,0x0606,0x0600,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,0x0000,
X 0x0000,0x0000,0x0000,0x0006,0x0606,0x0606,0x0606,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0707,
X 0x0000,0x0000,0x0000,0x0000,0x0606,0x0606,0x0606,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0707,0x0000,0x0000,0x0000,0x0006,0x0606,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0007,0x0707,0x0000,0x0000,0x0006,0x0606,0x0600,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0007,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0700,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0007,0x0707,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0007,
X 0x0707,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0707,0x0707,0x0707,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0707,0x0700,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0707,
X 0x0707,0x0707,0x0707,0x0707,0x0707,0x0707,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0101,
X 0x0101,0x0100,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0001,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,
X 0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0101,0x0100
X
SHAR_EOF
if test 14926 -ne "`wc -c < 'color.icon'`"
then
echo shar: error transmitting "'color.icon'" '(should have been 14926 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'desktop.c'" '(3323 characters)'
if test -f 'desktop.c'
then
echo shar: will not over-write existing file "'desktop.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'desktop.c'
X/*
X * desktop.c - This module contains the routines to access other windows
X * on the screen.
X *
X * Exported routines:
X * WalkWinTree
X * Get_Root
X */
X
X/**************************************************************************
X * palette - a colormap editor
X * Copyright (c) 1988 Wayne Mesard *
X * *
X * This is free software. It may be reproduced, retransmitted, *
X * redistributed and otherwise propogated at will, provided that *
X * no monetary profit is realized and that this notice remains *
X * intact and in place. *
X * *
X * Please direct bug reports, code enhancements and comments *
X * to mesard at BBN.COM. *
X * *
X **************************************************************************/
X
X#include <suntool/sunview.h>
X#include <suntool/panel.h>
X#include <sunwindow/win_enum.h>
X#include <stdio.h>
X#include <fcntl.h>
X
X#include "wsm_types.h"
X
X/*
X * WalkWinTree - Given a root fd, call the function Get_CMS_Data() on
X * every window on the screen, or if kids_onlyP, only call
X * it on the children of the root (i.e., top level frames).
X */
X
Xboolean WalkWinTree(root_fd, kids_onlyP)
Xint root_fd;
Xboolean kids_onlyP;
X{
X enum win_enumerator_result Get_CMS_Data();
X enum win_enumerator_result result;
X
X if (kids_onlyP) {
X (void) Get_CMS_Data(root_fd);
X result = win_enumerate_children(root_fd, Get_CMS_Data, NULL);
X }
X else
X result = win_enumerate_subtree(root_fd, Get_CMS_Data, NULL);
X return ((result == Enum_Fail) ? false : true);
X}
X
X
X
X/*
X * Get_Root - Given a window, return an open fd of its root window.
X */
X
Xint Get_Root(win)
XWindow win;
X{
X struct screen rootscreen;
X
X win_screenget((int) window_get(win, WIN_FD), &rootscreen);
X return(open(rootscreen.scr_rootname, O_RDONLY));
X}
X
X
X
X/*
X * Get_CMS_Data - Given a window fd, get its color map, and if this map
X * isn't in the table yet (because it's not being shared with
X * another window), call MakeCMS() to have it inserted.
X */
X
Xstatic enum win_enumerator_result Get_CMS_Data(fd)
Xint fd;
X{
X extern char *malloc();
X boolean MakeCMS();
X struct colormapseg cmsdata;
X struct cms_map themap;
X int planes;
X Pixwin *pw;
X enum win_enumerator_result result = Enum_Normal;
X
X pw = (Pixwin *) pw_open(fd);
X pw_getattributes(pw, &planes);
X pw_getcmsdata(pw, &cmsdata, &planes);
X if (H_Member(cmsdata.cms_name, NIL(struct cms_map),
X NIL(Panel_item *)) == 0) {
X themap.cm_red = (unsigned char *) malloc((unsigned)cmsdata.cms_size);
X themap.cm_green = (unsigned char *) malloc((unsigned)cmsdata.cms_size);
X themap.cm_blue = (unsigned char *) malloc((unsigned)cmsdata.cms_size);
X pw_getcolormap(pw, 0, cmsdata.cms_size,
X themap.cm_red, themap.cm_green, themap.cm_blue);
X if (!MakeCMS(&cmsdata, &themap))
X result = Enum_Fail;
X }
X pw_close(pw);
X return(result);
X}
X
SHAR_EOF
if test 3323 -ne "`wc -c < 'desktop.c'`"
then
echo shar: error transmitting "'desktop.c'" '(should have been 3323 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'hash.c'" '(4238 characters)'
if test -f 'hash.c'
then
echo shar: will not over-write existing file "'hash.c'"
else
sed 's/^ X//' << \SHAR_EOF > 'hash.c'
X/*
X * hash.c - This module implements and maintains a closed hash table
X * containing one entry for each colormap.
X *
X * Note that the data structure is stored locally in hash_tab.
X *
X * Exported routines:
X * H_MakeNull
X * H_Insert
X * H_Member
X * H_Delete
X */
X
X/**************************************************************************
X * palette - a colormap editor
X * Copyright (c) 1988 Wayne Mesard *
X * *
X * This is free software. It may be reproduced, retransmitted, *
X * redistributed and otherwise propogated at will, provided that *
X * no monetary profit is realized and that this notice remains *
X * intact and in place. *
X * *
X * Please direct bug reports, code enhancements and comments *
X * to mesard at BBN.COM. *
X * *
X **************************************************************************/
X
X#include <stdio.h>
X#include "hash.h"
X#include <strings.h>
X
X#define NullP(ENTRY) (ENTRY.name[0] == '\0')
X#define NotNullP(ENTRY) (ENTRY.name[0] != '\0')
X#define DeletedP(ENTRY) (ENTRY.name[0] == '\001')
X#define NotDeletedP(ENTRY) (ENTRY.name[0] != '\001')
X#define DoDelete(ENTRY) (ENTRY.name[0] = '\001')
X#define STREQ(S1, S2) (!strcmp(S1, S2))
X
Xstatic cms_tab_t hash_tab;
X
X/*
X * H_MakeNull
X */
X
Xvoid H_MakeNull()
X{
X int i;
X
X for (i = -1; ++i < CMS_TAB_SIZE;)
X hash_tab[i].name[0] = '\0';
X}
X
X
X/*
X * H_Insert - Places an entry in the table if it isn't already there.
X * Returns false, iff the hash table was full.
X */
X
Xboolean H_Insert(targ, size, presentation, RGB)
Xchar *targ;
Xint size;
Xcaddr_t presentation;
Xstruct cms_map *RGB;
X{
X int b;
X
X if (!STREQ(hash_tab[b = locate(targ, false)].name, targ)) {
X b = locate(targ, true);
X if (NullP(hash_tab[b]) || DeletedP(hash_tab[b])) {
X (void) strcpy(hash_tab[b].name, targ);
X hash_tab[b].size = size;
X hash_tab[b].presentation = presentation;
X hash_tab[b].map = *RGB;
X return(true);
X }
X else
X return(false);
X }
X else
X return(true);
X}
X
X
X
X/*
X * H_Member - Returns zero if targ is not in the hash table. Otherwise
X * it returns the size field. Additionally, if the second
X * and third params are non-null, it fills copies the map and
X * presentation fields into them.
X */
X
Xint H_Member(targ, cms, presentation)
Xchar *targ;
Xcaddr_t *presentation;
Xstruct cms_map *cms;
X{
X int b;
X
X if (STREQ(hash_tab[b = locate(targ, false)].name, targ)) {
X if (cms)
X bcopy((char *)&(hash_tab[b].map), (char *)cms,
X sizeof(struct cms_map));
X if (presentation)
X *presentation = hash_tab[b].presentation;
X return(hash_tab[b].size);
X }
X else
X return(0);
X}
X
X
X
X
X/*
X * H_Delete - Removes an entry from the hash-table.
X * Note non-modular bogosity: frees memory which was not
X * allocated by this package.
X */
X
Xvoid H_Delete(targ)
Xchar *targ;
X{
X int b = locate(targ, false);
X
X if (STREQ(hash_tab[b].name, targ)) {
X DoDelete(hash_tab[b]);
X free((char *) hash_tab[b].map.cm_red);
X free((char *) hash_tab[b].map.cm_green);
X free((char *) hash_tab[b].map.cm_blue);
X }
X}
X
X
X
Xstatic int h(s)
Xchar *s;
X{
X int val = 0;
X
X while (*s)
X val += (*s++<<1);
X
X return (val % CMS_TAB_SIZE);
X}
X
X
X/*
X * locate - Scans until it finds targ or an empty bucket. If deletedP
X * is true it will also stop at deleted buckets. Returns the
X * bucket number.
X */
X
Xstatic int locate(targ, deletedP)
Xchar *targ;
Xboolean deletedP;
X{
X int h();
X int i=0, initial=h(targ);
X
X while ((i < CMS_TAB_SIZE) &&
X NotNullP(hash_tab[(initial+i) % CMS_TAB_SIZE]) &&
X (deletedP ? NotDeletedP(hash_tab[(initial+i) % CMS_TAB_SIZE]) : true) &&
X !STREQ(hash_tab[(initial+i) % CMS_TAB_SIZE].name, targ))
X i++;
X
X return((initial+i) % CMS_TAB_SIZE);
X}
X
SHAR_EOF
if test 4238 -ne "`wc -c < 'hash.c'`"
then
echo shar: error transmitting "'hash.c'" '(should have been 4238 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'hash.h'" '(331 characters)'
if test -f 'hash.h'
then
echo shar: will not over-write existing file "'hash.h'"
else
sed 's/^ X//' << \SHAR_EOF > 'hash.h'
X#include <sunwindow/cms.h>
X#include <sys/types.h>
X#include "wsm_types.h"
X
X#define CMS_TAB_SIZE 16
X
Xtypedef struct cms_tab_entry {
X char name[CMS_NAMESIZE];
X short int size;
X caddr_t presentation;
X struct cms_map map;
X} cms_tab_t[CMS_TAB_SIZE];
X
X
Xvoid H_MakeNull();
Xvoid H_Delete();
Xboolean H_Insert();
Xint H_Member();
X
SHAR_EOF
if test 331 -ne "`wc -c < 'hash.h'`"
then
echo shar: error transmitting "'hash.h'" '(should have been 331 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'left_arrow.pr'" '(194 characters)'
if test -f 'left_arrow.pr'
then
echo shar: will not over-write existing file "'left_arrow.pr'"
else
sed 's/^ X//' << \SHAR_EOF > 'left_arrow.pr'
X/* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
X */
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x018C,0x07BC,0x1FFC,
X 0x3FFC,0x1FFC,0x07BC,0x018C,0x0000,0x0000,0x0000,0x0000
X
SHAR_EOF
if test 194 -ne "`wc -c < 'left_arrow.pr'`"
then
echo shar: error transmitting "'left_arrow.pr'" '(should have been 194 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'right_arrow.pr'" '(194 characters)'
if test -f 'right_arrow.pr'
then
echo shar: will not over-write existing file "'right_arrow.pr'"
else
sed 's/^ X//' << \SHAR_EOF > 'right_arrow.pr'
X/* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
X */
X 0x0000,0x0000,0x0000,0x0000,0x0000,0x3180,0x3DE0,0x3FF8,
X 0x3FFC,0x3FF8,0x3DE0,0x3180,0x0000,0x0000,0x0000,0x0000
X
SHAR_EOF
if test 194 -ne "`wc -c < 'right_arrow.pr'`"
then
echo shar: error transmitting "'right_arrow.pr'" '(should have been 194 characters)'
fi
fi # end of overwriting check
# End of shell archive
exit 0
More information about the Comp.sources.sun
mailing list