~ubuntu-branches/ubuntu/trusty/python-imaging/trusty

« back to all changes in this revision

Viewing changes to decode.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-03-20 16:44:01 UTC
  • mfrom: (2.1.13 experimental)
  • Revision ID: package-import@ubuntu.com-20130320164401-ptf6m0ttg4zw72az
Tags: 1.1.7+2.0.0-1
Pillow 2.0.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
388
388
    return (PyObject*) decoder;
389
389
}
390
390
 
 
391
/* -------------------------------------------------------------------- */
 
392
/* LibTiff                                                              */
 
393
/* -------------------------------------------------------------------- */
 
394
 
 
395
#ifdef HAVE_LIBTIFF
 
396
 
 
397
#include "TiffDecode.h"
 
398
 
 
399
#include <string.h>
 
400
#ifdef __WIN32__
 
401
#define strcasecmp(s1, s2) stricmp(s1, s2)
 
402
#endif
 
403
 
 
404
PyObject*
 
405
PyImaging_LibTiffDecoderNew(PyObject* self, PyObject* args)
 
406
{
 
407
    ImagingDecoderObject* decoder;
 
408
    char* mode;
 
409
    char* rawmode;
 
410
    char* compname;
 
411
    int compression;
 
412
        int fp;
 
413
 
 
414
    if (! PyArg_ParseTuple(args, "sssi", &mode, &rawmode, &compname, &fp))
 
415
    return NULL;
 
416
 
 
417
    TRACE(("new tiff decoder %s\n", compname));
 
418
        
 
419
        /* UNDONE -- we can probably do almost any arbitrary compression here, 
 
420
         * since we're effective passing in the whole file in one shot and
 
421
         * getting back the data row by row. V2 maybe 
 
422
         */
 
423
 
 
424
    if (strcasecmp(compname, "tiff_ccitt") == 0) {
 
425
        compression = COMPRESSION_CCITTRLE;
 
426
    
 
427
    } else if (strcasecmp(compname, "group3") == 0) {
 
428
        compression = COMPRESSION_CCITTFAX3;
 
429
 
 
430
    } else if (strcasecmp(compname, "group4") == 0) {
 
431
        compression = COMPRESSION_CCITTFAX4;
 
432
 
 
433
    } else if (strcasecmp(compname, "tiff_raw_16") == 0) {
 
434
        compression = COMPRESSION_CCITTRLEW;
 
435
 
 
436
    } else {
 
437
        PyErr_SetString(PyExc_ValueError, "unknown compession");
 
438
        return NULL;
 
439
    }
 
440
 
 
441
    decoder = PyImaging_DecoderNew(sizeof(TIFFSTATE));
 
442
    if (decoder == NULL)
 
443
        return NULL;
 
444
 
 
445
    if (get_unpacker(decoder, mode, rawmode) < 0)
 
446
        return NULL;
 
447
 
 
448
    if (! ImagingLibTiffInit(&decoder->state, compression, fp)) {
 
449
        Py_DECREF(decoder);
 
450
        PyErr_SetString(PyExc_RuntimeError, "tiff codec initialization failed");
 
451
        return NULL;
 
452
    }
 
453
 
 
454
    decoder->decode  = ImagingLibTiffDecode;
 
455
 
 
456
    return (PyObject*) decoder;
 
457
}
 
458
 
 
459
#endif
391
460
 
392
461
/* -------------------------------------------------------------------- */
393
462
/* MSP                                                                  */