Changeset 811 for libcaca/trunk/cucul/cucul.c
- Timestamp:
- Apr 18, 2006, 5:11:25 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/cucul.c
r810 r811 44 44 cucul_canvas_t * cucul_create(unsigned int width, unsigned int height) 45 45 { 46 cucul_canvas_t *c = malloc(sizeof(cucul_canvas_t));47 48 c ->refcount = 0;49 50 c ->fgcolor = CUCUL_COLOR_LIGHTGRAY;51 c ->bgcolor = CUCUL_COLOR_BLACK;52 53 c ->width = c->height = 0;54 c ->chars = NULL;55 c ->attr = NULL;56 c ->empty_line = c->scratch_line = NULL;46 cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t)); 47 48 cv->refcount = 0; 49 50 cv->fgcolor = CUCUL_COLOR_LIGHTGRAY; 51 cv->bgcolor = CUCUL_COLOR_BLACK; 52 53 cv->width = cv->height = 0; 54 cv->chars = NULL; 55 cv->attr = NULL; 56 cv->empty_line = cv->scratch_line = NULL; 57 57 58 58 /* Initialise to a default size. 80x32 is arbitrary but matches AAlib's … … 60 60 * a different size. */ 61 61 if(width && height) 62 _cucul_set_size(c , width, height);62 _cucul_set_size(cv, width, height); 63 63 else 64 _cucul_set_size(c , 80, 32);64 _cucul_set_size(cv, 80, 32); 65 65 66 66 if(_cucul_init_dither()) 67 67 { 68 free(c );69 return NULL; 70 } 71 72 return c ;68 free(cv); 69 return NULL; 70 } 71 72 return cv; 73 73 } 74 74 … … 84 84 cucul_canvas_t *cucul_load(void *data, unsigned int size) 85 85 { 86 cucul_canvas_t *c ;86 cucul_canvas_t *cv; 87 87 uint8_t *buf = (uint8_t *)data; 88 88 unsigned int width, height, n; … … 109 109 return NULL; 110 110 111 c = cucul_create(width, height);112 113 if(!c )111 cv = cucul_create(width, height); 112 113 if(!cv) 114 114 return NULL; 115 115 116 116 for(n = height * width; n--; ) 117 117 { 118 c ->chars[n] = ((uint32_t)buf[12 + 8 * n] << 24)118 cv->chars[n] = ((uint32_t)buf[12 + 8 * n] << 24) 119 119 | ((uint32_t)buf[13 + 8 * n] << 16) 120 120 | ((uint32_t)buf[14 + 8 * n] << 8) 121 121 | (uint32_t)buf[15 + 8 * n]; 122 c ->attr[n] = ((uint32_t)buf[16 + 8 * n] << 24)122 cv->attr[n] = ((uint32_t)buf[16 + 8 * n] << 24) 123 123 | ((uint32_t)buf[17 + 8 * n] << 16) 124 124 | ((uint32_t)buf[18 + 8 * n] << 8) … … 126 126 } 127 127 128 return c ;128 return cv; 129 129 } 130 130 … … 144 144 * for more about this. 145 145 * 146 * \param c A libcucul canvas146 * \param cv A libcucul canvas 147 147 * \param width The desired canvas width 148 148 * \param height The desired canvas height 149 149 */ 150 void cucul_set_size(cucul_canvas_t *c , unsigned int width, unsigned int height)151 { 152 if(c ->refcount)150 void cucul_set_size(cucul_canvas_t *cv, unsigned int width, unsigned int height) 151 { 152 if(cv->refcount) 153 153 return; 154 154 155 _cucul_set_size(c , width, height);155 _cucul_set_size(cv, width, height); 156 156 } 157 157 … … 160 160 * This function returns the current canvas width, in character cells. 161 161 * 162 * \param c A libcucul canvas162 * \param cv A libcucul canvas 163 163 * \return The canvas width. 164 164 */ 165 unsigned int cucul_get_width(cucul_canvas_t *c )166 { 167 return c ->width;165 unsigned int cucul_get_width(cucul_canvas_t *cv) 166 { 167 return cv->width; 168 168 } 169 169 … … 172 172 * This function returns the current canvas height, in character cells. 173 173 * 174 * \param c A libcucul canvas174 * \param cv A libcucul canvas 175 175 * \return The canvas height. 176 176 */ 177 unsigned int cucul_get_height(cucul_canvas_t *c )178 { 179 return c ->height;177 unsigned int cucul_get_height(cucul_canvas_t *cv) 178 { 179 return cv->height; 180 180 } 181 181 … … 222 222 * unless a new call to cucul_create() is done. 223 223 * 224 * \param c A libcucul canvas225 */ 226 void cucul_free(cucul_canvas_t *c )224 * \param cv A libcucul canvas 225 */ 226 void cucul_free(cucul_canvas_t *cv) 227 227 { 228 228 _cucul_end_dither(); 229 229 230 free(c ->empty_line);231 free(c ->scratch_line);232 233 free(c ->chars);234 free(c ->attr);235 236 free(c );230 free(cv->empty_line); 231 free(cv->scratch_line); 232 233 free(cv->chars); 234 free(cv->attr); 235 236 free(cv); 237 237 } 238 238 … … 291 291 */ 292 292 293 void _cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height) 293 void _cucul_set_size(cucul_canvas_t *cv, unsigned int width, 294 unsigned int height) 294 295 { 295 296 unsigned int x, y, old_width, old_height, new_size, old_size; 296 297 297 old_width = c ->width;298 old_height = c ->height;298 old_width = cv->width; 299 old_height = cv->height; 299 300 old_size = old_width * old_height; 300 301 301 c ->width = width;302 c ->height = height;302 cv->width = width; 303 cv->height = height; 303 304 new_size = width * height; 304 305 … … 306 307 if(new_size > old_size) 307 308 { 308 c ->chars = realloc(c->chars, new_size * sizeof(uint32_t));309 c ->attr = realloc(c->attr, new_size * sizeof(uint32_t));309 cv->chars = realloc(cv->chars, new_size * sizeof(uint32_t)); 310 cv->attr = realloc(cv->attr, new_size * sizeof(uint32_t)); 310 311 } 311 312 … … 325 326 for(x = old_width; x--; ) 326 327 { 327 c ->chars[y * width + x] = c->chars[y * old_width + x];328 c ->attr[y * width + x] = c->attr[y * old_width + x];328 cv->chars[y * width + x] = cv->chars[y * old_width + x]; 329 cv->attr[y * width + x] = cv->attr[y * old_width + x]; 329 330 } 330 331 331 332 /* Zero the end of the line */ 332 333 for(x = width - old_width; x--; ) 333 c ->chars[y * width + old_width + x] = (uint32_t)' ';334 memset(c ->attr + y * width + old_width, 0,334 cv->chars[y * width + old_width + x] = (uint32_t)' '; 335 memset(cv->attr + y * width + old_width, 0, 335 336 (width - old_width) * 4); 336 337 } … … 346 347 for(x = 0; x < width; x++) 347 348 { 348 c ->chars[y * width + x] = c->chars[y * old_width + x];349 c ->attr[y * width + x] = c->attr[y * old_width + x];349 cv->chars[y * width + x] = cv->chars[y * old_width + x]; 350 cv->attr[y * width + x] = cv->attr[y * old_width + x]; 350 351 } 351 352 } … … 357 358 /* Zero the bottom of the screen */ 358 359 for(x = (height - old_height) * width; x--; ) 359 c ->chars[old_height * width + x] = (uint32_t)' ';360 memset(c ->attr + old_height * width, 0,360 cv->chars[old_height * width + x] = (uint32_t)' '; 361 memset(cv->attr + old_height * width, 0, 361 362 (height - old_height) * width * 4); 362 363 } … … 365 366 if(new_size <= old_size) 366 367 { 367 c ->chars = realloc(c->chars, new_size * sizeof(uint32_t));368 c ->attr = realloc(c->attr, new_size * sizeof(uint32_t));368 cv->chars = realloc(cv->chars, new_size * sizeof(uint32_t)); 369 cv->attr = realloc(cv->attr, new_size * sizeof(uint32_t)); 369 370 } 370 371 … … 372 373 if(width != old_width) 373 374 { 374 c ->empty_line = realloc(c->empty_line, width + 1);375 memset(c ->empty_line, ' ', width);376 c ->empty_line[width] = '\0';377 378 c ->scratch_line = realloc(c->scratch_line, width + 1);379 } 380 } 381 375 cv->empty_line = realloc(cv->empty_line, width + 1); 376 memset(cv->empty_line, ' ', width); 377 cv->empty_line[width] = '\0'; 378 379 cv->scratch_line = realloc(cv->scratch_line, width + 1); 380 } 381 } 382
Note: See TracChangeset
for help on using the changeset viewer.