[comp.sources.amiga] v02i067: oneplane - convert workbench screen to one bitplane

page@swan.ulowell.edu (Bob Page) (11/29/88)

Submitted-by: erd@saqqara.cis.ohio-state.edu (Ethan R. Dicks)
Posting-number: Volume 2, Issue 67
Archive-name: workbench/oneplane.1

I got the encouragement for this program from the discussion on
comp.sys.amiga regarding fast text scrolling.  Someone called for a
program to reduce the Workbench screen to 1 bitplane to enhance the
speed of CON: output.

[uuencoded binary also included here, it's small.  This is *not* the
same as 'wbdepth' posted to comp.binaries.amiga.  ..Bob]

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	oneplane.c
#	oneplane.uu
# This archive created: Mon Nov 28 20:22:26 1988
cat << \SHAR_EOF > oneplane.c
/*

 oneplane.c - program to steal bottom bitplane from workbench screen

Ethan Dicks
(c) 15-Nov-1988

This progam is *not* in the public domain, but may be freely redistributed on
the condition that it is not sold, nor used in any commercial or shareware
package without express written permission of the author.  In other words,
selling this program is right out, but giving it away is encouraged.

I got the encouragement for this program from the discussion on comp.sys.amiga
regarding fast text scrolling.  Someone called for a program to reduce the
Workbench screen to 1 bitplane to enhance the speed of CON: output.

COMPILATION INSTUCTIONS:

I used Lattice C, V4.01, with the commands...

lc -b0 -v oneplane.c
blink oneplane.o SC SD ND

This is why some of the structure looks odd; I don't link with any external
files.  I know that the program could be made even smaller, but what do want
for a one night's hack?


HOW IT WORKS:

In the structure GfxBase, there is a field, ActView, which describes the 
current ViewPort.  This program uses the active viewport information to
aquire the active BitPlane structure, which contains information about how
many bitplanes are in use, their location in memory, the number of rows in
the bitplane, and the number of bytes in each row.  With this information,
is it trival to change the number of bitplanes down by one, and to free
up the memory held by the highest bitplane.  The request is checked in case
this is the only bitplane allocated.  The advantage of this system is that
the number of bitplanes can be increased and decreased at will, without
fear of a visit from the GURU.

Most of the information I got came from the RKM graphic primitives section,
in the Libraries and Devices volume, especially the examples, and most of the
rest came from picking apart the include files.

*/

#include <exec/types.h>
#include <exec/execbase.h>
#include <intuition/intuition.h>
#include <graphics/gfxbase.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>

#define MIN_DEPTH 1


#pragma libcall ExecBase FreeMem d2 0902
#pragma libcall IntuitionBase RemakeDisplay 180 00
#pragma libcall ExecBase CloseLibrary 19e 901
#pragma libcall ExecBase OpenLibrary 228 0902

struct View *currentview;	/* pointer to active View */
struct ViewPort *currentvp;	/* pointer to active ViewPort */
struct RasInfo *currentri;	/* pointer to active RasInfo */
struct BitMap *b;		/* pointer to current BitMap */

/* struct Execbase *ExecBase; */
struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;
struct ExecBase *ExecBase, **EBase;



/* 
    Here goes nuthin'
*/
void main()

{
/* Set the ExecBase pointer manually, since we do not link with anybody */
	EBase = (struct ExecBase **)(4L);
	ExecBase = *EBase;

/* Open the graphics.library and the intuition.library */

/* error checking not done, because if they won't open, the system is hosed */
	GfxBase
	    = (struct GfxBase *)OpenLibrary("graphics.library",0);

	IntuitionBase
	    = (struct IntuitionBase *)OpenLibrary("intuition.library",0);

/* Here goes with the pointer game... the idea is to end up at the BitMap */

	currentview = GfxBase -> ActiView;	/* get current View */
	currentvp = currentview -> ViewPort;	/* get current ViewPort */
	currentri = currentvp -> RasInfo;	/* get current RasInfo */
	b 	 = currentri -> BitMap;		/* get current BitMap */

/* And here is where we fiddle with the numbers */

/* ---> ONLY DO THIS IF THERE ARE BITPLANES LEFT TO REMOVE <--- */
	if ( (b -> Depth) > MIN_DEPTH) {

		b -> Depth -= 1;
		FreeMem( (b -> Planes)[(b -> Depth)],
			 (b-> Rows) * (b -> BytesPerRow) );

	}

/* Now that we are done fiddling with it, redraw the display */
	RemakeDisplay();
    
/* Now clean up and go home */
	CloseLibrary((struct Library *)GfxBase);
	CloseLibrary((struct Library *)IntuitionBase);
}

void MemCleanUp(){}
SHAR_EOF
cat << \SHAR_EOF > oneplane.uu

begin 777 oneplane
M```#\P`````````#``````````(````]````"0````@```/I````/4CG(`)PS
M!"/`````'")Y````'"!1(\@````80_D`````<``L2$ZN_=@CP````!!#^0``.
M`!)P`"QY````&$ZN_=@CP````!0@>0```!`CZ``B`````")Y`````"/1````L
M!")Y````!"/I`"0````((GD````((^D`!`````PB>0````P0*0`%#````6,VE
M(@!3`2!Y````#!%!``4"00#_(`%(P.6`(DC3P#`H``(R$"0`Q,$B:0`((`(LE
M>0```!A.KO\N+'D````43J[^@")Y````$"QY````&$ZN_F(B>0```!0L>0``%
M`!A.KOYB3-]`!$YU3G4```/L`````@````$````P````'````!8````"````_
MY````-X```#4````S@```,0```"Z````D@```'X```!X````<````&H```!BF
M````7````%8```!0````2````$(````X````*@```!8````.````"```````:
M``/R```#Z@````EG<F%P:&EC<RYL:6)R87)Y``!I;G1U:71I;VXN;&EB<F%RL
2>0````/R```#ZP````@```/R9
``
end
size 468
SHAR_EOF
#	End of shell archive
exit 0
-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
Have five nice days.