Crossfire Server, Trunk  R21670
image.c File Reference
#include "global.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "image.h"
+ Include dependency graph for image.c:

Go to the source code of this file.

Functions

static void check_faceset_fallback (int faceset, int togo)
 
static int compare_face (const Face *a, const Face *b)
 
static uint8_t find_color (const char *name)
 
const Facefind_face (const char *name, const Face *error)
 
int find_smooth (const Face *face, const Face **smoothed)
 
void free_all_images (void)
 
void free_socket_images (void)
 
const Faceget_face_by_id (uint16_t id)
 
const Faceget_face_by_index (int index)
 
int get_face_fallback (int faceset, int imageno)
 
unsigned int get_faces_count ()
 
static Faceinternal_find_face (const char *name)
 
int is_valid_faceset (int fsn)
 
void read_bmap_names (void)
 
void read_client_images (void)
 
static void read_face_data (void)
 
int read_smooth (void)
 

Variables

const Faceblank_face
 
static const char *const colorname []
 
const Faceempty_face
 
face_sets facesets [MAX_FACE_SETS]
 
Facenew_faces
 
static unsigned int nrofpixmaps = 0
 
const Facesmooth_face
 

Detailed Description

Handles face-related stuff, including the actual face data.

Definition in file image.c.

Function Documentation

◆ check_faceset_fallback()

static void check_faceset_fallback ( int  faceset,
int  togo 
)
static

Checks fallback are correctly defined. This is a simple recursive function that makes sure the fallbacks are all proper (eg, the fall back to defined sets, and also eventually fall back to 0). At the top level, togo is set to MAX_FACE_SETS. If togo gets to zero, it means we have a loop. This is only run when we first load the facesets.

Definition at line 418 of file image.c.

References face_sets::fallback, llevError, and LOG().

Referenced by read_client_images().

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

◆ compare_face()

static int compare_face ( const Face a,
const Face b 
)
static

Used for bsearch searching for faces by name. The face "bug.111" is always put at first.

Todo:
"bug.111" should be a regular face, alas many places consider face 0 to be that face. This should be fixed at some point.
Parameters
afirst item to compare.
bsecond item to compare.
Return values
-1if a < b
0if a == b
1if a > b

Definition at line 83 of file image.c.

References Face::name.

Referenced by internal_find_face(), and read_bmap_names().

+ Here is the caller graph for this function:

◆ find_color()

static uint8_t find_color ( const char *  name)
static

Finds a color by name.

Parameters
namecolor name, case-sensitive.
Returns
the matching color in the coloralias if found, 0 otherwise.
Note
0 will actually be black, so there is no way the calling function can tell if an error occurred or not

Definition at line 122 of file image.c.

References colorname, llevError, and LOG().

Referenced by read_bmap_names(), and read_face_data().

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

◆ find_face()

const Face* find_face ( const char *  name,
const Face error 
)

This returns the face with 'name'.

Parameters
nameface to search for.
errorvalue to return if face was not found.
Returns
found face, or error.
Note
If a face is not found, then error is returned. This can be useful if you want some default face used, or can be set to NULL so that it will be known that the face could not be found (needed in client, so that it will know to request that image from the server)

Definition at line 316 of file image.c.

References internal_find_face().

Referenced by add_abilities(), cfapi_object_set_property(), cfapi_system_find_face(), fix_flesh_item(), init_anim(), init_msgfile(), knowledge_process_incremental(), knowledge_send_info(), load_quests_from_file(), object_give_identified_properties(), read_client_images(), send_account_players(), set_object_face_main(), set_object_face_other(), and transport_type_apply().

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

◆ find_smooth()

int find_smooth ( const Face face,
const Face **  smoothed 
)

Find the smooth face for a given face.

Parameters
facethe face to find the smoothing face for
smoothedreturn value: set to smooth face
Returns
1=smooth face found, 0=no smooth face found

Definition at line 388 of file image.c.

References Face::smoothface.

Referenced by send_smooth().

+ Here is the caller graph for this function:

◆ free_all_images()

void free_all_images ( void  )

Deallocates memory allocated by read_bmap_names() and read_smooth().

Definition at line 402 of file image.c.

References nrofpixmaps.

Referenced by cleanup().

+ Here is the caller graph for this function:

◆ free_socket_images()

void free_socket_images ( void  )

Frees all faceset information

Definition at line 580 of file image.c.

References MAX_FACE_SETS, and nrofpixmaps.

Referenced by free_all_newserver().

+ Here is the caller graph for this function:

◆ get_face_by_id()

const Face* get_face_by_id ( uint16_t  id)

Get a face from its unique identifier.

Parameters
idface identifier.
Returns
matching face, NULL if no face with this identifier.

Definition at line 653 of file image.c.

References nrofpixmaps.

Referenced by ask_smooth_cmd(), cfapi_system_find_face(), and send_face_cmd().

+ Here is the caller graph for this function:

◆ get_face_by_index()

const Face* get_face_by_index ( int  index)

Return the face at the specified index.

Parameters
indexindex, between 0 and get_faces_count() excluded.
Returns
face, NULL if the index is invalid.

Definition at line 642 of file image.c.

References nrofpixmaps.

Referenced by CRESmoothFaceMaker::CRESmoothFaceMaker(), ResourcesManager::load(), send_image_sums(), and CREFacePanel::setItem().

+ Here is the caller graph for this function:

◆ get_face_fallback()

int get_face_fallback ( int  faceset,
int  imageno 
)

This returns the set we will actually use when sending a face. This is used because the image files may be sparse. This function is recursive. imageno is the face number we are trying to send

If face is not found in specified faceset, tries with 'fallback' faceset.

Parameters
facesetfaceset to check
imagenoimage number

Definition at line 610 of file image.c.

References get_face_fallback(), llevError, and LOG().

Referenced by esrv_send_face(), get_face_fallback(), process_map(), and send_image_sums().

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

◆ get_faces_count()

unsigned int get_faces_count ( void  )

Return the number of faces, including the "bug" one.

Returns
number of faces.

Definition at line 633 of file image.c.

References nrofpixmaps.

Referenced by CRESmoothFaceMaker::CRESmoothFaceMaker(), init_connection(), ResourcesManager::load(), main(), monsterFight(), new_connection(), send_image_info(), send_image_sums(), and CREFacePanel::setItem().

+ Here is the caller graph for this function:

◆ internal_find_face()

static Face* internal_find_face ( const char *  name)
static

This returns the face with 'name'.

Parameters
nameface to search for.
Returns
matching face, NULL if not found.

Definition at line 100 of file image.c.

References compare_face(), Face::name, and nrofpixmaps.

Referenced by find_face(), read_bmap_names(), read_face_data(), and read_smooth().

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

◆ is_valid_faceset()

int is_valid_faceset ( int  fsn)

Checks specified faceset is valid

Parameters
fsnfaceset number

Definition at line 571 of file image.c.

References FALSE, MAX_FACE_SETS, and TRUE.

Referenced by main(), and set_up_cmd().

+ Here is the caller graph for this function:

◆ read_bmap_names()

void read_bmap_names ( void  )

This reads the bmaps file to get all the bitmap names and stuff. It only needs to be done once, because it is player independent (ie, what display the person is on will not make a difference.)

Note
will call exit() if file doesn't exist, and abort() in case of memory error.

Definition at line 196 of file image.c.

References BLANK_FACE_NAME, bmaps_checksum, compare_face(), Settings::datadir, EMPTY_FACE_NAME, FACE_FLOOR, fatal(), find_color(), internal_find_face(), llevDebug, llevError, LOG(), Face::magicmap, MAX_BUF, Face::name, nrofpixmaps, Face::number, OUT_OF_MEMORY, read_face_data(), ROTATE_RIGHT, SEE_LAST_ERROR, settings, SMOOTH_FACE_NAME, Face::smoothface, snprintf, strdup_local, and Face::visibility.

Referenced by cctk_init_std_archetypes(), and init_library().

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

◆ read_client_images()

void read_client_images ( void  )

Loads all the image types into memory.

This way, we can easily send them to the client. We should really do something better than abort on any errors - on the other hand, these are all fatal to the server (can't work around them), but the abort just seems a bit messy (exit would probably be better.)

Couple of notes: We assume that the faces are in a continous block. This works fine for now, but this could perhaps change in the future

Function largely rewritten May 2000 to be more general purpose. The server itself does not care what the image data is - to the server, it is just data it needs to allocate. As such, the code is written to do such.

Definition at line 454 of file image.c.

References check_faceset_fallback(), face_info::checksum, face_sets::comment, face_info::data, Settings::datadir, face_info::datalen, face_sets::extension, face_sets::faces, face_sets::fallback, find_face(), face_sets::fullname, HUGE_BUF, llevDebug, llevError, LOG(), MAX_FACE_SETS, MAX_IMAGE_SIZE, nrofpixmaps, Face::number, face_sets::prefix, ROTATE_RIGHT, settings, face_sets::size, snprintf, split_string(), and strdup_local.

Referenced by init_server(), ResourcesManager::load(), and main().

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

◆ read_face_data()

static void read_face_data ( void  )
static

This reads the lib/faces file, getting color and visibility information. It is called by read_bmap_names().

Note
will call exit() if file doesn't exist.

Definition at line 140 of file image.c.

References Settings::datadir, FACE_FLOOR, find_color(), internal_find_face(), llevDebug, llevError, LOG(), Face::magicmap, MAX_BUF, settings, snprintf, and Face::visibility.

Referenced by read_bmap_names().

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

◆ read_smooth()

int read_smooth ( void  )

Reads the smooth file to know how to smooth datas. the smooth file if made of 2 elements lines. lines starting with # are comment the first element of line is face to smooth the next element is the 16x2 faces picture used for smoothing

Note
will call exit() if file can't be opened.

Definition at line 332 of file image.c.

References Settings::datadir, internal_find_face(), llevDebug, llevError, LOG(), MAX_BUF, settings, Face::smoothface, and snprintf.

Referenced by cctk_init_std_archetypes(), and init_library().

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

Variable Documentation

◆ blank_face

const Face* blank_face

◆ colorname

const char* const colorname[]
static
Initial value:
= {
"black",
"white",
"blue",
"red",
"orange",
"light_blue",
"dark_orange",
"green",
"light_green",
"grey",
"brown",
"yellow",
"khaki"
}

The only thing this table is used for now is to translate the colorname in the magicmap field of the face into a numeric index that is then sent to the client for magic map commands. The order of this table must match that of the NDI colors in include/newclient.h.

Definition at line 56 of file image.c.

Referenced by find_color().

◆ empty_face

const Face * empty_face

Definition at line 39 of file image.c.

Referenced by esrv_draw_look(), and esrv_send_inventory().

◆ facesets

All facesets

Definition at line 47 of file image.c.

Referenced by esrv_send_face(), CREPixmap::getIcon(), main(), process_map(), send_image_info(), and send_image_sums().

◆ new_faces

Face* new_faces

Contains face information, with names, numbers, magicmap color and such. It is sorted by alphabetical order.

Definition at line 33 of file image.c.

◆ nrofpixmaps

unsigned int nrofpixmaps = 0
static

Number of bitmaps loaded from the "bmaps" file.

Definition at line 45 of file image.c.

Referenced by free_all_images(), free_socket_images(), get_face_by_id(), get_face_by_index(), get_faces_count(), internal_find_face(), read_bmap_names(), and read_client_images().

◆ smooth_face

const Face * smooth_face

Definition at line 39 of file image.c.

Referenced by send_smooth().