Crossfire Server, Trunk  R22047
image.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <assert.h>
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 
27 #include "image.h"
28 
29 #include "assets.h"
30 
36 
37 
45 static const char *const colorname[] = {
46  "black", /* 0 */
47  "white", /* 1 */
48  "blue", /* 2 */
49  "red", /* 3 */
50  "orange", /* 4 */
51  "light_blue", /* 5 */
52  "dark_orange", /* 6 */
53  "green", /* 7 */
54  "light_green", /* 8 */
55  "grey", /* 9 */
56  "brown", /* 10 */
57  "yellow", /* 11 */
58  "khaki" /* 12 */
59 };
60 
74 uint8_t find_color(const char *name) {
75  uint8_t i;
76 
77  for (i = 0; i < sizeof(colorname)/sizeof(*colorname); i++)
78  if (!strcmp(name, colorname[i]))
79  return i;
80 
81  LOG(llevError, "Unknown color: %s\n", name);
82  return 0;
83 }
84 
85 const char *get_colorname(uint8_t index) {
86  if (index < sizeof(colorname) / sizeof(*colorname)) {
87  return colorname[index];
88  }
89  return "";
90 }
91 
101 int find_smooth(const Face *face, const Face **smoothed) {
102  (*smoothed) = NULL;
103 
104  if (face && face->smoothface) {
105  (*smoothed) = face->smoothface;
106  return 1;
107  }
108 
109  return 0;
110 }
111 
116 int is_valid_faceset(int fsn) {
117  return find_faceset(fsn) != NULL;
118 }
119 
132 int get_face_fallback(int faceset, int imageno) {
133  /* faceset 0 is supposed to have every image, so just return. Doing
134  * so also prevents infinite loops in the case if it not having
135  * the face, but in that case, we are likely to crash when we try
136  * to access the data, but that is probably preferable to an infinite
137  * loop.
138  */
139 
140  face_sets *fs = find_faceset(faceset);
141  if (!fs || !fs->prefix) {
142  LOG(llevError, "get_face_fallback called with unused set (%d)?\n", faceset);
143  return 0; /* use default set */
144  }
145  if (imageno < fs->allocated && fs->faces[imageno].data)
146  return faceset;
147 
148  if (!fs->fallback) {
149  return 0;
150  }
151 
152  return get_face_fallback(fs->fallback->id, imageno);
153 }
154 
155 static void do_face(const Face *face) {
156  fprintf(stderr, "%5d %50s %50s\n", face->number, face->name, face->smoothface ? face->smoothface->name : "(none)");
157 }
158 
162 void dump_faces(void) {
163  Face *face;
164  fprintf(stderr, "id name smooth\n");
166 }
const Face * smooth_face
Definition: image.c:35
void dump_faces(void)
Definition: image.c:162
face_info * faces
Definition: image.h:26
unsigned char uint8_t
Definition: win32.h:161
const Face * blank_face
Definition: image.c:35
Definition: face.h:14
const char * get_colorname(uint8_t index)
Definition: image.c:85
int id
Definition: image.h:18
const char * name
Definition: face.h:19
int is_valid_faceset(int fsn)
Definition: image.c:116
face_sets * find_faceset(int id)
Definition: assets.cpp:335
static void do_face(const Face *face)
Definition: image.c:155
const Face * empty_face
Definition: image.c:35
uint8_t * data
Definition: image.h:11
struct Face * smoothface
Definition: face.h:18
char * prefix
Definition: image.h:19
uint16_t number
Definition: face.h:15
uint8_t find_color(const char *name)
Definition: image.c:74
void faces_for_each(face_op op)
Definition: assets.cpp:292
struct face_sets * fallback
Definition: image.h:21
static const char *const colorname[]
Definition: image.c:45
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:51
int get_face_fallback(int faceset, int imageno)
Definition: image.c:132
int find_smooth(const Face *face, const Face **smoothed)
Definition: image.c:101