Laxkit  0.0.7.1
Classes | Typedefs | Functions | Variables
Images

Classes

class  Laxkit::MemCachedObject
class  Laxkit::ImageLoader
 Class to facilitate getting an image from the disk into memory suitable for the current graphics backend. More...
class  Laxkit::LaxBufferImage
class  Laxkit::LaxImage
 Abstraction around images. More...

Typedefs

typedef int(* Laxkit::DefaultImageTypeFunc )()
 Returns what the default image format is.
typedef void(* Laxkit::ImageOutFunc )(LaxImage *image, aDrawable *win, int ulx, int uly)
 Simply oriented drawing of image to aDrawable.
typedef void(* Laxkit::ImageOutRotatedFunc )(LaxImage *image, aDrawable *win, int ulx, int uly, int urx, int ury)
 Drawing image to aDrawable with rotation and scaling.
typedef void(* Laxkit::ImageOutSkewedFunc )(LaxImage *image, aDrawable *win, int ulx, int uly, int urx, int ury, int llx, int lly)
 Drawing image to aDrawable with rotation, scaling, and skewing.
typedef void(* Laxkit::ImageOutMatrixFunc )(LaxImage *image, aDrawable *win, double *m)
 Drawing an image to aDrawable with an affine matrix.
typedef LaxImage *(* Laxkit::ImageFromBufferFunc )(unsigned char *buffer, int w, int h, int stride)
 Create a LaxImage from ARGB 8 bit data.
typedef LaxImage *(* Laxkit::LoadImageFunc )(const char *filename)
 The type of function that loads a file to a LaxImage. Defines load_image().
typedef LaxImage *(* Laxkit::LoadImageWithPreviewFunc )(const char *filename, const char *previewfile, int maxx, int maxy, char delpreview)
 Loads an image, using a preview image.
typedef LaxImage *(* Laxkit::CreateNewImageFunc )(int w, int h)
 Type of function that creates a new image based on a certain width and height.

Functions

void Laxkit::laximlib_usealpha (int yes)
 Set the imlib color modifier to use transparency.
void Laxkit::laximlib_update_alpha (int alpha)
void Laxkit::laximlib_image_out (LaxImage *image, aDrawable *win, int ulx, int uly)
void Laxkit::laximlib_image_out_rotated (LaxImage *image, aDrawable *win, int ulx, int uly, int urx, int ury)
void Laxkit::laximlib_image_out_skewed (LaxImage *image, aDrawable *win, int ulx, int uly, int urx, int ury, int llx, int lly)
void Laxkit::laximlib_image_out_matrix (LaxImage *image, aDrawable *win, double *m)
LaxImage * Laxkit::load_imlib_image (const char *filename)
 Function that returns a new LaxImlibImage.
LaxImage * Laxkit::load_imlib_image_with_preview (const char *filename, const char *previewfile, int maxx, int maxy, char del)
 Function that returns a new LaxImlibImage with preview.
int Laxkit::add_image_loader (ImageLoader *loader, int where)
 Add loader to list of available loaders.
LaxImage * Laxkit::load_image_with_loaders (const char *file, const char *previewfile, int maxx, int maxy, char delpreview, int required_state, int target_format, int must_be_that_format, int *actual_format)
 Laxkit::MemCachedObject::MemCachedObject ()
virtual int Laxkit::MemCachedObject::inc_cache ()
 Increment the cache count, returning the new current count.
virtual int Laxkit::MemCachedObject::dec_cache ()
 Decrement the cache count, returning the new current count.
virtual void Laxkit::LaxImage::doneForNow ()
 The file that the image is supposed to correspond to.
virtual void Laxkit::LaxImage::clear ()=0
 Clear all data contained in this image.
 Laxkit::LaxImage::LaxImage (const char *fname)
virtual int Laxkit::LaxImage::imagetype ()=0
virtual unsigned int Laxkit::LaxImage::imagestate ()=0
 Return whether this is valid image, is whole image, etc.
virtual int Laxkit::LaxImage::w ()=0
 Return the width of the actual image.
virtual int Laxkit::LaxImage::h ()=0
 Return the height of the actual image.
virtual int Laxkit::LaxImage::dataw ()=0
 Return the width of the image in memory (the actual or preview), or 0 if neither is in memory.
virtual int Laxkit::LaxImage::datah ()=0
 Return the height of the image in memory (the actual or preview), or 1 if neither is in memory.
virtual unsigned charLaxkit::LaxImage::getImageBuffer ()=0
virtual Laxkit::LaxImage::~LaxImage ()
virtual int Laxkit::LaxBufferImage::Stride ()
 The number of bytes between rows.

Variables

DefaultImageTypeFunc Laxkit::default_image_type = NULL
ImageOutFunc Laxkit::image_out = NULL
 The default image to window drawing function.
ImageOutRotatedFunc Laxkit::image_out_rotated = NULL
 The default image to window drawing function with rotation and scaling.
ImageOutSkewedFunc Laxkit::image_out_skewed = NULL
 The default image to window drawing function with skewing.
ImageOutMatrixFunc Laxkit::image_out_matrix = NULL
 The default image to window drawing function with an affine matrix.
LoadImageFunc Laxkit::load_image = NULL
 The default image loading function.
LoadImageWithPreviewFunc Laxkit::load_image_with_preview = NULL
ImageFromBufferFunc Laxkit::image_from_buffer = NULL
CreateNewImageFunc Laxkit::create_new_image = NULL
static ImageLoader * Laxkit::imageloaders = NULL
GeneratePreviewFunc Laxkit::generate_preview_image = NULL
 The base preview creator.
char Laxkit::LaxImage::delpreview
 1 to unlink previewfile in the destructor, else 0.

Detailed Description

The class LaxImage abstracts various image related tasks. No actual image data is stored in a base LaxImage.

The default image type can be Imlib based image manipulation using LaxImlibImage classes, for instance.

The following function pointers can be redefined if you prefer to use your own kind of LaxImage. They function like the Imlib equivalents.

*** update me!!

LaxImage is derived from anObject, so code should use the dec_count() and inc_count() member functions when using LaxImages, rather than delete someimage

Todo:
In the future, will probably want some kind of load_image_to_buffer, but that means I have to understand color management much more thoroughly.

Typedef Documentation

int(* Laxkit::DefaultImageTypeFunc)()

Returns what the default image format is.

For the forseeable future, this will be LAX_IMAGE_IMLIB or LAX_IMAGE_CAIRO.

void Laxkit::ImageOutFunc

Simply oriented drawing of image to aDrawable.

Draw an image with upper left corner at window coordinates (ulx,uly). Positive y is down.

void Laxkit::ImageOutRotatedFunc

Drawing image to aDrawable with rotation and scaling.

Draw an image so that the upper left and right corners are at (ulx,uly) and (ulx+urx,uly+ury).

void Laxkit::ImageOutSkewedFunc

Drawing image to aDrawable with rotation, scaling, and skewing.

Draw an image so that the upper left and right corners are at (ulx,uly) and (ulx+urx,uly+ury), and the lower left corner is at (ulx+llx,uly+lly).

LaxImage *(* Laxkit::LoadImageWithPreviewFunc)(const char *filename, const char *pfile, int maxx, int maxy, char delpreview)

Loads an image, using a preview image.

If delpreview, then when the LaxImage is destroyed, the file at LaxImage::previewfile is deleted. Note that if an already existing preview is used (that is, no new one is generated), then delpreview reverts to 0, and the already existing preview is untouched in the destructor.


Function Documentation

int Laxkit::add_image_loader ( ImageLoader *  loader,
int  where 
)

Add loader to list of available loaders.

This function takes possession of the loader. If it is later removed, loader->dec_count() is called on it. If the loader cannot be installed for some reason, it's count is decremented also.

Return 0 for success or nonzero for error. On error, dec_count() is still called on loader.

void Laxkit::LaxImage::clear ( )
pure virtual

Clear all data contained in this image.

Derived classes should remember to delete[] filename and preview.

int Laxkit::MemCachedObject::dec_cache ( )
virtual

Decrement the cache count, returning the new current count.

If the cache count is zero, nothing is done. When it is zero, whatever internal memory is allocated can be freed or disk cached if the memory is needed.

void Laxkit::LaxImage::doneForNow ( )
inlinevirtual

The file that the image is supposed to correspond to.

var char *LaxImage::filename If w()<=0, then filename is invalid.

var char *LaxImage::previewfile A sort of proxy image that can shadow the actual image.

If dataw()<=0, then previewfile is invalid.

This allows programs to potentially start up much more quickly, since they might need to load only a smaller preview or thumbnail into memory, rather than the entire image, which might be huge.

previewfile is always assumed to be an image file on your harddrive somewhere, never an in-memory image. A common use is to refer to a freedesktop.org specified thumbnail.

This might free the image to make room in a cache, for instance.

Reimplemented in Laxkit::LaxImlibImage.

Referenced by Laxkit::Button::draw(), Laxkit::IconSelector::drawbox(), and Laxkit::IconNode::IconNode().

unsigned char * Laxkit::LaxImage::getImageBuffer ( )
pure virtual

This is mainly to assist auto cached preview images for some interface data classes. More specialized low level data manipulation should be done by accessing the particular implementation of LaxImage.

This checks out data of the actual image (in filename) not the previewfile, in 8 bit ARGB format, with the row stride==4*width.

It MUST be checked back in with doneWithBuffer() if you make changes in it.

Implemented in Laxkit::LaxImlibImage.

int Laxkit::LaxImage::imagestate ( )
pure virtual

Return whether this is valid image, is whole image, etc.

If the object does not hold a valid object, then 0 should be returned. Otherwise, the image data should be able to be gotten or already be in memory, and the return value should be an or'd combination of the following:

#define LAX_IMAGE_METRICS <-- whether metric info is ready
#define LAX_IMAGE_PREVIEW <-- whether (maybe) smaller preview is in memory
#define LAX_IMAGE_WHOLE <-- whether the whole data is in memory
#define LAX_IMAGE_HAS_FILE <-- whether the image corresponds to a file
#define LAX_IMAGE_HAS_TEMP_FILE <-- whether the image is held in a temporary file

Referenced by Laxkit::Button::SetIcon().

int Laxkit::LaxImage::imagetype ( )
pure virtual

Return what sort of image this is. Currently, only LAX_IMAGE_IMLIB is implemented, but the following words are reserved for future use maybe:

#define LAX_IMAGE_NULL 0
#define LAX_IMAGE_BUFFER 1
#define LAX_IMAGE_XIMAGE 2
#define LAX_IMAGE_PIXMAP 3
#define LAX_IMAGE_IMLIB 4
#define LAX_IMAGE_CAIRO 5
#define LAX_IMAGE_ANTIGRAIN 6
#define LAX_IMAGE_GL 7

Referenced by Laxkit::laximlib_image_out(), Laxkit::laximlib_image_out_matrix(), Laxkit::laximlib_image_out_rotated(), and Laxkit::laximlib_image_out_skewed().

Laxkit::LaxImage::LaxImage ( const char fname)

Constructor should get metric info on the image from file fname. It need not read in the actual pixel data.

fname is file name, but the default base class only sets filename, it does no loading on its own.

References newstr().

void Laxkit::laximlib_image_out ( LaxImage *  image,
aDrawable *  win,
int  ulx,
int  uly 
)

Set image, set drawable, then uses imlib_render_image_on_drawable().

References Laxkit::LaxImage::imagetype().

Referenced by Laxkit::InitImlib2Backend().

void Laxkit::laximlib_image_out_matrix ( LaxImage *  image,
aDrawable *  win,
double *  m 
)

Set image, set drawable, then uses imlib_render_image_on_drawable_skewed() according to the affine matrix m.

References Laxkit::LaxImage::imagetype(), and Laxkit::transform_point().

Referenced by Laxkit::InitImlib2Backend().

void Laxkit::laximlib_image_out_rotated ( LaxImage *  image,
aDrawable *  win,
int  ulx,
int  uly,
int  urx,
int  ury 
)

Set image, set drawable, then uses imlib_render_image_on_drawable_at_angle().

References Laxkit::LaxImage::imagetype().

Referenced by Laxkit::InitImlib2Backend().

void Laxkit::laximlib_image_out_skewed ( LaxImage *  image,
aDrawable *  win,
int  ulx,
int  uly,
int  urx,
int  ury,
int  llx,
int  lly 
)

Set image, set drawable, then uses imlib_render_image_on_drawable_skewed().

References Laxkit::LaxImage::imagetype().

Referenced by Laxkit::InitImlib2Backend().

void Laxkit::laximlib_update_alpha ( int  alpha)

Set alpha_modifier, and the cached alphamap for use later in image_out() with transparency. If usealpha==0, then the imlib_context_set_color_modifier(NULL) is called, otherwise, the imlib context color modifier is set to use the laximlib alpha modifier.

Referenced by Laxkit::laximlib_usealpha().

void Laxkit::laximlib_usealpha ( int  yes)

Set the imlib color modifier to use transparency.

To actually activate or adjust the alpha you must call laximlib_update_alpha().

References Laxkit::laximlib_update_alpha().

LaxImage * Laxkit::load_imlib_image ( const char filename)

Function that returns a new LaxImlibImage.

This loads the image, grabs the dimensions and does LaxImlibImage::doneForNow().

To use a preview image, see _load_imlib_image_with_preview().

References Laxkit::LaxImlibImage::doneForNow().

Referenced by Laxkit::InitImlib2Backend().

LaxImage * Laxkit::load_imlib_image_with_preview ( const char filename,
const char previewfile,
int  maxx,
int  maxy,
char  del 
)

Function that returns a new LaxImlibImage with preview.

This loads the images, grabs the dimensions. If the preview path does not exist, then a new preview is generated that is within the bounds of maxx and maxy, and saved to the path if possible.

If the preview already exists, then use it, without regenerating. If the preview path is not a valid image, then previewfile is set to NULL, but filename is still used as possible.

LaxImlibImage::doneForNow() is finally called.

References Laxkit::LaxImlibImage::doneForNow().

Referenced by Laxkit::InitImlib2Backend().

Laxkit::MemCachedObject::MemCachedObject ( )

Default is to start with the object data not being needed, so the count is 0.

int Laxkit::LaxBufferImage::Stride ( )
virtual

The number of bytes between rows.

So say an image is 40 pixels wide, 16 bits per channel, and has 4 channels, and has no padding. Then the stride is 40*(16/8)*4.

Laxkit::LaxImage::~LaxImage ( )
virtual

If delpreview and previewfile, then unlink(previewfile). Note that this is hazardous, and great care must be taken to ensure that previewfile is always what it is supposed to be. The Laxkit will never directly set delpreview to 1, except if you tell it to, via load_image_with_preview().

Todo:
*** perhaps unlink also only if dataw()>0? not sure if that is accessible in destructor, might have to intercept dec_count().

Variable Documentation

LoadImageFunc Laxkit::load_image = NULL

Mon Feb 17 2014 11:52:58, Laxkit