JX Application Framework
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
JXImage Class Reference

#include <JXImage.h>

Inheritance diagram for JXImage:
[legend]

Public Types

enum  State {
  kLocalStorage ,
  kRemoteStorage
}
 
- Public Types inherited from JImage
enum  FileType {
  kUnknownType ,
  kGIFType ,
  kPNGType ,
  kJPEGType ,
  kXPMType ,
  kXBMType
}
 

Public Member Functions

 JXImage (JXDisplay *display, const JCoordinate width, const JCoordinate height, const JColorID initColor=kJXTransparentColor, const JSize depth=0, const State initState=kRemoteStorage)
 
 JXImage (JXDisplay *display, Drawable source)
 
 JXImage (JXDisplay *display, Drawable source, const JRect &rect)
 
 JXImage (JXDisplay *display, const JConstBitmap &bitmap, const JColorID foreColor=kJXTransparentColor, const JColorID backColor=kJXTransparentColor, const JSize depth=0)
 
 JXImage (JXDisplay *display, const JXPM &data)
 
 JXImage (const JXImage &source)
 
 JXImage (const JXImage &source, const JRect &rect)
 
 ~JXImage () override
 
JError WriteXPM (const JString &fileName) const
 
virtual JXImageCopy () const
 
JXDisplayGetDisplay () const
 
JSize GetDepth () const
 
bool HasMask () const
 
bool GetMask (JImageMask **mask) const override
 
bool GetMask (JXImageMask **mask) const
 
void SetMask (JXImageMask *mask)
 
void ClearMask ()
 
void Draw (const Drawable drawable, JXGC *gc, const JRect &srcRect, const JRect &destRect) const
 
JXImagePainterCreatePainter ()
 
JColorID GetColor (const JCoordinate x, const JCoordinate y) const override
 
void SetColor (const JCoordinate x, const JCoordinate y, const JColorID color) override
 
State GetDefaultState () const
 
void SetDefaultState (const State state)
 
void ConvertToDefaultState ()
 
State GetCurrentState () const
 
void ConvertToLocalStorage ()
 
void ConvertToRemoteStorage ()
 
Pixmap CreatePixmap () const
 
XImage * CreateXImage () const
 
unsigned long GetSystemColor (const JColorID color) const override
 
unsigned long GetSystemColor (const JCoordinate x, const JCoordinate y) const override
 
- Public Member Functions inherited from JImage
 JImage (const JCoordinate width, const JCoordinate height, JColorManager *colorManager)
 
virtual ~JImage ()
 
JCoordinate GetWidth () const
 
JCoordinate GetHeight () const
 
JRect GetBounds () const
 
JColorManagerGetColorManager () const
 
JError WriteGIF (const JString &fileName, const bool compressColorsToFit, const bool interlace=false) const
 
JError WritePNG (const JString &fileName, const bool useTrueColor=true, const bool compressColorsToFit=false, const bool interlace=false) const
 
JError WriteJPEG (const JString &fileName, const bool interlace=false, const int quality=-1) const
 
- Public Member Functions inherited from JBroadcaster
 JBroadcaster ()
 
virtual ~JBroadcaster ()
 
JBroadcasteroperator= (const JBroadcaster &source)
 
bool HasSenders () const
 
JSize GetSenderCount () const
 
bool HasRecipients () const
 
JSize GetRecipientCount () const
 
virtual JString ToString () const
 
template<class T >
void ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f)
 

Static Public Member Functions

static JError CreateFromFile (JXDisplay *display, const JString &fileName, JXImage **image)
 
static JError CreateFromGIF (JXDisplay *display, const JString &fileName, JXImage **image)
 
static JError CreateFromPNG (JXDisplay *display, const JString &fileName, JXImage **image)
 
static JError CreateFromJPEG (JXDisplay *display, const JString &fileName, JXImage **image)
 
static JError CreateFromXPM (JXDisplay *display, const JXPM &data, JXImage **image)
 
static JError CreateFromXPM (JXDisplay *display, const JString &fileName, JXImage **image)
 
- Static Public Member Functions inherited from JImage
static FileType GetFileType (const JString &fileName)
 

Protected Member Functions

XImage * GetImage () const
 
void ConvertToImage () const
 
Pixmap GetPixmap () const
 
void ConvertToPixmap () const
 
const JXGCGetGC () const
 
void ForcePrivateGC ()
 
void SetImageData (const JSize colorCount, const JColorID *colorTable, unsigned short **imageData, const bool hasMask, const unsigned long maskColor) override
 
void PrepareForImageData () override
 
void ImageDataFinished () override
 
 JXImage (const Pixmap bitmap, const JCoordinate width, const JCoordinate height, JXDisplay *display)
 
- Protected Member Functions inherited from JImage
 JImage (const JImage &source)
 
void SetDimensions (const JCoordinate width, const JCoordinate height)
 
JError ReadGIF (const JString &fileName)
 
JError ReadPNG (const JString &fileName)
 
JError ReadJPEG (const JString &fileName)
 
void ReadFromJXPM (const JXPM &pixmap)
 
- Protected Member Functions inherited from JBroadcaster
 JBroadcaster (const JBroadcaster &source)
 
void ListenTo (const JBroadcaster *sender)
 
void StopListening (const JBroadcaster *sender)
 
void ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember)
 
void StopListening (const JBroadcaster *sender, const std::type_info &messageType)
 
template<class T >
void Send (JBroadcaster *recipient, const T &message)
 
template<class T >
void Broadcast (const T &message)
 
virtual void Receive (JBroadcaster *sender, const Message &message)
 
void SendWithFeedback (JBroadcaster *recipient, Message *message)
 
void BroadcastWithFeedback (Message *message)
 
virtual void ReceiveWithFeedback (JBroadcaster *sender, Message *message)
 
virtual void ReceiveGoingAway (JBroadcaster *sender)
 

Friends

class JXWindow
 
class JXImagePainter
 

Additional Inherited Members

- Static Public Attributes inherited from JImage
static const JUtf8BytekUnknownFileType = "UnknownFileType::JImage"
 
static const JUtf8BytekFileIsNotGIF = "FileIsNotGIF::JImage"
 
static const JUtf8BytekGIFNotAvailable = "GIFNotAvailable::JImage"
 
static const JUtf8BytekFileIsNotPNG = "FileIsNotPNG::JImage"
 
static const JUtf8BytekPNGNotAvailable = "PNGNotAvailable::JImage"
 
static const JUtf8BytekFileIsNotJPEG = "FileIsNotJPEG::JImage"
 
static const JUtf8BytekJPEGNotAvailable = "JPEGNotAvailable::JImage"
 
static const JUtf8BytekFileIsNotXPM = "FileIsNotXPM::JImage"
 
static const JUtf8BytekXPMNotAvailable = "XPMNotAvailable::JImage"
 
static const JUtf8BytekFileIsNotXBM = "FileIsNotXBM::JImage"
 
static const JUtf8BytekTooManyColors = "TooManyColors::JImage"
 
- Static Protected Member Functions inherited from JImage
static JError AllocateImageData (const JCoordinate w, const JCoordinate h, unsigned short **data, unsigned short ***cols)
 

Detailed Description

Class representing an offscreen drawable and XImage.  These are combined
into a single class because the issue of where the image is stored should
be hidden, for convenience.  It is, however, *very* expensive to convert
an image between a drawable (remote storage) and an XImage (local storage).
Therefore, do not interleave GetColor()/SetColor() with drawing commands
(via JXImagePainter).  Collect them into blocks of calls.  (This is usually
what one does anyway.)

Planned features:
    For image read from file: store raw rgb values separately and
        then rewrite JPSPrinter to ask for rgb instead of JColorID.
Image format functions separated out to allow smarter linking.
JPEG functions separated out to allow smarter linking.
PNG functions separated out to allow smarter linking.

Member Enumeration Documentation

◆ State

Enumerator
kLocalStorage 
kRemoteStorage 

Constructor & Destructor Documentation

◆ JXImage() [1/8]

JXImage::JXImage ( JXDisplay display,
const JCoordinate  width,
const JCoordinate  height,
const JColorID  origInitColor = kJXTransparentColor,
const JSize  depth = 0,
const State  initState = kRemoteStorage 
)

initState == kLocalStorage accepts origInitColor=0

◆ JXImage() [2/8]

JXImage::JXImage ( JXDisplay display,
Drawable  source 
)

We assume that the given JXColorManager is the colormap used by the given Drawable. (X does not seem to provide a way to check this because XGetWindowAttributes() only works on a Window, not a Pixmap.) This means that we assume that all the colors used by the Drawable have been registered with the JXColorManager. If we didn't assume this, we would have to call XQueryColor for every pixel and that would be really slow.

This routine can still be slow because we have to analyze the given Drawable and register all the colors that are used.

◆ JXImage() [3/8]

JXImage::JXImage ( JXDisplay display,
Drawable  source,
const JRect rect 
)

◆ JXImage() [4/8]

JXImage::JXImage ( JXDisplay display,
const JConstBitmap bitmap,
const JColorID  foreColor = kJXTransparentColor,
const JColorID  backColor = kJXTransparentColor,
const JSize  depth = 0 
)

◆ JXImage() [5/8]

JXImage::JXImage ( JXDisplay display,
const JXPM data 
)

This only works for XPM's with up to 256 colors.

◆ JXImage() [6/8]

JXImage::JXImage ( const JXImage source)

◆ JXImage() [7/8]

JXImage::JXImage ( const JXImage source,
const JRect rect 
)

◆ ~JXImage()

JXImage::~JXImage ( )
override

◆ JXImage() [8/8]

JXImage::JXImage ( const Pixmap  bitmap,
const JCoordinate  width,
const JCoordinate  height,
JXDisplay display 
)
protected

This is used by JXImageMask. The depth is assumed to be 1.

Member Function Documentation

◆ ClearMask()

void JXImage::ClearMask ( )

◆ ConvertToDefaultState()

void JXImage::ConvertToDefaultState ( )

◆ ConvertToImage()

void JXImage::ConvertToImage ( ) const
protected

◆ ConvertToLocalStorage()

void JXImage::ConvertToLocalStorage ( )
inline

Convert the image to local storage on the client side.

◆ ConvertToPixmap()

void JXImage::ConvertToPixmap ( ) const
protected

◆ ConvertToRemoteStorage()

void JXImage::ConvertToRemoteStorage ( )
inline

Convert the image to remote storage on the server side.

◆ Copy()

JXImage * JXImage::Copy ( ) const
virtual

We can't support operator= because there are derived classes.

Reimplemented in JXImageMask.

◆ CreateFromFile()

JError JXImage::CreateFromFile ( JXDisplay display,
const JString fileName,
JXImage **  image 
)
static

Returns an error if the file does not contain a recognizable image format.

◆ CreateFromGIF()

JError JXImage::CreateFromGIF ( JXDisplay display,
const JString fileName,
JXImage **  image 
)
static

Returns an error if the file does not contain a GIF.

◆ CreateFromJPEG()

JError JXImage::CreateFromJPEG ( JXDisplay display,
const JString fileName,
JXImage **  image 
)
static

Returns an error if the file does not contain a JPEG.

◆ CreateFromPNG()

JError JXImage::CreateFromPNG ( JXDisplay display,
const JString fileName,
JXImage **  image 
)
static

Returns an error if the file does not contain a PNG.

◆ CreateFromXPM() [1/2]

JError JXImage::CreateFromXPM ( JXDisplay display,
const JString fileName,
JXImage **  image 
)
static

Returns an error if the file does not contain an XPM.

◆ CreateFromXPM() [2/2]

JError JXImage::CreateFromXPM ( JXDisplay display,
const JXPM data,
JXImage **  image 
)
static

◆ CreatePainter()

JXImagePainter * JXImage::CreatePainter ( )

◆ CreatePixmap()

Pixmap JXImage::CreatePixmap ( ) const

The caller is responsible for calling XFreePixmap().

◆ CreateXImage()

XImage * JXImage::CreateXImage ( ) const

The caller is responsible for calling XDestroyImage().

◆ Draw()

void JXImage::Draw ( const Drawable  drawable,
JXGC gc,
const JRect srcRect,
const JRect destRect 
) const

Copy the specified portion of the image, centered within destRect.

◆ ForcePrivateGC()

void JXImage::ForcePrivateGC ( )
protected

◆ GetColor()

JColorID JXImage::GetColor ( const JCoordinate  x,
const JCoordinate  y 
) const
overridevirtual

Implements JImage.

◆ GetCurrentState()

JXImage::State JXImage::GetCurrentState ( ) const

◆ GetDefaultState()

JXImage::State JXImage::GetDefaultState ( ) const
inline

◆ GetDepth()

JSize JXImage::GetDepth ( ) const
inline

◆ GetDisplay()

JXDisplay * JXImage::GetDisplay ( ) const
inline

◆ GetGC()

const JXGC * JXImage::GetGC ( ) const
protected

◆ GetImage()

XImage * JXImage::GetImage ( ) const
inlineprotected

◆ GetMask() [1/2]

bool JXImage::GetMask ( JImageMask **  mask) const
overridevirtual

Implements JImage.

◆ GetMask() [2/2]

bool JXImage::GetMask ( JXImageMask **  mask) const
inline

◆ GetPixmap()

Pixmap JXImage::GetPixmap ( ) const
inlineprotected

◆ GetSystemColor() [1/2]

unsigned long JXImage::GetSystemColor ( const JColorID  color) const
overridevirtual

Implements JImage.

◆ GetSystemColor() [2/2]

unsigned long JXImage::GetSystemColor ( const JCoordinate  x,
const JCoordinate  y 
) const
overridevirtual

Implements JImage.

◆ HasMask()

bool JXImage::HasMask ( ) const
inline

◆ ImageDataFinished()

void JXImage::ImageDataFinished ( )
overrideprotectedvirtual

Implements JImage.

◆ PrepareForImageData()

void JXImage::PrepareForImageData ( )
overrideprotectedvirtual

Implements JImage.

◆ SetColor()

void JXImage::SetColor ( const JCoordinate  x,
const JCoordinate  y,
const JColorID  color 
)
overridevirtual

In the long run, it is usually more efficient to convert to an XImage once, rather than sending a large number of XDrawPoint() messages to the server.

Implements JImage.

◆ SetDefaultState()

void JXImage::SetDefaultState ( const State  state)
inline

◆ SetImageData()

void JXImage::SetImageData ( const JSize  colorCount,
const JColorID colorTable,
unsigned short **  imageData,
const bool  hasMask,
const unsigned long  maskColor 
)
overrideprotectedvirtual

colorTable[ imageData[x][y] ] is the JColorID for pixel (x,y)

colorTable[ maskColor ] is the transparent color, which shouldn't be used

Implements JImage.

◆ SetMask()

void JXImage::SetMask ( JXImageMask mask)

◆ WriteXPM()

JError JXImage::WriteXPM ( const JString fileName) const

Returns an error if we are unable to create the specified file.

Friends And Related Symbol Documentation

◆ JXImagePainter

friend class JXImagePainter
friend

◆ JXWindow

friend class JXWindow
friend

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