Changeset 348
- Timestamp:
- 03/24/07 15:18:42 (2 years ago)
- Files:
-
- trunk/ILDAInspector/ILDAlib.c (modified) (18 diffs)
- trunk/ILDAInspector/ILDAlib.h (modified) (1 diff)
- trunk/ILDAInspector/ILDAtypes.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ILDAInspector/ILDAlib.c
r184 r348 49 49 while(sysCall = close(ildaFD), sysCall == -1 && sysCall == EINTR); 50 50 if(sysCall < 0) 51 retval = errno; //something weird happend in close()51 retval = -1; //something weird happend in close() 52 52 53 53 OPEN_EXIT: … … 67 67 dst->frames = (ILDAFrame *)malloc(sizeof(ILDAFrame)*src->frameCount); 68 68 if(dst->frames == NULL) 69 { retval = errno; goto COPY_EXIT; }69 { retval = -1; goto COPY_EXIT; } 70 70 for(i = 0; i < src->frameCount; i++) 71 71 { … … 73 73 (dst->frames)[i].points = (ILDAPoint *)malloc(sizeof(ILDAPoint)*(src->frames)[i].header.entryCount); 74 74 if((dst->frames)[i].points == NULL) 75 { retval = errno; goto COPY_FREE1; }75 { retval = -1; goto COPY_FREE1; } 76 76 77 77 memcpy((dst->frames)[i].points, (src->frames)[i].points, sizeof(ILDAPoint)*(src->frames)[i].header.entryCount); … … 82 82 dst->palettes = (ILDAPalette *)malloc(sizeof(ILDAPalette)*src->paletteCount); 83 83 if(dst->palettes == NULL) 84 { retval = errno; goto COPY_FREE2; }84 { retval = -1; goto COPY_FREE2; } 85 85 for(i = 0; i < src->paletteCount; i++) 86 86 { … … 88 88 (dst->palettes)[i].colors = (ILDAColor *)malloc(sizeof(ILDAColor)*(src->palettes)[i].header.entryCount); 89 89 if((dst->palettes)[i].colors == NULL) 90 { retval = errno; goto COPY_FREE3; }90 { retval = -1; goto COPY_FREE3; } 91 91 92 92 memcpy((dst->palettes)[i].colors, (src->palettes)[i].colors, sizeof(ILDAColor)*(src->palettes)[i].header.entryCount); … … 94 94 95 95 //Copy the palette mapping 96 dst->paletteMap = ( short *)malloc(sizeof(short)*src->frameCount);97 memcpy(dst->paletteMap, src->paletteMap, sizeof( short)*src->frameCount);96 dst->paletteMap = (unsigned short *)malloc(sizeof(unsigned short)*src->frameCount); 97 memcpy(dst->paletteMap, src->paletteMap, sizeof(unsigned short)*src->frameCount); 98 98 if(dst->paletteMap == NULL) 99 99 { retval = errno; goto COPY_FREE4; } … … 101 101 return 0; 102 102 103 104 103 COPY_FREE4: 105 while(i >= 0) 106 free((dst->frames)[i].points); 104 i = src->paletteCount; 107 105 COPY_FREE3: 106 while(i > 0) 107 free((dst->frames)[--i].points); 108 COPY_FREE2: 108 109 free(dst->palettes); 109 i = src->frameCount-1; 110 COPY_FREE2: 111 for(i; i >= 0; i--) 112 free((dst->frames)[i].points); 110 i = src->frameCount; 113 111 COPY_FREE1: 112 while(i > 0) 113 free((dst->frames)[--i].points); 114 114 free(dst->frames); 115 115 COPY_EXIT: … … 129 129 int retval = 0; 130 130 131 seq->frameCount = -1; 132 seq->paletteCount = -1; 133 short currentPalette = -1; 134 short currentFrame = -1; 131 seq->frames = NULL; 132 seq->palettes = NULL; 133 seq->frameCount = 0; 134 seq->paletteCount = 0; 135 short currentPalette = 0; 136 short currentFrame = 0; 135 137 136 138 while(bytes_read < size && read_header(&header, buffer+bytes_read, size-bytes_read)) … … 140 142 case ILDA3DFrameType: 141 143 case ILDA2DFrameType: 142 if(seq->frameCount == -1) //we need to allocate room for the frames144 if(seq->frameCount == 0) //we need to allocate room for the frames 143 145 { 144 seq->frameCount = header.objectCount; 145 if(seq->frameCount <0)146 return errno;146 seq->frameCount = header.objectCount; //this is our best guess for the sequence size 147 if(seq->frameCount == 0) 148 return ECORPT; 147 149 seq->frames = (ILDAFrame *)malloc(sizeof(ILDAFrame)*header.objectCount); 148 150 if(seq->frames == NULL) 149 return errno;150 seq->paletteMap = ( short *)malloc(sizeof(short)*header.objectCount);151 { retval = -1; goto CREATE_ABORT; } 152 seq->paletteMap = (unsigned short *)malloc(sizeof(unsigned short)*header.objectCount); 151 153 if(seq->paletteMap == NULL) 152 return errno;154 { retval = -1; goto CREATE_ABORT; } 153 155 } 154 156 if(header.entryCount == 0) //this is the EOF Header 155 return 1; 156 157 if(header.objectNumber > seq->frameCount || 158 header.objectCount != seq->frameCount ) 159 return ECORPT; //we found a inconsistacy 160 161 read_status = read_frame(&(seq->frames)[header.objectNumber], buffer+bytes_read, size-bytes_read); 162 seq->paletteMap[header.objectNumber] = currentPalette; 157 goto CREATE_FINALIZE; 158 159 if(currentFrame >= seq->frameCount) //more frames are found than there is space for 160 { 161 void *newSpace = realloc(seq->frames, sizeof(ILDAFrame)*(currentFrame+1)); 162 if(newSpace == NULL) 163 { retval = -1; goto CREATE_ABORT; } 164 seq->frames = newSpace; 165 166 newSpace = (short *)malloc(sizeof(unsigned short)*(currentFrame+1)); 167 if(newSpace == NULL) 168 { retval = -1; goto CREATE_ABORT; } 169 seq->paletteMap = newSpace; 170 171 seq->frameCount = currentFrame+1; 172 } 173 174 read_status = read_frame(&(seq->frames)[currentFrame], buffer+bytes_read, size-bytes_read); 175 seq->paletteMap[currentFrame] = currentPalette; 163 176 currentFrame++; 164 177 165 if(read_status > 0) 178 if(read_status < 0) 179 { retval = read_status; goto CREATE_ABORT; } 180 else //something messed up in the read 166 181 bytes_read += read_status; 167 else //something messed up in the read168 { retval = read_status; goto CREATE_FREE; }169 182 170 183 break; 171 184 172 185 case ILDAPaletteType: 173 if(seq->palette Count == -1) //we need to allocate room for the palette186 if(seq->palettes == NULL) //we need to allocate room for the palette 174 187 { 175 188 seq->palettes = (ILDAPalette *)malloc(sizeof(ILDAPalette)); 176 189 if(seq->palettes == NULL) 177 return errno; 178 seq->paletteCount = 0; 190 { retval = -1; goto CREATE_ABORT; } 179 191 } 180 192 else … … 182 194 void *newSpace = realloc(seq->palettes, sizeof(ILDAPalette)*(seq->paletteCount+1)); 183 195 if(newSpace == NULL) 184 return errno;196 { retval = -1; goto CREATE_ABORT; } 185 197 seq->palettes = newSpace; 186 198 } … … 191 203 192 204 if(read_status > 0) 205 { retval = read_status; goto CREATE_ABORT; } 206 else 193 207 bytes_read += read_status; 194 else195 return read_status; //something messed up in the read196 208 197 209 break; 198 210 199 211 case ILDATrueColorType: 200 bytes_read += *(( int *)(buffer+bytes_read+8));212 bytes_read += *((uint32_t *)(buffer+bytes_read+8)); 201 213 break; 202 214 default: … … 204 216 } 205 217 } 218 219 CREATE_FINALIZE: 220 seq->frameCount = currentFrame; 221 while(currentFrame > 0) 222 { 223 currentFrame--; 224 seq->frames[currentFrame].header.objectNumber = currentFrame; 225 seq->frames[currentFrame].header.objectCount = seq->frameCount; 226 } 206 227 return 1; 207 228 208 CREATE_FREE: 209 if(seq->frameCount != -1) 210 { 229 CREATE_ABORT: 230 while(currentFrame > 0) 231 (seq->frames)[--currentFrame].points; 232 233 if(seq->frames) 211 234 free(seq->frames); 235 if(seq->paletteMap) 212 236 free(seq->paletteMap); 213 } 214 if(seq->paletteCount != -1) 215 { 237 238 while(currentPalette > 0) 239 (seq->palettes)[currentPalette--].colors; 240 241 if(seq->palettes) 216 242 free(seq->palettes); 217 }243 218 244 return retval; 219 245 } … … 320 346 321 347 322 int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, short index)323 { 324 if(seq == NULL || frame == NULL || index < 0)348 int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, unsigned short index) 349 { 350 if(seq == NULL || frame == NULL) 325 351 return EINVAL; 326 352 … … 376 402 377 403 378 int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, short index)379 { 380 if(seq == NULL || palette == NULL || index < 0)404 int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, unsigned short index) 405 { 406 if(seq == NULL || palette == NULL) 381 407 return EINVAL; 382 408 … … 415 441 416 442 417 int ILDASequence_remove_frame(ILDASequence *seq, short index)418 { 419 if(seq == NULL || index < 0 || index> seq->frameCount)443 int ILDASequence_remove_frame(ILDASequence *seq, unsigned short index) 444 { 445 if(seq == NULL || index > seq->frameCount) 420 446 return EINVAL; 421 447 … … 458 484 459 485 460 int ILDASequence_remove_palette(ILDASequence *seq, short index)461 { 462 if(seq == NULL || index < 0 || index> seq->frameCount)486 int ILDASequence_remove_palette(ILDASequence *seq, unsigned short index) 487 { 488 if(seq == NULL || index > seq->frameCount) 463 489 return EINVAL; 464 490 … … 466 492 467 493 //index is relative to frames, we need to change it to a palette indexs 468 if((index == 0 && (seq->paletteMap[index] == -1)) ||494 if((index == 0 && (seq->paletteMap[index] == 0)) || 469 495 (index >= 1 && (seq->paletteMap[index] == seq->paletteMap[index-1]))) 470 496 { … … 694 720 695 721 696 ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const short index)697 { 698 if(seq == NULL || index < 0 || index>= seq->frameCount)722 ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const unsigned short index) 723 { 724 if(seq == NULL || index >= seq->frameCount) 699 725 return NULL; 700 726 701 727 short paletteIndex = seq->paletteMap[index]; 702 728 703 if(paletteIndex == -1)704 return ( void*)&ILDADefaultPalette;729 if(paletteIndex == 0) 730 return (ILDAPalette *)&ILDADefaultPalette; 705 731 else 706 return &seq->palettes[paletteIndex ];707 } 708 709 710 ILDAPoint *ILDAFrame_get_point(const ILDAFrame *frame, const short index)711 { 712 if(frame == NULL || index < 0 || index>= frame->header.entryCount)732 return &seq->palettes[paletteIndex-1]; 733 } 734 735 736 ILDAPoint *ILDAFrame_get_point(const ILDAFrame *frame, const unsigned short index) 737 { 738 if(frame == NULL || index >= frame->header.entryCount) 713 739 return NULL; 714 740 trunk/ILDAInspector/ILDAlib.h
r115 r348 40 40 //Modification 41 41 int ILDASequence_append(ILDASequence *seq, const ILDASequence *append); 42 int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, short index);43 int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, short index);44 int ILDASequence_remove_frame(ILDASequence *seq, short index);45 int ILDASequence_remove_palette(ILDASequence *seq, short index);42 int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, unsigned short index); 43 int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, unsigned short index); 44 int ILDASequence_remove_frame(ILDASequence *seq, unsigned short index); 45 int ILDASequence_remove_palette(ILDASequence *seq, unsigned short index); 46 46 47 47 48 48 //Information 49 49 ILDAPalette *ILDASequence_get_palette_for_frame(const ILDASequence *seq, const ILDAFrame *frame); 50 ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const short index);51 ILDAPoint *ILDAFrame_get_point(const ILDAFrame *frame, const short index);50 ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const unsigned short index); 51 ILDAPoint *ILDAFrame_get_point(const ILDAFrame *frame, const unsigned short index); 52 52 bool ILDAPoint_blank_bit(ILDAPoint *point); 53 53 char ILDAPoint_color_index(ILDAPoint *point); trunk/ILDAInspector/ILDAtypes.h
r184 r348 96 96 { 97 97 ILDAFrame *frames; 98 short frameCount;98 unsigned short frameCount; 99 99 ILDAPalette *palettes; 100 short paletteCount;101 short *paletteMap;100 unsigned short paletteCount; 101 unsigned short *paletteMap; 102 102 } ILDASequence; 103 103
