Laxkit  0.0.7.1
Public Member Functions | Public Attributes
LaxInterfaces::ImageData Class Reference

Holds an image and a transform. More...

Inheritance diagram for LaxInterfaces::ImageData:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual const charwhattype ()
 ImageData (const char *nfilename=NULL, const char *npreview=NULL, int maxpx=0, int maxpy=0, char delpreview=0)
 Constructor. Configures based on the image in nfilename.
ImageDataoperator= (ImageData &i)
virtual SomeDataduplicate (SomeData *dup)
 Return a new ImageData, based on this.
virtual void Flip (int horiz)
 Flip an image vertically or horizontally, but keep the same bounding box.
virtual int SetImage (Laxkit::LaxImage *newimage)
 Set the image to this one, dec counting the old one.
virtual void SetDescription (const char *ndesc)
 Set a new description for the data.
virtual int UsePreview (const char *npreview, int maxpx=0, int maxpy=0, char del=0)
 Use a different preview.
virtual int LoadImage (const char *fname, const char *npreview=NULL, int maxpx=0, int maxpy=0, char del=0, char fit=0)
 Set the image to the image in fname, if possible. Sets filename regardless.
virtual void dump_out (FILE *f, int indent, int what, Laxkit::anObject *context)
virtual void dump_in_atts (LaxFiles::Attribute *att, int flag, Laxkit::anObject *context)
- Public Member Functions inherited from Laxkit::ImageInfo
 ImageInfo (const char *f, const char *p, const char *t, const char *d, int pf)
virtual ~ImageInfo ()
ImageInfooperator= (ImageInfo &f)
virtual int SetInfo (ImageInfo *f)
- Public Member Functions inherited from Laxkit::anObject
 anObject ()
 Set object_id=getUniqueNumber().
virtual ~anObject ()
 Empty virtual destructor.
virtual anObjectduplicate (anObject *ref=NULL)
virtual int inc_count ()
 Increment the data's count by 1. Returns count.
virtual int dec_count ()
 Decrement the count of the data, deleting if count is less than or equal to 0.
virtual int the_count ()
- Public Member Functions inherited from Laxkit::Tagged
virtual int HasTag (const char *tag, int casematters)
 Return whether the tag exists.
virtual int NumberOfTags ()
 Return the number of tags, strangely enough.
virtual const charGetTag (int i)
 Return const pointer to the tag text for tag number i, where i==0 is the first tag.
virtual charGetAllTags ()
 Return a new char[] with a space separated list of all the tags.
virtual int InsertTags (const char *tags, int casematters)
 Insert tags from a string such as 'tag1 tag2 tag3 "tag with spaces" tag4'.
virtual int InsertTag (const char *tag, int casematters)
 Insert tag if it doesn't exist already.
virtual int RemoveTag (const char *tag)
 The tag must be an exact match.
virtual int RemoveTag (int i)
 Remove tag number i. i must be in range [0..NumberOfTags()-1].
virtual void FlushTags ()
- Public Member Functions inherited from LaxInterfaces::SomeData
virtual void touchContents ()
virtual Laxkit::LaxImageGetPreview ()
 If usepreview==1 and preview, then return preview.
virtual void GeneratePreview (int w, int h)
 Create a preview image with transparency for a cached screen preview.
virtual int renderToBuffer (unsigned char *buffer, int bufw, int bufh, int bufstride, int bufdepth, int bufchannels)
 Render the object to a buffer.
virtual const charId ()
virtual const charId (const char *newid)
 SomeData ()
 SomeData (double nminx, double nmaxx, double nminy, double nmaxy)
 Constructor, setting the bounds.
virtual void FindBBox ()
 Theoretically, find and set the bounds of the data.
virtual flatpoint BBoxPoint (double x, double y, bool transform_to_parent)
virtual flatpoint ReferencePoint (int which, bool transform_to_parent)
virtual int pointin (flatpoint pp, int pin=1)
 Return if pp transformed to data coords is within the bounds.
virtual int fitto (double *boxm, DoubleBBox *box, double alignx, double aligny, int whentoscale=2)
 Fit this data to box.
virtual SomeDataGetParent ()
virtual void dump_in (FILE *f, int indent, Laxkit::anObject *context, LaxFiles::Attribute **Att=NULL)
 Dump in an attribute, then call dump_in_atts(thatatt,0).
virtual LaxFiles::Attributedump_out_atts (LaxFiles::Attribute *att, int what, Laxkit::anObject *savecontext)

Public Attributes

char previewflag
Laxkit::LaxImageimage
- Public Attributes inherited from Laxkit::ImageInfo
charfilename
charpreviewfile
chartitle
chardescription
int previewflags
unsigned int mask
ImageInfonext
- Public Attributes inherited from Laxkit::anObject
int suppress_debug
DeleteRefCountedFunc deleteMe
 Called when the count is decremented to 0.
unsigned long object_id
charobject_idstr
- Public Attributes inherited from Laxkit::Tagged
int sorttags
- Public Attributes inherited from LaxInterfaces::SomeData
Laxkit::LaxImagepreview
 A preview image potentially to be used to not have to rerender on each refresh.
int usepreview
 Flag for whether to use SomeData::preview rather than rendering.
std::time_t previewtime
 The time the preview was generated, if at all, as returned by time().
std::time_t modtime
 The time of last modification through a SomeData function.
int bboxstyle
flatpoint centerpoint
unsigned int flags
int iid
 Id of the interface that should handle this data.
charnameid

Detailed Description

Holds an image and a transform.

The image is held from (0,0) to (image_width,image_height) such that, by convention, minx=miny=0, maxx=image_width, and maxy=image_height. However, please note that in class ImageInterface, when an image's width and height need to be found, maxx-minx and maxy-miny are used instead.

Please note that these are not really designed with the idea of editting the contained image, but are more just a container to move around and scale images.

Be forewarned that if previewflag==1, then the preview image will be unlinked (deleted from the harddrive) in the LaxImage destructor. The default for ImageData objects is to not delete (previewflag==0).

Todo:

In addition to have filename ande previewimage, perhaps make allowances for a transformedImageCache to facilitate use of ImagePatchData, for instance..... this is relevant because the ImageInterface has lots of drawing code, and it is easier to use a temp ImageData than an ImagePatchInterface, for instance, figuring out how to draw it itself?

should probably have an option for deferred loading? (not needed if using imlib, which basically does that automatically)

have flag: Don't display image|Use original|Use preview?


Constructor & Destructor Documentation

LaxInterfaces::ImageData::ImageData ( const char nfilename = NULL,
const char npreview = NULL,
int  maxpx = 0,
int  maxpy = 0,
char  delpreview = 0 
)

Constructor. Configures based on the image in nfilename.

If nfilename is not a valid image, then image is NULL, and maxx==maxy==0.

If npreview is passed in, then potentially generate a preview for the image. These previews will not exceed dimensions maxpx by maxpy. Note that If there is already an image at npreview, and it exceeds these bounds, then it is not forced down into the lower bounds. A new preview is generated only when the file doesn't exist.

If delpreview!=0, then for previews that are newly created, they should be deleted when the associated LaxImage is destroyed. See LaxImage for more about that convention.

If npreview, load_image_with_preview() is used, otherwise load_image() is used.

References LoadImage(), and previewflag.

Referenced by duplicate().


Member Function Documentation

void LaxInterfaces::ImageData::dump_in_atts ( LaxFiles::Attribute att,
int  flag,
Laxkit::anObject context 
)
virtual

When the image listed in the attribute cannot be loaded, image is set to NULL, and the width and height attributes are used if present. If the image can be loaded, then width and height as given in the file are curretly ignored, and the actual pixel width and height of the image are used instead.

Reimplemented from LaxInterfaces::SomeData.

References LaxFiles::DoubleAttribute(), LaxFiles::DoubleListAttribute(), Laxkit::PtrStack< T >::e, LaxFiles::full_path_for_file(), LoadImage(), makestr(), Laxkit::PtrStack< T >::n, and previewflag.

void LaxInterfaces::ImageData::Flip ( int  horiz)
virtual

Flip an image vertically or horizontally, but keep the same bounding box.

This does not flip the image data, only the transform. Especially useful when a Displayer has unexpected handedness. Horizontal flipping is provided for completeness (horiz!=0).

Todo:
perhaps this should be in SomeData, since it is not dependent on content
int LaxInterfaces::ImageData::LoadImage ( const char fname,
const char npreview = NULL,
int  maxpx = 0,
int  maxpy = 0,
char  del = 0,
char  fit = 0 
)
virtual

Set the image to the image in fname, if possible. Sets filename regardless.

Return 0 for success, other for error.

If fit!=0, then if the object's bounds are valid and nonzero, fit the image by centering into those bounds, change the object's transform, and update the bounds.

Be forewarned that dump_in_atts() calls this function.

If fname cannot be opened as an image, then maxx and maxy are set to 0, but filename is set to fname, and the previous image is freed. 1 is returned.

If npreview is NULL, then use whatever was in previewfile...?

Pass 1 for del if the preview should be deleted when image is destroyed.

References Laxkit::anObject::dec_count(), LaxInterfaces::SomeData::fitto(), Laxkit::LaxImage::h(), Laxkit::load_image, makestr(), Laxkit::DoubleBBox::setbounds(), and Laxkit::LaxImage::w().

Referenced by dump_in_atts(), duplicate(), ImageData(), LaxInterfaces::ImageInterface::newData(), UsePreview(), and LaxInterfaces::ImageInterface::UseThis().

int LaxInterfaces::ImageData::SetImage ( Laxkit::LaxImage newimage)
virtual

Set the image to this one, dec counting the old one.

Sets minx=miny=0, and maxx=image width and maxy=image height. Clears filename.

Increments count on newimage.

Returns 0 for success, 1 for error.

Todo:
*** implement fit in here too

References Laxkit::anObject::dec_count(), Laxkit::LaxImage::h(), Laxkit::anObject::inc_count(), makestr(), and Laxkit::LaxImage::w().

int LaxInterfaces::ImageData::UsePreview ( const char npreview,
int  maxpx = 0,
int  maxpy = 0,
char  del = 0 
)
virtual

Use a different preview.

This simply calls LoadImage() with the old filename, and the new preview info.

Todo:
Check that this works as intended.

References LoadImage().


Member Data Documentation

char LaxInterfaces::ImageData::previewflag

If previewflag&1, then the preview file path is saved in a dump_out, and is used when loading from a dump_in. On a dump_in, if a preview file is given, then the 1 bit of previewflag gets set to 1.

Referenced by dump_in_atts(), dump_out(), and ImageData().


The documentation for this class was generated from the following files:

Mon Feb 17 2014 11:52:58, Laxkit