~ubuntu-branches/ubuntu/gutsy/tk8.4/gutsy-updates

« back to all changes in this revision

Viewing changes to generic/tkImgGIF.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Waters
  • Date: 2005-09-06 14:35:13 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050906143513-7ns3rwufmpiq871b
Tags: 8.4.11-1
* New upstream release.
* Needed to fix mechanism for picking up SONAME.  Now uses special
  macro, TK_SHLIB_LD_EXTRAS, and only for Linux, Hurd and DebianBSD.
* Fixed some possible-bashisms in preinst.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 * |   provided "as is" without express or implied warranty.            |
30
30
 * +-------------------------------------------------------------------+
31
31
 *
32
 
 * RCS: @(#) $Id: tkImgGIF.c,v 1.24.2.1 2004/07/27 20:31:02 das Exp $
 
32
 * RCS: @(#) $Id: tkImgGIF.c,v 1.24.2.2 2005/06/20 10:28:00 dkf Exp $
33
33
 */
34
34
 
35
35
/*
55
55
 
56
56
typedef struct mFile {
57
57
    unsigned char *data;        /* mmencoded source string */
 
58
    int length;                 /* Length of string in bytes */
58
59
    int c;                      /* bits left over from previous character */
59
60
    int state;                  /* decoder state (0-4 or GIF_DONE) */
60
61
} MFile;
173
174
static int              Mgetc _ANSI_ARGS_((MFile *handle));
174
175
static int              char64 _ANSI_ARGS_((int c));
175
176
static void             mInit _ANSI_ARGS_((unsigned char *string,
176
 
                            MFile *handle));
 
177
                            int length, MFile *handle));
177
178
 
178
179
 
179
180
/*
552
553
        /*
553
554
         * Try interpreting the data as Base64 encoded
554
555
         */
555
 
        mInit((unsigned char *) data, &handle);
 
556
        mInit((unsigned char *) data, length, &handle);
556
557
        got = Mread(header, 10, 1, &handle);
557
558
        if (got != 10
558
559
                || ((strncmp(GIF87a, (char *) header, 6) != 0)
599
600
    int width, height;          /*   image to copy */
600
601
    int srcX, srcY;
601
602
{
602
 
    int result;
 
603
    int result, length;
603
604
    MFile handle;
604
605
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
605
606
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
609
610
    /*
610
611
     * Check whether the data is Base64 encoded
611
612
     */
612
 
    data = (char *) Tcl_GetByteArrayFromObj(dataObj, NULL);
 
613
    data = (char *) Tcl_GetByteArrayFromObj(dataObj, &length);
613
614
    if ((strncmp(GIF87a, data, 6) != 0) && (strncmp(GIF89a, data, 6) != 0)) {
614
 
        mInit((unsigned char *)data, &handle);
 
615
        mInit((unsigned char *)data, length, &handle);
615
616
        tsdPtr->fromData = 1;
616
617
        dataSrc = (Tcl_Channel) &handle;
617
618
    } else {
618
619
        tsdPtr->fromData = 2;
619
 
        mInit((unsigned char *)data, &handle);
 
620
        mInit((unsigned char *)data, length, &handle);
620
621
        dataSrc = (Tcl_Channel) &handle;
621
622
    }
622
623
    result = FileReadGIF(interp, dataSrc, "inline data",
1123
1124
 */
1124
1125
 
1125
1126
static void
1126
 
mInit(string, handle)
1127
 
   unsigned char *string;       /* string containing initial mmencoded data */
1128
 
   MFile *handle;               /* mmdecode "file" handle */
 
1127
mInit(string, length, handle)
 
1128
    unsigned char *string;      /* string containing initial mmencoded data */
 
1129
    int length;                 /* Length of string */
 
1130
    MFile *handle;              /* mmdecode "file" handle */
1129
1131
{
1130
 
   handle->data = string;
1131
 
   handle->state = 0;
1132
 
   handle->c = 0;
 
1132
    handle->data = string;
 
1133
    handle->length = length;
 
1134
    handle->state = 0;
 
1135
    handle->c = 0;
1133
1136
}
1134
1137
 
1135
1138
/*
1152
1155
 
1153
1156
static int
1154
1157
Mread(dst, chunkSize, numChunks, handle)  
1155
 
   unsigned char *dst;  /* where to put the result */
1156
 
   size_t chunkSize;    /* size of each transfer */
1157
 
   size_t numChunks;    /* number of chunks */
1158
 
   MFile *handle;       /* mmdecode "file" handle */
 
1158
    unsigned char *dst; /* where to put the result */
 
1159
    size_t chunkSize;   /* size of each transfer */
 
1160
    size_t numChunks;   /* number of chunks */
 
1161
    MFile *handle;      /* mmdecode "file" handle */
1159
1162
{
1160
 
   register int i, c;
1161
 
   int count = chunkSize * numChunks;
 
1163
    register int i, c;
 
1164
    int count = chunkSize * numChunks;
1162
1165
 
1163
 
   for(i=0; i<count && (c=Mgetc(handle)) != GIF_DONE; i++) {
 
1166
    for(i=0; i<count && (c=Mgetc(handle)) != GIF_DONE; i++) {
1164
1167
        *dst++ = c;
1165
 
   }
1166
 
   return i;
 
1168
    }
 
1169
    return i;
1167
1170
}
1168
1171
 
1169
1172
/*
1201
1204
    }
1202
1205
 
1203
1206
    do {
 
1207
        if (handle->length-- <= 0) {
 
1208
            handle->state = GIF_DONE;
 
1209
            return GIF_DONE;
 
1210
        }
1204
1211
        c = char64(*handle->data);
1205
1212
        handle->data++;
1206
1213
    } while (c == GIF_SPACE);
1315
1322
        return Mread(dst, hunk, count, (MFile *) chan);
1316
1323
    case 2:
1317
1324
        handle = (MFile *) chan;
 
1325
        if (handle->length <= 0 || (size_t)handle->length < (size_t) (hunk * count)) {
 
1326
            return -1;
 
1327
        }
1318
1328
        memcpy((VOID *)dst, (VOID *) handle->data, (size_t) (hunk * count));
1319
1329
        handle->data += hunk * count;
 
1330
        handle->length -= hunk * count;
1320
1331
        return (int)(hunk * count);
1321
1332
    default:
1322
1333
        return Tcl_Read(chan, (char *) dst, (int) (hunk * count));