v06i072: Scantool -- Read from a scanner, Part02/03
Rich Burridge
richb at Aus
Thu Apr 12 19:13:06 AEST 1990
Submitted-by: richb at Aus (Rich Burridge)
Posting-number: Volume 6, Issue 72
Archive-name: xscan/part02
------CUT HERE------Part2of3------CUT HERE------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix at uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
# "End of archive 2 (of 3)."
# Contents: scantool/Makefile scantool/graphics.c scantool/misc.c
# scantool/scan_compress.c scantool/scan_extern.h
# scantool/scantool.1 scantool/scantool.c
# Wrapped by argv at turnpike on Thu Apr 12 02:08:23 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'scantool/Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/Makefile'\"
else
echo shar: Extracting \"'scantool/Makefile'\" \(5399 characters\)
sed "s/^X//" >'scantool/Makefile' <<'END_OF_FILE'
X#
X# Makefile for the Microtek MS-300A to Sun rasterfile converter.
X#
X# @(#)Makefile 1.5 90/04/12
X#
X# Copyright (c) Rich Burridge - Sun Microsystems Australia.
X#
X# No responsibility is taken for any errors inherent either in the comments
X# or the code of this program, but if reported to me then an attempt will
X# be made to fix them.
X#
X#=========================================================================
X#
X# There are various small changes needed when compiling faces on
X# different systems. These have been isolated here, and should
X# be uncommented if needed.
X#-------------------------------------------------------------------------
X# Scantool uses a helpfile to supply online help for various functions.
X# By default this file is called "scantool.help". You can also
X# override it's location and name at runtime with the -h option.
X# It can also be specified here by uncommenting the following
X# macro definition and setting appropriately.
X#
X#HELPNAME = -DHELPNAME=\"$(LIBDIR)/scantool.help\"
X#-------------------------------------------------------------------------
X# If you not running under a BSD4.3 derived system, the parameters
X# to the select call are different, and this definition should be
X# uncommented. You need to uncomment this for SunOS v3.x.
X#
X#SELTYPE = -DNO_4.3SELECT
X#-------------------------------------------------------------------------
X# Some versions of Unix use a pointer to a function returning an
X# integer as the return type of signal(). Newer systems use pointer to
X# function returning void. You need to uncomment this for SunOS v3.x.
X#
X#SIGRET = -DSIGRET=int
X#-------------------------------------------------------------------------
X# If you are compiling the XView version, then the following two lines
X# should be uncommented, and set appropriately.
X#
X#XVIEWINCDIR = -I$(OPENWINHOME)/include
X#XVIEWLIBDIR = -L$(OPENWINHOME)/lib
X#
X#=========================================================================
X#
X# Default locations where scantool files will be installed.
X# You might wish to alter these values.
X#
XBINDIR = /usr/local/bin
XLIBDIR = /usr/local/lib
XMANDIR = /usr/man/man$(MANSECT)
XMANSECT = l
X#
X# Compilation flags and standard macro definitions.
X#
XCFLAGS = -g $(HELPNAME) $(SELTYPE) $(SIGRET) $(XVIEWINCDIR)
X#
X#=========================================================================
X
XBINARIES = sv_scantool xv_scantool scan
X
XCC = cc
X
XSTDSTSRCS = scantool.c graphics.c misc.c
XSTDSTOBJS = scantool.o graphics.o misc.o
X
XSTDSSRCS = scan.c scan_compress.c
XSTDSOBJS = scan.o scan_compress.o
X
XGSRCS = sunview.c xview.c
XHDRS = images.h patchlevel.h scan.h scan_extern.h \
X scantool.h scantool_extern.h
XOTHERS = Makefile CHANGES README black.codes white.codes \
X Imakefile scantool.help scan.1 scantool.1
XIMAGES = exclaim.icon scantool.icon \
X button.normal.icon button.invert.icon \
X switch.normal.cursor switch.invert.cursor \
X frame.cursor help.cursor main.cursor
X
XSFILES1 = $(STDSTSRCS) $(STDSSRCS)
XSFILES2 = $(GSRCS) $(HDRS)
XSFILES3 = $(OTHERS) $(IMAGES)
X
XSVIEWLIBS = -lsuntool -lsunwindow -lpixrect
XXVIEWLIBS = -lxview -lolgx -lX11 -lpixrect
X
Xhelp:
X @echo
X @echo "You need to specify one of the following options:"
X @echo
X @echo " make sunview - to make the SunView version."
X @echo " make xview - to make the XView version."
X @echo
X @echo "This should be followed by:"
X @echo
X @echo " make install"
X @echo " make clean"
X @echo
X
Xall: $(BINARIES)
X
Xsunview: sv_scantool scan
X
Xsv_scantool: $(STDSTOBJS) sunview.o
X $(CC) -o sv_scantool $(CFLAGS) $(STDSTOBJS) \
X sunview.o $(SVIEWLIBS)
X -cp sv_scantool scantool
X
Xxview: xv_scantool scan
X
Xxv_scantool: $(STDSTOBJS) xview.o
X $(CC) -o xv_scantool $(XVIEWLIBDIR) $(CFLAGS) $(STDSTOBJS) \
X xview.o $(XVIEWLIBS)
X -cp xv_scantool scantool
X
Xscan: $(STDSOBJS)
X $(CC) -o scan $(CFLAGS) $(STDSOBJS)
X
Xinstall:
X install -s -m 751 scantool $(BINDIR)
X install -s -m 751 scan $(BINDIR)
X install -c -m 644 black.codes.ps $(LIBDIR)
X install -c -m 644 white.codes.ps $(LIBDIR)
X install -c -m 644 scantool.help $(LIBDIR)
X install -c -m 644 scantool.1 $(MANDIR)/scantool.$(MANSECT)
X install -c -m 644 scan.1 $(MANDIR)/scan.$(MANSECT)
X
Xclean:; rm -rf *.o archive.* *~ scantool $(BINARIES) core
X
Xshar:; shar.script $(SFILES1) > Part1
X shar.script $(SFILES2) > Part2
X shar.script $(SFILES3) > Part3
X
Xlint:; lint $(STDSTSRCS) sunview.c $(SVIEWLIBS)
X lint $(STDSSRCS)
X lint $(STDSTSRCS) xview.c $(XVIEWLIBS)
X
Xcreate: SCCS
X -sccs create $(STDSTSRCS) $(STDSSRCS) $(GSRCS) \
X $(HDRS) $(OTHERS) $(IMAGES)
X
XSCCS:
X mkdir SCCS
X chmod 755 SCCS
X
Xgraphics.o: graphics.c scantool_extern.h scantool.h
Xmisc.o: misc.c patchlevel.h scantool_extern.h scantool.h
Xscan.o: scan.c patchlevel.h scan.h
Xscan_compress.o: scan_compress.c scan_extern.h scan.h
Xscantool.o: scantool.c scantool.h
Xsunview.o: sunview.c scantool_extern.h images.h scantool.h \
X exclaim.icon scantool.icon \
X button.normal.icon button.invert.icon \
X switch.normal.cursor switch.invert.cursor \
X frame.cursor help.cursor main.cursor
Xxview.o: xview.c scantool_extern.h images.h scantool.h \
X exclaim.icon scantool.icon \
X button.normal.icon button.invert.icon \
X switch.normal.cursor switch.invert.cursor \
X frame.cursor help.cursor main.cursor
END_OF_FILE
if test 5399 -ne `wc -c <'scantool/Makefile'`; then
echo shar: \"'scantool/Makefile'\" unpacked with wrong size!
fi
# end of 'scantool/Makefile'
fi
if test -f 'scantool/graphics.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/graphics.c'\"
else
echo shar: Extracting \"'scantool/graphics.c'\" \(12024 characters\)
sed "s/^X//" >'scantool/graphics.c' <<'END_OF_FILE'
X
X/* @(#)graphics.c 1.5 90/04/10
X *
X * Independent graphics routines associated with the scantool program.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright messages are not removed, and no monies are exchanged.
X *
X * No responsibility is taken for any errors or inaccuracies inherent
X * either to the comments or the code of this program, but if
X * reported to me, then an attempt will be made to fix them.
X */
X
X#include <stdio.h>
X#include <strings.h>
X#include <signal.h>
X#include "scantool.h"
X#include "scantool_extern.h"
X
X
Xdo_repaint() /* Draw titleline and page layout. */
X{
X int i ;
X
X draw_area(0, 0, SCAN_WIDTH, SCAN_HEIGHT, GCLR) ;
X draw_text(0*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Brightness") ;
X draw_text(1*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Contrast") ;
X draw_text(2*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Grain") ;
X draw_text(3*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Help") ;
X draw_text(4*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Resolution") ;
X draw_text(5*MBAR_WIDTH+10, 15, STEN_OFF, BFONT, "Set") ;
X draw_area(0, 0, SCAN_WIDTH, MBAR_HEIGHT, GNOT) ;
X
X make_switch(SCAN_WIDTH-150, 0*SWITCH_HEIGHT+40,
X "Mode", "Line Art", "Halftone") ;
X make_switch(SCAN_WIDTH-150, 1*SWITCH_HEIGHT+40,
X "Data Transfer", "Uncompressed", "Compressed") ;
X make_switch(SCAN_WIDTH-150, 2*SWITCH_HEIGHT+40,
X "Serial Port", "A", "B") ;
X make_switch(SCAN_WIDTH-150, 3*SWITCH_HEIGHT+40,
X "Baud Rate", "9600", "19200") ;
X
X for (i = 0; i < 4; i++)
X set_switch(SCAN_WIDTH-150, i*SWITCH_HEIGHT+50+switches[i]*20, ON) ;
X
X if (scanning)
X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_INVERT) ;
X else make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_NORMAL) ;
X
X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ;
X
X if (showing)
X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ;
X else make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ;
X
X draw_scanning_frame(SCAN_FRAME_X, SCAN_FRAME_Y) ;
X
X switch ((int) drawstate)
X {
X case DO_NOTHING : break ;
X case DO_PICNAME : draw_picarea() ;
X break ;
X case DO_MESSAGE : make_message() ;
X break ;
X case DO_HELP : get_help() ;
X break ;
X case DO_SETTINGS : draw_settings() ;
X }
X}
X
X
Xdraw_frame(x, y, width, height)
Xint x, y, width, height ;
X{
X draw_area(x, y, width, height, GSET) ;
X draw_area(x+1, y+1, width-2, height-2, GCLR) ;
X draw_area(x+3, y+3, width-6, height-6, GSET) ;
X draw_area(x+5, y+5, width-10, height-10, GCLR) ;
X}
X
X
Xdraw_picarea()
X{
X char dummy[MAXLINE] ;
X int nochars, x, y ;
X
X x = (SCAN_WIDTH - 500) / 2 ;
X y = (SCAN_HEIGHT - 50) / 2 ;
X draw_frame(x, y, 500, 50) ;
X draw_text(x + 10, y + 27, STEN_OFF, BFONT, "Name:") ;
X draw_rect(x + 70, y + 10, x + 265, y + 35, GSET) ;
X nochars = (strlen(picname) <= 20) ? strlen(picname) : 20 ;
X STRNCPY(dummy, &picname[strlen(picname) - nochars], nochars) ;
X dummy[nochars] = '\0' ;
X draw_text(x + 80, y + 27, STEN_OFF, BFONT, dummy) ;
X draw_line(x + 80 + get_strwidth(BFONT, dummy), y + 15,
X x + 80 + get_strwidth(BFONT, dummy), y + 30, GSET) ;
X make_button(x + 300, y + 10, "OK", B_NORMAL) ;
X make_button(x + 400, y + 10, "Cancel", B_NORMAL) ;
X drawstate = DO_PICNAME ;
X butx = x ;
X buty = y ;
X}
X
X
Xdraw_rect(x1, y1, x2, y2, op)
Xint x1, y1, x2, y2 ;
Xenum op_type op ;
X{
X draw_line(x1, y1, x2, y1, op) ;
X draw_line(x1, y1, x1, y2, op) ;
X draw_line(x2, y1, x2, y2, op) ;
X draw_line(x1, y2, x2, y2, op) ;
X}
X
X
Xdraw_scanning_frame(x, y) /* Draw the current scanning frame. */
Xint x, y ;
X{
X char number[3] ;
X int i ;
X
X for (i = 0; i <= 35; i++) /* Draw horizontal rule. */
X if (!(i % 4))
X {
X SPRINTF(number, "%1d", i / 4) ;
X draw_text(x+i*LINEGAP+2, y-15, STEN_ON, NFONT, number) ;
X draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-26, GSET) ;
X }
X else if (!(i % 2))
X draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-18, GSET) ;
X else draw_line(x+i*LINEGAP, y-10, x+i*LINEGAP, y-14, GSET) ;
X
X draw_line(x, y-10, x+36*LINEGAP, y-10, GSET) ;
X
X for (i = 0; i <= 45; i++) /* Draw vertical rule. */
X if (!(i % 4))
X {
X SPRINTF(number, "%1d", i / 4) ;
X draw_text(x-26, y+i*LINEGAP+12, STEN_ON, NFONT, number) ;
X draw_line(x-10, y+i*LINEGAP, x-26, y+i*LINEGAP, GSET) ;
X }
X else if (!(i % 2))
X draw_line(x-10, y+i*LINEGAP, x-18, y+i*LINEGAP, GSET) ;
X else draw_line(x-10, y+i*LINEGAP, x-14, y+i*LINEGAP, GSET) ;
X
X draw_line(x-10, y, x-10, y+46*LINEGAP, GSET) ;
X
X/* Initial page frame. */
X draw_rect(x, y, x+34*LINEGAP, y+44*LINEGAP, GSET) ;
X draw_rect(x+1, y+1, x+34*LINEGAP+1, y+44*LINEGAP+1, GSET) ;
X
X/* Make gray surrondings. */
X draw_line(x, y+44*LINEGAP, x, SCAN_HEIGHT, GSET) ;
X draw_line(x+34*LINEGAP, y,x+36*LINEGAP, y, GSET) ;
X draw_line(x+36*LINEGAP, y-26,x+36*LINEGAP, SCAN_HEIGHT, GSET) ;
X grey_area(x+1, y+44*LINEGAP+2, 36*LINEGAP-1, 2*LINEGAP-2) ;
X grey_area(x+LINEGAP*34+2, y+1, 2*LINEGAP-2, SCAN_HEIGHT-65) ;
X
X/* Draw initial scanning frame. */
X draw_rect(x+framevals[X1]*FRAMEGAP, y+framevals[Y1]*FRAMEGAP,
X x+framevals[X2]*FRAMEGAP, y+framevals[Y2]*FRAMEGAP, GSET) ;
X}
X
X
Xget_picname() /* Get new picture name. */
X{
X char c, dummy[MAXLINE] ;
X int finished, nochars, state ;
X
X finished = 0 ;
X if (type == LEFT_DOWN)
X {
X if (curx > butx+300 && curx < butx+300+BUTTON_WIDTH &&
X cury > buty+10 && cury < buty+10+BUTTON_HEIGHT)
X {
X make_button(butx+300, buty+10, "OK", B_INVERT) ;
X state = OK ;
X finished = 1 ;
X }
X else if (curx > butx+400 && curx < butx+400+BUTTON_WIDTH &&
X cury > buty+10 && cury < buty+10+BUTTON_HEIGHT)
X {
X state = CANCEL ;
X make_button(butx+400, buty+10, "Cancel", B_INVERT) ;
X finished = 1 ;
X }
X }
X else if (type == KEYBOARD)
X {
X c = cur_ch ;
X if (c == BACKSPACE || c == DEL)
X picname[strlen(picname)-1] = '\0' ;
X else if (c == RETURN || c == LINEFEED)
X {
X state = OK ;
X finished = 1 ;
X }
X else if (c >= 32) STRNCAT(picname, &c, 1) ;
X draw_area(butx+71, buty+11, 193, 23, GCLR) ;
X nochars = (strlen(picname) <= 20) ? strlen(picname) : 20 ;
X STRNCPY(dummy, &picname[strlen(picname) - nochars], nochars) ;
X dummy[nochars] = '\0' ;
X draw_text(butx+80, buty+27, STEN_OFF, BFONT, dummy) ;
X draw_line(butx + 80 + get_strwidth(BFONT, dummy), buty + 15,
X butx + 80 + get_strwidth(BFONT, dummy), buty + 30, GSET) ;
X }
X
X if (finished)
X {
X if (state == CANCEL) STRCPY(picname, old_picname) ;
X drawstate = DO_NOTHING ;
X do_repaint() ; /* Redraw original screen. */
X }
X}
X
X
Xmake_menus()
X{
X create_menu(BRIGHTNESS_M, "BRIGHTNESS", br_strs) ;
X create_menu(CONTRAST_M, "CONTRAST", con_strs) ;
X create_menu(GRAIN_M, "GRAIN", gr_strs) ;
X create_menu(HELP_M, "HELP", help_strs) ;
X create_menu(RESOLUTION_M, "RESOLUTION", res_strs) ;
X create_menu(SET_M, "SET", set_strs) ;
X}
X
X
Xprocess_event()
X{
X enum menu_type column ;
X int row, value ;
X
X if (type == IGNORE) return ;
X else if (type == REPAINT) do_repaint() ;
X else if (drawstate == DO_MESSAGE ||
X drawstate == DO_HELP ||
X drawstate == DO_SETTINGS) wait_for_ok() ;
X else if (drawstate == DO_PICNAME) get_picname() ;
X else
X {
X column = (enum menu_type) ((curx - 10) / MBAR_WIDTH) ;
X row = cury / MBAR_HEIGHT ;
X if (type == RIGHT_DOWN && row == 0)
X {
X value = display_menu(column) ;
X if (value) process_menu(column, value) ;
X }
X else if (type == LEFT_DOWN)
X {
X if (curx > SCAN_WIDTH-150 &&
X curx < SCAN_WIDTH-90 &&
X cury > 4*SWITCH_HEIGHT+20 &&
X cury < 4*SWITCH_HEIGHT+20+BUTTON_HEIGHT) make_scan() ;
X else if (curx > SCAN_WIDTH-150 &&
X curx < SCAN_WIDTH-90 &&
X cury > 4*SWITCH_HEIGHT+60 &&
X cury < 4*SWITCH_HEIGHT+60+BUTTON_HEIGHT) stop_scan() ;
X else if (curx > SCAN_WIDTH-150 &&
X curx < SCAN_WIDTH-90 &&
X cury > 4*SWITCH_HEIGHT+100 &&
X cury < 4*SWITCH_HEIGHT+100+BUTTON_HEIGHT) show() ;
X else test_switch(curx, cury) ; /* Test for a box switch press. */
X }
X }
X}
X
X
Xselect_frame() /* Construct a new scanning window. */
X{
X int oldx = 0 ;
X int oldy = 0 ;
X int x1, y1, x2, y2 ;
X int drawold = 0 ;
X int found = 0 ;
X
X set_cursor(FRAME_CUR) ;
X
X/* Remove current scan settings, if any. */
X draw_area(SCAN_FRAME_X+2, SCAN_FRAME_Y+2, 34*LINEGAP-4, 44*LINEGAP-4, GCLR) ;
X draw_area(SCAN_FRAME_X-9, SCAN_FRAME_Y, 9, 46*LINEGAP-1, GCLR) ;
X draw_area(SCAN_FRAME_X, SCAN_FRAME_Y-9, 34*LINEGAP-1, 9, GCLR) ;
X
X do
X {
X get_event() ;
X handle_event() ;
X if (curx > SCAN_FRAME_X && curx < SCAN_FRAME_X+34*LINEGAP &&
X cury > SCAN_FRAME_Y && cury < SCAN_FRAME_Y+44*LINEGAP)
X {
X curx = (curx / (FRAMEGAP) * (FRAMEGAP)) + 1 ;
X cury = (cury / (FRAMEGAP) * (FRAMEGAP)) + 2 ;
X if (type == LEFT_DOWN) found = 1 ;
X if (type != MOUSE_MOVE) continue ;
X if (drawold)
X {
X draw_line(oldx, SCAN_FRAME_Y-1, oldx, SCAN_FRAME_Y-9, GXOR) ;
X draw_line(SCAN_FRAME_X-1, oldy, SCAN_FRAME_X-9, oldy, GXOR) ;
X }
X draw_line(curx, SCAN_FRAME_Y-1, curx, SCAN_FRAME_Y-9, GXOR) ;
X draw_line(SCAN_FRAME_X-1, cury, SCAN_FRAME_X-9, cury, GXOR) ;
X oldx = curx ;
X oldy = cury ;
X drawold++ ;
X }
X }
X while (!found) ;
X x1 = curx ;
X y1 = cury ;
X
X found = 0 ;
X drawold = 0 ;
X do
X {
X get_event() ;
X handle_event() ;
X if (curx > SCAN_FRAME_X && curx < SCAN_FRAME_X+34*LINEGAP &&
X cury > SCAN_FRAME_Y && cury < SCAN_FRAME_Y+44*LINEGAP)
X {
X curx = (curx / (FRAMEGAP) * (FRAMEGAP)) + 1 ;
X cury = (cury / (FRAMEGAP) * (FRAMEGAP)) + 2 ;
X if (type == LEFT_UP) found = 1 ;
X if (type != MOUSE_DRAG) continue ;
X if (drawold)
X {
X draw_line(oldx, SCAN_FRAME_Y-1, oldx, SCAN_FRAME_Y-9, GXOR) ;
X draw_line(SCAN_FRAME_X-1, oldy, SCAN_FRAME_X-9, oldy, GXOR) ;
X draw_rect(x1, y1, oldx, oldy, GXOR) ;
X }
X draw_line(curx, SCAN_FRAME_Y-1, curx, SCAN_FRAME_Y-9, GXOR) ;
X draw_line(SCAN_FRAME_X-1, cury, SCAN_FRAME_X-9, cury, GXOR) ;
X draw_rect(x1, y1, curx, cury, GXOR) ;
X oldx = curx ;
X oldy = cury ;
X drawold++ ;
X }
X }
X while (!found) ;
X
X x2 = curx ;
X y2 = cury ;
X if (x1 > x2)
X {
X oldx = x2 ;
X x2 = x1 ;
X x1 = oldx ;
X }
X if (y1 > y2)
X {
X oldy = y2 ;
X y2 = y1 ;
X y1 = oldy ;
X }
X framevals[X1] = (x1 - SCAN_FRAME_X) / (FRAMEGAP) ;
X framevals[Y1] = (y1 - SCAN_FRAME_Y) / (FRAMEGAP) ;
X framevals[X2] = (x2 - SCAN_FRAME_X) / (FRAMEGAP) ;
X framevals[Y2] = (y2 - SCAN_FRAME_Y) / (FRAMEGAP) ;
X set_cursor(MAIN_CUR) ;
X}
X
X
Xset_switch(x, y, position)
Xint x, y, position ;
X{
X if (position == ON) draw_image(x, y-2, 16, 16, S_INVERT) ;
X else draw_image(x, y-2, 16, 16, S_NORMAL) ;
X}
X
X
Xstop_scan() /* Stop the current scan (if there is one). */
X{
X if (!scanning) return ;
X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_INVERT) ;
X KILL(pid, SIGHUP) ;
X}
END_OF_FILE
if test 12024 -ne `wc -c <'scantool/graphics.c'`; then
echo shar: \"'scantool/graphics.c'\" unpacked with wrong size!
fi
# end of 'scantool/graphics.c'
fi
if test -f 'scantool/misc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/misc.c'\"
else
echo shar: Extracting \"'scantool/misc.c'\" \(11480 characters\)
sed "s/^X//" >'scantool/misc.c' <<'END_OF_FILE'
X
X/* @(#)misc.c 1.4 90/04/04
X *
X * Miscellaneous routines used by the scantool program.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright messages are not removed, and no monies are exchanged.
X *
X * No responsibility is taken for any errors or inaccuracies inherent
X * either to the comments or the code of this program, but if
X * reported to me, then an attempt will be made to fix them.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <strings.h>
X#include "scantool.h"
X#include "patchlevel.h"
X#include "scantool_extern.h"
X
X
Xdraw_settings() /* Display text for current scanner settings. */
X{
X int texty = 20 ;
X int x, y ;
X
X x = (SCAN_WIDTH - 430) / 2 ;
X y = (SCAN_HEIGHT - 100) / 2 ;
X draw_frame(x, y, 430, 100) ;
X
X SPRINTF(output, "Brightness: %s", br_strs[brightness-1]) ;
X draw_text(x+10, y+texty, STEN_OFF, NFONT, output) ;
X
X SPRINTF(output, "Contrast: %s", con_strs[contrast-1]) ;
X draw_text(x+10, y+texty+15, STEN_OFF, NFONT, output) ;
X
X SPRINTF(output, "Grain: %s", gr_strs[grain]) ;
X draw_text(x+10, y+texty+30, STEN_OFF, NFONT, output) ;
X
X SPRINTF(output, "Resolution: %s", res_strs[resolution]) ;
X draw_text(x+10, y+texty+45, STEN_OFF, NFONT, output) ;
X
X SPRINTF(output, "Filename: %s", picname) ;
X draw_text(x+10, y+texty+60, STEN_OFF, NFONT, output) ;
X}
X
X
Xget_help() /* Read the help file and display. */
X{
X char help_str[MAXLINE], *p ;
X int x, y ;
X int length = 0 ; /* Length of longest help line. */
X int nolines = 0 ; /* Number of lines in help file. */
X char line[MAXLINE] ; /* Current line read from help file. */
X int texty = 20 ; /* Initial y coordinate for help message. */
X
X if (nohelp) make_display("No help file found.") ;
X else
X {
X SPRINTF(help_str, "%%%s%%\n", helpname) ;
X rewind(hfd) ;
X while (p = fgets(line, MAXLINE, hfd))
X if (*p == '%' && EQUAL(p, help_str)) break ;
X
X for (;;) /* Check for the length of the longest line. */
X {
X FGETS(line, MAXLINE, hfd) ;
X if (EQUAL(line, "%%\n")) break ;
X if (strlen(line) > length) length = strlen(line) ;
X nolines++ ;
X }
X
X rewind(hfd) ;
X while (p = fgets(line, MAXLINE, hfd))
X if (*p == '%' && EQUAL(p, help_str)) break ;
X
X set_cursor(HELP_CUR) ;
X x = (SCAN_WIDTH - length*font_width - 20) / 2 ;
X y = (SCAN_HEIGHT - nolines*15+texty) / 2 ;
X draw_frame(x, y, length*font_width+20, nolines*15+texty) ;
X
X for (;;)
X {
X FGETS(line, MAXLINE, hfd) ;
X if (EQUAL(line, "%%\n")) break ;
X line[strlen(line)-1] = '\0' ;
X draw_text(x+10, y+texty, STEN_OFF, NFONT, line) ;
X texty += 15 ;
X }
X }
X}
X
X
Xget_options(argc, argv) /* Extract command line options. */
Xint argc ;
Xchar *argv[] ;
X{
X INC ;
X while (argc > 0)
X {
X if (argv[0][0] == '-')
X switch (argv[0][1])
X {
X case 'h' : INC ; /* Help filename. */
X getparam(helpname, argv, "-h needs help filename") ;
X break ;
X case 'v' : FPRINTF(stderr, "%s version 1.4.%1d\n",
X progname, PATCHLEVEL) ;
X break ;
X case '?' : usage() ;
X }
X INC ;
X }
X}
X
X
Xgetparam(s, argv, errmes)
Xchar *s, *argv[], *errmes ;
X{
X if (*argv != NULL && argv[0][0] != '-') STRCPY(s, *argv) ;
X else
X {
X FPRINTF(stderr,"%s: %s as next argument.\n", progname, errmes) ;
X exit(1) ;
X }
X}
X
X
Xmake_button(x, y, text, state) /* Draw a text button. */
Xint x, y ;
Xchar *text ;
Xenum image_type state ;
X{
X enum sten_type stencil ;
X
X draw_image(x, y, BUTTON_WIDTH, BUTTON_HEIGHT, state) ;
X width = get_strwidth(BFONT, text) ;
X if (state == B_NORMAL) stencil = STEN_ON ;
X else stencil = STEN_INV ;
X draw_text(x + ((64 - width) / 2),
X y + FONT_HEIGHT + ((BUTTON_HEIGHT - FONT_HEIGHT) / 2) - 5,
X stencil, BFONT, text) ;
X}
X
X
Xmake_display(output) /* Output message to the display window. */
Xchar *output ;
X{
X STRCPY(last_message, output) ; /* Save in case of a redraw. */
X make_message() ; /* Output message as popup to the canvas. */
X}
X
X
Xmake_help(value)
X{
X if (value)
X {
X STRCPY(helpname, help_strs[value-1]) ;
X if (isupper(helpname[0])) helpname[0] = tolower(helpname[0]) ;
X get_help() ; /* Read the help file and display. */
X drawstate = DO_HELP ;
X butx = buty = 0 ;
X }
X}
X
X
Xmake_message() /* Output message to the display window. */
X{
X int x, y ;
X
X width = strlen(last_message) * font_width + 20 ;
X if (width < 300) width = 300 ;
X x = (SCAN_WIDTH - width) / 2 ;
X y = (SCAN_HEIGHT - 90) / 2 ;
X draw_frame(x, y, width, 90) ;
X draw_image(x + 30, y + 15, 64, 64, EXCLAIM_IMAGE) ;
X butx = x + width - 90 ;
X buty = y + 15 ;
X make_button(x + width - 90, y + 15, "OK", B_NORMAL) ;
X draw_text(x + 10, y + 65, STEN_OFF, NFONT, last_message) ;
X drawstate = DO_MESSAGE ;
X}
X
X
Xmake_scan() /* Start scanning process, and wait for it to terminate. */
X{
X char arg_brightness[MAXLINE] ; /* Brightness value. */
X char arg_contrast[MAXLINE] ; /* Contrast value. */
X char arg_datatrans[MAXLINE] ; /* Data transfer (or blank). */
X char arg_framevals[4][MAXLINE] ; /* Scanning frame values. */
X char arg_grain[MAXLINE] ; /* Grain value. */
X char arg_mode[MAXLINE] ; /* Mode (or blank). */
X char arg_picname[MAXLINE] ; /* Picture name. */
X char arg_resolution[MAXLINE] ; /* Resolution value. */
X char arg_speed[MAXLINE] ; /* Speed of connection (or blank). */
X char arg_ttyport[MAXLINE] ; /* Tty port (or blank). */
X
X SPRINTF(arg_brightness, "%1d", brightness) ;
X SPRINTF(arg_contrast, "%1d", contrast) ;
X SPRINTF(arg_datatrans, "%1d", switches[DATA_TRANSFER]) ;
X SPRINTF(arg_framevals[X1], "%1d", framevals[X1]) ;
X SPRINTF(arg_framevals[Y1], "%1d", framevals[Y1]) ;
X SPRINTF(arg_framevals[X2], "%1d", framevals[X2]) ;
X SPRINTF(arg_framevals[Y2], "%1d", framevals[Y2]) ;
X SPRINTF(arg_grain, "%1d", grain) ;
X SPRINTF(arg_mode, "%1d", switches[MODE]) ;
X SPRINTF(arg_picname, "%s", picname) ;
X SPRINTF(arg_resolution, "%1d", resolution) ;
X SPRINTF(arg_speed, "%1d", switches[BAUD_RATE]) ;
X SPRINTF(arg_ttyport, "%1d", switches[SERIAL_PORT]) ;
X
X if (scanning)
X {
X make_display("There is a scan already in progress") ;
X return ;
X }
X scanning = 1 ;
X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_INVERT) ;
X if ((pid = vfork()) == 0)
X {
X EXECL("scan", "-b", arg_brightness, "-c", arg_contrast,
X "-d", arg_datatrans, "-f", arg_framevals[X1],
X arg_framevals[Y1], arg_framevals[X2], arg_framevals[Y2],
X "-g", arg_grain, "-m", arg_mode,
X "-p", arg_picname, "-r", arg_resolution,
X "-s", arg_speed, "-t", arg_ttyport,
X (char *) 0) ;
X FPRINTF(stderr, "%s: Couldn't fork the scan process.\n", progname) ;
X exit(1) ; /* Should never get here. */
X }
X wait_on_child(pid) ;
X}
X
X
Xmake_set(value)
Xint value ;
X{
X switch (value)
X {
X case SET_PICTURE : STRCPY(old_picname, picname) ;
X draw_picarea() ;
X break ;
X case SET_DEFAULTS : set_defaults() ;
X break ;
X case SET_CLEAR_FRAME : framevals[X1] = 0 ;
X framevals[Y1] = 0 ;
X framevals[X2] = 68 ;
X framevals[Y2] = 88 ;
X draw_area(SCAN_FRAME_X+2, SCAN_FRAME_Y+2,
X 34*LINEGAP-4, 44*LINEGAP-4, GCLR) ;
X draw_area(SCAN_FRAME_X-9, SCAN_FRAME_Y,
X 9, 46*LINEGAP-1, GCLR) ;
X draw_area(SCAN_FRAME_X, SCAN_FRAME_Y-9,
X 34*LINEGAP-1, 9, GCLR) ;
X break ;
X case SET_NEW_FRAME : select_frame() ;
X break ;
X case SET_CURRENT : show_settings() ;
X }
X}
X
X
Xmake_switch(x, y, title, boxa, boxb)
Xint x, y ;
Xchar *title, *boxa, *boxb ;
X{
X draw_text(x, y, STEN_OFF, BFONT, title) ;
X set_switch(x, y+10, OFF) ;
X draw_text(x+30, y+20, STEN_OFF, BFONT, boxa) ;
X set_switch(x, y+30, OFF) ;
X draw_text(x+30, y+40, STEN_OFF, BFONT, boxb) ;
X}
X
X
Xprocess_menu(mtype, value) /* Process a menu choice. */
Xenum menu_type mtype ;
Xint value ;
X{
X switch (mtype)
X {
X case BRIGHTNESS_M : brightness = value ;
X break ;
X case CONTRAST_M : contrast = value ;
X break ;
X case GRAIN_M : grain = value-1 ;
X break ;
X case HELP_M : make_help(value) ;
X break ;
X case RESOLUTION_M : resolution = value-1 ;
X break ;
X case SET_M : make_set(value) ;
X }
X}
X
X
Xset_defaults() /* Return scanner setting to default. */
X{
X brightness = 7 ; /* Brightness value (no adjustment). */
X contrast = 7 ; /* Contrast value (no adjustment). */
X grain = 2 ; /* Grain value (grain size: 8x8 levels: 33). */
X resolution = 0 ; /* Resolution value (300 dpi). */
X}
X
X
Xshow_settings() /* Display current scanner settings in a popup window. */
X{
X draw_settings() ; /* Display setting values. */
X drawstate = DO_SETTINGS ;
X butx = buty = 0 ;
X}
X
X
Xtest_switch(x, y) /* Test for a switch box being pressed. */
Xint x, y ;
X{
X int i, j ;
X
X if (x > SCAN_WIDTH-150 && x < SCAN_WIDTH-130)
X for (i = 0; i < 2; i++)
X for (j = 0; j < 4; j++)
X if ((y > j*SWITCH_HEIGHT+50+i*20) && (y < j*SWITCH_HEIGHT+70+i*20))
X if (i)
X {
X set_switch(SCAN_WIDTH-150, j*SWITCH_HEIGHT+50, OFF) ;
X set_switch(SCAN_WIDTH-150, j*SWITCH_HEIGHT+70, ON) ;
X switches[j] = i ;
X }
X else
X {
X set_switch(SCAN_WIDTH-150, j*SWITCH_HEIGHT+50, ON) ;
X set_switch(SCAN_WIDTH-150, j*SWITCH_HEIGHT+70, OFF) ;
X switches[j] = i ;
X }
X}
X
X
Xusage()
X{
X FPRINTF(stderr, "Usage: %s: [-h helpname] [-v] [-?]\n", progname) ;
X exit(1) ;
X}
X
X
Xwait_for_ok() /* Wait for user to acknowledge. */
X{
X int doexit = 0 ;
X
X switch (type)
X {
X case LEFT_DOWN : if (butx && buty)
X {
X if (curx > butx && curx < butx+BUTTON_WIDTH &&
X cury > buty && cury < buty+BUTTON_HEIGHT)
X {
X make_button(butx, buty, "OK", B_INVERT) ;
X doexit = 1 ;
X }
X }
X else doexit = 1 ;
X break ;
X case KEYBOARD : if (cur_ch == LINEFEED || cur_ch == RETURN)
X doexit = 1 ;
X }
X
X if (doexit)
X {
X set_cursor(MAIN_CUR) ;
X drawstate = DO_NOTHING ;
X do_repaint() ;
X }
X}
END_OF_FILE
if test 11480 -ne `wc -c <'scantool/misc.c'`; then
echo shar: \"'scantool/misc.c'\" unpacked with wrong size!
fi
# end of 'scantool/misc.c'
fi
if test -f 'scantool/scan_compress.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/scan_compress.c'\"
else
echo shar: Extracting \"'scantool/scan_compress.c'\" \(6931 characters\)
sed "s/^X//" >'scantool/scan_compress.c' <<'END_OF_FILE'
X
X/* @(#)scan_compress.c 1.2 90/04/02
X *
X * Routines for uncompressing a scanned file, which has been compressed
X * using the CCITT Recommendation T.4 (modified Huffman code).
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright messages are not removed, and no monies are exchanged.
X *
X * No responsibility is taken for any errors or inaccuracies inherent
X * either to the comments or the code of this program, but if
X * reported to me, then an attempt will be made to fix them.
X */
X
X#include <stdio.h>
X#include "scan.h"
X#include "scan_extern.h"
X
X
Xinitialise_white(filename) /* Read white Make Up and Terminating Codes. */
Xchar filename[MAXLINE] ;
X{
X char bitstring[MAXLINE] ; /* This lines huffman encoded bit string. */
X char line[MAXLINE] ; /* Current line read from file. */
X int bvalue, i, indexval, n, runlength ;
X struct code *ptr ; /* Current codes structure pointer. */
X
X for (i = 0; i < 16; i++)
X {
X whites[i] = (struct code *) LINT_CAST(malloc(sizeof(struct code))) ;
X whites[i]->next[0] = NULL ;
X whites[i]->next[1] = NULL ;
X }
X
X if ((rd = fopen(filename,"r")) == NULL)
X {
X FPRINTF(stderr, "%s: can't open %s\n", progname, filename) ;
X exit(1) ;
X }
X
X while (fgets(line, MAXLINE, rd) != NULL)
X {
X SSCANF(line, "%d %s", &runlength, bitstring) ;
X n = 0 ;
X indexval = 0 ;
X for (i = 0; i < 4; i++)
X {
X bvalue = bitstring[n++] - '0' ;
X indexval = (indexval << 1) + bvalue ;
X }
X ptr = whites[indexval] ;
X for (i = n ; i < strlen(bitstring); i++)
X {
X if (ptr->next[bvalue] == NULL)
X {
X ptr->next[bvalue] = (struct code *) LINT_CAST(malloc(sizeof(struct code))) ;
X ptr->next[bvalue]->next[0] = NULL ;
X ptr->next[bvalue]->next[1] = NULL ;
X }
X ptr = ptr->next[bvalue] ;
X bvalue = bitstring[i] - '0' ;
X }
X ptr->value[bvalue] = runlength ;
X }
X FCLOSE(rd) ;
X}
X
X
Xinitialise_black(filename) /* Read black Make Up and Terminating Codes. */
Xchar filename[MAXLINE] ;
X{
X char bitstring[MAXLINE] ; /* This lines huffman encoded bit string. */
X char line[MAXLINE] ; /* Current line read from file. */
X int bvalue, i, indexval, n, runlength ;
X struct code *ptr ; /* Current codes structure pointer. */
X
X for (i = 0; i < 4; i++)
X {
X blacks[i] = (struct code *) LINT_CAST(malloc(sizeof(struct code))) ;
X blacks[i]->next[0] = NULL ;
X blacks[i]->next[1] = NULL ;
X }
X
X if ((rd = fopen(filename,"r")) == NULL)
X {
X FPRINTF(stderr, "%s: can't open %s\n", progname, filename) ;
X exit(1) ;
X }
X
X while (fgets(line, MAXLINE, rd) != NULL)
X {
X SSCANF(line, "%d %s", &runlength, bitstring) ;
X n = 0 ;
X indexval = 0 ;
X for (i = 0; i < 2; i++)
X {
X bvalue = bitstring[n++] - '0' ;
X indexval = (indexval << 1) + bvalue ;
X }
X ptr = blacks[indexval] ;
X for (i = n ; i < strlen(bitstring); i++)
X {
X if (ptr->next[bvalue] == NULL)
X {
X ptr->next[bvalue] = (struct code *) LINT_CAST(malloc(sizeof(struct code))) ;
X ptr->next[bvalue]->next[0] = NULL ;
X ptr->next[bvalue]->next[1] = NULL ;
X }
X ptr = ptr->next[bvalue] ;
X bvalue = bitstring[i] - '0' ;
X }
X ptr->value[bvalue] = runlength ;
X }
X FCLOSE(rd) ;
X}
X
X
Xget_bitval() /* Get next bit value from compressed scanned file. */
X{
X if (rcount == 8)
X {
X if ((rc = getc(rd)) == EOF)
X {
X finished = 1 ;
X return(-1) ;
X }
X rcount = 0 ;
X }
X return((rc >> (7-rcount++)) & 1) ;
X}
X
X
Xget_code(color) /* Get next huffman code for this color. */
Xint color ;
X{
X int bvalue, i, indexval ;
X struct code *ptr ;
X
X indexval = 0 ;
X for (i = 0; i < color; i++)
X {
X if ((bvalue = get_bitval()) == -1) return(-1) ;
X indexval = (indexval << 1) + bvalue ;
X }
X if (color == WHITE) ptr = whites[indexval] ;
X else ptr = blacks[indexval] ;
X for (;;)
X {
X if (ptr->next[bvalue] == NULL) return(ptr->value[bvalue]) ;
X ptr = ptr->next[bvalue] ;
X if ((bvalue = get_bitval()) == -1) return(-1) ;
X }
X}
X
X
Xwrite_code(color, length) /* Send uncompressed data to temporary file. */
Xint color, length ;
X{
X int i ;
X
X for (i = 0; i < length; i++)
X {
X if (color == BLACK) wc |= (1 << 7 - wcount) ;
X if (++wcount == 8)
X {
X PUTC(wc, wd) ;
X wc = 0 ;
X wcount = 0 ;
X }
X }
X}
X
X
Xuncompress(filename) /* Uncompress the scanned file using huffman codes. */
Xchar filename[MAXLINE] ;
X{
X int rem, runlength ;
X
X finished = 0 ;
X if ((rd = fopen(filename, "r")) == NULL)
X {
X FPRINTF(stderr, "%s: can't open %s\n", progname, filename) ;
X exit(1) ;
X }
X SPRINTF(finalimage, "/usr/tmp/%s.unc.image", mktemp("XXXXXX")) ;
X if ((wd = fopen(finalimage, "w")) == NULL)
X {
X FPRINTF(stderr, "%s: can't open %s\n", progname, finalimage) ;
X exit(1) ;
X }
X
X width = 0 ;
X height = 0 ;
X rcount = 8 ; /* Force a character read. */
X wcount = 0 ;
X do
X {
X runlength = get_code(WHITE) ;
X if (runlength != -1) width += runlength ;
X if (finished) break ;
X if (runlength == -1)
X {
X height++ ;
X rem = width % 16 ;
X if (rem) write_code(WHITE, rem) ;
X fwidth = width + rem ;
X if (!finished) width = 0 ;
X rcount = 8 ;
X continue ;
X }
X write_code(WHITE, runlength) ;
X if (runlength >= 64)
X {
X runlength = get_code(WHITE) ;
X if (runlength != -1) width += runlength ;
X write_code(WHITE, runlength) ;
X }
X
X runlength = get_code(BLACK) ;
X if (runlength != -1) width += runlength ;
X if (finished) break ;
X if (runlength == -1)
X {
X height++ ;
X rem = width % 16 ;
X if (rem) write_code(WHITE, rem) ;
X fwidth = width + rem ;
X if (!finished) width = 0 ;
X rcount = 8 ;
X continue ;
X }
X write_code(BLACK, runlength) ;
X if (runlength >= 64)
X {
X runlength = get_code(BLACK) ;
X if (runlength != -1) width += runlength ;
X write_code(BLACK, runlength) ;
X }
X }
X while (!finished) ;
X FCLOSE(rd) ;
X FCLOSE(wd) ;
X if (!make_header(fwidth, height)) /* Write out Sun rasterfile header. */
X {
X SPRINTF(line, "cat %s %s > %s", temphead, finalimage, picname) ;
X SYSTEM(line) ; /* Create Sun rasterfile. */
X UNLINK(temphead) ; /* Remove header file. */
X }
X UNLINK(tempimage) ;
X UNLINK(finalimage) ;
X}
END_OF_FILE
if test 6931 -ne `wc -c <'scantool/scan_compress.c'`; then
echo shar: \"'scantool/scan_compress.c'\" unpacked with wrong size!
fi
# end of 'scantool/scan_compress.c'
fi
if test -f 'scantool/scan_extern.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/scan_extern.h'\"
else
echo shar: Extracting \"'scantool/scan_extern.h'\" \(1744 characters\)
sed "s/^X//" >'scantool/scan_extern.h' <<'END_OF_FILE'
X
X/* @(#)scan_extern.h 1.2 90/04/02
X *
X * External variables used by the scan program.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright messages are not removed, and no monies are exchanged.
X *
X * No responsibility is taken for any errors or inaccuracies inherent
X * either to the comments or the code of this program, but if
X * reported to me, then an attempt will be made to fix them.
X */
X
Xextern char finalimage[] ; /* Name of uncompressed image file. */
Xextern char line[] ;
Xextern char picname[] ; /* Name of file for raster image. */
Xextern char progname[] ; /* This programs name. */
Xextern char temphead[] ; /* Temporary filename for header file. */
Xextern char tempimage[] ; /* Temporary filename for saved scanned data. */
X
Xextern int finished ; /* Indicates if we have finished uncompressing. */
Xextern int fwidth ; /* Final width of rasterfile. */
Xextern int height ; /* Height in scan lines of raster file image. */
Xextern int rc ; /* Current character from scanned file. */
Xextern int rcount ; /* Bit position count within read character. */
Xextern int wc ; /* Current char to write to final image file. */
Xextern int wcount ; /* Bit position count within write character. */
Xextern int width ; /* Width in pixels of rasterfile image. */
X
Xextern struct code *whites[] ; /* White initial starting pointers. */
Xextern struct code *blacks[] ; /* Black initial starting pointers. */
X
Xextern FILE *rd ; /* File descriptor for input files. */
Xextern FILE *wd ; /* File descriptor for final image. */
END_OF_FILE
if test 1744 -ne `wc -c <'scantool/scan_extern.h'`; then
echo shar: \"'scantool/scan_extern.h'\" unpacked with wrong size!
fi
# end of 'scantool/scan_extern.h'
fi
if test -f 'scantool/scantool.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/scantool.1'\"
else
echo shar: Extracting \"'scantool/scantool.1'\" \(6726 characters\)
sed "s/^X//" >'scantool/scantool.1' <<'END_OF_FILE'
X.\" @(#)scantool.1 1.3 90/04/04
X.TH SCANTOOL 1L "2 April 1990"
X.SH NAME
Xscantool \- a program to scan images using a Microtek MS300A scanner.
X.SH SYNOPSIS
X.B "scantool
X[
X.B -v
X]
X[
X.B \-Wi
X]
X[
X.B \-Wp
X.I x y
X]
X[
X.B \-WP
X.I x y
X]
X.SH DESCRIPTION
X.I Scantool
Xallows the user to scan in documents using a Microtek
XMS300A scanner, and turn the resulting image into a Sun rasterfile.
XThis program uses either SunView or XView graphics. These graphics
Xroutines are fairly trivial, and have been isolated into a single
Xfile, so it would be relatively easy to write a set of graphics
Xroutines for another graphics system.
X.LP
XWhen you run scantool, a window is displayed. There is a black bar
Xat the top with containing six headings. Hitting a mouse button when
Xthe cursor is above one of those six headings, will display a popup
Xmenu. These options are explained in more detail below, and also by
Xselecting entries from the Help popup menu.
X.LP
XThere are also four box toggle switches. Each toggle has two settings.
XThere are toggles for setting the line mode,
Xdata transfer method, serial port and baud rate.
X.LP
XThere are three buttons. The Scan button initiates a scan. Should you
Xwish to cancel a scan once it has been started, then you should press
Xthe Canel button.
X.LP
XThe Show button allows you to display the scanned rasterfile images in
Xa separate window.
X.SS "Display mode."
X.LP
XThe scanner can handle input from the image sensor in
Xtwo modes: Line Art mode and Halftone mode. Line Art
Xmode produces an all black-and-white image, while
XHalftone mode results in an image that appears to contain
Xvarying shades of gray.
X.LP
XIn Line Art mode, the amount of light falling on the
Xsensor is compared against a "threshold" determined by
Xthe Brightness and Contrast controls. Whenever it falls
Xbelow the threshold, a black dot is sent to the Sun; when
Xit exceeds the threshold a white dot is sent. This mode
Xis normally used for material in which everything is
Xeither black or white.
X.LP
XHalftone mode is used to detect and reproduce finer
Xdifferences in shading. In this mode the dots sent to
Xthe Sun are organised into squares, or "grains", of
Xuniform size. By varying the ratio of black and white
Xdots in the grains, different degrees of shading, or
X"gray levels", are achieved.
X.SS "Data transfer."
X.LP
XIn order to reduce the amount of time needed to
Xtransmit a scanned image to the computer, the
XMS-300A can compress image data using a one-
Xdimensional coding scheme based on CCITT
XRecommendation T.4 (modified Huffman code). By default the scanner
Xwill send compressed data to the computer.
X.SS " Serial connection."
X.LP
XThe scanner connects to the computer using an RS232 connection.
XThis is currently setup to allow you to select between the RS232
XA and B ports. The baud rate can also be toggled between 9600
Xand 1920 baud.
X.SS "Brightness."
X.LP
XThere are 14 Brightness levels to choose from. The
Xeffect of this control depends on whether the image
Xis scanned in Line Art or Halftone mode.
X.LP
XIn Line Art mode, the higher the Brightness setting
Xthe darker a spot must be in order for the scanner to
Xconsider it "black". Lower settings can therefore be
Xused to get a sharper image if the original is too
Xlight or blurry, while higher settings can be used to
Xprevent slightly shaded areas from coming out black
Xin the scanned image.
X.LP
XIn Halftone mode, the Brightness setting affects
Xshading in all areas of the scanned image, both dark
Xand light. The higher the value selected, the lighter
Xthe overall image; the lower the setting, the darker image.
X.SS "Contrast."
X.LP
XThe Contrast control also has 14 different settings.
XThe effect of this control in Line Art mode is identical
Xto that of the Brightness control. In Halftone mode, a
Xhigher Contrast setting causes all but the darkest areas
Xof the original document to come out lighter in the
Xscanned image. Too high a setting can result in "glare
Xspots" of pure white; too low a setting can make the
Ximage almost uniformly gray.
X.SS "Grain."
X.LP
XAll the grains in any one halftone image are the same
Xsize (see the Mode help). It is desirable, however, to
Xuse different grain sizes for different kinds of images.
XThe Grain control makes it possible to do this. Six
Xdifferent grain sizes are available: 2, 3, 4, 5, 6, and
X8 dots square.
X.LP
XWhen smaller grain sizes (i.e. higher settings) are
Xused, fine details in the original document are captured
Xmore clearly, but the smaller number of dot positions in
Xthe grains limits the scanner's "palette" of gray levels.
XA Grain setting of 11, for instance produces grains that
Xare 2 dots high by 2 dots wide. With only 4 dot positions
Xto fill, only 5 distinct gray levels are possible, from
Xall white to all black.
X.SS "Resolution."
X.LP
XThe Resolution control determines the degree of
Xreduction of the scanned image relative to the original.
XSince the dots that make up the scanned image cannot be
Xreduced in size, reduction is achieved by deleting dots
Xat selected intervals when transmitting the image to
Xthe Sun, resulting in an effective resolution of less
Xthan the scanner's maximum of 300 dots per inch.
X.LP
XThere are 16 possible Resolution settings, providing
Xscaling operations from 25% to 100%.
X.SS "Setting the picture name."
X.LP
XThere are various options that can be set via the Set popup menu.
XOne of these is the picture name. This is the name of the file on
Xthe Sun that the scanned picture will be saved in. The default is
Xa file called "Noname.rf".
X.SS "Setting the scaning frame."
X.LP
XThe frame is the area to be scanned. Scantool allows
Xyou to scan an area as small as 1/8" x 1/8", or as large
Xas 8.5" x 11". Using the Set Scanning Frame function in
Xthe Set menu, you can adjust the size and location of
Xthe frame in order to scan any part of the document that
Xyou feed into the scanner.
X.SS "Initiating a scan."
X.LP
XWhen you click the Scan button, scantool checks
Xto see if the scanner is on line, i.e. powered up,
Xproperly connected and ready to receive commands.
X.LP
XIf everything checks out OK, the current settings
Xwill be transmitted to the scanner, and the rollers
Xwill begin to turn. Actual scanning will begin after
Xa document is detected by the paper sensor, which is
Xlocated in the middle of the feed slot just below
Xthe top rollers.
X.SH OPTIONS
X.TP
X.B \-v
XPrint the version number of this release of the scantool program.
X.TP
X.B \-Wi
XStart the
X.B scantool
Xprogram up in iconic form.
X.TP
X.BI \-Wp " x y"
XStart the open window position at
X.I x y
X.TP
X.BI \-WP " x y"
XStart the icon position at
X.I x y
X.SH FILES
X.TP
X/usr/local/lib/scantool/scantool.help
X.SH AUTHOR
XRich Burridge, Domain: richb at Aus.Sun.COM
X.nf
XPHONE: +61 2 413 2666 Path: {uunet,mcvax,ukc}!munnari!sunaus.oz!richb
X.fi
END_OF_FILE
if test 6726 -ne `wc -c <'scantool/scantool.1'`; then
echo shar: \"'scantool/scantool.1'\" unpacked with wrong size!
fi
# end of 'scantool/scantool.1'
fi
if test -f 'scantool/scantool.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scantool/scantool.c'\"
else
echo shar: Extracting \"'scantool/scantool.c'\" \(6434 characters\)
sed "s/^X//" >'scantool/scantool.c' <<'END_OF_FILE'
X
X/* @(#)scantool.c 1.4 90/04/04
X *
X * Main routine for scantool, which will read a scanned image
X * from a Microtek MS-300A scanner and convert it to a Sun rasterfile.
X *
X * Copyright (c) Rich Burridge.
X * Sun Microsystems, Australia - All rights reserved.
X *
X * Permission is given to distribute these sources, as long as the
X * copyright messages are not removed, and no monies are exchanged.
X *
X * No responsibility is taken for any errors or inaccuracies inherent
X * either to the comments or the code of this program, but if
X * reported to me, then an attempt will be made to fix them.
X */
X
X#include <stdio.h>
X#include <strings.h>
X#include "scantool.h"
X
Xchar *br_strs[] = { /* Brightness menu item strings. */
X "1 -24% Darker",
X "2 -20% Darker",
X "3 -16% Darker",
X "4 -12% Darker",
X "5 -8% Darker",
X "6 -4% Darker",
X "7 No adjustment",
X "8 +4% Lighter",
X "9 +8% Lighter",
X "10 +12% Lighter",
X "11 +16% Lighter",
X "12 +20% Lighter",
X "13 +24% Lighter",
X "14 +28% Lighter",
X NULL
X} ;
X
Xchar *con_strs[] = { /* Contrast menu item strings. */
X "1 -24% Lower",
X "2 -20% Lower",
X "3 -16% Lower",
X "4 -12% Lower",
X "5 -8% Lower",
X "6 -4% Lower",
X "7 No adjustment",
X "8 +4% Higher",
X "9 +8% Higher",
X "10 +12% Higher",
X "11 +16% Higher",
X "12 +20% Higher",
X "13 +24% Higher",
X "14 +28% Higher",
X NULL
X} ;
X
Xchar *gr_strs[] = { /* Grain menu item strings. */
X "0 Grain Size: 8x8 Gray Levels: 33",
X "1 Grain Size: 8x8 Gray Levels: 33",
X "2 Grain Size: 8x8 Gray Levels: 33",
X "3 Grain Size: 8x8 Gray Levels: 33",
X "4 Grain Size: 6x6 Gray Levels: 37",
X "5 Grain Size: 5x5 Gray Levels: 26",
X "6 Grain Size: 5x5 Gray Levels: 18",
X "7 Grain Size: 4x4 Gray Levels: 17",
X "8 Grain Size: 4x4 Gray Levels: 17",
X "9 Grain Size: 4x4 Gray Levels: 17",
X "10 Grain Size: 3x3 Gray Levels: 10",
X "11 Grain Size: 2x2 Gray Levels: 5",
X NULL
X} ;
X
Xchar *help_strs[] = { /* Help menu item strings. */
X "Brightness",
X "Contrast",
X "Frame",
X "Grain",
X "Mode",
X "Resolution",
X "Scan",
X "Compress",
X "Port",
X "Speed",
X "Picture",
X NULL
X} ;
X
Xchar *res_strs[] = { /* Resolution menu item strings. */
X "0 300 dpi Scale: Full size",
X "1 285 dpi Scale: 95%",
X "2 270 dpi Scale: 90%",
X "3 255 dpi Scale: 85%",
X "4 240 dpi Scale: 80%",
X "5 225 dpi Scale: 75%",
X "6 210 dpi Scale: 70%",
X "7 200 dpi Scale: 66%",
X "8 180 dpi Scale: 60%",
X "9 165 dpi Scale: 55%",
X "10 150 dpi Scale: 50%",
X "11 135 dpi Scale: 45%",
X "12 120 dpi Scale: 40%",
X "13 100 dpi Scale: 33%",
X "14 90 dpi Scale: 30%",
X "15 75 dpi Scale: 25%",
X NULL
X} ;
X
Xchar *set_strs[] = { /* Set menu item strings. */
X "Picture Name",
X "Default Settings",
X "Clear Scanning Frame",
X "New Scanning Frame",
X "Show Current Settings",
X NULL
X} ;
X
Xchar helpname[MAXLINE] ; /* Current help file to display. */
Xchar last_message[MAXLINE] ; /* Last message that was make_displayed. */
Xchar old_picname[MAXLINE] ; /* Previous picture name. */
Xchar output[MAXLINE] ; /* Panel_set string to be output. */
Xchar picname[MAXLINE] ; /* Name of file for raster image. */
Xchar progname[MAXLINE] ; /* Name of this program. */
X
Xint ops[MAXOPS] ; /* Rasterop functions. */
X
Xint switches[4] =
X {
X 0, /* Mode (Line Art). */
X 1, /* Data Transfer (Compressed). */
X 0, /* Serial Port (A). */
X 1 /* Baud Rate (19200). */
X } ;
X
Xint framevals[4] = /* Initial frame in 1/8th inch intervals. */
X {
X 16, /* X1. */
X 16, /* Y1. */
X 48, /* X2. */
X 48, /* Y2. */
X } ;
X
Xint butx ; /* Top left X position of popup button. */
Xint buty ; /* Top left Y position of popup button. */
Xint cur_ch ; /* Last keyboard character pressed. */
Xint curx ; /* Current X position of the mouse. */
Xint cury ; /* Current Y position of the mouse. */
Xint font_width ; /* Width of a single character. */
Xint nohelp = 0 ; /* Indicates if a help file was found. */
Xint pid ; /* Process id of the child scan process. */
Xint scanning = 0 ; /* Set if we are in the middle of a scan. */
Xint showing = 0 ; /* Set if we are in the middle of a show. */
Xint type ; /* Current pseudo event type. */
Xint width ; /* Width in pixels of scantool window. */
X
X/* Cyclic switches. */
Xint brightness ; /* Brightness value. */
Xint contrast ; /* Contrast value. */
Xint grain ; /* Grain value. */
Xint resolution ; /* Resolution value. */
X
Xenum draw_type drawstate ; /* Current action if a redraw is needed. */
X
XFILE *hfd ; /* File descriptor for help file. */
X
X
Xmain(argc, argv)
Xint argc ;
Xchar *argv[] ;
X{
X STRCPY(progname, argv[0]) ; /* Save program name. */
X get_options(argc, argv) ; /* Extract command line options. */
X init_ws_type() ; /* Setup pseudo rasterop functions. */
X drawstate = DO_NOTHING ; /* No popups currently displayed. */
X if ((hfd = fopen(HELPNAME, "r")) == NULL)
X {
X FPRINTF(stderr, "Help file %s not found\r\n", HELPNAME) ;
X nohelp = 1 ;
X }
X
X STRCPY(picname, "NoName.rf") ;
X set_defaults() ; /* Set scanner settings to default. */
X make_frames(argc, argv) ; /* Create main scantool frame and show window. */
X make_subframes() ; /* Create canvases for each window. */
X init_fonts() ; /* Open fonts used by scantool. */
X make_menus() ; /* Create scantool menubar pulldown menus. */
X start_tool() ; /* Fit window and wait for events. */
X}
END_OF_FILE
if test 6434 -ne `wc -c <'scantool/scantool.c'`; then
echo shar: \"'scantool/scantool.c'\" unpacked with wrong size!
fi
# end of 'scantool/scantool.c'
fi
echo shar: End of archive 2 \(of 3\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 3 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
dan
-----------------------------------------------------------
O'Reilly && Associates
argv at sun.com / argv at ora.com
632 Petaluma Ave, Sebastopol, CA 95472
800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list