Crossfire Client, Trunk
png.c File Reference
#include "client.h"
#include <errno.h>
#include <gtk/gtk.h>
#include <png.h>
+ Include dependency graph for png.c:

Go to the source code of this file.

Macros

#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

guint8 * png_to_data (guint8 *data, int len, guint32 *width, guint32 *height)
 
guint8 * rescale_rgba_data (guint8 *data, int *width, int *height, int scale)
 
cairo_surface_t * rgba_to_cairo_surface (guint8 *data, int width, int height)
 
GdkPixbuf * rgba_to_gdkpixbuf (guint8 *data, int width, int height)
 
static void user_read_data (png_structp png_ptr, png_bytep data, png_size_t length)
 

Variables

static guint8 * data_cp
 
static int data_len
 
static int data_start
 

Detailed Description

Functions for manipulating graphics in the GTK-V2 client.

Definition in file png.c.

Macro Definition Documentation

◆ BPP

#define BPP   4

Definition at line 205 of file png.c.

◆ MAX_IMAGE_HEIGHT

#define MAX_IMAGE_HEIGHT   1024

Definition at line 204 of file png.c.

◆ MAX_IMAGE_WIDTH

#define MAX_IMAGE_WIDTH   1024

Definition at line 203 of file png.c.

◆ PNGX_DATA

#define PNGX_DATA   3

Definition at line 32 of file png.c.

◆ PNGX_NOFILE

#define PNGX_NOFILE   1

Definition at line 30 of file png.c.

◆ PNGX_OUTOFMEM

#define PNGX_OUTOFMEM   2

Definition at line 31 of file png.c.

◆ RATIO

#define RATIO   100

Definition at line 201 of file png.c.

Function Documentation

◆ png_to_data()

guint8* png_to_data ( guint8 *  data,
int  len,
guint32 *  width,
guint32 *  height 
)

Definition at line 49 of file png.c.

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

Referenced by display_newpng(), and finish_face_cmd().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rescale_rgba_data()

guint8* rescale_rgba_data ( guint8 *  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 g_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 235 of file png.c.

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

Referenced by create_and_rescale_image_from_data(), and map_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rgba_to_cairo_surface()

cairo_surface_t* rgba_to_cairo_surface ( guint8 *  data,
int  width,
int  height 
)

Create a Cairo surface for the given RGBA data.

Definition at line 440 of file png.c.

References height, and width.

Referenced by create_map_image().

+ Here is the caller graph for this function:

◆ rgba_to_gdkpixbuf()

GdkPixbuf* rgba_to_gdkpixbuf ( guint8 *  data,
int  width,
int  height 
)

Create a GdkPixbuf for the given RGBA data.

Definition at line 414 of file png.c.

References height, and width.

Referenced by create_full_icon_image(), and create_icon_image().

+ Here is the caller graph for this function:

◆ user_read_data()

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 43 of file png.c.

References data_cp, and data_start.

Referenced by png_to_data().

+ Here is the caller graph for this function:

Variable Documentation

◆ data_cp

guint8* data_cp
static

Definition at line 34 of file png.c.

Referenced by png_to_data(), and user_read_data().

◆ data_len

int data_len
static

Definition at line 35 of file png.c.

Referenced by png_to_data(), and script_watch().

◆ data_start

int data_start
static

Definition at line 35 of file png.c.

Referenced by png_to_data(), and user_read_data().