Crossfire Client, Branch  R11627
Data Structures | Defines | Functions | Variables
png.c File Reference
#include <config.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <png.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "client-types.h"
#include "client.h"
#include "x11.h"
Include dependency graph for png.c:

Go to the source code of this file.

Data Structures

struct  Pngx_Color_Values

Defines

#define BPP   4
#define BRIGHTNESS_FACTOR   1
#define COLOR_FACTOR   3
#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

int create_and_rescale_image_from_data (Cache_Entry *ce, int pixmap_num, uint8 *rgba_data, int width, int height)
 Takes the pixmap to put the data into, as well as the rgba data (ie, already loaded with png_to_data).
void get_map_image_size (int face, uint8 *w, uint8 *h)
int init_pngx_loader (Display *display)
uint8png_to_data (uint8 *data, int len, uint32 *width, uint32 *height)
int png_to_xpixmap (Display *display, Drawable draw, unsigned char *data, int len, Pixmap *pix, Pixmap *mask, Colormap *cmap, unsigned long *width, unsigned long *height)
long pngx_find_color (Display *display, Colormap *cmap, int red, int green, int blue)
uint8rescale_rgba_data (uint8 *data, int *width, int *height, int scale)
 Takes png data and scales it accordingly.
int rgba_to_xpixmap (Display *display, Drawable draw, uint8 *pixels, Pixmap *pix, Pixmap *mask, Colormap *cmap, unsigned long width, unsigned long height)
static void user_read_data (png_structp png_ptr, png_bytep data, png_size_t length)

Variables

static int bmask = 0
static int bshift = 0
struct Pngx_Color_Valuescolor_values
static int colormap_size
static int colors_alloced = 0
static unsigned char * data_cp
static int data_len
static int data_start
static int gmask = 0
static int gshift = 8
static int need_color_alloc = 0
static int private_cmap = 0
const char * rcsid_x11_png_c = "$Id: png.c 9195 2008-06-01 15:36:42Z anmaster $"
static int rev_bshift = 0
static int rev_gshift = 0
static int rev_rshift = 0
static int rmask = 0
static int rshift = 16
static XImage * ximage

Define Documentation

#define BPP   4

Definition at line 237 of file png.c.

Referenced by rescale_rgba_data().

#define BRIGHTNESS_FACTOR   1

Definition at line 407 of file png.c.

Referenced by pngx_find_color().

#define COLOR_FACTOR   3

Definition at line 406 of file png.c.

Referenced by pngx_find_color().

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

Referenced by png_to_xpixmap().

#define PNGX_NOFILE   1

Definition at line 52 of file png.c.

#define PNGX_OUTOFMEM   2

Definition at line 53 of file png.c.

Referenced by png_to_xpixmap().

#define RATIO   100

Definition at line 233 of file png.c.

Referenced by rescale_rgba_data().


Function Documentation

int create_and_rescale_image_from_data ( Cache_Entry ce,
int  pixmap_num,
uint8 rgba_data,
int  width,
int  height 
)

Takes the pixmap to put the data into, as well as the rgba data (ie, already loaded with png_to_data).

Scales and stores the relevant data into the pixmap structure.

Parameters:
cecan be NULL
pixmap_num
rgba_data
width
height
Returns:
1 on failure.

Definition at line 888 of file png.c.

References BPP, CFG_DM_PIXMAP, CFG_DM_SDL, colormap, CONFIG_DISPLAYMODE, CONFIG_ICONSCALE, CONFIG_MAPSCALE, create_icon_image(), create_map_image(), DEFAULT_IMAGE_SIZE, display, free_pixmap(), PixmapInfo::height, height, PixmapInfo::icon_height, PixmapInfo::icon_image, PixmapInfo::icon_mask, icon_rescale_factor, PixmapInfo::icon_width, Cache_Entry::image_data, image_size, PixmapInfo::map_height, PixmapInfo::map_image, PixmapInfo::map_mask, PixmapInfo::map_width, PixmapInfo::mask, mask, MAX_ICON_SPACES, MAXPIXMAPNUM, PixmapInfo::pixmap, pixmap, pixmaps, redraw_needed, rescale_rgba_data(), rgba_to_xpixmap(), use_config, PixmapInfo::width, width, and win_game.

Referenced by display_newpng(), and finish_face_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void get_map_image_size ( int  face,
uint8 w,
uint8 h 
)
Parameters:
face
w
h

Definition at line 929 of file png.c.

References PixmapInfo::height, PixmapInfo::map_height, map_image_size, PixmapInfo::map_width, MAXPIXMAPNUM, pixmaps, and PixmapInfo::width.

Referenced by mapdata_get_image_size().

Here is the caller graph for this function:

int init_pngx_loader ( Display *  display)

Definition at line 482 of file png.c.

References bmask, bshift, color_values, colormap_size, gmask, gshift, MAX_IMAGE_SIZE, need_color_alloc, rev_bshift, rev_gshift, rev_rshift, rmask, rshift, and ximage.

Referenced by get_root_display().

Here is the caller graph for this function:

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

Definition at line 65 of file png.c.

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

Referenced by display_newpng(), and finish_face_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

int png_to_xpixmap ( Display *  display,
Drawable  draw,
unsigned char *  data,
int  len,
Pixmap *  pix,
Pixmap *  mask,
Colormap *  cmap,
unsigned long *  width,
unsigned long *  height 
)

Definition at line 573 of file png.c.

References bmask, bshift, data_cp, data_len, data_start, gmask, gshift, height, need_color_alloc, PNGX_DATA, pngx_find_color(), PNGX_OUTOFMEM, rev_bshift, rev_gshift, rev_rshift, rmask, rshift, user_read_data(), width, and ximage.

Here is the call graph for this function:

long pngx_find_color ( Display *  display,
Colormap *  cmap,
int  red,
int  green,
int  blue 
)
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 239 of file png.c.

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

Referenced by create_and_rescale_image_from_data().

Here is the call graph for this function:

Here is the caller graph for this function:

int rgba_to_xpixmap ( Display *  display,
Drawable  draw,
uint8 pixels,
Pixmap *  pix,
Pixmap *  mask,
Colormap *  cmap,
unsigned long  width,
unsigned long  height 
)

Definition at line 811 of file png.c.

References bmask, bshift, gmask, gshift, height, need_color_alloc, pngx_find_color(), rev_bshift, rev_gshift, rev_rshift, rmask, rshift, width, and ximage.

Referenced by create_and_rescale_image_from_data().

Here is the call graph for this function:

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]

Definition at line 59 of file png.c.

References data_cp, and data_start.

Referenced by png_to_data(), and png_to_xpixmap().

Here is the caller graph for this function:


Variable Documentation

int bmask = 0 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int bshift = 0 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int colormap_size [static]

Definition at line 400 of file png.c.

Referenced by init_pngx_loader(), and pngx_find_color().

int colors_alloced = 0 [static]

Definition at line 400 of file png.c.

Referenced by pngx_find_color().

unsigned char* data_cp [static]

Definition at line 56 of file png.c.

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

int data_len [static]

Definition at line 57 of file png.c.

Referenced by png_to_data(), and png_to_xpixmap().

int data_start [static]

Definition at line 57 of file png.c.

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

int gmask = 0 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int gshift = 8 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int need_color_alloc = 0 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int private_cmap = 0 [static]

Definition at line 400 of file png.c.

Referenced by pngx_find_color().

const char* rcsid_x11_png_c = "$Id: png.c 9195 2008-06-01 15:36:42Z anmaster $"

Definition at line 1 of file png.c.

int rev_bshift = 0 [static]

Definition at line 399 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int rev_gshift = 0 [static]

Definition at line 399 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int rev_rshift = 0 [static]

Definition at line 399 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int rmask = 0 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

int rshift = 16 [static]

Definition at line 398 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().

XImage* ximage [static]

Definition at line 397 of file png.c.

Referenced by init_pngx_loader(), png_to_xpixmap(), and rgba_to_xpixmap().