Image_3, ImageIO, vmpendian and fgets

This commit is contained in:
Guillaume Damiand 2015-03-16 16:11:01 +01:00
parent 162c6c2cc0
commit a4afce92b6
13 changed files with 2203 additions and 2006 deletions

View File

@ -700,5 +700,8 @@ CGAL_IMAGEIO_EXPORT float evaluate(const _image* image,const std::size_t i,const
*/
CGAL_IMAGEIO_EXPORT void convertImageTypeToFloat(_image* image);
#ifdef CGAL_HEADER_ONLY
#include "ImageIO_impl.h"
#endif // CGAL_HEADER_ONLY
#endif // end IMAGEIO_H

File diff suppressed because it is too large Load Diff

View File

@ -490,10 +490,12 @@ Image_3::labellized_trilinear_interpolation(const Coord_type& x,
} // end namespace CGAL
#ifdef CGAL_HEADER_ONLY
#include "Image_3_impl.h"
#endif // CGAL_HEADER_ONLY
#if defined(BOOST_MSVC)
# pragma warning(pop)
#endif
#endif // CGAL_IMAGE_3_H

View File

@ -0,0 +1,232 @@
// Copyright (c) 2005-2008 INRIA Sophia-Antipolis (France).
// 2008 GeometryFactory, Sophia Antipolis (France)
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Laurent Rineau, Pierre Alliez
#ifdef CGAL_HEADER_ONLY
#define CGAL_INLINE_FUNCTION inline
#else
#define CGAL_INLINE_FUNCTION
#endif
#include <CGAL/gl.h>
namespace CGAL {
CGAL_INLINE_FUNCTION
bool Image_3::private_read(_image* im)
{
if(im != 0)
{
if(image() != 0)
{
::_freeImage(image());
}
image_ptr = Image_shared_ptr(im, Image_deleter());
// std::cerr <<
// boost::format("image=%1% (xdim=%2%, ydim=%3%, zdim=%4%)\n")
// % image_ptr.get() % image_ptr->xdim % image_ptr->ydim % image_ptr->zdim;
}
return im != 0;
}
CGAL_INLINE_FUNCTION
void Image_3::gl_draw(const float point_size,
const unsigned char r,
const unsigned char g,
const unsigned char b)
{
if(image_ptr.get() == NULL)
return;
glPointSize(point_size);
glColor3ub(r,g,b);
glBegin(GL_POINTS);
unsigned char *pData = (unsigned char*)image_ptr->data;
unsigned int xy = image_ptr->xdim * image_ptr->ydim;
for(unsigned int i=0;i<image_ptr->xdim;i+=5)
for(unsigned int j=0;j<image_ptr->ydim;j+=5)
for(unsigned int k=0;k<image_ptr->zdim;k+=5)
{
unsigned char value = pData[xy*k + j*image_ptr->xdim + i];
if(value > 0)
{
double x = image_ptr->vx * i;
double y = image_ptr->vy * j;
double z = image_ptr->vz * k;
glVertex3d(x,y,z);
}
}
glEnd();
} // end Image_3::gl_draw
CGAL_INLINE_FUNCTION
void Image_3::gl_draw_bbox(const float line_width,
const unsigned char red,
const unsigned char green,
const unsigned char blue)
{
if(!image_ptr)
return;
glLineWidth(line_width);
glColor3ub(red,green,blue);
glBegin(GL_LINES);
struct Point {
double x_;
double y_;
double z_;
Point(double x, double y, double z) : x_(x), y_(y), z_(z) {};
double x() const { return x_; }
double y() const { return y_; }
double z() const { return z_; }
};
const double xmax = (image_ptr->xdim - 1.0)*(image_ptr->vx);
const double ymax = (image_ptr->ydim - 1.0)*(image_ptr->vy);
const double zmax = (image_ptr->zdim - 1.0)*(image_ptr->vz);
Point a(0.0, 0.0, 0.0);
Point b(0.0, ymax, 0.0);
Point c(0.0, ymax, zmax);
Point d(0.0, 0.0, zmax);
Point e(xmax, 0.0, 0.0);
Point f(xmax, ymax, 0.0);
Point g(xmax, ymax, zmax);
Point h(xmax, 0.0, zmax);
glVertex3d(a.x(),a.y(),a.z());
glVertex3d(b.x(),b.y(),b.z());
glVertex3d(b.x(),b.y(),b.z());
glVertex3d(c.x(),c.y(),c.z());
glVertex3d(c.x(),c.y(),c.z());
glVertex3d(d.x(),d.y(),d.z());
glVertex3d(d.x(),d.y(),d.z());
glVertex3d(a.x(),a.y(),a.z());
glVertex3d(e.x(),e.y(),e.z());
glVertex3d(f.x(),f.y(),f.z());
glVertex3d(f.x(),f.y(),f.z());
glVertex3d(g.x(),g.y(),g.z());
glVertex3d(g.x(),g.y(),g.z());
glVertex3d(h.x(),h.y(),h.z());
glVertex3d(h.x(),h.y(),h.z());
glVertex3d(e.x(),e.y(),e.z());
glVertex3d(a.x(),a.y(),a.z());
glVertex3d(e.x(),e.y(),e.z());
glVertex3d(d.x(),d.y(),d.z());
glVertex3d(h.x(),h.y(),h.z());
glVertex3d(c.x(),c.y(),c.z());
glVertex3d(g.x(),g.y(),g.z());
glVertex3d(b.x(),b.y(),b.z());
glVertex3d(f.x(),f.y(),f.z());
glEnd();
} // end Image_3::gl_draw_bbox
} // end namespace CGAL
#ifdef CGAL_USE_VTK
#include <vtkImageData.h>
#include <CGAL/Image_3_vtk_interface.h>
namespace CGAL {
namespace {
struct VTK_to_ImageIO_type_mapper {
WORD_KIND wordKind;
SIGN sign;
unsigned int wdim;
};
static const VTK_to_ImageIO_type_mapper VTK_to_ImageIO_type[VTK_ID_TYPE] =
{ { WK_UNKNOWN, SGN_UNKNOWN, 0}, // 0=VTK_VOID
{ WK_UNKNOWN, SGN_UNKNOWN, 0}, // 1=VTK_BIT
{ WK_FIXED, SGN_SIGNED, 1}, // 2=VTK_CHAR
{ WK_FIXED, SGN_UNSIGNED, 1}, // 3=VTK_UNSIGNED_CHAR
{ WK_FIXED, SGN_SIGNED, 2}, // 4=VTK_SHORT
{ WK_FIXED, SGN_UNSIGNED, 2}, // 5=VTK_UNSIGNED_SHORT
{ WK_FIXED, SGN_SIGNED, 4}, // 6=VTK_INT
{ WK_FIXED, SGN_UNSIGNED, 4}, // 7=VTK_UNSIGNED_INT
{ WK_FIXED, SGN_SIGNED, 8}, // 8=VTK_LONG
{ WK_FIXED, SGN_UNSIGNED, 8}, // 9=VTK_UNSIGNED_LONG
{ WK_FLOAT, SGN_SIGNED, 4}, // 10=VTK_FLOAT
{ WK_FIXED, SGN_SIGNED, 8} // 11=VTK_DOUBLE
};
} //end anonymous namespace
CGAL_INLINE_FUNCTION
bool
Image_3::read_vtk_image_data(vtkImageData* vtk_image)
{
if(!vtk_image)
return false;
_image* image = ::_initImage();
const int* dims = vtk_image->GetDimensions();
const double* spacing = vtk_image->GetSpacing();
image->vectMode = VM_SCALAR;
image->xdim = dims[0];
image->ydim = dims[1];
image->zdim = dims[2];
image->vdim = 1;
image->vx = spacing[0];
image->vy = spacing[1];
image->vz = spacing[2];
vtk_image->Update();
image->endianness = ::_getEndianness();
int vtk_type = vtk_image->GetScalarType();
if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;
if(vtk_type < 0 || vtk_type > VTK_DOUBLE)
vtk_type = VTK_DOUBLE;
const VTK_to_ImageIO_type_mapper& imageio_type =
VTK_to_ImageIO_type[vtk_type];
image->wdim = imageio_type.wdim;
image->wordKind = imageio_type.wordKind;
image->sign = imageio_type.sign;
image->data = ::ImageIO_alloc(dims[0]*dims[1]*dims[2]*image->wdim);
std::cerr << "GetNumberOfTuples()=" << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples()
<< "\nimage->size()=" << dims[0]*dims[1]*dims[2]
<< "\nwdim=" << image->wdim << '\n';
assert(vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() == dims[0]*dims[1]*dims[2]);
vtk_image->GetPointData()->GetScalars()->ExportToVoidPointer(image->data);
return this->private_read(image);
}
} // end namespace CGAL
#endif // CGAL_USE_VTK

File diff suppressed because it is too large Load Diff

View File

@ -18,206 +18,9 @@
//
// Author(s) : Laurent Rineau, Pierre Alliez
#ifndef CGAL_HEADER_ONLY
#include <CGAL/Image_3.h>
#include <CGAL/gl.h>
#include <CGAL/Image_3_impl.h>
namespace CGAL {
bool Image_3::private_read(_image* im)
{
if(im != 0)
{
if(image() != 0)
{
::_freeImage(image());
}
image_ptr = Image_shared_ptr(im, Image_deleter());
// std::cerr <<
// boost::format("image=%1% (xdim=%2%, ydim=%3%, zdim=%4%)\n")
// % image_ptr.get() % image_ptr->xdim % image_ptr->ydim % image_ptr->zdim;
}
return im != 0;
}
void Image_3::gl_draw(const float point_size,
const unsigned char r,
const unsigned char g,
const unsigned char b)
{
if(image_ptr.get() == NULL)
return;
glPointSize(point_size);
glColor3ub(r,g,b);
glBegin(GL_POINTS);
unsigned char *pData = (unsigned char*)image_ptr->data;
unsigned int xy = image_ptr->xdim * image_ptr->ydim;
for(unsigned int i=0;i<image_ptr->xdim;i+=5)
for(unsigned int j=0;j<image_ptr->ydim;j+=5)
for(unsigned int k=0;k<image_ptr->zdim;k+=5)
{
unsigned char value = pData[xy*k + j*image_ptr->xdim + i];
if(value > 0)
{
double x = image_ptr->vx * i;
double y = image_ptr->vy * j;
double z = image_ptr->vz * k;
glVertex3d(x,y,z);
}
}
glEnd();
} // end Image_3::gl_draw
void Image_3::gl_draw_bbox(const float line_width,
const unsigned char red,
const unsigned char green,
const unsigned char blue)
{
if(!image_ptr)
return;
glLineWidth(line_width);
glColor3ub(red,green,blue);
glBegin(GL_LINES);
struct Point {
double x_;
double y_;
double z_;
Point(double x, double y, double z) : x_(x), y_(y), z_(z) {};
double x() const { return x_; }
double y() const { return y_; }
double z() const { return z_; }
};
const double xmax = (image_ptr->xdim - 1.0)*(image_ptr->vx);
const double ymax = (image_ptr->ydim - 1.0)*(image_ptr->vy);
const double zmax = (image_ptr->zdim - 1.0)*(image_ptr->vz);
Point a(0.0, 0.0, 0.0);
Point b(0.0, ymax, 0.0);
Point c(0.0, ymax, zmax);
Point d(0.0, 0.0, zmax);
Point e(xmax, 0.0, 0.0);
Point f(xmax, ymax, 0.0);
Point g(xmax, ymax, zmax);
Point h(xmax, 0.0, zmax);
glVertex3d(a.x(),a.y(),a.z());
glVertex3d(b.x(),b.y(),b.z());
glVertex3d(b.x(),b.y(),b.z());
glVertex3d(c.x(),c.y(),c.z());
glVertex3d(c.x(),c.y(),c.z());
glVertex3d(d.x(),d.y(),d.z());
glVertex3d(d.x(),d.y(),d.z());
glVertex3d(a.x(),a.y(),a.z());
glVertex3d(e.x(),e.y(),e.z());
glVertex3d(f.x(),f.y(),f.z());
glVertex3d(f.x(),f.y(),f.z());
glVertex3d(g.x(),g.y(),g.z());
glVertex3d(g.x(),g.y(),g.z());
glVertex3d(h.x(),h.y(),h.z());
glVertex3d(h.x(),h.y(),h.z());
glVertex3d(e.x(),e.y(),e.z());
glVertex3d(a.x(),a.y(),a.z());
glVertex3d(e.x(),e.y(),e.z());
glVertex3d(d.x(),d.y(),d.z());
glVertex3d(h.x(),h.y(),h.z());
glVertex3d(c.x(),c.y(),c.z());
glVertex3d(g.x(),g.y(),g.z());
glVertex3d(b.x(),b.y(),b.z());
glVertex3d(f.x(),f.y(),f.z());
glEnd();
} // end Image_3::gl_draw_bbox
} // end namespace CGAL
#ifdef CGAL_USE_VTK
#include <vtkImageData.h>
#include <CGAL/Image_3_vtk_interface.h>
namespace CGAL {
namespace {
struct VTK_to_ImageIO_type_mapper {
WORD_KIND wordKind;
SIGN sign;
unsigned int wdim;
};
static const VTK_to_ImageIO_type_mapper VTK_to_ImageIO_type[VTK_ID_TYPE] =
{ { WK_UNKNOWN, SGN_UNKNOWN, 0}, // 0=VTK_VOID
{ WK_UNKNOWN, SGN_UNKNOWN, 0}, // 1=VTK_BIT
{ WK_FIXED, SGN_SIGNED, 1}, // 2=VTK_CHAR
{ WK_FIXED, SGN_UNSIGNED, 1}, // 3=VTK_UNSIGNED_CHAR
{ WK_FIXED, SGN_SIGNED, 2}, // 4=VTK_SHORT
{ WK_FIXED, SGN_UNSIGNED, 2}, // 5=VTK_UNSIGNED_SHORT
{ WK_FIXED, SGN_SIGNED, 4}, // 6=VTK_INT
{ WK_FIXED, SGN_UNSIGNED, 4}, // 7=VTK_UNSIGNED_INT
{ WK_FIXED, SGN_SIGNED, 8}, // 8=VTK_LONG
{ WK_FIXED, SGN_UNSIGNED, 8}, // 9=VTK_UNSIGNED_LONG
{ WK_FLOAT, SGN_SIGNED, 4}, // 10=VTK_FLOAT
{ WK_FIXED, SGN_SIGNED, 8} // 11=VTK_DOUBLE
};
} //end anonymous namespace
bool
Image_3::read_vtk_image_data(vtkImageData* vtk_image)
{
if(!vtk_image)
return false;
_image* image = ::_initImage();
const int* dims = vtk_image->GetDimensions();
const double* spacing = vtk_image->GetSpacing();
image->vectMode = VM_SCALAR;
image->xdim = dims[0];
image->ydim = dims[1];
image->zdim = dims[2];
image->vdim = 1;
image->vx = spacing[0];
image->vy = spacing[1];
image->vz = spacing[2];
vtk_image->Update();
image->endianness = ::_getEndianness();
int vtk_type = vtk_image->GetScalarType();
if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;
if(vtk_type < 0 || vtk_type > VTK_DOUBLE)
vtk_type = VTK_DOUBLE;
const VTK_to_ImageIO_type_mapper& imageio_type =
VTK_to_ImageIO_type[vtk_type];
image->wdim = imageio_type.wdim;
image->wordKind = imageio_type.wordKind;
image->sign = imageio_type.sign;
image->data = ::ImageIO_alloc(dims[0]*dims[1]*dims[2]*image->wdim);
std::cerr << "GetNumberOfTuples()=" << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples()
<< "\nimage->size()=" << dims[0]*dims[1]*dims[2]
<< "\nwdim=" << image->wdim << '\n';
assert(vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() == dims[0]*dims[1]*dims[2]);
vtk_image->GetPointData()->GetScalars()->ExportToVoidPointer(image->data);
return this->private_read(image);
}
} // end namespace CGAL
#endif // CGAL_USE_VTK
#endif // CGAL_HEADER_ONLY

View File

@ -19,223 +19,9 @@
//
// Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau
#ifndef CGAL_HEADER_ONLY
/*
* These functions read and write our basic integer types from a little-endian
* file. The endian and word-size of the host machine will not affect this
* code. The only assumption made is that the C data type (char) is one byte
* long. This should be a safe assumption.
*/
#include <stdio.h>
#include "bmptypes.h"
#include "bmpendian.h"
#include "bmpendian_impl.h"
/*****************************************************************************
*
* Read functions. All read functions take an open file pointer as the first
* parameter and a pointer to data as the second parameter. The return value
* will be 0 on success, and EOF on failure. If successful, the second
* parameter will point to the data read.
*/
/*
* The CGAL_INT8 and CGAL_UINT8 types are stored as a single byte on disk. The INT8
* type is a signed integer with range (-128..127). The CGAL_UINT8 type is an
* unsigned integer with range (0..255).
*/
int readINT8little(FILE *f, CGAL_INT8 *i)
{
int rc;
rc = fgetc(f);
if (rc == EOF)
return rc;
*i = (rc & 0xff);
return 0;
}
int readUINT8little(FILE *f, CGAL_UINT8 *i)
{
int rc;
rc = fgetc(f);
if (rc == EOF)
return rc;
*i = (rc & 0xff);
return 0;
}
/*
* The CGAL_INT16 and CGAL_UINT16 types are stored as two bytes on disk. The INT16 type
* is a signed integer with range (-32768..32767). The CGAL_UINT16 type is an
* unisgned integer with range (0..65535).
*/
int readINT16little(FILE *f, CGAL_INT16 *i)
{
int rc;
CGAL_INT16 temp = 0;
temp = (fgetc(f) & 0xff);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= ((rc & 0xff) << 8);
*i = temp;
return 0;
}
int readUINT16little(FILE *f, CGAL_UINT16 *i)
{
int rc;
CGAL_UINT16 temp = 0;
temp = (fgetc(f) & 0xff);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= ((rc & 0xff) << 8);
*i = temp;
return 0;
}
/*
* The CGAL_INT32 and CGAL_UINT32 types are stored as four bytes on disk. The INT32
* type is a signed integer with range (-2147483648..2147483647). The CGAL_UINT32
* type is an unisgned integer with range (0..4294967295).
*/
int readINT32little(FILE *f, CGAL_INT32 *i)
{
int rc;
CGAL_INT32 temp = 0;
temp = ((long)fgetc(f) & 0xff);
temp |= (((long)fgetc(f) & 0xff) << 8);
temp |= (((long)fgetc(f) & 0xff) << 16);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= (((long)rc & 0xff) << 24);
*i = temp;
return 0;
}
int readUINT32little(FILE *f, CGAL_UINT32 *i)
{
int rc;
CGAL_UINT32 temp = 0;
temp = ((long)fgetc(f) & 0xff);
temp |= (((long)fgetc(f) & 0xff) << 8);
temp |= (((long)fgetc(f) & 0xff) << 16);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= (((long)rc & 0xff) << 24);
*i = temp;
return 0;
}
/*****************************************************************************
*
* Write functions. All write functions take an open file pointer as the first
* parameter and a data as the second parameter. The return value will be 0 on
* success, and EOF on failure. If successful, the second parameter will have
* been written to the open file.
*/
int writeINT8little(FILE *f, CGAL_INT8 i)
{
return fputc(i, f);
}
int writeUINT8little(FILE *f, CGAL_UINT8 i)
{
return fputc(i, f);
}
int writeINT16little(FILE *f, CGAL_INT16 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 8) & 0xff), f);
}
int writeUINT16little(FILE *f, CGAL_UINT16 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 8) & 0xff), f);
}
int writeINT32little(FILE *f, CGAL_INT32 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 8) & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 16) & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 24) & 0xff), f);
}
int writeUINT32little(FILE *f, CGAL_UINT32 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 8) & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 16) & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 24) & 0xff), f);
}
/*
* Formatting information for emacs in c-mode
*
* Local Variables:
* c-indent-level:4
* c-continued-statement-offset:4
* c-brace-offset:-4
* c-brace-imaginary-offset:0
* c-argdecl-indent:4
* c-label-offset:-4
* End:
*/
#endif // CGAL_HEADER_ONLY

View File

@ -54,6 +54,10 @@ int writeUINT8little(FILE *f, CGAL_UINT8 i);
int writeUINT16little(FILE *f, CGAL_UINT16 i);
int writeUINT32little(FILE *f, CGAL_UINT32 i);
#ifdef CGAL_HEADER_ONLY
#include "bmpendian_impl.h"
#endif // CGAL_HEADER_ONLY
#endif /* __ENDIAN_H_INCLUDED__ */

View File

@ -0,0 +1,257 @@
// Copyright (c) 2005-2008 ASCLEPIOS Project, INRIA Sophia-Antipolis (France)
// All rights reserved.
//
// This file is part of the ImageIO Library, and as been adapted for
// CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the
// GNU Lesser General Public License as published by the Free Software Foundation;
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// These files are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau
#ifdef CGAL_HEADER_ONLY
#define CGAL_INLINE_FUNCTION inline
#else
#define CGAL_INLINE_FUNCTION
#endif
/*
* These functions read and write our basic integer types from a little-endian
* file. The endian and word-size of the host machine will not affect this
* code. The only assumption made is that the C data type (char) is one byte
* long. This should be a safe assumption.
*/
#include <stdio.h>
#include "bmptypes.h"
/*****************************************************************************
*
* Read functions. All read functions take an open file pointer as the first
* parameter and a pointer to data as the second parameter. The return value
* will be 0 on success, and EOF on failure. If successful, the second
* parameter will point to the data read.
*/
/*
* The CGAL_INT8 and CGAL_UINT8 types are stored as a single byte on disk. The INT8
* type is a signed integer with range (-128..127). The CGAL_UINT8 type is an
* unsigned integer with range (0..255).
*/
CGAL_INLINE_FUNCTION
int readINT8little(FILE *f, CGAL_INT8 *i)
{
int rc;
rc = fgetc(f);
if (rc == EOF)
return rc;
*i = (rc & 0xff);
return 0;
}
CGAL_INLINE_FUNCTION
int readUINT8little(FILE *f, CGAL_UINT8 *i)
{
int rc;
rc = fgetc(f);
if (rc == EOF)
return rc;
*i = (rc & 0xff);
return 0;
}
/*
* The CGAL_INT16 and CGAL_UINT16 types are stored as two bytes on disk. The INT16 type
* is a signed integer with range (-32768..32767). The CGAL_UINT16 type is an
* unisgned integer with range (0..65535).
*/
CGAL_INLINE_FUNCTION
int readINT16little(FILE *f, CGAL_INT16 *i)
{
int rc;
CGAL_INT16 temp = 0;
temp = (fgetc(f) & 0xff);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= ((rc & 0xff) << 8);
*i = temp;
return 0;
}
CGAL_INLINE_FUNCTION
int readUINT16little(FILE *f, CGAL_UINT16 *i)
{
int rc;
CGAL_UINT16 temp = 0;
temp = (fgetc(f) & 0xff);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= ((rc & 0xff) << 8);
*i = temp;
return 0;
}
/*
* The CGAL_INT32 and CGAL_UINT32 types are stored as four bytes on disk. The INT32
* type is a signed integer with range (-2147483648..2147483647). The CGAL_UINT32
* type is an unisgned integer with range (0..4294967295).
*/
CGAL_INLINE_FUNCTION
int readINT32little(FILE *f, CGAL_INT32 *i)
{
int rc;
CGAL_INT32 temp = 0;
temp = ((long)fgetc(f) & 0xff);
temp |= (((long)fgetc(f) & 0xff) << 8);
temp |= (((long)fgetc(f) & 0xff) << 16);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= (((long)rc & 0xff) << 24);
*i = temp;
return 0;
}
CGAL_INLINE_FUNCTION
int readUINT32little(FILE *f, CGAL_UINT32 *i)
{
int rc;
CGAL_UINT32 temp = 0;
temp = ((long)fgetc(f) & 0xff);
temp |= (((long)fgetc(f) & 0xff) << 8);
temp |= (((long)fgetc(f) & 0xff) << 16);
rc = fgetc(f);
if (rc == EOF)
return rc;
temp |= (((long)rc & 0xff) << 24);
*i = temp;
return 0;
}
/*****************************************************************************
*
* Write functions. All write functions take an open file pointer as the first
* parameter and a data as the second parameter. The return value will be 0 on
* success, and EOF on failure. If successful, the second parameter will have
* been written to the open file.
*/
CGAL_INLINE_FUNCTION
int writeINT8little(FILE *f, CGAL_INT8 i)
{
return fputc(i, f);
}
CGAL_INLINE_FUNCTION
int writeUINT8little(FILE *f, CGAL_UINT8 i)
{
return fputc(i, f);
}
CGAL_INLINE_FUNCTION
int writeINT16little(FILE *f, CGAL_INT16 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 8) & 0xff), f);
}
CGAL_INLINE_FUNCTION
int writeUINT16little(FILE *f, CGAL_UINT16 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 8) & 0xff), f);
}
CGAL_INLINE_FUNCTION
int writeINT32little(FILE *f, CGAL_INT32 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 8) & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 16) & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 24) & 0xff), f);
}
CGAL_INLINE_FUNCTION
int writeUINT32little(FILE *f, CGAL_UINT32 i)
{
int rc;
rc = fputc((i & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 8) & 0xff), f);
if (rc == EOF)
return rc;
rc = fputc(((i >> 16) & 0xff), f);
if (rc == EOF)
return rc;
return fputc(((i >> 24) & 0xff), f);
}
/*
* Formatting information for emacs in c-mode
*
* Local Variables:
* c-indent-level:4
* c-continued-statement-offset:4
* c-brace-offset:-4
* c-brace-imaginary-offset:0
* c-argdecl-indent:4
* c-label-offset:-4
* End:
*/

View File

@ -19,23 +19,9 @@
//
// Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau
#include <string.h>
#ifndef CGAL_HEADER_ONLY
#include "gis.h"
#include "inr.h"
#include "fgets.h"
#include "fgets_impl.h"
/* get a string from a file and discard the ending newline character
if any */
char *fgetns(char *str, int n, _image *im ) {
char *ret;
int l;
memset( str, 0, n );
ret = ImageIO_gets( im, str, n );
if(!ret) return NULL;
l = strlen(str);
if(l > 0 && str[l-1] == '\n') str[l-1] = '\0';
return ret;
}
#endif // CGAL_HEADER_ONLY

View File

@ -19,6 +19,9 @@
//
// Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau
#ifndef FGETNS_H
#define FGETNS_H
#include <string.h>
#include "gis.h"
@ -27,3 +30,9 @@
/* get a string from a file and discard the ending newline character
if any */
char *fgetns(char *str, int n, _image *im );
#ifdef CGAL_HEADER_ONLY
#include "fgetns_impl.h"
#endif // CGAL_HEADER_ONLY
#endif // FGETNS_H

View File

@ -0,0 +1,48 @@
// Copyright (c) 2005-2008 ASCLEPIOS Project, INRIA Sophia-Antipolis (France)
// All rights reserved.
//
// This file is part of the ImageIO Library, and as been adapted for
// CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the
// GNU Lesser General Public License as published by the Free Software Foundation;
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// These files are provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : ASCLEPIOS Project (INRIA Sophia-Antipolis), Laurent Rineau
#ifdef CGAL_HEADER_ONLY
#define CGAL_INLINE_FUNCTION inline
#else
#define CGAL_INLINE_FUNCTION
#endif
#include <string.h>
#include "gis.h"
#include "inr.h"
/* get a string from a file and discard the ending newline character
if any */
CGAL_INLINE_FUNCTION
char *fgetns(char *str, int n, _image *im ) {
char *ret;
int l;
memset( str, 0, n );
ret = ImageIO_gets( im, str, n );
if(!ret) return NULL;
l = strlen(str);
if(l > 0 && str[l-1] == '\n') str[l-1] = '\0';
return ret;
}

View File

@ -66,11 +66,11 @@ DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/gif.cpp
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/gis.cpp"
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmp.cpp"
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/reech4x4.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmpendian.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/iris.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/fgetns.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp"
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/bmpendian.cpp"
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/fgetns.cpp"
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp"
DONE #include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/iris.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/ImageIO.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/pnm.cpp"
#include "/home/gdamiand/sources/CGAL/CGAL_ImageIO/src/CGAL_ImageIO/inr.cpp"