Crossfire Client, Trunk
Classes | Macros | Functions | Variables
image.c File Reference
#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.

Classes

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)
 
void display_newpng (int face, guint8 *buf, int buflen, int setnum)
 
void Face2Cmd (guint8 *data, int len)
 
void finish_face_cmd (int pnum, guint32 checksum, int has_sum, char *face, int faceset)
 
void get_image_info (guint8 *data, int len)
 
void get_image_sums (char *data, int len)
 
void Image2Cmd (guint8 *data, int len)
 
static Cache_Entryimage_add_hash (char *imagename, char *filename, guint32 checksum, guint32 ispublic)
 
static Cache_Entryimage_find_cache_entry (char *imagename, guint32 checksum, int has_sum)
 
static gint32 image_find_hash (char *str)
 
static guint32 image_hash_name (char *str, int tablesize)
 
static void image_process_line (char *line, guint32 ispublic)
 
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)
 
void requestface (int pnum, char *facename)
 
void reset_image_cache_data (void)
 

Variables

Face_Information face_info
 
char facecachedir [MAX_BUF]
 
static char * facetoname [MAXPIXMAPNUM]
 
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

◆ IMAGE_HASH

#define IMAGE_HASH   8192

Definition at line 167 of file image.c.

◆ ROTATE_RIGHT

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

Definition at line 33 of file image.c.

Function Documentation

◆ cache_newpng()

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_info, 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:

◆ display_newpng()

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:

◆ Face2Cmd()

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 Cache_Entry::checksum, CONFIG_CACHE, finish_face_cmd(), GetInt_String(), GetShort_String(), LOG(), LOG_WARNING, and use_config.

Here is the call graph for this function:

◆ finish_face_cmd()

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, Cache_Entry::checksum, 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:

◆ get_image_info()

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_info, 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:

◆ get_image_sums()

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 Cache_Entry::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:

◆ Image2Cmd()

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:

◆ image_add_hash()

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, 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:

◆ image_find_cache_entry()

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:

◆ image_find_hash()

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:

◆ image_hash_name()

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:

◆ image_process_line()

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 Cache_Entry::checksum, Cache_Entry::filename, image_add_hash(), Cache_Entry::ispublic, 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:

◆ image_remove_hash()

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:

◆ init_common_cache_data()

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:

◆ load_image()

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, LOG(), LOG_ERROR, LOG_WARNING, MAX_FACE_SETS, and ROTATE_RIGHT.

Referenced by finish_face_cmd().

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

◆ requestface()

void requestface ( int  pnum,
char *  facename 
)

Definition at line 412 of file image.c.

References Face_Information_struct::cache_misses, cs_print_string(), csocket, face_info, 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:

◆ reset_image_cache_data()

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_info

Face_Information face_info

◆ facecachedir

char facecachedir[MAX_BUF]

Definition at line 407 of file image.c.

◆ facetoname

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().

◆ fd_cache

struct FD_Cache fd_cache[MAX_FACE_SETS]

◆ image_cache

struct Image_Cache image_cache[IMAGE_HASH]