2002-02-27 09:59:52 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file GraphicsImageXPM.h
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Baruch Even <baruch.even@writeme.com>
|
2002-07-15 10:19:45 +00:00
|
|
|
* \author Angus Leeming <leeming@lyx.org>
|
2002-02-27 09:59:52 +00:00
|
|
|
*
|
2002-06-28 11:22:56 +00:00
|
|
|
* An instantiation of Image that makes use of libXPM to load and store
|
2002-02-27 09:59:52 +00:00
|
|
|
* the image in memory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICSIMAGEXPM_H
|
|
|
|
#define GRAPHICSIMAGEXPM_H
|
|
|
|
|
|
|
|
#include "GraphicsImage.h"
|
|
|
|
#include XPM_H_LOCATION
|
|
|
|
#include "support/smart_ptr.h"
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace grfx {
|
|
|
|
|
2002-06-28 11:22:56 +00:00
|
|
|
class ImageXPM : public Image
|
2002-02-27 09:59:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Access to this class is through this static method.
|
|
|
|
static ImagePtr newImage();
|
|
|
|
|
|
|
|
/// Return the list of loadable formats.
|
|
|
|
static FormatList loadableFormats();
|
|
|
|
|
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
~ImageXPM();
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Create a copy
|
2002-06-28 11:22:56 +00:00
|
|
|
Image * clone() const;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
Pixmap getPixmap() const;
|
|
|
|
|
|
|
|
/// Get the image width
|
|
|
|
unsigned int getWidth() const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Get the image height
|
|
|
|
unsigned int getHeight() const;
|
|
|
|
|
2002-07-16 21:17:10 +00:00
|
|
|
bool isDrawable() const;
|
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/** Load the image file into memory.
|
2002-06-28 11:22:56 +00:00
|
|
|
* In this case (ImageXPM), the process is blocking.
|
2002-02-27 09:59:52 +00:00
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
void load(string const & filename);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** Generate the pixmap, based on the current state of the
|
|
|
|
* xpm_image_ (clipped, rotated, scaled etc).
|
|
|
|
* Uses the params to decide on color, grayscale etc.
|
|
|
|
* Returns true if the pixmap is created.
|
|
|
|
*/
|
2002-06-28 11:22:56 +00:00
|
|
|
bool setPixmap(Params const & params);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/// Clip the image using params.
|
2002-06-28 11:22:56 +00:00
|
|
|
void clip(Params const & params);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Rotate the image using params.
|
2002-06-28 11:22:56 +00:00
|
|
|
void rotate(Params const & params);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
/// Scale the image using params.
|
2002-06-28 11:22:56 +00:00
|
|
|
void scale(Params const & params);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Access to the class is through newImage() and clone.
|
2002-06-28 11:22:56 +00:00
|
|
|
ImageXPM();
|
2002-02-27 09:59:52 +00:00
|
|
|
///
|
2002-06-28 11:22:56 +00:00
|
|
|
ImageXPM(ImageXPM const &);
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
|
|
/** Contains the data read from file.
|
|
|
|
* This class is a wrapper for a XpmImage struct, but all views
|
|
|
|
* of a single file's data will share the same color table.
|
|
|
|
* This is done by ensuring that the color table contains a "none"
|
|
|
|
* c_color together with g_color and m_color entries for each c_color
|
|
|
|
* entry when it is first stored.
|
|
|
|
*/
|
2002-03-21 17:27:08 +00:00
|
|
|
class Data
|
2002-02-27 09:59:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Default c-tor. Initialise everything to zero.
|
|
|
|
Data();
|
|
|
|
~Data();
|
|
|
|
|
|
|
|
bool empty() const { return width_ == 0; }
|
|
|
|
|
|
|
|
/** Wrap an XpmImage in a nice, clean C++ interface.
|
|
|
|
* Empty the original XpmImage.
|
|
|
|
* Does some analysis of the color table to ensure that
|
|
|
|
* it is suitable for all future eventualities. (See above
|
|
|
|
* description.)
|
|
|
|
*/
|
|
|
|
void reset(XpmImage & image);
|
|
|
|
|
|
|
|
/// Reset the data struct with this data.
|
|
|
|
void resetData(int width, int height, unsigned int * data);
|
|
|
|
|
|
|
|
/** Returns a ptr to an initialised block of memory.
|
|
|
|
* the data is initialised to the color "none" entry.
|
|
|
|
*/
|
|
|
|
unsigned int * initialisedData(int width, int height) const;
|
|
|
|
|
|
|
|
/** Construct an XpmImage from the stored contents.
|
|
|
|
* To pass to XpmCreatePixmapFromXpmImage.
|
|
|
|
* Efficient, because we only copy the ptrs to the structs.
|
|
|
|
*/
|
|
|
|
XpmImage get() const;
|
|
|
|
|
2002-02-27 11:43:04 +00:00
|
|
|
unsigned int width() const { return width_; }
|
|
|
|
unsigned int height() const { return height_; }
|
|
|
|
unsigned int cpp() const { return cpp_; }
|
|
|
|
unsigned int ncolors() const { return ncolors_; }
|
2002-02-27 09:59:52 +00:00
|
|
|
unsigned int const * data() const
|
|
|
|
{ return data_.get(); }
|
|
|
|
XpmColor const * colorTable() const
|
|
|
|
{ return colorTable_.get(); }
|
|
|
|
|
|
|
|
private:
|
2002-02-27 11:43:04 +00:00
|
|
|
unsigned int width_;
|
|
|
|
unsigned int height_;
|
|
|
|
unsigned int cpp_;
|
|
|
|
unsigned int ncolors_;
|
2002-02-27 09:59:52 +00:00
|
|
|
lyx::shared_c_ptr<unsigned int> data_;
|
|
|
|
lyx::shared_c_ptr<XpmColor> colorTable_;
|
|
|
|
|
|
|
|
unsigned int color_none_id() const;
|
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
Data image_;
|
|
|
|
|
|
|
|
/// The pixmap itself.
|
|
|
|
Pixmap pixmap_;
|
|
|
|
|
|
|
|
/// Is the pixmap initialized?
|
|
|
|
enum PixmapStatus {
|
|
|
|
///
|
|
|
|
PIXMAP_UNINITIALISED,
|
|
|
|
///
|
|
|
|
PIXMAP_FAILED,
|
|
|
|
///
|
|
|
|
PIXMAP_SUCCESS
|
|
|
|
};
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2002-02-27 09:59:52 +00:00
|
|
|
PixmapStatus pixmap_status_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace grfx
|
|
|
|
|
|
|
|
#endif // GRAPHICSIMAGEXPM_H
|