"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/src/imfinfo.c" (19 Sep 2013, 6691 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "imfinfo.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.5.6_vs_0.12.1.

    1 /*
    2  * -------------------------------------------------------------------------
    3  * SIP - Scilab Image Processing toolbox
    4  * Copyright (C) 2002-2009  Ricardo Fabbri
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  * 
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  * 
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, write to the Free Software
   18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19  * -------------------------------------------------------------------------
   20  */ 
   21 #include <stdio.h>
   22 #include <string.h>
   23 #include <time.h>
   24 #include <sys/types.h>
   25 #include "sip_common.h"
   26 
   27 
   28 /*----------------------------------------------------------
   29  * int_imfinfo: 
   30  *     interface for imfinfo function.
   31  *     should provide  type=imfinfo(name)  at Scilab level 
   32  * $Revision: 1.3 $ $Date: 2009-04-14 14:02:45 $
   33  *----------------------------------------------------------*/
   34 SipExport int 
   35 int_imfinfo(char *fname)
   36 {
   37    /* Interface variables */ 
   38    int   mC, nC, lC,  /* for name input  arg */
   39          mV, nV, lV,  /* for "verbose" optional input arg */
   40          mL=12, nL=1, lL,  /* for list output arg */
   41          mS=1, nS=12,
   42          mFileName, nFileName=1, 
   43          mFileSize=1, nFileSize=1,
   44          mFormat, nFormat=1, 
   45          mWidth=1, nWidth=1, 
   46          mHeight=1, nHeight=1, 
   47          mDepth=1, nDepth=1, 
   48          mStorageType, nStorageType=1, 
   49          mNumberOfColors=1, nNumberOfColors=1, 
   50          mResolutionUnit, nResolutionUnit=1, 
   51          mXResolution=1, nXResolution=1, 
   52          mYResolution=1, nYResolution=1, 
   53          pos,
   54          minlhs=1, maxlhs=1, minrhs=1, maxrhs=2, i;
   55    unsigned long int *lWidth, *lHeight, *lDepth, *lNumberOfColors,
   56                      *lFileSize, fsize;
   57    char *lFileName, *lStorageType, *lFormat, *lResolutionUnit, *arg2;
   58    double *lXResolution, *lYResolution;
   59    static char 
   60       *Str[]= {   "type", "FileName", "FileSize", "Format", 
   61                   "Width", "Height", "Depth", "StorageType", 
   62                   "NumberOfColors", "ResolutionUnit", "XResolution", 
   63                   "YResolution" }; 
   64 
   65    /* ImageMagick variables */
   66    ExceptionInfo  exception;
   67    Image          *image;
   68    ImageInfo      *image_info;
   69 
   70    CheckRhs(minrhs, maxrhs);
   71    CheckLhs(minlhs, maxlhs);
   72 
   73 
   74    /* Get name (#1) and "verbose" optional arg (#2)*/
   75    GetRhsVar(1, "c", &mC, &nC, &lC);  
   76    if (Rhs == 2) {
   77       GetRhsVar(2, "c", &mV, &nV, &lV);
   78       arg2 = (char *)calloc(strlen(cstk(lV))+1, sizeof(char));
   79       if (!arg2)
   80          sip_error("unable to alloc memory");
   81       strcpy(arg2,cstk(lV));
   82    }
   83 
   84    InitializeMagick(NULL);
   85    GetExceptionInfo(&exception);
   86    image_info=CloneImageInfo((ImageInfo *) NULL);
   87    (void) strcpy(image_info->filename,cstk(lC));
   88 
   89    image = PingImage(image_info, &exception);
   90    if (image == (Image *) NULL) {
   91       /* clean up */
   92       if (Rhs==2)
   93         free(arg2);
   94       if(exception.reason != NULL) {
   95          char errmsg[50];
   96          for (i=0; i<49; i++)
   97             errmsg[i]=' ';
   98          errmsg[49]='\0';
   99          strncpy(errmsg,SipGetLocaleExceptionMessage(exception.severity,exception.reason),50);
  100          DestroyImageInfo(image_info);
  101          DestroyExceptionInfo(&exception);
  102          DestroyMagick();
  103          sip_error(errmsg);
  104       }
  105       DestroyImageInfo(image_info);
  106       DestroyExceptionInfo(&exception);
  107       DestroyMagick();
  108       sip_error("unknown reason");
  109    }
  110 
  111    pos =1;
  112    CreateVar(1, "t", &mL, &nL, &lL);
  113    CreateListVarFromPtr(1,pos++,"S", &mS, &nS, Str);
  114 
  115    lFileName = image->filename;
  116    mFileName = strlen(image->filename);
  117    CreateListVarFromPtr(1,pos++,"c", &mFileName, &nFileName, &lFileName);
  118 
  119    fsize = SizeBlob(image);
  120    lFileSize = &fsize;
  121    CreateListVarFromPtr(1,pos++,"i", &mFileSize, &nFileSize, &lFileSize);
  122 
  123    lFormat = image->magick;
  124    mFormat = strlen(image->magick);
  125    CreateListVarFromPtr(1,pos++,"c", &mFormat, &nFormat, &lFormat);
  126 
  127    lWidth = &(image->columns);
  128    CreateListVarFromPtr(1,pos++,"i", &mWidth, &nWidth, &lWidth);
  129 
  130    lHeight = &(image->rows);
  131    CreateListVarFromPtr(1,pos++,"i", &mHeight, &nHeight, &lHeight);
  132 
  133    lDepth = &(image->depth);
  134    CreateListVarFromPtr(1,pos++,"i", &mDepth, &nDepth, &lDepth);
  135 
  136    lStorageType = (image->storage_class == DirectClass)? "truecolor":"indexed";
  137    mStorageType = strlen(lStorageType);
  138    CreateListVarFromPtr(1,pos++,"c", &mStorageType, &nStorageType, &lStorageType);
  139 
  140    lNumberOfColors = &(image->colors);
  141    CreateListVarFromPtr(1,pos++,"i", &mNumberOfColors, \
  142                                      &nNumberOfColors, &lNumberOfColors);
  143 
  144    /*
  145    lComments = image->comments;
  146    mComments = strlen(image->comments);
  147    CreateListVarFromPtr(1,pos++,"c", &mComments, &nComments, &lComments);
  148    */
  149 
  150    lResolutionUnit = (image->units == PixelsPerInchResolution)?"inch":"centimeter";
  151    mResolutionUnit = strlen(lResolutionUnit);
  152    CreateListVarFromPtr(1,pos++,"c", &mResolutionUnit, \
  153                                      &nResolutionUnit, &lResolutionUnit);
  154 
  155    lXResolution = &(image->x_resolution);
  156    CreateListVarFromPtr(1,pos++,"i", &mXResolution, &nXResolution, &lXResolution);
  157 
  158    lYResolution = &(image->y_resolution);
  159    CreateListVarFromPtr(1,pos++,"i", &mYResolution, &nYResolution, &lYResolution);
  160 
  161    if (Rhs==2) {
  162       if (strcmp(arg2,"verbose") != 0)
  163          sip_error("invalid 2nd argument");
  164       sciprint("       FileName: %s\n\r", image->filename);
  165       sciprint("       FileSize: %d\n\r", fsize);
  166       sciprint("         Format: %s\n\r", image->magick);
  167       sciprint("          Width: %d\n\r", image->columns);
  168       sciprint("         Height: %d\n\r", image->rows);
  169       sciprint("          Depth: %d\n\r", image->depth);
  170       sciprint("    StorageType: %s\n\r", lStorageType);
  171       sciprint(" NumberOfColors: %d\n\r", image->colors);
  172       sciprint(" ResolutionUnit: %s\n\r", lResolutionUnit);
  173       sciprint("    XResolution: %f\n\r", image->x_resolution);
  174       sciprint("    YResolution: %f\n\r", image->y_resolution);
  175       free(arg2);
  176    }
  177 
  178    /* Terminate Imagemagick */
  179    DestroyImageInfo(image_info);
  180    DestroyImage(image);
  181    DestroyExceptionInfo(&exception);
  182    DestroyMagick();
  183 
  184    /*  Return variables  */
  185    LhsVar(1) = 1;
  186    return true;
  187 }