

Images & X Display
==================


in your makefile do:

GKPATH = /projects/vision/code/gregk-library

or

GKPATH = /homes/gregk/libgregk   ## my personal copy which is not stable but is newest

GKINC = $(GKPATH)/include
GKLIB = $(GKPATH)/library


compile with:

gcc -I$(GKINC) ...


link with:


gcc -L$(GKLIB) ..... -lgregk

you'll also need -lX11 if you use any of the X routines.

Code is in GKSRC = $(GKPATH)/src.  From there, directories are named
{bin,adt,support}-<author>.  the "bin" directories have source for unix programs
which give access to the C code in the library.  You may want to put
$(GKPATH)/bin on your path so you have access to these.  (that directory has
links to the executables.)  Many useful image manipulation routines are in
there.  Also you may want /usr/local/pbmplus on your path. 

The code in the "adt" and "support" directories is all in the library and those
that are documented have entries in $(GKPATH)/DOCUMENTATION


Basics for how to use the stuff:

#include "image.h"

then you can declare images:

GrayImage gimg;
FloatImage fimg;
BinaryImage bimg;
RGBImage rgbimg;   ....

allocating images:

gimg = imNew(IMAGE_GRAY, width, height);
bimg = imNewOffset(IMAGE_BINARY, with, height, xoffset, yoffset);

wrap an image:

gimg = imWrap(raw_uchar_ptr, IMAGE_GRAY, width, height);

done using an image:

imFree(gimg);    

don't worry, this won't free the raw data of a wrapped image.


load/save images (PBM, PGM, PPM (all raw) + analogous formats for other types):

imSave(gimg, "filename");
imSaveF(bimg, fileptr);
gimg = imLoad(IMAGE_GRAY, "file");
imLoadInto(gimg, "file");

*** you can enable automatic conversion by setting "ImageAllowLoadConversion" to 1.
*** loading a compressed (with gzip) image will cause it to be automatically converted.

use:

val = imRef(gimg, x, y);
imRef(bimg, x, y) = 1;

w = imGetWidth(rgbimg);
h = imGetHeight(fimg);

see image.c for a full list of the functions suported.  note that most are
implemented as wrappers to make them work polymorphically.


Display:

#include "x-stuff.h"

xOpenDisplay()
xAllocateGrayColorMap();

xWindow win;
GrayImage img;

win = xShowImage(img, "title", xpos, ypos);

xShowImageIn(img, win);


finally:

xCloseDisplay();


Note that xShowImage{In} destroys values in the image you give it (it maps the
bytes to x colors).  you'll want to use imCopy() to first copy an image then
display the copy.  Also, you may want to see xShowImage{In}NoRemap() -- it takes
an image that's already been mapped to x colors.  this is useful for doing
overlays.  see "uchar-remap.h" and the function ucharRemap().

A good place to look for example code is $(GKSRC)/bin-gregk/*.c.



