Changeset 348

Show
Ignore:
Timestamp:
03/24/07 15:18:42 (2 years ago)
Author:
cweider2
Message:

ILDAlib refresh part I

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ILDAInspector/ILDAlib.c

    r184 r348  
    4949        while(sysCall = close(ildaFD), sysCall == -1 && sysCall == EINTR);  
    5050        if(sysCall < 0) 
    51                 retval = errno;       //something weird happend in close() 
     51                retval = -1;  //something weird happend in close() 
    5252 
    5353OPEN_EXIT:       
     
    6767        dst->frames = (ILDAFrame *)malloc(sizeof(ILDAFrame)*src->frameCount); 
    6868        if(dst->frames == NULL) 
    69                 { retval = errno; goto COPY_EXIT; } 
     69                { retval = -1; goto COPY_EXIT; } 
    7070        for(i = 0; i < src->frameCount; i++) 
    7171                { 
     
    7373                (dst->frames)[i].points = (ILDAPoint *)malloc(sizeof(ILDAPoint)*(src->frames)[i].header.entryCount); 
    7474                if((dst->frames)[i].points == NULL) 
    75                         { retval = errno; goto COPY_FREE1; } 
     75                        { retval = -1; goto COPY_FREE1; } 
    7676                 
    7777                memcpy((dst->frames)[i].points, (src->frames)[i].points, sizeof(ILDAPoint)*(src->frames)[i].header.entryCount); 
     
    8282        dst->palettes = (ILDAPalette *)malloc(sizeof(ILDAPalette)*src->paletteCount); 
    8383        if(dst->palettes == NULL) 
    84                 { retval = errno; goto COPY_FREE2; } 
     84                { retval = -1; goto COPY_FREE2; } 
    8585        for(i = 0; i < src->paletteCount; i++) 
    8686                { 
     
    8888                (dst->palettes)[i].colors = (ILDAColor *)malloc(sizeof(ILDAColor)*(src->palettes)[i].header.entryCount); 
    8989                if((dst->palettes)[i].colors == NULL) 
    90                         { retval = errno; goto COPY_FREE3; } 
     90                        { retval = -1; goto COPY_FREE3; } 
    9191                 
    9292                memcpy((dst->palettes)[i].colors, (src->palettes)[i].colors, sizeof(ILDAColor)*(src->palettes)[i].header.entryCount); 
     
    9494         
    9595        //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); 
    9898        if(dst->paletteMap == NULL) 
    9999                { retval = errno; goto COPY_FREE4; } 
     
    101101        return 0; 
    102102 
    103  
    104103COPY_FREE4: 
    105         while(i >= 0) 
    106                 free((dst->frames)[i].points); 
     104        i = src->paletteCount; 
    107105COPY_FREE3: 
     106        while(i > 0) 
     107                free((dst->frames)[--i].points); 
     108COPY_FREE2: 
    108109        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; 
    113111COPY_FREE1: 
     112        while(i > 0) 
     113                free((dst->frames)[--i].points); 
    114114        free(dst->frames); 
    115115COPY_EXIT: 
     
    129129        int retval = 0; 
    130130         
    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; 
    135137         
    136138        while(bytes_read < size && read_header(&header, buffer+bytes_read, size-bytes_read)) 
     
    140142                        case ILDA3DFrameType: 
    141143                        case ILDA2DFrameType: 
    142                                 if(seq->frameCount == -1)     //we need to allocate room for the frames 
     144                                if(seq->frameCount == 0)      //we need to allocate room for the frames 
    143145                                        { 
    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
    147149                                        seq->frames = (ILDAFrame *)malloc(sizeof(ILDAFrame)*header.objectCount); 
    148150                                        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); 
    151153                                        if(seq->paletteMap == NULL) 
    152                                                 return errno; 
     154                                                { retval = -1; goto CREATE_ABORT; } 
    153155                                        } 
    154156                                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; 
    163176                                currentFrame++; 
    164177                                 
    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 
    166181                                        bytes_read += read_status; 
    167                                 else     //something messed up in the read 
    168                                         { retval = read_status; goto CREATE_FREE; } 
    169182                                 
    170183                                break; 
    171184                                 
    172185                        case ILDAPaletteType: 
    173                                 if(seq->paletteCount == -1)   //we need to allocate room for the palette 
     186                                if(seq->palettes == NULL)     //we need to allocate room for the palette 
    174187                                        { 
    175188                                        seq->palettes = (ILDAPalette *)malloc(sizeof(ILDAPalette)); 
    176189                                        if(seq->palettes == NULL) 
    177                                                 return errno; 
    178                                         seq->paletteCount = 0; 
     190                                                { retval = -1; goto CREATE_ABORT; } 
    179191                                        } 
    180192                                else 
     
    182194                                        void *newSpace = realloc(seq->palettes, sizeof(ILDAPalette)*(seq->paletteCount+1)); 
    183195                                        if(newSpace == NULL) 
    184                                                 return errno; 
     196                                                { retval = -1; goto CREATE_ABORT; } 
    185197                                        seq->palettes = newSpace; 
    186198                                        } 
     
    191203                                 
    192204                                if(read_status > 0) 
     205                                        { retval = read_status; goto CREATE_ABORT; } 
     206                                else 
    193207                                        bytes_read += read_status; 
    194                                 else 
    195                                         return read_status; //something messed up in the read 
    196208                                 
    197209                                break; 
    198210                                 
    199211                        case ILDATrueColorType: 
    200                                 bytes_read += *((int *)(buffer+bytes_read+8)); 
     212                                bytes_read += *((uint32_t *)(buffer+bytes_read+8)); 
    201213                                break; 
    202214                        default: 
     
    204216                        } 
    205217                } 
     218 
     219CREATE_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                } 
    206227        return 1; 
    207228 
    208 CREATE_FREE: 
    209         if(seq->frameCount != -1) 
    210                 { 
     229CREATE_ABORT: 
     230        while(currentFrame > 0) 
     231                (seq->frames)[--currentFrame].points; 
     232                 
     233        if(seq->frames) 
    211234                free(seq->frames); 
     235        if(seq->paletteMap) 
    212236                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) 
    216242                free(seq->palettes); 
    217                } 
     243         
    218244        return retval; 
    219245        } 
     
    320346 
    321347 
    322 int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, short index) 
    323         { 
    324         if(seq == NULL || frame == NULL || index < 0
     348int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, unsigned short index) 
     349        { 
     350        if(seq == NULL || frame == NULL
    325351                return EINVAL; 
    326352         
     
    376402 
    377403 
    378 int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, short index) 
    379         { 
    380         if(seq == NULL || palette == NULL || index < 0
     404int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, unsigned short index) 
     405        { 
     406        if(seq == NULL || palette == NULL
    381407                return EINVAL; 
    382408         
     
    415441 
    416442 
    417 int ILDASequence_remove_frame(ILDASequence *seq, short index) 
    418         { 
    419         if(seq == NULL || index < 0 || index > seq->frameCount) 
     443int ILDASequence_remove_frame(ILDASequence *seq, unsigned short index) 
     444        { 
     445        if(seq == NULL || index > seq->frameCount) 
    420446                return EINVAL; 
    421447         
     
    458484 
    459485 
    460 int ILDASequence_remove_palette(ILDASequence *seq, short index) 
    461         { 
    462         if(seq == NULL || index < 0 || index > seq->frameCount) 
     486int ILDASequence_remove_palette(ILDASequence *seq, unsigned short index) 
     487        { 
     488        if(seq == NULL || index > seq->frameCount) 
    463489                return EINVAL; 
    464490         
     
    466492         
    467493        //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)) || 
    469495           (index >= 1 && (seq->paletteMap[index] == seq->paletteMap[index-1]))) 
    470496                { 
     
    694720 
    695721 
    696 ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const short index) 
    697         { 
    698         if(seq == NULL || index < 0 || index >= seq->frameCount) 
     722ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const unsigned short index) 
     723        { 
     724        if(seq == NULL || index >= seq->frameCount) 
    699725                return NULL; 
    700726         
    701727        short paletteIndex = seq->paletteMap[index]; 
    702728         
    703         if(paletteIndex == -1
    704                 return (void *)&ILDADefaultPalette; 
     729        if(paletteIndex == 0
     730                return (ILDAPalette *)&ILDADefaultPalette; 
    705731        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 
     736ILDAPoint *ILDAFrame_get_point(const ILDAFrame *frame, const unsigned short index) 
     737        { 
     738        if(frame == NULL || index >= frame->header.entryCount) 
    713739                return NULL; 
    714740         
  • trunk/ILDAInspector/ILDAlib.h

    r115 r348  
    4040//Modification 
    4141int 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); 
     42int ILDASequence_insert_frame(ILDASequence *seq, const ILDAFrame *frame, unsigned short index); 
     43int ILDASequence_insert_palette(ILDASequence *seq, const ILDAPalette *palette, unsigned short index); 
     44int ILDASequence_remove_frame(ILDASequence *seq, unsigned short index); 
     45int ILDASequence_remove_palette(ILDASequence *seq, unsigned short index); 
    4646 
    4747 
    4848//Information 
    4949ILDAPalette *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); 
     50ILDAPalette *ILDASequence_get_palette(const ILDASequence *seq, const unsigned short index); 
     51ILDAPoint *ILDAFrame_get_point(const ILDAFrame *frame, const unsigned short index); 
    5252bool ILDAPoint_blank_bit(ILDAPoint *point); 
    5353char ILDAPoint_color_index(ILDAPoint *point); 
  • trunk/ILDAInspector/ILDAtypes.h

    r184 r348  
    9696        { 
    9797        ILDAFrame *frames; 
    98         short frameCount; 
     98        unsigned short frameCount; 
    9999        ILDAPalette *palettes; 
    100         short paletteCount; 
    101         short *paletteMap; 
     100        unsigned short paletteCount; 
     101        unsigned short *paletteMap; 
    102102        } ILDASequence;  
    103103