~ubuntu-branches/debian/squeeze/python-imaging/squeeze

« back to all changes in this revision

Viewing changes to libImaging/Storage.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-08-28 23:14:10 UTC
  • mfrom: (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20060828231410-lca9enmne3ecmkup
Tags: 1.1.5-11
* python-imaging-sane: Depend on python-numarray. Closes: #382190.
* Add dependencies on ${shlibs:Depends}, lost in -6. Closes: #378596.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * The Python Imaging Library
3
 
 * $Id: //modules/pil/libImaging/Storage.c#4 $
 
3
 * $Id: Storage.c 2134 2004-10-06 08:55:20Z fredrik $
4
4
 *
5
5
 * imaging storage object
6
6
 *
25
25
 * 1998-12-29 fl   Fixed allocation bug caused by previous fix
26
26
 * 1999-02-03 fl   Added "RGBa" and "BGR" modes (experimental)
27
27
 * 2001-04-22 fl   Fixed potential memory leak in ImagingCopyInfo
 
28
 * 2003-09-26 fl   Added "LA" and "PA" modes (experimental)
28
29
 *
29
30
 * Copyright (c) 1998-2003 by Secret Labs AB 
30
31
 * Copyright (c) 1995-2003 by Fredrik Lundh
45
46
                          int size)
46
47
{
47
48
    Imaging im;
 
49
    ImagingSectionCookie cookie;
48
50
 
49
51
    im = (Imaging) calloc(1, size);
50
52
    if (!im)
67
69
        im->linesize = xsize;
68
70
        im->palette = ImagingPaletteNew("RGB");
69
71
 
 
72
    } else if (strcmp(mode, "PA") == 0) {
 
73
        /* 8-bit palette with alpha */
 
74
        im->bands = 2;
 
75
        im->pixelsize = 4; /* store in image32 memory */
 
76
        im->linesize = xsize * 4;
 
77
        im->palette = ImagingPaletteNew("RGB");
 
78
 
70
79
    } else if (strcmp(mode, "L") == 0) {
71
80
        /* 8-bit greyscale (luminance) images */
72
81
        im->bands = im->pixelsize = 1;
73
82
        im->linesize = xsize;
74
83
 
 
84
    } else if (strcmp(mode, "LA") == 0) {
 
85
        /* 8-bit greyscale (luminance) with alpha */
 
86
        im->bands = 2;
 
87
        im->pixelsize = 4; /* store in image32 memory */
 
88
        im->linesize = xsize * 4;
 
89
 
75
90
    } else if (strcmp(mode, "F") == 0) {
76
91
        /* 32-bit floating point images */
77
92
        im->bands = 1;
167
182
    /* Setup image descriptor */
168
183
    strcpy(im->mode, mode);
169
184
 
 
185
    ImagingSectionEnter(&cookie);
 
186
 
170
187
    /* Pointer array (allocate at least one line, to avoid MemoryError
171
188
       exceptions on platforms where calloc(0, x) returns NULL) */
172
189
    im->image = (char **) calloc((ysize > 0) ? ysize : 1, sizeof(void *));
 
190
 
 
191
    ImagingSectionLeave(&cookie);
 
192
 
173
193
    if (!im->image) {
174
194
        free(im);
175
195
        return (Imaging) ImagingError_MemoryError();
246
266
ImagingNewArray(const char *mode, int xsize, int ysize)
247
267
{
248
268
    Imaging im;
 
269
    ImagingSectionCookie cookie;
 
270
 
249
271
    int y;
250
272
    char* p;
251
273
 
253
275
    if (!im)
254
276
        return NULL;
255
277
 
 
278
    ImagingSectionEnter(&cookie);
 
279
 
256
280
    /* Allocate image as an array of lines */
257
281
    for (y = 0; y < im->ysize; y++) {
258
282
        p = (char *) malloc(im->linesize);
263
287
        im->image[y] = p;
264
288
    }
265
289
 
 
290
    ImagingSectionLeave(&cookie);
 
291
 
266
292
    if (y == im->ysize)
267
293
        im->destroy = ImagingDestroyArray;
268
294