Crossfire Client, Trunk  R20507
Data Structures | Macros | Functions | Variables
image.c File Reference

Contains image related functions at a high level. More...

#include "client.h"
#include <ctype.h>
#include <glib/gstdio.h>
#include "external.h"
Include dependency graph for image.c:

Go to the source code of this file.

Data Structures

struct  FD_Cache
 
struct  Image_Cache
 

Macros

#define IMAGE_HASH   8192
 
#define ROTATE_RIGHT(c)   if ((c) & 01) (c) = ((c) >>1) + 0x80000000; else (c) >>= 1;
 

Functions

static void cache_newpng (int face, guint8 *buf, int buflen, int setnum, Cache_Entry **ce)
 Helper for display_newpng, implements the caching of the image to disk. More...
 
void display_newpng (int face, guint8 *buf, int buflen, int setnum)
 This function is called when the server has sent us the actual png data for an image. More...
 
void Face2Cmd (guint8 *data, int len)
 We only get here if the server believes we are caching images. More...
 
void finish_face_cmd (int pnum, guint32 checksum, int has_sum, char *face, int faceset)
 This is common for all the face commands (face2, face1, face). More...
 
void get_image_info (guint8 *data, int len)
 Takes the data from a replyinfo image_info and breaks it down. More...
 
void get_image_sums (char *data, int len)
 This gets a block of checksums from the server. More...
 
void Image2Cmd (guint8 *data, int len)
 
static Cache_Entryimage_add_hash (char *imagename, char *filename, guint32 checksum, guint32 ispublic)
 Add a hash entry. More...
 
static Cache_Entryimage_find_cache_entry (char *imagename, guint32 checksum, int has_sum)
 This finds and returns the Cache_Entry of the image that matches name and checksum if has_sum is set. More...
 
static gint32 image_find_hash (char *str)
 This function returns an index into the image_cache for a matching entry, -1 if no match is found. More...
 
static guint32 image_hash_name (char *str, int tablesize)
 This function is basically hasharch from the server, common/arch.c a few changes - first, we stop processing when we reach the first . More...
 
static void image_process_line (char *line, guint32 ispublic)
 Process a line from the bmaps.client file. More...
 
static void image_remove_hash (char *imagename, Cache_Entry *ce)
 
void init_common_cache_data (void)
 
static int load_image (char *filename, guint8 *data, int *len, guint32 *csum)
 Given a filename, this tries to load the data. More...
 
void requestface (int pnum, char *facename)
 
void reset_image_cache_data (void)
 We can now connect to different servers, so we need to clear out any old images. More...
 

Variables

Face_Information face_info
 
char facecachedir [MAX_BUF]
 
static char * facetoname [MAXPIXMAPNUM]
 This holds the name we recieve with the 'face' command so we know what to save it as when we actually get the face. More...
 
struct FD_Cache fd_cache [MAX_FACE_SETS]
 
struct Image_Cache image_cache [IMAGE_HASH]
 

Detailed Description

Contains image related functions at a high level.

It mostly deals with the caching of the images, processing the image commands from the server, etc.

Definition in file image.c.

Macro Definition Documentation

#define IMAGE_HASH   8192

Definition at line 167 of file image.c.

Referenced by image_add_hash(), image_find_hash(), and init_common_cache_data().

#define ROTATE_RIGHT (   c)    if ((c) & 01) (c) = ((c) >>1) + 0x80000000; else (c) >>= 1;

Definition at line 33 of file image.c.

Referenced by cache_newpng(), and load_image().

Function Documentation

static void cache_newpng ( int  face,
guint8 *  buf,
int  buflen,
int  setnum,
Cache_Entry **  ce 
)
static

Helper for display_newpng, implements the caching of the image to disk.

Definition at line 570 of file image.c.

References cache_dir, Face_Information_struct::facesets, facetoname, Cache_Entry::filename, image_add_hash(), LOG(), LOG_WARNING, MAX_BUF, MAX_FACE_SETS, FaceSets_struct::prefix, and ROTATE_RIGHT.

Referenced by display_newpng().

Here is the call graph for this function:

Here is the caller graph for this function:

void display_newpng ( int  face,
guint8 *  buf,
int  buflen,
int  setnum 
)

This function is called when the server has sent us the actual png data for an image.

If caching, we need to write this data to disk (this is handled in the function cache_newpng).

Definition at line 669 of file image.c.

References cache_newpng(), CONFIG_CACHE, create_and_rescale_image_from_data(), facetoname, height, LOG(), LOG_ERROR, LOG_WARNING, png_to_data(), use_config, and width.

Referenced by Image2Cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void Face2Cmd ( guint8 *  data,
int  len 
)

We only get here if the server believes we are caching images.

We rely on the fact that the server will only send a face command for a particular number once - at current time, we have no way of knowing if we have already received a face for a particular number.

Definition at line 526 of file image.c.

References checksum, CONFIG_CACHE, finish_face_cmd(), GetInt_String(), GetShort_String(), LOG(), LOG_WARNING, and use_config.

Here is the call graph for this function:

void finish_face_cmd ( int  pnum,
guint32  checksum,
int  has_sum,
char *  face,
int  faceset 
)

This is common for all the face commands (face2, face1, face).

For face1 and face commands, faceset should always be zero. for face commands, has_sum and checksum will be zero. pnum is the face number, while face is the name. We actually don't care what the set it - it could be useful right now, but in the current caching scheme, we look through all the facesets for the image and if the checksum matches, we assume we have match. This approach makes sure that we don't have to store the same image multiple times simply because the set number may be different.

Definition at line 429 of file image.c.

References associate_cache_entry(), cache_dir, create_and_rescale_image_from_data(), Cache_Entry::filename, Cache_Entry::image_data, image_find_cache_entry(), image_remove_hash(), Cache_Entry::ispublic, load_image(), LOG(), LOG_WARNING, png_to_data(), and requestface().

Referenced by Face2Cmd(), and get_image_sums().

Here is the call graph for this function:

Here is the caller graph for this function:

void get_image_info ( guint8 *  data,
int  len 
)

Takes the data from a replyinfo image_info and breaks it down.

The info contained is the checkums, number of images, and faceset information. It stores this data into the face_info structure. Since we know data is null terminated, we can use the strchr operations with safety. In each block, we find the newline - if we find one, we presume the data is good, and update the face_info accordingly. if we don't find a newline, we return.

Definition at line 706 of file image.c.

References Face_Information_struct::bmaps_checksum, FaceSets_struct::comment, cs_print_string(), csocket, draw_ext_info(), FaceSets_struct::extension, Face_Information_struct::faceset, Face_Information_struct::facesets, FaceSets_struct::fallback, ClientSocket::fd, FaceSets_struct::fullname, Face_Information_struct::have_faceset_info, LOG(), LOG_WARNING, MAX_BUF, MAX_FACE_SETS, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_CONFIG, NDI_RED, Face_Information_struct::num_images, FaceSets_struct::prefix, replyinfo_status, RI_IMAGE_INFO, FaceSets_struct::size, and Face_Information_struct::want_faceset.

Referenced by ReplyInfoCmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void get_image_sums ( char *  data,
int  len 
)

This gets a block of checksums from the server.

This lets it prebuild the images or what not. It would probably be nice to add a gui callback someplace that gives a little status display (18% done or whatever) - that probably needs to be done further up.

The start and stop values are not meaningful - they are here because the semantics of the requestinfo/replyinfo is that replyinfo includes the same request data as the requestinfo (thus, if the request failed for some reason, the client would know which one failed and then try again). Currently, we don't have any logic in the function below to deal with failures.

Definition at line 802 of file image.c.

References checksum, finish_face_cmd(), GetInt_String(), GetShort_String(), LOG(), LOG_WARNING, and replyinfo_last_face.

Referenced by ReplyInfoCmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void Image2Cmd ( guint8 *  data,
int  len 
)

Definition at line 552 of file image.c.

References display_newpng(), GetInt_String(), LOG(), and LOG_WARNING.

Here is the call graph for this function:

static Cache_Entry* image_add_hash ( char *  imagename,
char *  filename,
guint32  checksum,
guint32  ispublic 
)
static

Add a hash entry.

Returns the entry we added, NULL on failure.

Definition at line 296 of file image.c.

References Image_Cache::cache_entry, checksum, Cache_Entry::checksum, Cache_Entry::filename, image_cache, Cache_Entry::image_data, IMAGE_HASH, image_hash_name(), Image_Cache::image_name, Cache_Entry::ispublic, LOG(), LOG_WARNING, and Cache_Entry::next.

Referenced by cache_newpng(), and image_process_line().

Here is the call graph for this function:

Here is the caller graph for this function:

static Cache_Entry* image_find_cache_entry ( char *  imagename,
guint32  checksum,
int  has_sum 
)
static

This finds and returns the Cache_Entry of the image that matches name and checksum if has_sum is set.

If has_sum is not set, we can't do a checksum comparison.

Definition at line 272 of file image.c.

References Image_Cache::cache_entry, Cache_Entry::checksum, image_cache, image_find_hash(), and Cache_Entry::next.

Referenced by finish_face_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

static gint32 image_find_hash ( char *  str)
static

This function returns an index into the image_cache for a matching entry, -1 if no match is found.

Definition at line 208 of file image.c.

References image_cache, IMAGE_HASH, image_hash_name(), LOG(), and LOG_WARNING.

Referenced by image_find_cache_entry(), and image_remove_hash().

Here is the call graph for this function:

Here is the caller graph for this function:

static guint32 image_hash_name ( char *  str,
int  tablesize 
)
static

This function is basically hasharch from the server, common/arch.c a few changes - first, we stop processing when we reach the first .

  • this is because I'm not sure if hashing .111 at the end of all the image names will be very useful.

Definition at line 188 of file image.c.

Referenced by image_add_hash(), and image_find_hash().

Here is the caller graph for this function:

static void image_process_line ( char *  line,
guint32  ispublic 
)
static

Process a line from the bmaps.client file.

In theory, the format should be quite strict, as it is computer generated, but we try to be lenient/follow some conventions. Note that this is destructive to the data passed in line.

Definition at line 340 of file image.c.

References checksum, Cache_Entry::filename, image_add_hash(), LOG(), LOG_WARNING, and MAX_BUF.

Referenced by init_common_cache_data().

Here is the call graph for this function:

Here is the caller graph for this function:

static void image_remove_hash ( char *  imagename,
Cache_Entry ce 
)
static

Definition at line 237 of file image.c.

References Image_Cache::cache_entry, Cache_Entry::filename, image_cache, image_find_hash(), LOG(), LOG_ERROR, and Cache_Entry::next.

Referenced by finish_face_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void init_common_cache_data ( void  )

Definition at line 359 of file image.c.

References cache_dir, CONFIG_CACHE, draw_ext_info(), facetoname, FD_Cache::fd, fd_cache, image_cache, IMAGE_HASH, image_process_line(), MAX_BUF, MAX_FACE_SETS, MAXPIXMAPNUM, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_NOTICE, FD_Cache::name, NDI_RED, and want_config.

Referenced by init_image_cache_data().

Here is the call graph for this function:

Here is the caller graph for this function:

static int load_image ( char *  filename,
guint8 *  data,
int *  len,
guint32 *  csum 
)
static

Given a filename, this tries to load the data.

It returns 0 success, -1 on failure. It returns the data and len, the passed options. This function is called only if the client caching feature is enabled.

Parameters
filenameFile name of an image to try to load.
dataCaller-allocated pointer to a buffer to load image into.
lenAmount of buffer used by the loaded image.
csumReturns 0/unset (caller already knows if checksum matches?). Changes have made such that the caller knows whether or not the checksum matches, so there is little point to re-do it.
Returns
0 on success, -1 on failure.

Definition at line 55 of file image.c.

References Face_Information_struct::cache_hits, face_info, FD_Cache::fd, fd_cache, LOG(), LOG_ERROR, LOG_WARNING, MAX_FACE_SETS, FD_Cache::name, and ROTATE_RIGHT.

Referenced by finish_face_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void requestface ( int  pnum,
char *  facename 
)

Definition at line 412 of file image.c.

References Face_Information_struct::cache_misses, cs_print_string(), csocket, facetoname, and ClientSocket::fd.

Referenced by finish_face_cmd().

Here is the call graph for this function:

Here is the caller graph for this function:

void reset_image_cache_data ( void  )

We can now connect to different servers, so we need to clear out any old images.

We try to free the data also to prevent memory leaks. Note that we don't touch our hashed entries - so that when we connect to a new server, we still have all that information.

Definition at line 509 of file image.c.

References CONFIG_CACHE, facetoname, MAXPIXMAPNUM, and want_config.

Referenced by reset_image_data().

Here is the caller graph for this function:

Variable Documentation

Face_Information face_info
char facecachedir[MAX_BUF]

Definition at line 407 of file image.c.

char* facetoname[MAXPIXMAPNUM]
static

This holds the name we recieve with the 'face' command so we know what to save it as when we actually get the face.

Definition at line 174 of file image.c.

Referenced by cache_newpng(), display_newpng(), init_common_cache_data(), requestface(), and reset_image_cache_data().

struct FD_Cache fd_cache[MAX_FACE_SETS]
struct Image_Cache image_cache[IMAGE_HASH]