Back to index

nux  3.0.0
Public Member Functions | Private Attributes
nux::GdkGraphics Class Reference

#include <GdkGraphics.h>

List of all members.

Public Member Functions

 GdkGraphics ()
 GdkGraphics (const char *filename)
 GdkGraphics (GdkPixbuf *pixbuf)
 ~GdkGraphics ()
bool LoadImage (const char *filename)
NBitmapDataGetBitmap () const

Private Attributes

GdkPixbuf * pixbuf_

Detailed Description

Definition at line 30 of file GdkGraphics.h.


Constructor & Destructor Documentation

Definition at line 36 of file GdkGraphics.cpp.

    : pixbuf_(0)
  {
  }
nux::GdkGraphics::GdkGraphics ( const char *  filename) [explicit]

Definition at line 46 of file GdkGraphics.cpp.

    : pixbuf_(0)
  {
    LoadImage(filename);
  }

Here is the call graph for this function:

nux::GdkGraphics::GdkGraphics ( GdkPixbuf *  pixbuf) [explicit]

Definition at line 41 of file GdkGraphics.cpp.

    : pixbuf_(pixbuf)
  {
  }

Definition at line 52 of file GdkGraphics.cpp.

  {
    if (pixbuf_)
      g_object_unref(pixbuf_);
  }

Member Function Documentation

Definition at line 76 of file GdkGraphics.cpp.

  {
    if (!pixbuf_)
    {
      LOG_WARN(logger) << "No pixbuf loaded";
      return 0;
    }

    unsigned int width = gdk_pixbuf_get_width(pixbuf_);
    unsigned int height = gdk_pixbuf_get_height(pixbuf_);
    int channels = gdk_pixbuf_get_n_channels(pixbuf_);
    int src_pitch = gdk_pixbuf_get_rowstride(pixbuf_);

    NTextureData* texture = NULL;

    if (channels == 4)
    {
      texture = new NTextureData(BITFMT_R8G8B8A8, width, height, 1);
    }
    else if (channels == 3)
    {
      texture = new NTextureData(BITFMT_R8G8B8, width, height, 1);
    }
    else if (channels == 1)
    {
      texture = new NTextureData(BITFMT_A8, width, height, 1);
    }
    else
    {
      LOG_ERROR(logger) << __func__ << ": Invalid number of channels";
      return 0;
    }

    ImageSurface& image_surface = texture->GetSurface(0);
    unsigned char* dest = image_surface.GetPtrRawData();
    int dest_pitch = image_surface.GetPitch();

    guchar* src = gdk_pixbuf_get_pixels(pixbuf_);

    for (unsigned int i = 0; i < height; ++i)
    {
      Memcpy(dest, src + i*src_pitch, width*channels);
      dest += dest_pitch;
    }
    return texture;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nux::GdkGraphics::LoadImage ( const char *  filename)

Definition at line 58 of file GdkGraphics.cpp.

  {
    if (pixbuf_)
      g_object_unref(pixbuf_);

    GError* error = 0;
    pixbuf_ = gdk_pixbuf_new_from_file(filename, &error);

    if (error)
    {
      LOG_ERROR(logger) << error->message;
      g_error_free(error);
      return false;
    }

    return true;
  }

Here is the caller graph for this function:


Member Data Documentation

GdkPixbuf* nux::GdkGraphics::pixbuf_ [private]

Definition at line 45 of file GdkGraphics.h.


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