+ unify DLL export defines to namespace names
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
37
src/Mod/Image/App/AppImage.cpp
Normal file
37
src/Mod/Image/App/AppImage.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* Jürgen Riegel 2002 *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <Python.h>
|
||||
#endif
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include "ImagePlane.h"
|
||||
|
||||
|
||||
/* registration table */
|
||||
static struct PyMethodDef Image_methods[] = {
|
||||
{NULL, NULL} /* end of table marker */
|
||||
};
|
||||
|
||||
/* Python entry */
|
||||
extern "C" {
|
||||
void ImageExport initImage() {
|
||||
(void) Py_InitModule("Image", Image_methods); /* mod name, table ptr */
|
||||
Base::Console().Log("Loading Image module... done\n");
|
||||
|
||||
Image::ImagePlane::init();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
49
src/Mod/Image/App/CMakeLists.txt
Normal file
49
src/Mod/Image/App/CMakeLists.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
if(WIN32)
|
||||
add_definitions(-DFCAppImage)
|
||||
endif(WIN32)
|
||||
|
||||
include_directories(
|
||||
#${OPENCV_INCLUDE_DIR}
|
||||
${PYTHON_INCLUDE_PATH}
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
${XERCESC_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
set(Image_LIBS
|
||||
#${OPENCV_LIBRARIES}
|
||||
FreeCADApp
|
||||
)
|
||||
|
||||
set(Image_SRCS
|
||||
#CaptureClass.cpp
|
||||
#CaptureClass.h
|
||||
ImageBase.cpp
|
||||
ImageBase.h
|
||||
ImagePlane.cpp
|
||||
ImagePlane.h
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
AppImage.cpp
|
||||
)
|
||||
|
||||
add_library(Image SHARED ${Image_SRCS})
|
||||
target_link_libraries(Image ${Image_LIBS})
|
||||
fc_copy_script("Mod/Image" "Image" Init.py)
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(Image PROPERTIES SUFFIX ".pyd")
|
||||
set_target_properties(Image PROPERTIES DEBUG_OUTPUT_NAME "Image_d")
|
||||
set_target_properties(Image PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/Image)
|
||||
set_target_properties(Image PROPERTIES PREFIX "../")
|
||||
elseif(MINGW)
|
||||
set_target_properties(Image PROPERTIES SUFFIX ".pyd")
|
||||
set_target_properties(Image PROPERTIES DEBUG_OUTPUT_NAME "Image_d")
|
||||
set_target_properties(Image PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/Image)
|
||||
set_target_properties(Image PROPERTIES PREFIX "")
|
||||
else(MSVC)
|
||||
set_target_properties(Image PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Mod/Image)
|
||||
set_target_properties(Image PROPERTIES PREFIX "")
|
||||
endif(MSVC)
|
||||
|
||||
install(TARGETS Image DESTINATION lib)
|
||||
147
src/Mod/Image/App/CaptureClass.cpp
Normal file
147
src/Mod/Image/App/CaptureClass.cpp
Normal file
@@ -0,0 +1,147 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "CaptureClass.h"
|
||||
|
||||
#ifdef _MSC_VER // this file is not available on Linux
|
||||
//# include <cvcam.h>
|
||||
#endif
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
/// Constructor with an Capture number, 0 will ask for one
|
||||
Capturerer::Capturerer(int num)
|
||||
: capture(NULL),captureImage(0),_bIsWinOn(false)
|
||||
{
|
||||
capture = cvCaptureFromCAM( num );
|
||||
|
||||
if( !capture )
|
||||
throw "Cant create capture device";
|
||||
|
||||
hScale=0.5;
|
||||
vScale=0.5;
|
||||
lineWidth=1;
|
||||
useLabel=true;
|
||||
|
||||
// Init font
|
||||
cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX/*|CV_FONT_ITALIC*/, hScale,vScale,0,lineWidth);
|
||||
|
||||
|
||||
}
|
||||
/// Constructor with an File name. Object will capture from that Video file
|
||||
Capturerer::Capturerer(const char* fileName)
|
||||
: capture(NULL), captureImage(0),_bIsWinOn(false)
|
||||
{
|
||||
capture = cvCaptureFromAVI( fileName );
|
||||
|
||||
if( !capture )
|
||||
throw "Cant create capture device";
|
||||
|
||||
}
|
||||
|
||||
int Capturerer::chooseCamNum(void)
|
||||
{
|
||||
#if 0
|
||||
int ncams = cvcamGetCamerasCount( );//returns the number of available cameras in the system
|
||||
//printf("Number of Cams: %d\n",ncams);
|
||||
int* out;
|
||||
if(ncams >1){
|
||||
int nselected = cvcamSelectCamera(&out);
|
||||
if(nselected>0)
|
||||
printf("the 1-st selected camera is camera number %d", out[0]);
|
||||
if(nselected == 2)
|
||||
printf("the 2-nd selected camera is camera number %d", out[1]);
|
||||
}else if (ncams < 1){
|
||||
printf("No camara in system! Terminating.\n");
|
||||
return -1;
|
||||
}else
|
||||
out = new int(0);
|
||||
|
||||
return *out;
|
||||
#else
|
||||
//FIXME: cvcamGetCamerasCount is not available on Linux
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
Capturerer::~Capturerer()
|
||||
{
|
||||
if(_bIsWinOn)
|
||||
cvDestroyWindow("Capture");
|
||||
if(capture)
|
||||
cvReleaseCapture(&capture);
|
||||
}
|
||||
|
||||
|
||||
void Capturerer::setCaptureWindows(bool On)
|
||||
{
|
||||
if(!_bIsWinOn && On)
|
||||
{
|
||||
cvNamedWindow( "Capture", 0 );
|
||||
_bIsWinOn = true;
|
||||
}
|
||||
if(_bIsWinOn && !On)
|
||||
{
|
||||
cvDestroyWindow("Capture");
|
||||
_bIsWinOn = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char Capturerer::getOneCapture(const char *text)
|
||||
{
|
||||
//static int i = 0;
|
||||
// Get frame
|
||||
IplImage* frame = NULL;
|
||||
frame = cvQueryFrame( capture );
|
||||
|
||||
if( !frame )
|
||||
throw "Cannot get frame";
|
||||
|
||||
if(! captureImage)
|
||||
size = cvGetSize(frame);
|
||||
captureImage = cvCreateImage( size, 8, 3 );
|
||||
|
||||
// copy memory frame to image
|
||||
cvCopy( frame, captureImage, 0 );
|
||||
|
||||
// Flip
|
||||
cvFlip(captureImage, captureImage);
|
||||
|
||||
// label
|
||||
if (text)
|
||||
cvPutText (captureImage,text, cvPoint(0,size.height - 5) , &font, cvScalar(0,255,0));
|
||||
|
||||
|
||||
if(_bIsWinOn)
|
||||
cvShowImage( "Capture", captureImage );
|
||||
|
||||
return cvWaitKey(1);
|
||||
|
||||
}
|
||||
|
||||
71
src/Mod/Image/App/CaptureClass.h
Normal file
71
src/Mod/Image/App/CaptureClass.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2007 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef CaptureClassH
|
||||
#define CaptureClassH
|
||||
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class ImageAppExport Capturerer
|
||||
{
|
||||
public:
|
||||
/// Constructor with an Capture number, 0 will ask for one
|
||||
Capturerer(int num = 0);
|
||||
/// Constructor with an File name. Object will capture from that Video file
|
||||
Capturerer(const char* fileName);
|
||||
|
||||
~Capturerer();
|
||||
|
||||
static int chooseCamNum(void);
|
||||
|
||||
void setCaptureWindows(bool On);
|
||||
|
||||
char getOneCapture(const char *text=0);
|
||||
|
||||
private:
|
||||
CvCapture* capture;
|
||||
IplImage *captureImage;
|
||||
bool _bIsWinOn;
|
||||
|
||||
CvSize size;
|
||||
|
||||
// font stuff
|
||||
CvFont font;
|
||||
double hScale;
|
||||
double vScale;
|
||||
int lineWidth;
|
||||
bool useLabel;
|
||||
char buff[100];
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
346
src/Mod/Image/App/ImageBase.cpp
Normal file
346
src/Mod/Image/App/ImageBase.cpp
Normal file
@@ -0,0 +1,346 @@
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This is a class for holding and handling basic image data *
|
||||
* *
|
||||
* Author: Graeme van der Vlugt *
|
||||
* Copyright: Imetric 3D GmbH *
|
||||
* Year: 2004 *
|
||||
* *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <cmath>
|
||||
# include <cstring>
|
||||
#endif
|
||||
|
||||
#include "ImageBase.h"
|
||||
#include <Base/Exception.h>
|
||||
|
||||
using namespace Image;
|
||||
|
||||
// Constructor (constructs an empty image)
|
||||
ImageBase::ImageBase()
|
||||
{
|
||||
_pPixelData = NULL;
|
||||
_owner = true;
|
||||
_width = 0;
|
||||
_height = 0;
|
||||
_setColorFormat(IB_CF_GREY8, 8);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
ImageBase::~ImageBase()
|
||||
{
|
||||
try
|
||||
{
|
||||
clear();
|
||||
}
|
||||
catch(...) {}
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
ImageBase::ImageBase(const ImageBase &rhs)
|
||||
{
|
||||
// Do the copy
|
||||
if (rhs._owner == true)
|
||||
{
|
||||
// rhs is the owner - do a deep copy
|
||||
_pPixelData = NULL;
|
||||
_owner = false; // avoids a superfluous delete
|
||||
if (createCopy((void *)(rhs._pPixelData), rhs._width, rhs._height, rhs._format, rhs._numSigBitsPerSample) != 0)
|
||||
throw Base::Exception("ImageBase::ImageBase. Error creating copy of image");
|
||||
}
|
||||
else
|
||||
{
|
||||
// rhs is not the owner - do a shallow copy
|
||||
_pPixelData = rhs._pPixelData;
|
||||
_owner = rhs._owner;
|
||||
_width = rhs._width;
|
||||
_height = rhs._height;
|
||||
_setColorFormat(rhs._format, rhs._numSigBitsPerSample);
|
||||
}
|
||||
}
|
||||
|
||||
// = operator
|
||||
ImageBase & ImageBase::operator=(const ImageBase &rhs)
|
||||
{
|
||||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
// Implement any deletion necessary
|
||||
clear();
|
||||
|
||||
// Do the copy
|
||||
if (rhs._owner == true)
|
||||
{
|
||||
// rhs is the owner - do a deep copy
|
||||
_owner = false; // avoids a superfluous delete
|
||||
if (createCopy((void *)(rhs._pPixelData), rhs._width, rhs._height, rhs._format, rhs._numSigBitsPerSample) != 0)
|
||||
throw Base::Exception("ImageBase::operator=. Error creating copy of image");
|
||||
}
|
||||
else
|
||||
{
|
||||
// rhs is not the owner - do a shallow copy
|
||||
_pPixelData = rhs._pPixelData;
|
||||
_owner = rhs._owner;
|
||||
_width = rhs._width;
|
||||
_height = rhs._height;
|
||||
_setColorFormat(rhs._format, rhs._numSigBitsPerSample);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Clears the image data
|
||||
// It only deletes the pixel data if this object is the owner of the data
|
||||
void ImageBase::clear()
|
||||
{
|
||||
// If object is the owner of the data then delete the allocated memory
|
||||
if (_owner == true)
|
||||
{
|
||||
delete [] _pPixelData;
|
||||
_pPixelData = NULL;
|
||||
}
|
||||
// Else just reset the pointer (the owner of the pixel data must be responsible for deleting it)
|
||||
else
|
||||
{
|
||||
_pPixelData = NULL;
|
||||
}
|
||||
|
||||
// Re-initialise the other variables
|
||||
_owner = true;
|
||||
_width = 0;
|
||||
_height = 0;
|
||||
_setColorFormat(IB_CF_GREY8, 8);
|
||||
}
|
||||
|
||||
// Sets the color format and the dependant parameters
|
||||
// Returns 0 for OK, -1 for invalid color format
|
||||
int ImageBase::_setColorFormat(int format, unsigned short numSigBitsPerSample)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case IB_CF_GREY8:
|
||||
_numSamples = 1;
|
||||
_numBitsPerSample = 8;
|
||||
_numBytesPerPixel = 1;
|
||||
break;
|
||||
case IB_CF_GREY16:
|
||||
_numSamples = 1;
|
||||
_numBitsPerSample = 16;
|
||||
_numBytesPerPixel = 2;
|
||||
break;
|
||||
case IB_CF_GREY32:
|
||||
_numSamples = 1;
|
||||
_numBitsPerSample = 32;
|
||||
_numBytesPerPixel = 4;
|
||||
break;
|
||||
case IB_CF_RGB24:
|
||||
_numSamples = 3;
|
||||
_numBitsPerSample = 8;
|
||||
_numBytesPerPixel = 3;
|
||||
break;
|
||||
case IB_CF_RGB48:
|
||||
_numSamples = 3;
|
||||
_numBitsPerSample = 16;
|
||||
_numBytesPerPixel = 6;
|
||||
break;
|
||||
case IB_CF_BGR24:
|
||||
_numSamples = 3;
|
||||
_numBitsPerSample = 8;
|
||||
_numBytesPerPixel = 3;
|
||||
break;
|
||||
case IB_CF_BGR48:
|
||||
_numSamples = 3;
|
||||
_numBitsPerSample = 16;
|
||||
_numBytesPerPixel = 6;
|
||||
break;
|
||||
case IB_CF_RGBA32:
|
||||
_numSamples = 4;
|
||||
_numBitsPerSample = 8;
|
||||
_numBytesPerPixel = 4;
|
||||
break;
|
||||
case IB_CF_RGBA64:
|
||||
_numSamples = 4;
|
||||
_numBitsPerSample = 16;
|
||||
_numBytesPerPixel = 8;
|
||||
break;
|
||||
case IB_CF_BGRA32:
|
||||
_numSamples = 4;
|
||||
_numBitsPerSample = 8;
|
||||
_numBytesPerPixel = 4;
|
||||
break;
|
||||
case IB_CF_BGRA64:
|
||||
_numSamples = 4;
|
||||
_numBitsPerSample = 16;
|
||||
_numBytesPerPixel = 8;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((numSigBitsPerSample == 0) || (numSigBitsPerSample > _numBitsPerSample))
|
||||
_numSigBitsPerSample = _numBitsPerSample;
|
||||
else
|
||||
_numSigBitsPerSample = numSigBitsPerSample;
|
||||
|
||||
_format = format;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allocate own space for an image based on the current color space and image size parameters
|
||||
// Returns:
|
||||
// 0 for OK
|
||||
// -1 for error
|
||||
int ImageBase::_allocate()
|
||||
{
|
||||
// Check that pixel data pointer is null
|
||||
if (_pPixelData != NULL)
|
||||
return -1;
|
||||
|
||||
// Allocate the space needed to store the pixel data
|
||||
_owner = true;
|
||||
try
|
||||
{
|
||||
_pPixelData = new unsigned char [_width * _height * _numBytesPerPixel];
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// memory allocation error
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Load an image by copying the pixel data
|
||||
// This object will take ownership of the copied pixel data
|
||||
// (the source image is still controlled by the caller)
|
||||
// If numSigBitsPerSample = 0 then the full range is assumed to be significant
|
||||
// Returns:
|
||||
// 0 for OK
|
||||
// -1 for invalid color format
|
||||
// -2 for memory allocation error
|
||||
int ImageBase::createCopy(void* pSrcPixelData, unsigned long width, unsigned long height, int format, unsigned short numSigBitsPerSample)
|
||||
{
|
||||
// Clear any existing data
|
||||
clear();
|
||||
|
||||
// Set the color format and the dependant parameters
|
||||
if (_setColorFormat(format, numSigBitsPerSample) != 0)
|
||||
return -1;
|
||||
|
||||
// Set the image size
|
||||
_width = width;
|
||||
_height = height;
|
||||
|
||||
// Allocate our own memory for the pixel data
|
||||
if (_allocate() != 0)
|
||||
{
|
||||
clear();
|
||||
return -2;
|
||||
}
|
||||
|
||||
// Copy the pixel data
|
||||
memcpy((void *)_pPixelData, pSrcPixelData, _width * _height * _numBytesPerPixel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Make this object point to another image source
|
||||
// If takeOwnership is false then:
|
||||
// This object will not own (control) or copy the pixel data
|
||||
// (the source image is still controlled by the caller)
|
||||
// Else if takeOwnership is true then:
|
||||
// This object will take ownership (control) of the pixel data
|
||||
// (the source image is not (should not be) controlled by the caller anymore)
|
||||
// In this case the memory must have been allocated with the new operator (because this class will use the delete operator)
|
||||
// If numSigBitsPerSample = 0 then the full range is assumed to be significant
|
||||
// Returns:
|
||||
// 0 for OK
|
||||
// -1 for invalid color format
|
||||
int ImageBase::pointTo(void* pSrcPixelData, unsigned long width, unsigned long height, int format, unsigned short numSigBitsPerSample, bool takeOwnership)
|
||||
{
|
||||
// Clear any existing data
|
||||
clear();
|
||||
|
||||
// Set the color format and the dependant parameters
|
||||
if (_setColorFormat(format, numSigBitsPerSample) != 0)
|
||||
return -1;
|
||||
|
||||
// Set the image size
|
||||
_width = width;
|
||||
_height = height;
|
||||
|
||||
// Point to the source pixel data
|
||||
_owner = false;
|
||||
_pPixelData = (unsigned char *)pSrcPixelData;
|
||||
|
||||
// Flag ownership
|
||||
if (takeOwnership == true)
|
||||
_owner = true;
|
||||
else
|
||||
_owner = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Gets the value of a sample at the given pixel position
|
||||
// Returns 0 for valid value or -1 if coordinates or sample index are out of range or
|
||||
// if there is no image data
|
||||
int ImageBase::getSample(int x, int y, unsigned short sampleIndex, double &value)
|
||||
{
|
||||
if ((_pPixelData == NULL) ||
|
||||
(sampleIndex >= _numSamples) ||
|
||||
(x < 0) || (x >= (int)_width) ||
|
||||
(y < 0) || (y >= (int)_height))
|
||||
return -1;
|
||||
|
||||
// Get pointer to sample
|
||||
switch (_format)
|
||||
{
|
||||
case IB_CF_GREY8:
|
||||
case IB_CF_RGB24:
|
||||
case IB_CF_BGR24:
|
||||
case IB_CF_RGBA32:
|
||||
case IB_CF_BGRA32:
|
||||
{
|
||||
unsigned char* pSample = _pPixelData + _numSamples * (y * _width + x) + sampleIndex;
|
||||
value = (double)(*pSample);
|
||||
}
|
||||
break;
|
||||
case IB_CF_GREY16:
|
||||
case IB_CF_RGB48:
|
||||
case IB_CF_BGR48:
|
||||
case IB_CF_RGBA64:
|
||||
case IB_CF_BGRA64:
|
||||
{
|
||||
unsigned short* pPix16 = (unsigned short *)_pPixelData;
|
||||
unsigned short* pSample = pPix16 + _numSamples * (y * _width + x) + sampleIndex;
|
||||
value = (double)(*pSample);
|
||||
}
|
||||
break;
|
||||
case IB_CF_GREY32:
|
||||
{
|
||||
unsigned long* pPix32 = (unsigned long *)_pPixelData;
|
||||
unsigned long* pSample = pPix32 + y * _width + x;
|
||||
value = (double)(*pSample);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
82
src/Mod/Image/App/ImageBase.h
Normal file
82
src/Mod/Image/App/ImageBase.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This is a class for holding and handling basic image data *
|
||||
* *
|
||||
* Author: Graeme van der Vlugt *
|
||||
* Copyright: Imetric 3D GmbH *
|
||||
* Year: 2004 *
|
||||
* *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Library General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* for detail see the LICENCE text file. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef IMAGEBASE_H
|
||||
#define IMAGEBASE_H
|
||||
|
||||
namespace Image
|
||||
{
|
||||
|
||||
#define IB_CF_GREY8 1 // 8-bit grey level images
|
||||
#define IB_CF_GREY16 2 // 16-bit grey level images
|
||||
#define IB_CF_GREY32 3 // 32-bit grey level images
|
||||
#define IB_CF_RGB24 4 // 24-bit (8,8,8) RGB color images
|
||||
#define IB_CF_RGB48 5 // 48-bit (16,16,16) RGB color images
|
||||
#define IB_CF_BGR24 6 // 24-bit (8,8,8) BGR color images
|
||||
#define IB_CF_BGR48 7 // 48-bit (16,16,16) BGR color images
|
||||
#define IB_CF_RGBA32 8 // 32-bit (8,8,8,8) RGBA color images (A = alpha)
|
||||
#define IB_CF_RGBA64 9 // 64-bit (16,16,16,16) RGBA color images (A = alpha)
|
||||
#define IB_CF_BGRA32 10 // 32-bit (8,8,8,8) BGRA color images (A = alpha)
|
||||
#define IB_CF_BGRA64 11 // 64-bit (16,16,16,16) BGRA color images (A = alpha)
|
||||
|
||||
class ImageExport ImageBase
|
||||
{
|
||||
public:
|
||||
|
||||
ImageBase();
|
||||
virtual ~ImageBase();
|
||||
ImageBase(const ImageBase &rhs);
|
||||
ImageBase & operator=(const ImageBase &rhs);
|
||||
|
||||
bool hasValidData() const { return (_pPixelData != 0); }
|
||||
void* getPixelDataPtr() { return (void *)_pPixelData; }
|
||||
bool isOwner() const { return _owner; }
|
||||
unsigned long getWidth() const { return _width; }
|
||||
unsigned long getHeight() const { return _height; }
|
||||
int getFormat() const { return _format; }
|
||||
unsigned short getNumSigBitsPerSample() const { return _numSigBitsPerSample; }
|
||||
unsigned short getNumSamples() const { return _numSamples; }
|
||||
unsigned short getNumBitsPerSample() const { return _numBitsPerSample; }
|
||||
unsigned short getNumBytesPerPixel() const { return _numBytesPerPixel; }
|
||||
|
||||
virtual void clear();
|
||||
virtual int createCopy(void* pSrcPixelData, unsigned long width, unsigned long height, int format, unsigned short numSigBitsPerSample);
|
||||
virtual int pointTo(void* pSrcPixelData, unsigned long width, unsigned long height, int format, unsigned short numSigBitsPerSample, bool takeOwnership);
|
||||
|
||||
virtual int getSample(int x, int y, unsigned short sampleIndex, double &value);
|
||||
|
||||
protected:
|
||||
|
||||
int _setColorFormat(int format, unsigned short numSigBitsPerSample);
|
||||
int _allocate();
|
||||
|
||||
unsigned char* _pPixelData; // pointer to the pixel data
|
||||
bool _owner; // flag defining if the object owns the pixel data or not
|
||||
unsigned long _width; // width of image (number of pixels in horizontal direction)
|
||||
unsigned long _height; // height of image (number of pixels in vertical direction)
|
||||
int _format; // colour format of the pixel data
|
||||
unsigned short _numSigBitsPerSample;// number of significant bits per sample (always <= _numBitsPerSample)
|
||||
|
||||
// Dependant parameters
|
||||
unsigned short _numSamples; // number of samples per pixel (e.g. 1 for grey, 3 for rgb, 4 for rgba)
|
||||
unsigned short _numBitsPerSample; // number of bits per sample (e.g. 8 for Grey8)
|
||||
unsigned short _numBytesPerPixel; // number of bytes per pixel (e.g. 1 for Grey8)
|
||||
};
|
||||
|
||||
} // namespace ImageApp
|
||||
|
||||
#endif // IMAGEBASE_H
|
||||
51
src/Mod/Image/App/ImagePlane.cpp
Normal file
51
src/Mod/Image/App/ImagePlane.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Jürgen Riegel (juergen.riegel@web.de) *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include "ImagePlane.h"
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <Base/Placement.h>
|
||||
|
||||
using namespace Image;
|
||||
using namespace App;
|
||||
|
||||
PROPERTY_SOURCE(Image::ImagePlane, App::GeoFeature)
|
||||
|
||||
|
||||
ImagePlane::ImagePlane()
|
||||
{
|
||||
|
||||
ADD_PROPERTY_TYPE( ImageFile,(0) , "ImagePlane",Prop_None,"File of the image");
|
||||
ADD_PROPERTY_TYPE( XSize, (100) , "ImagePlane",Prop_None,"Size of a pixel in X");
|
||||
ADD_PROPERTY_TYPE( YSize, (100) , "ImagePlane",Prop_None,"Size of a pixel in Y");
|
||||
|
||||
}
|
||||
|
||||
ImagePlane::~ImagePlane()
|
||||
{
|
||||
}
|
||||
|
||||
56
src/Mod/Image/App/ImagePlane.h
Normal file
56
src/Mod/Image/App/ImagePlane.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2011 Jürgen Riegel (juergen.riegel@web.de) *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef Image_ImagePlane_H
|
||||
#define Image_ImagePlane_H
|
||||
|
||||
#include <App/GeoFeature.h>
|
||||
#include <App/PropertyFile.h>
|
||||
#include <App/PropertyUnits.h>
|
||||
|
||||
namespace Image
|
||||
{
|
||||
|
||||
class ImageExport ImagePlane : public App::GeoFeature
|
||||
{
|
||||
PROPERTY_HEADER(Image::ImagePlane);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ImagePlane(void);
|
||||
virtual ~ImagePlane();
|
||||
|
||||
App::PropertyFileIncluded ImageFile;
|
||||
App::PropertyLength XSize;
|
||||
App::PropertyLength YSize;
|
||||
|
||||
/// returns the type name of the ViewProvider
|
||||
virtual const char* getViewProviderName(void) const {
|
||||
return "ImageGui::ViewProviderImagePlane";
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace Image
|
||||
|
||||
|
||||
#endif // Image_ImagePlane_H
|
||||
54
src/Mod/Image/App/Makefile.am
Normal file
54
src/Mod/Image/App/Makefile.am
Normal file
@@ -0,0 +1,54 @@
|
||||
|
||||
lib_LTLIBRARIES=libImage.la Image.la
|
||||
|
||||
libImage_la_SOURCES=\
|
||||
ImageBase.cpp \
|
||||
ImagePlane.cpp \
|
||||
PreCompiled.cpp \
|
||||
PreCompiled.h
|
||||
|
||||
includedir = @includedir@/Mod/Image/App
|
||||
|
||||
include_HEADERS=\
|
||||
ImageBase.h \
|
||||
ImagePlane.h
|
||||
|
||||
# the library search path.
|
||||
libImage_la_LDFLAGS = -L../../../Base -L../../../App $(all_libraries) \
|
||||
-version-info @LIB_CURRENT@:@LIB_REVISION@:@LIB_AGE@
|
||||
libImage_la_CPPFLAGS = -DImageAppExport=
|
||||
|
||||
# $(opencv_LIBS)
|
||||
libImage_la_LIBADD = \
|
||||
@BOOST_SYSTEM_LIB@ \
|
||||
-l@PYTHON_LIB@ \
|
||||
-lxerces-c \
|
||||
-lFreeCADBase \
|
||||
-lFreeCADApp
|
||||
|
||||
#--------------------------------------------------------------------------------------
|
||||
# Loader of libImage
|
||||
|
||||
Image_la_SOURCES=\
|
||||
AppImage.cpp
|
||||
|
||||
# the library search path.
|
||||
Image_la_LDFLAGS = $(libImage_la_LDFLAGS) -module -avoid-version
|
||||
Image_la_CPPFLAGS = $(libImage_la_CPPFLAGS)
|
||||
|
||||
Image_la_LIBADD = \
|
||||
$(libImage_la_LIBADD) \
|
||||
-lImage
|
||||
|
||||
Image_la_DEPENDENCIES = libImage.la
|
||||
|
||||
#--------------------------------------------------------------------------------------
|
||||
|
||||
# set the include path found by configure
|
||||
# $(opencv_CFLAGS)
|
||||
AM_CXXFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src $(all_includes)
|
||||
|
||||
libdir = $(prefix)/Mod/Image
|
||||
|
||||
EXTRA_DIST = \
|
||||
CMakeLists.txt
|
||||
24
src/Mod/Image/App/PreCompiled.cpp
Normal file
24
src/Mod/Image/App/PreCompiled.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
59
src/Mod/Image/App/PreCompiled.h
Normal file
59
src/Mod/Image/App/PreCompiled.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) Jürgen Riegel (juergen.riegel@web.de) 2002 *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef __PRECOMPILED__
|
||||
#define __PRECOMPILED__
|
||||
|
||||
#include <FCConfig.h>
|
||||
|
||||
// Exporting of App classes
|
||||
#ifdef FC_OS_WIN32
|
||||
# define ImageExport __declspec(dllexport)
|
||||
#else // for Linux
|
||||
# define ImageExport
|
||||
#endif
|
||||
|
||||
#ifdef _PreComp_
|
||||
/// here get the warnings of to long specifieres disabled (needed for VC6)
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning( disable : 4251 )
|
||||
# pragma warning( disable : 4503 )
|
||||
# pragma warning( disable : 4786 ) // specifier longer then 255 chars
|
||||
#endif
|
||||
|
||||
// standard
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <bitset>
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#endif // _PreComp_
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user