[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bit images and Inferno



>>Does anyone know how to convert from .gif to .bit -- preferably using an
>>easily available package

>>Does anyone know whether the .bit images support transparent pixels a la
>>gifs and backgrounds (not just background colors)

.bit files are in the format described by image(6).

as to conversion routines, the following gif2bit.b seems to work on
the few GIFs i've tried.
	gif2pic [-e] <in.gif >out.b
the -e option causes remap from imagefile(2) to apply
Floyd-Steinberg error diffusion.  handling .jpg files is a simple
extension.

handling the transparent GIF hack needs more work, since
the transparent flag and colour are in a GIF graphics control extension
block, and /appl/lib/readgif.b would need to look for it.

i'd be more inclined to build a mask Image, but other approaches
might be more suitable, depending on the application.

# To unbundle, run this file
echo gif2bit.b
sed 's/.//' >gif2bit.b <<'//GO.SYSIN DD gif2bit.b'
-implement Command;
-
-include "sys.m";
-	sys: Sys;
-	FORKFD, FORKNS: import Sys;
-
-include "draw.m";
-	draw: Draw;
-	Display, Image: import draw;
-
-include "bufio.m";
-	bio: Bufio;
-
-include "imagefile.m";
-	gifread: RImagefile;
-	remap: Imageremap;
-
-Command: module
-{
-	init: fn(nil: ref Draw->Context, argv: list of string);
-};
-
-init(ctx: ref Draw->Context, argv: list of string)
-{
-	image: ref Image;
-
-	sys = load Sys Sys->PATH;
-
-	bio = load Bufio Bufio->PATH;
-	draw = load Draw Draw->PATH;
-	gifread = load RImagefile RImagefile->READGIFPATH;
-	remap = load Imageremap Imageremap->PATH;
-	if(bio == nil || draw == nil || gifread == nil || remap == nil)
-		err("failed to load a needed module");
-
-	sys->pctl(FORKFD|FORKNS, nil);
-
-	diffuse := 0;
-	if(argv != nil && (argv = tl argv) != nil) {
-		if(hd argv == "-e" && tl argv == nil)
-			diffuse = 1;
-		else
-			err("Usage: gif2pic [-e] <in.gif >out.b");
-	}
-
-	stdin := sys->fildes(0);
-	if(stdin == nil)
-		err(sys->sprint("no standard input: %r"));
-	fp := bio->fopen(stdin, Bufio->OREAD);
-	if(fp == nil)
-		err(sys->sprint("can't fopen standard input: %r"));
-
-	gifread->init(bio);
-	(rawimage, diag) := gifread->read(fp);
-	if(rawimage == nil)
-		err(sys->sprint("can't read GIF: %s", diag));
-	else if(diag != nil)
-		sys->fprint(sys->fildes(2), "gif2pic: warning: troublesome GIF: %s\n", diag);
-
-	(image, diag) = remap->remap(rawimage, ctx.display, diffuse);
-	if(image == nil)
-		err(sys->sprint("can't convert GIF to Image: %s", diag));
-	if(ctx.display.writeimage(sys->fildes(1), image) < 0)
-		err(sys->sprint("error writing output Image: %r"));
-}
-
-err(s: string)
-{
-	sys->fprint(sys->fildes(2), "gif2bit: %s\n", s);
-	exit;
-}
//GO.SYSIN DD gif2bit.b