LCOV - code coverage report
Current view: top level - gutils - gimagereadtiff.c (source / functions) Hit Total Coverage
Test: FontForge coverage report 2017-08-04 01:21:11+02:00 (commit d35f7e4107a9e1db65cce47c468fcc914cecb8fd) Lines: 0 26 0.0 %
Date: 2017-08-04 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2000-2012 by George Williams */
       2             : /* 2013feb15, added file and mem error checks, Jose Da Silva */
       3             : /*
       4             :  * Redistribution and use in source and binary forms, with or without
       5             :  * modification, are permitted provided that the following conditions are met:
       6             : 
       7             :  * Redistributions of source code must retain the above copyright notice, this
       8             :  * list of conditions and the following disclaimer.
       9             : 
      10             :  * Redistributions in binary form must reproduce the above copyright notice,
      11             :  * this list of conditions and the following disclaimer in the documentation
      12             :  * and/or other materials provided with the distribution.
      13             : 
      14             :  * The name of the author may not be used to endorse or promote products
      15             :  * derived from this software without specific prior written permission.
      16             : 
      17             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
      18             :  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      19             :  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
      20             :  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      21             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      22             :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
      23             :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
      24             :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      25             :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
      26             :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             :  */
      28             : 
      29             : #include <fontforge-config.h>
      30             : 
      31             : #ifdef _NO_LIBTIFF
      32             : 
      33             : static int a_file_must_define_something=0;      /* ANSI says so */
      34             : 
      35             : #else
      36             : 
      37             : #include <tiffio.h>
      38             : 
      39             : #define int32 _int32
      40             : #define uint32 _uint32
      41             : #define int16 _int16
      42             : #define uint16 _uint16
      43             : #define int8 _int8
      44             : #define uint8 _uint8
      45             : 
      46             : #include "gimage.h"
      47             : 
      48             : #undef uint32
      49             : 
      50           0 : GImage *GImageReadTiff(char *filename) {
      51             : /* Import a TIF image, else return NULL if error  */
      52             :     TIFF* tif;
      53             :     uint32 w,h,i,j;
      54           0 :     uint32 *ipt,*fpt,*raster=NULL;
      55           0 :     GImage *ret=NULL;
      56             :     struct _GImage *base;
      57             : 
      58           0 :     if ( (tif=TIFFOpen(filename,"rb"))==NULL ) {
      59             :         /* if error, then report "built-in" error message and then exit       */
      60           0 :         return( NULL );
      61             :     }
      62             : 
      63             :     /* Get width and height of TIF image, exit if error */
      64           0 :     if ( TIFFGetField(tif,TIFFTAG_IMAGEWIDTH,&w)!=1 || \
      65           0 :          TIFFGetField(tif,TIFFTAG_IMAGELENGTH,&h)!=1 )
      66             :         goto errorGImageReadTiff;
      67             : 
      68             :     /* Create memory to hold image & raster, exit if not enough memory      */
      69           0 :     if ( (ret=GImageCreate(it_true,w,h))==NULL )
      70           0 :         goto errorGImageReadTiffMem;
      71           0 :     if ( (raster=(uint32*) malloc(w*h*sizeof(uint32)))==NULL ) {
      72           0 :         NoMoreMemMessage();
      73           0 :         goto errorGImageReadTiffMem;
      74             :     }
      75             : 
      76             :     /* Read TIF image and process it into an internal FF usable format  */
      77           0 :     if ( TIFFReadRGBAImage(tif,w,h,raster,0) ) {
      78           0 :         TIFFClose(tif);
      79           0 :         base=ret->u.image;
      80           0 :         for ( i=0; i<h; ++i ) {
      81           0 :             ipt=(uint32 *)(base->data+i*base->bytes_per_line);
      82           0 :             fpt=raster+(h-1-i)*w;
      83           0 :             for ( j=0; j<w; ++j )
      84           0 :                 *ipt++ =COLOR_CREATE(
      85             :                         TIFFGetR(fpt[j]),TIFFGetG(fpt[j]),TIFFGetB(fpt[j]));
      86             :         }
      87           0 :         free(raster);
      88           0 :         return( ret );
      89             :     }
      90             : 
      91             : errorGImageReadTiff:
      92           0 :     fprintf(stderr,"Bad input file \"%s\"\n",filename );
      93             : errorGImageReadTiffMem:
      94           0 :     free(raster); free(ret);
      95           0 :     TIFFClose(tif);
      96           0 :     return( NULL );
      97             : }
      98             : 
      99             : #endif

Generated by: LCOV version 1.10