Crossfire Client, Branch  R11627
Defines | Functions | Variables
png.c File Reference

Functions for manipulating graphics in the GTK-V2 client. More...

#include <config.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <png.h>
#include <client-types.h>
#include <client.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
Include dependency graph for png.c:

Go to the source code of this file.

Defines

#define BPP   4
#define MAX_IMAGE_HEIGHT   1024
#define MAX_IMAGE_WIDTH   1024
#define PNGX_DATA   3
#define PNGX_NOFILE   1
#define PNGX_OUTOFMEM   2
#define RATIO   100

Functions

uint8png_to_data (uint8 *data, int len, uint32 *width, uint32 *height)
int png_to_gdkpixmap (GdkWindow *window, uint8 *data, int len, GdkPixmap **pix, GdkBitmap **mask, GdkColormap *colormap)
uint8rescale_rgba_data (uint8 *data, int *width, int *height, int scale)
 Takes png data and scales it accordingly.
int rgba_to_gdkpixbuf (uint8 *data, int width, int height, GdkPixbuf **pix)
 Takes data that has already been converted into RGBA format (via png_to_data above perhaps) and creates a GdkPixbuf of it.
int rgba_to_gdkpixmap (GdkWindow *window, uint8 *data, int width, int height, GdkPixmap **pix, GdkBitmap **mask, GdkColormap *colormap)
 Takes data that has already been converted into RGBA format (via png_to_data above perhaps) and creates a GdkPixmap and GdkBitmap out of it.
static void user_read_data (png_structp png_ptr, png_bytep data, png_size_t length)

Variables

static uint8data_cp
static int data_len
static int data_start
const char *const rcsid_gtk2_png_c = "$Id: png.c 9193 2008-06-01 14:26:32Z anmaster $"
guchar rgb [512 *512 *3]
 Make this especially big to support larger images in the future.

Detailed Description

Functions for manipulating graphics in the GTK-V2 client.

Definition in file png.c.


Define Documentation

#define BPP   4

Definition at line 237 of file png.c.

Referenced by rescale_rgba_data().

#define MAX_IMAGE_HEIGHT   1024

Definition at line 236 of file png.c.

Referenced by rescale_rgba_data().

#define MAX_IMAGE_WIDTH   1024

Definition at line 235 of file png.c.

Referenced by rescale_rgba_data().

#define PNGX_DATA   3

Definition at line 57 of file png.c.

Referenced by png_to_gdkpixmap().

#define PNGX_NOFILE   1

Definition at line 55 of file png.c.

#define PNGX_OUTOFMEM   2

Definition at line 56 of file png.c.

Referenced by png_to_gdkpixmap().

#define RATIO   100

Definition at line 233 of file png.c.

Referenced by rescale_rgba_data().


Function Documentation

uint8* png_to_data ( uint8 data,
int  len,
uint32 width,
uint32 height 
)
Parameters:
*data
len
*width
*height

Definition at line 80 of file png.c.

References data_cp, data_len, data_start, height, LOG(), LOG_CRITICAL, and user_read_data().

Here is the call graph for this function:

int png_to_gdkpixmap ( GdkWindow *  window,
uint8 data,
int  len,
GdkPixmap **  pix,
GdkBitmap **  mask,
GdkColormap *  colormap 
)
Parameters:
*window
*data
len
**pix
**mask
*colormap

Definition at line 544 of file png.c.

References data_cp, data_len, data_start, height, PNGX_DATA, PNGX_OUTOFMEM, rgb, user_read_data(), and width.

Here is the call graph for this function:

uint8* rescale_rgba_data ( uint8 data,
int *  width,
int *  height,
int  scale 
)

Takes png data and scales it accordingly.

This function is based on pnmscale, but has been modified to support alpha channel - instead of blending the alpha channel, it takes the most opaque value - blending it is not likely to give sane results IMO - for any image that has transparent information, if we blended the alpha, the result would be the edges of that region being partially transparent. This function has also been re-written to use more static data - in the case of the client, it will be called thousands of times, so it doesn't make sense to free the data and then re-allocate it.

For pixels that are fully transparent, the end result after scaling is they will be tranparent black. This is a needed effect for blending to work properly.

This function returns a new pointer to the scaled image data. This is malloc'd data, so should be freed at some point to prevent leaks. This function does not modify the data passed to it - the caller is responsible for freeing it if it is no longer needed.

function arguments:

Parameters:
*dataPNG data - this is any 4 byte per pixel data, in RGBA format.
*widthSource width modified to contain the new image size.
*heightSource height modified to contain the new image size.
scalePercentage size that new image should be. 100 is a same size image - values larger than 100 will result in zoom, values less than 100 will result in a shrinkage.

Definition at line 267 of file png.c.

References BPP, LOG(), LOG_CRITICAL, MAX_IMAGE_HEIGHT, MAX_IMAGE_WIDTH, RATIO, and width.

Here is the call graph for this function:

int rgba_to_gdkpixbuf ( uint8 data,
int  width,
int  height,
GdkPixbuf **  pix 
)

Takes data that has already been converted into RGBA format (via png_to_data above perhaps) and creates a GdkPixbuf of it.

Parameters:
*data
width
height
**pix
Returns:
Non-zero on error (currently, no checks for error conditions is done

Definition at line 500 of file png.c.

References height, TRUE, and width.

Referenced by create_icon_image().

Here is the caller graph for this function:

int rgba_to_gdkpixmap ( GdkWindow *  window,
uint8 data,
int  width,
int  height,
GdkPixmap **  pix,
GdkBitmap **  mask,
GdkColormap *  colormap 
)

Takes data that has already been converted into RGBA format (via png_to_data above perhaps) and creates a GdkPixmap and GdkBitmap out of it.

Parameters:
*window
*data
width
height
**pix
**mask
*colormap
Returns:
Non-zero on error (currently, no checks for error conditions is done

Definition at line 441 of file png.c.

References height, and width.

Referenced by create_icon_image(), and create_map_image().

Here is the caller graph for this function:

static void user_read_data ( png_structp  png_ptr,
png_bytep  data,
png_size_t  length 
) [static]
Parameters:
png_ptr
data
length

Definition at line 68 of file png.c.

References data_cp, and data_start.

Referenced by png_to_data(), and png_to_gdkpixmap().

Here is the caller graph for this function:


Variable Documentation

uint8* data_cp [static]

Definition at line 59 of file png.c.

Referenced by png_to_data(), png_to_gdkpixmap(), and user_read_data().

int data_len [static]

Definition at line 60 of file png.c.

Referenced by png_to_data(), and png_to_gdkpixmap().

int data_start [static]

Definition at line 60 of file png.c.

Referenced by png_to_data(), png_to_gdkpixmap(), and user_read_data().

const char* const rcsid_gtk2_png_c = "$Id: png.c 9193 2008-06-01 14:26:32Z anmaster $"

Definition at line 1 of file png.c.

guchar rgb[512 *512 *3]

Make this especially big to support larger images in the future.

Definition at line 425 of file png.c.

Referenced by png_to_gdkpixmap().