Previous section To contents Next section

12.8 Image.X

DESCRIPTION
This submodule handles encoding and decoding of the binary formats of X11.

SEE ALSO
Image, Image.Image and Image.Colortable

METHOD
Image.X.decode_pseudocolor

SYNTAX
object decode_pseudocolor(string data, int width, int height, int bpp, int alignbits, int swapbytes, object colortable)

DESCRIPTION
lazy support for pseudocolor ZPixmaps

NOTE
currently, only byte-aligned pixmaps are supported

METHOD
Image.X.decode_truecolor_masks,
Image.X.decode_truecolor

SYNTAX
object decode_truecolor(string data, int width, int height, int bpp, int alignbits, int swapbytes, int rbits, int rshift, int gbits, int gshift, int bbits, int bshift)
object decode_truecolor_masks(string data, int width, int height, int bpp, int alignbits, int swapbytes, int rmask, int gmask, int bmask)

DESCRIPTION
lazy support for truecolor ZPixmaps

NOTE
currently, only byte-aligned masks are supported

METHOD
Image.X.encode_pseudocolor

SYNTAX
string encode_pseudocolor(object image, int bpp, int alignbits, int vbpp, object colortable)
string encode_pseudocolor(object image, int bpp, int alignbits, int vbpp, object colortable, string translate)

DESCRIPTION

ARGUMENTS
argument(s)description
object image
the image object to encode
int bpp
bits per pixel, how many bits each pixel should take
int vbpp
value bits per pixel; how many bits per pixel that really contains information
int alignbits
the number of even bits each line should be padded to
object colortable
colortable to get indices for pseudocolor
string translate
translate table for colors. Length of this string should be 1<<vbpp (or 2<<vbpp if vbpp are greater than 8).

NOTE
currently, only upto 16 bits pseudocolor are supported.

METHOD
Image.X.encode_truecolor,
Image.X.encode_truecolor_masks

SYNTAX
string encode_truecolor(object image, int bpp, int alignbits, int swapbytes, int rbits, int rshift, int gbits, int gshift, int bbits, int bshift)
string encode_truecolor_masks(object image, int bpp, int alignbits, int swapbytes, int rmask, int gmask, int bmask)
string encode_truecolor(object image, int bpp, int alignbits, int swapbytes, int rbits, int rshift, int gbits, int gshift, int bbits, int bshift, object ct)
string encode_truecolor_masks(object image, int bpp, int alignbits, int swapbytes, int rmask, int gmask, int bmask, object ct)

DESCRIPTION
Pack an image into a truecolor string. You will get a string of packed red, green and blue bits; ie:

encode_truecolor(img, 12,32, 0, 3,5, 4,0, 3,8) will give (aligned to even 32 bits for each row):
0bbbrrr0 gggg0bbb rrr0gggg 0bbb...
<--pixel 1--><--pixel 2--> <--3-->
10987654 32101098 76543210 1098... <- bit position <-><-> <--> | | +--- 4,0: 4 bits green shifted 0 bits | +-------- 3,5: 3 bits red shifted 5 bits +----------- 3,8: 3 bits blue shifted 8 bits

The above call is equal to
encode_truecolor_masks(img, 12,32, 0, 224, 15, 768) and
encode_truecolor(img, 12,32, 0, 3,5,4,0,3,8, colortable(1<<3,1<<4,1<<3)).
The latter gives possibility to use dither algorithms, but is slightly slower.

ARGUMENTS
argument(s)description
object image
the image object to encode
int bpp
bits per pixel, how many bits each pixel should take
int alignbits
the number of even bits each line should be padded to
int rbits
int gbits
int bbits
bits for each basecolor
int rshift
int gshift
int bshift
leftshifts for each basecolor
int rmask
int gmask
int bmask
masks for each basecolor (xbits and gbits are calculated from this), needs to be massive (no zeroes among the ones in the mask).
object ct
colortable object (for dithering, or whatever)
int swapbytes
swap bytes for bpp==16,24,32, swaps bits in the bytes if bpp==1, for change of byte/bitorder between client and server.

Previous section To contents Next section