⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imgio.c

📁 数字水印技术处理程序集合
💻 C
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
// StirMark Benchmark - imgio.c
//
// Contents: Read write functions for PPM images
//
// Purpose:  
//
// Created:  C. Rey, G. Do雛r, J.-L. Dugelay and G. Csurka, Eur閏om, January 2002
//
// Modified: 
//
// History:  
//
// Copyright (c) 2000-2002, Microsoft Research Ltd , Institut National
// de Recherche en Informatique et Automatique (INRIA), Institut Eur閏om
// and the Integrated Publication and Information Systems Institute at
// GMD - Forschungszentrum Informationstechnik GmbH (GMD-IPSI).
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted for non-commercial research and academic
// use only, provided that the following conditions are met:
// 
// - Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer. Each
//   individual file must retain its own copyright notice.
// 
// - Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions, the following disclaimer and the
//   list of contributors in the documentation and/or other materials
//   provided with the distribution.
// 
// - Modification of the program or portion of it is allowed provided
//   that the modified files carry prominent notices stating where and
//   when they have been changed. If you do modify this program you
//   should send to the contributors a general description of the changes
//   and send them a copy of your changes at their request. By sending
//   any changes to this program to the contributors, you are granting a
//   license on such changes under the same terms and conditions as
//   provided in this license agreement. However, the contributors are
//   under no obligation to accept your changes.
// 
// - All non-commercial advertising materials mentioning features or use
//   of this software must display the following acknowledgement:
// 
//     This product includes software developed by Microsoft Research
//     Ltd, Institut National de Recherche en Informatique et Automatique
//     (INRIA), Institut Eur閏om and the Integrated Publication and
//     Information Systems Institute at GMD - Forschungszentrum
//     Informationstechnik GmbH (GMD-IPSI).
// 
// - Neither name of Microsoft Research Ltd, INRIA, Eur閏om and GMD-IPSI
//   nor the names of their contributors may be used to endorse or
//   promote products derived from this software without specific prior
//   written permission.
// 
// - If you use StirMark Benchmark for your research, please cite:
// 
//     Fabien A. P. Petitcolas, Martin Steinebach, Fr閐閞ic Raynal, Jana
//     Dittmann, Caroline Fontaine, Nazim Fat鑣. A public automated
//     web-based evaluation service for watermarking schemes: StirMark
//     Benchmark. In Ping Wah Wong and Edward J. Delp, editors,
//     proceedings of electronic imaging, security and watermarking of
//     multimedia contents III, vol. 4314, San Jose, California, U.S.A.,
//     20-26 January 2001. The Society for imaging science and
//     technology (I.S.&T.) and the international Society for optical
//     engineering (SPIE). ISSN 0277-786X.
// 
// and
// 
//     Fabien A. P. Petitcolas. Watermarking schemes
//     evaluation. I.E.E.E. Signal Processing, vol. 17, no. 5,
//     pp. 58-64, September 2000.
// 
// THIS SOFTWARE IS NOT INTENDED FOR ANY COMMERCIAL APPLICATION AND IS
// PROVIDED BY MICROSOFT RESEARCH LTD, INRIA, EUR蒀OM, GMD-IPSI AND
// CONTRIBUTORS 'AS IS', WITH ALL FAULTS AND ANY EXPRESS OR IMPLIED
// REPRESENTATIONS OR WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE, TITLE OR NONINFRINGEMENT OF INTELLECTUAL
// PROPERTY ARE DISCLAIMED. IN NO EVENT SHALL MICROSOFT RESEARCH LTD,
// INRIA, EUR蒀OM, GMD-IPSI OR THEIR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 
// THE USE OF THIS SOFTWARE FOR CIRCUMVENTING WITHOUT AUTHORITY ANY
// EFFECTIVE TECHNOLOGICAL MEASURES DESIGNED TO PROTECT ANY COPYRIGHTS OR
// ANY RIGHTS RELATED TO COPYRIGHT AS PROVIDED BY LAW OR THE SUI GENERIS
// RIGHT PROVIDED BY SOME COUNTRIES IS STRICTLY PROHIBITED.
//
// $Header: /home/cvs/StirmarkBench/StirMark_Bench/SignalProcessing/SelfSimilarities/imgio.c,v 1.2 2002/04/19 10:23:58 petitcolas Exp $ 
//----------------------------------------------------------------------------
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>

#include "compil.h"
#include "imgio.h"
#define ERROR 0
#define SUCCESS 1


/******************************************************************/

image * readPGM(char *name,unsigned *width,unsigned *height)
{
  unsigned position;
  unsigned imageSize,levels;
  int  magic,number,currentCHAR;
  image *retimage;
  FILE *imageID;

  char Debugchar[5];
  
  if((imageID=fopen(name,"rb"))==0) 
  {
		fprintf(stderr,"Impossible d'ouvrir le fichier %s\n",name);
    exit(1);
  }
   
  if (((magic=getc(imageID))!='P') || ((number=getc(imageID))!= '5'))
		fprintf(stderr,"Version inconnue de fichier PPM");
        
	if ((currentCHAR=getc(imageID))!='\n')
		fprintf(stderr,"fichier deteriore\n");

  while ((currentCHAR=getc(imageID))=='#')
	while ((currentCHAR=getc(imageID))!='\n') {} 

  fseek(imageID,ftell(imageID)-1,SEEK_SET);
  fscanf(imageID,"%s",Debugchar);
  *width=atoi(Debugchar);
  currentCHAR=getc(imageID);
  fscanf(imageID,"%s",Debugchar);
  *height=atoi(Debugchar);

  /*fread(height,sizeof(unsigned),1,imageID);*/
  imageSize=(*width)*(*height);
   
  fscanf(imageID,"%s",Debugchar);
  levels=atoi(Debugchar);

  if((currentCHAR=getc(imageID))!='\n')
                fprintf(stderr,"fichier deteriore\n");

  position=ftell(imageID);

  retimage=(image *)(malloc(sizeof(image)*imageSize));
  fread(retimage,sizeof(image)*imageSize,1,imageID);
        return(retimage);
}


/*-----------------------------------------------------------------------*/

void writePGM(char *name,image *imageDATA,unsigned width,unsigned height)
{
        FILE *imageID;
        
  if((imageID=fopen(name,"wb"))==0)
  {
                fprintf(stderr,"Impossible d'ouvrir le fichier %s\n",name);
    exit(1);
  }

  fputs("P5\n",imageID);
  fputs("# Portable GrayMap file format\n",imageID);
  fputs("# IFS and SECURITY project\n",imageID);
  fputs("# S. ROCHE Eurecom Institute France\n",imageID);
  fputs("# Janv 97\n",imageID);

  fprintf(imageID,"%u %u\n255\n",width,height);
   
  fwrite(imageDATA,sizeof(image)*width*height,1,imageID);

  fclose(imageID);
}


/*-----------------------------------------------------------------------*/

image * readRAW(char *name,int data_type,unsigned width,unsigned height)
{
        unsigned imageSize;
  unsigned loop;
  image *retimage, *p_retimage;
  unsigned char  *imageUC;

  FILE *imageID;
  
  if((imageID=fopen(name,"rb"))==0) {
                fprintf(stderr,"Impossible d'ouvrir le fichier %s\n",name);
    exit(1);
        }
   
  imageSize = width * height;
  
  if((retimage =(image*)malloc(sizeof(image)*imageSize))==NULL)
                fprintf(stderr,"Probleme d'allocation memoire\n");

        switch (data_type) 
  {
                case sizeof(unsigned char) :
                                if((imageUC = (unsigned char *)malloc(sizeof(unsigned char)*imageSize))==NULL)
                                        fprintf(stderr,"Probleme d'allocation memoire\n");
          
        fread(imageUC,sizeof(unsigned char)*imageSize,1,imageID);
                        
        for(loop=0, p_retimage=retimage; loop < imageSize;loop++, p_retimage++, imageUC++){
                                        *p_retimage = (int)(*imageUC);
                                }
    /*    free(imageUC);*/
                                break;
                
                case sizeof(int) :
                                fread(retimage,sizeof(int)*imageSize,1,imageID);
        break;
        }     
  return(retimage);
}

/*-----------------------------------------------------------------------*/

void writeRAW(char *name,image *imageDATA, int data_type, unsigned width,\
              unsigned height)
{
  FILE *imageID;
  unsigned loop;
  unsigned char * p_imageDATA;
        
  if((imageID=fopen(name,"wb"))==0) {
                fprintf(stderr,"Impossible d'ouvrir le fichier %s\n",name);
    exit(1);
  }

  p_imageDATA = (unsigned char *)malloc(sizeof(unsigned char)*width*height);
  switch (data_type) {
                case sizeof(unsigned char) :
                         for(loop=0; loop < (width*height);loop++) 
       {
                                 if (imageDATA[loop] > 255)
                                         p_imageDATA[loop] = 255;
         else if (imageDATA[loop] < 0)
           p_imageDATA[loop] = 0;
         else
           p_imageDATA[loop] = (unsigned char)imageDATA[loop];
       }
       
                         fwrite(p_imageDATA,sizeof(unsigned char)*width*height,1,imageID);
       break;
       
                case sizeof(int) :
                         fwrite(imageDATA,sizeof(int)*width*height,1,imageID);
       break;
        }
  fclose(imageID);
}

/******************************************************************************/

int ReadPPM (char *filein_name, int *xsize, int *ysize, int *maxrgb,
        image **rarray, image **garray, image **barray ) 
{

  FILE *filein;
  int   numbytes;
  int   result;

  filein = fopen ( filein_name, "rb" );

  if ( filein == NULL ) {
    printf ( "\n" );
    printf ( "PPMB_READ: Fatal error!\n" );
    printf ( "  Cannot open the input file %s.\n", filein_name );
    return ERROR;
  }

  /* Read the header.*/
  result = ppmb_read_header ( filein, xsize, ysize, maxrgb );

  if ( result == ERROR ) {
    printf ( "\n" );
    printf ( "PPMB_READ: Fatal error!\n" );
    printf ( "  PPMB_READ_HEADER failed.\n" );
    return ERROR;
  }

/* Allocate storage for the data. */
  numbytes = (*xsize)*(*ysize)*sizeof (image);

  *rarray = (image*)malloc(numbytes);

  if ( *rarray == NULL ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -