Changeset 1338 for libcaca/trunk
- Timestamp:
- Nov 11, 2006, 1:57:03 PM (16 years ago)
- Location:
- libcaca/trunk/cucul
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/canvas.c
r1313 r1338 391 391 cucul_blit(new, -x, -y, cv, NULL); 392 392 393 free(cv->allchars[f]); 394 free(cv->allattrs[f]); 395 } 396 free(cv->allchars); 397 free(cv->allattrs); 393 free(cv->frames[f].chars); 394 free(cv->frames[f].attrs); 395 } 396 free(cv->frames); 398 397 399 398 memcpy(cv, new, sizeof(cucul_canvas_t)); -
libcaca/trunk/cucul/cucul.c
r1337 r1338 69 69 cv->frame = 0; 70 70 cv->framecount = 1; 71 cv-> allchars = malloc(sizeof(uint32_t *));72 if(!cv-> allchars)71 cv->frames = malloc(sizeof(struct cucul_frame)); 72 if(!cv->frames) 73 73 { 74 74 free(cv); 75 75 goto nomem; 76 76 } 77 cv->allattrs = malloc(sizeof(uint32_t *)); 78 if(!cv->allattrs) 79 { 80 free(cv->allchars); 81 free(cv); 82 goto nomem; 83 } 84 cv->allchars[0] = NULL; 85 cv->allattrs[0] = NULL; 77 78 cv->frames[0].width = cv->frames[0].height = 0; 79 cv->frames[0].chars = NULL; 80 cv->frames[0].attrs = NULL; 81 cv->frames[0].curattr = cv->curattr; 86 82 87 83 if(_cucul_set_canvas_size(cv, width, height) < 0) … … 90 86 int saved_errno = errno; 91 87 #endif 92 free(cv->allattrs); 93 free(cv->allchars); 88 free(cv->frames); 94 89 free(cv); 95 90 #if defined(HAVE_ERRNO_H) … … 201 196 for(f = 0; f < cv->framecount; f++) 202 197 { 203 free(cv->allchars[f]); 204 free(cv->allattrs[f]); 205 } 206 207 free(cv->allchars); 208 free(cv->allattrs); 198 free(cv->frames[f].chars); 199 free(cv->frames[f].attrs); 200 } 201 202 free(cv->frames); 209 203 free(cv); 210 204 … … 258 252 for(f = 0; f < cv->framecount; f++) 259 253 { 260 cv-> allchars[f] = realloc(cv->allchars[f],261 new_size * sizeof(uint32_t));262 cv-> allattrs[f] = realloc(cv->allattrs[f],263 new_size * sizeof(uint32_t));264 if(new_size && (!cv-> allchars[f] || !cv->allattrs[f]))254 cv->frames[f].chars = realloc(cv->frames[f].chars, 255 new_size * sizeof(uint32_t)); 256 cv->frames[f].attrs = realloc(cv->frames[f].attrs, 257 new_size * sizeof(uint32_t)); 258 if(new_size && (!cv->frames[f].chars || !cv->frames[f].attrs)) 265 259 { 266 260 #if defined(HAVE_ERRNO_H) … … 285 279 for(f = 0; f < cv->framecount; f++) 286 280 { 287 uint32_t *chars = cv-> allchars[f];288 uint32_t *attrs = cv-> allattrs[f];281 uint32_t *chars = cv->frames[f].chars; 282 uint32_t *attrs = cv->frames[f].attrs; 289 283 290 284 for(y = height < old_height ? height : old_height; y--; ) 291 285 { 292 uint32_t attr = cv-> curattr;286 uint32_t attr = cv->frames[f].curattr; 293 287 294 288 for(x = old_width; x--; ) … … 315 309 for(f = 0; f < cv->framecount; f++) 316 310 { 317 uint32_t *chars = cv-> allchars[f];318 uint32_t *attrs = cv-> allattrs[f];311 uint32_t *chars = cv->frames[f].chars; 312 uint32_t *attrs = cv->frames[f].attrs; 319 313 320 314 for(y = 1; y < lines; y++) … … 334 328 for(f = 0; f < cv->framecount; f++) 335 329 { 336 uint32_t *chars = cv-> allchars[f];337 uint32_t *attrs = cv-> allattrs[f];338 uint32_t attr = cv-> curattr;330 uint32_t *chars = cv->frames[f].chars; 331 uint32_t *attrs = cv->frames[f].attrs; 332 uint32_t attr = cv->frames[f].curattr; 339 333 340 334 /* Zero the bottom of the screen */ … … 348 342 349 343 /* Step 4: if new area is smaller, resize memory area now. */ 350 if(new_size < =old_size)351 { 352 for(f = 0; f < cv->framecount; f++) 353 { 354 cv-> allchars[f] = realloc(cv->allchars[f],355 new_size * sizeof(uint32_t));356 cv-> allattrs[f] = realloc(cv->allattrs[f],357 new_size * sizeof(uint32_t));358 if(new_size && (!cv-> allchars[f] || !cv->allattrs[f]))344 if(new_size < old_size) 345 { 346 for(f = 0; f < cv->framecount; f++) 347 { 348 cv->frames[f].chars = realloc(cv->frames[f].chars, 349 new_size * sizeof(uint32_t)); 350 cv->frames[f].attrs = realloc(cv->frames[f].attrs, 351 new_size * sizeof(uint32_t)); 352 if(new_size && (!cv->frames[f].chars || !cv->frames[f].attrs)) 359 353 { 360 354 #if defined(HAVE_ERRNO_H) … … 366 360 } 367 361 368 /* Reset the current frame shortcut */ 369 cv->chars = cv->allchars[cv->frame]; 370 cv->attrs = cv->allattrs[cv->frame]; 362 /* Set new size */ 363 for(f = 0; f < cv->framecount; f++) 364 { 365 cv->frames[f].width = width; 366 cv->frames[f].height = height; 367 } 368 369 /* Reset the current frame shortcuts */ 370 cv->chars = cv->frames[cv->frame].chars; 371 cv->attrs = cv->frames[cv->frame].attrs; 371 372 372 373 return 0; -
libcaca/trunk/cucul/cucul_internals.h
r1335 r1338 19 19 #endif 20 20 21 struct cucul_ canvas21 struct cucul_frame 22 22 { 23 /* Canvassize */23 /* Frame size */ 24 24 unsigned int width, height; 25 25 26 /* Shortcut to the active frame*/26 /* Cell information */ 27 27 uint32_t *chars; 28 28 uint32_t *attrs; 29 29 30 /* Painting context */ 31 uint32_t curattr; 32 }; 33 34 struct cucul_canvas 35 { 30 36 /* Frame information */ 31 37 unsigned int frame, framecount; 32 uint32_t **allchars; 33 uint32_t **allattrs; 34 35 /* Painting context */ 36 uint32_t curattr; 38 struct cucul_frame *frames; 37 39 38 40 unsigned int refcount; 41 42 /* Shortcut to the active frame information */ 43 unsigned int width, height; 44 uint32_t *chars; 45 uint32_t *attrs; 46 uint32_t curattr; 39 47 }; 40 48 -
libcaca/trunk/cucul/sprite.c
r1257 r1338 31 31 #include "cucul_internals.h" 32 32 33 static void save_frame_info(cucul_canvas_t *); 34 static void load_frame_info(cucul_canvas_t *); 35 33 36 /** \brief Get the number of frames in a canvas. 34 37 * … … 70 73 } 71 74 75 save_frame_info(cv); 72 76 cv->frame = frame; 73 74 cv->chars = cv->allchars[cv->frame]; 75 cv->attrs = cv->allattrs[cv->frame]; 77 load_frame_info(cv); 76 78 77 79 return 0; … … 85 87 * The frame index indicates where the frame should be inserted. Valid 86 88 * values range from 0 to the current canvas frame count. If the frame 87 * index is greater th eor equals the current canvas frame count, the new89 * index is greater than or equals the current canvas frame count, the new 88 90 * frame is appended at the end of the canvas. 89 91 * … … 107 109 108 110 cv->framecount++; 109 cv-> allchars = realloc(cv->allchars, sizeof(uint32_t *) * cv->framecount);110 cv->allattrs = realloc(cv->allattrs, sizeof(uint32_t *) * cv->framecount);111 cv->frames = realloc(cv->frames, 112 sizeof(struct cucul_frame) * cv->framecount); 111 113 112 114 for(f = cv->framecount - 1; f > frame; f--) 113 {114 cv->allchars[f] = cv->allchars[f - 1]; 115 cv->allattrs[f] = cv->allattrs[f - 1];116 }117 118 cv->allchars[frame] = malloc(size);119 memcpy(cv->allchars[frame], cv->chars,size);120 cv->allattrs[frame] = malloc(size);121 memcpy(cv->allattrs[frame], cv->attrs, size);115 cv->frames[f] = cv->frames[f - 1]; 116 117 cv->frames[frame].width = cv->width; 118 cv->frames[frame].height = cv->height; 119 cv->frames[frame].chars = malloc(size); 120 memcpy(cv->frames[frame].chars, cv->chars, size); 121 cv->frames[frame].attrs = malloc(size); 122 memcpy(cv->frames[frame].attrs, cv->attrs, size); 123 cv->frames[frame].curattr = cv->curattr; 122 124 123 125 if(cv->frame >= frame) 124 126 cv->frame++; 125 126 cv->chars = cv->allchars[cv->frame];127 cv->attrs = cv->allattrs[cv->frame];128 127 129 128 return 0; … … 171 170 } 172 171 173 free(cv-> allchars[frame]);174 free(cv-> allattrs[frame]);172 free(cv->frames[frame].chars); 173 free(cv->frames[frame].attrs); 175 174 176 175 for(f = frame + 1; f < cv->framecount; f++) 177 { 178 cv->allchars[f - 1] = cv->allchars[f]; 179 cv->allattrs[f - 1] = cv->allattrs[f]; 180 } 176 cv->frames[f - 1] = cv->frames[f]; 181 177 182 178 cv->framecount--; 183 cv-> allchars = realloc(cv->allchars, sizeof(uint32_t *) * cv->framecount);184 cv->allattrs = realloc(cv->allattrs, sizeof(uint32_t *) * cv->framecount);179 cv->frames = realloc(cv->frames, 180 sizeof(struct cucul_frame) * cv->framecount); 185 181 186 182 if(cv->frame > frame) 187 183 cv->frame--; 188 184 else if(cv->frame == frame) 185 { 189 186 cv->frame = 0; 190 191 cv->chars = cv->allchars[cv->frame]; 192 cv->attrs = cv->allattrs[cv->frame]; 187 load_frame_info(cv); 188 } 193 189 194 190 return 0; 195 191 } 196 192 193 /* 194 * XXX: the following functions are local. 195 */ 196 197 static void save_frame_info(cucul_canvas_t *cv) 198 { 199 cv->frames[cv->frame].width = cv->width; 200 cv->frames[cv->frame].height = cv->height; 201 202 cv->frames[cv->frame].curattr = cv->curattr; 203 } 204 205 static void load_frame_info(cucul_canvas_t *cv) 206 { 207 cv->width = cv->frames[cv->frame].width; 208 cv->height = cv->frames[cv->frame].height; 209 210 cv->chars = cv->frames[cv->frame].chars; 211 cv->attrs = cv->frames[cv->frame].attrs; 212 213 cv->curattr = cv->frames[cv->frame].curattr; 214 } 215
Note: See TracChangeset
for help on using the changeset viewer.