raw
This commit is contained in:
45
Thirdparty/Pangolin/include/pangolin/image/copy.h
vendored
Normal file
45
Thirdparty/Pangolin/include/pangolin/image/copy.h
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
// Hold a reference to an object to be copied
|
||||
template<typename T>
|
||||
struct CopyObject {
|
||||
CopyObject(const T& obj) : obj(obj) { }
|
||||
const T& obj;
|
||||
};
|
||||
|
||||
// Return copy wrapper for assignment to another object.
|
||||
template<typename T>
|
||||
typename pangolin::CopyObject<T> Copy(const T& obj) {
|
||||
return typename pangolin::CopyObject<T>(obj);
|
||||
}
|
||||
|
||||
}
|
||||
428
Thirdparty/Pangolin/include/pangolin/image/image.h
vendored
Normal file
428
Thirdparty/Pangolin/include/pangolin/image/image.h
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
#include <pangolin/image/memcpy.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef PANGO_ENABLE_BOUNDS_CHECKS
|
||||
# define PANGO_BOUNDS_ASSERT(...) PANGO_ENSURE(##__VA_ARGS__)
|
||||
#else
|
||||
# define PANGO_BOUNDS_ASSERT(...) ((void)0)
|
||||
#endif
|
||||
|
||||
// Allow user defined macro to be inserted into Image class.
|
||||
#ifndef PANGO_EXTENSION_IMAGE
|
||||
# define PANGO_EXTENSION_IMAGE
|
||||
#endif
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
// Simple image wrapper
|
||||
template<typename T>
|
||||
struct Image
|
||||
{
|
||||
using PixelType = T;
|
||||
|
||||
inline Image()
|
||||
: pitch(0), ptr(0), w(0), h(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline Image(T* ptr, size_t w, size_t h, size_t pitch)
|
||||
: pitch(pitch), ptr(ptr), w(w), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
size_t SizeBytes() const
|
||||
{
|
||||
return pitch * h;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
size_t Area() const
|
||||
{
|
||||
return w * h;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool IsValid() const
|
||||
{
|
||||
return ptr != 0;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool IsContiguous() const
|
||||
{
|
||||
return w*sizeof(T) == pitch;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Iterators
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T* begin()
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T* end()
|
||||
{
|
||||
return RowPtr(h-1) + w;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T* begin() const
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T* end() const
|
||||
{
|
||||
return RowPtr(h-1) + w;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
size_t size() const
|
||||
{
|
||||
return w*h;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Image transforms
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
template<typename UnaryOperation>
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Transform(UnaryOperation unary_op)
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
|
||||
for(size_t y=0; y < h; ++y) {
|
||||
T* el = RowPtr(y);
|
||||
const T* el_end = el+w;
|
||||
for( ; el != el_end; ++el) {
|
||||
*el = unary_op(*el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Fill(const T& val)
|
||||
{
|
||||
Transform( [&](const T&) {return val;} );
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Replace(const T& oldval, const T& newval)
|
||||
{
|
||||
Transform( [&](const T& val) {
|
||||
return (val == oldval) ? newval : val;
|
||||
});
|
||||
}
|
||||
|
||||
inline
|
||||
void Memset(unsigned char v = 0)
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
if(IsContiguous()) {
|
||||
::pangolin::Memset((char*)ptr, v, pitch*h);
|
||||
}else{
|
||||
for(size_t y=0; y < h; ++y) {
|
||||
::pangolin::Memset((char*)RowPtr(y), v, pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyFrom(const Image<T>& img)
|
||||
{
|
||||
if(IsValid() && img.IsValid()) {
|
||||
PANGO_ASSERT(w >= img.w && h >= img.h);
|
||||
PitchedCopy((char*)ptr,pitch,(char*)img.ptr,img.pitch, std::min(img.w,w)*sizeof(T), std::min(img.h,h) );
|
||||
}else if( img.IsValid() != IsValid() ){
|
||||
PANGO_ASSERT(false && "Cannot copy from / to an unasigned image." );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Reductions
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
template<typename BinaryOperation>
|
||||
PANGO_HOST_DEVICE inline
|
||||
T Accumulate(const T init, BinaryOperation binary_op)
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
|
||||
T val = init;
|
||||
for(size_t y=0; y < h; ++y) {
|
||||
T* el = RowPtr(y);
|
||||
const T* el_end = el+w;
|
||||
for(; el != el_end; ++el) {
|
||||
val = binary_op(val, *el);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
std::pair<T,T> MinMax() const
|
||||
{
|
||||
PANGO_ASSERT(IsValid());
|
||||
|
||||
std::pair<T,T> minmax(std::numeric_limits<T>::max(), std::numeric_limits<T>::lowest());
|
||||
for(size_t r=0; r < h; ++r) {
|
||||
const T* ptr = RowPtr(r);
|
||||
const T* end = ptr + w;
|
||||
while( ptr != end) {
|
||||
minmax.first = std::min(*ptr, minmax.first);
|
||||
minmax.second = std::max(*ptr, minmax.second);
|
||||
++ptr;
|
||||
}
|
||||
}
|
||||
return minmax;
|
||||
}
|
||||
|
||||
template<typename Tout=T>
|
||||
Tout Sum() const
|
||||
{
|
||||
return Accumulate((T)0, [](const T& lhs, const T& rhs){ return lhs + rhs; });
|
||||
}
|
||||
|
||||
template<typename Tout=T>
|
||||
Tout Mean() const
|
||||
{
|
||||
return Sum<Tout>() / Area();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Direct Pixel Access
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T* RowPtr(size_t y)
|
||||
{
|
||||
return (T*)((unsigned char*)(ptr) + y*pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T* RowPtr(size_t y) const
|
||||
{
|
||||
return (T*)((unsigned char*)(ptr) + y*pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T& operator()(size_t x, size_t y)
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(x,y) );
|
||||
return RowPtr(y)[x];
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T& operator()(size_t x, size_t y) const
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(x,y) );
|
||||
return RowPtr(y)[x];
|
||||
}
|
||||
|
||||
template<typename TVec>
|
||||
PANGO_HOST_DEVICE inline
|
||||
T& operator()(const TVec& p)
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(p[0],p[1]) );
|
||||
return RowPtr(p[1])[p[0]];
|
||||
}
|
||||
|
||||
template<typename TVec>
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T& operator()(const TVec& p) const
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InBounds(p[0],p[1]) );
|
||||
return RowPtr(p[1])[p[0]];
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
T& operator[](size_t ix)
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InImage(ptr+ix) );
|
||||
return ptr[ix];
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const T& operator[](size_t ix) const
|
||||
{
|
||||
PANGO_BOUNDS_ASSERT( InImage(ptr+ix) );
|
||||
return ptr[ix];
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Bounds Checking
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE
|
||||
bool InImage(const T* ptest) const
|
||||
{
|
||||
return ptr <= ptest && ptest < RowPtr(h);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool InBounds(int x, int y) const
|
||||
{
|
||||
return 0 <= x && x < (int)w && 0 <= y && y < (int)h;
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool InBounds(float x, float y, float border) const
|
||||
{
|
||||
return border <= x && x < (w-border) && border <= y && y < (h-border);
|
||||
}
|
||||
|
||||
template<typename TVec, typename TBorder>
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool InBounds( const TVec& p, const TBorder border = (TBorder)0 ) const
|
||||
{
|
||||
return border <= p[0] && p[0] < ((int)w - border) && border <= p[1] && p[1] < ((int)h - border);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Obtain slices / subimages
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const Image<const T> SubImage(size_t x, size_t y, size_t width, size_t height) const
|
||||
{
|
||||
PANGO_ASSERT( (x+width) <= w && (y+height) <= h);
|
||||
return Image<const T>( RowPtr(y)+x, width, height, pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<T> SubImage(size_t x, size_t y, size_t width, size_t height)
|
||||
{
|
||||
PANGO_ASSERT( (x+width) <= w && (y+height) <= h);
|
||||
return Image<T>( RowPtr(y)+x, width, height, pitch);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const Image<T> Row(int y) const
|
||||
{
|
||||
return SubImage(0,y,w,1);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<T> Row(int y)
|
||||
{
|
||||
return SubImage(0,y,w,1);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
const Image<T> Col(int x) const
|
||||
{
|
||||
return SubImage(x,0,1,h);
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<T> Col(int x)
|
||||
{
|
||||
return SubImage(x,0,1,h);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Data mangling
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
template<typename TRecast>
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<TRecast> Reinterpret() const
|
||||
{
|
||||
PANGO_ASSERT(sizeof(TRecast) == sizeof(T), "sizeof(TRecast) must match sizeof(T): % != %", sizeof(TRecast), sizeof(T) );
|
||||
return UnsafeReinterpret<TRecast>();
|
||||
}
|
||||
|
||||
template<typename TRecast>
|
||||
PANGO_HOST_DEVICE inline
|
||||
Image<TRecast> UnsafeReinterpret() const
|
||||
{
|
||||
return Image<TRecast>((TRecast*)ptr,w,h,pitch);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Deprecated methods
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
// PANGOLIN_DEPRECATED inline
|
||||
Image(size_t w, size_t h, size_t pitch, T* ptr)
|
||||
: pitch(pitch), ptr(ptr), w(w), h(h)
|
||||
{
|
||||
}
|
||||
|
||||
// Use RAII/move aware pangolin::ManagedImage instead
|
||||
// PANGOLIN_DEPRECATED inline
|
||||
void Dealloc()
|
||||
{
|
||||
if(ptr) {
|
||||
::operator delete(ptr);
|
||||
ptr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Use RAII/move aware pangolin::ManagedImage instead
|
||||
// PANGOLIN_DEPRECATED inline
|
||||
void Alloc(size_t w, size_t h, size_t pitch)
|
||||
{
|
||||
Dealloc();
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
this->pitch = pitch;
|
||||
this->ptr = (T*)::operator new(h*pitch);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Data members
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
size_t pitch;
|
||||
T* ptr;
|
||||
size_t w;
|
||||
size_t h;
|
||||
|
||||
PANGO_EXTENSION_IMAGE
|
||||
};
|
||||
|
||||
}
|
||||
31
Thirdparty/Pangolin/include/pangolin/image/image_convert.h
vendored
Normal file
31
Thirdparty/Pangolin/include/pangolin/image/image_convert.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/image/managed_image.h>
|
||||
#include <pangolin/utils/compontent_cast.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
template <typename To, typename T>
|
||||
void ImageConvert(Image<To>& dst, const Image<T>& src, To scale = 1.0)
|
||||
{
|
||||
for(unsigned int y = 0; y < dst.h; ++y)
|
||||
{
|
||||
const T* prs = src.RowPtr(y);
|
||||
To* prd = dst.RowPtr(y);
|
||||
for(unsigned int x = 0; x < dst.w; ++x)
|
||||
{
|
||||
*(prd++) = scale * ComponentCast<To, T>::cast(*(prs++));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename To, typename T>
|
||||
ManagedImage<To> ImageConvert(const Image<T>& src, To scale = 1.0)
|
||||
{
|
||||
ManagedImage<To> dst(src.w, src.h);
|
||||
ImageConvert<To,T>(dst,src,scale);
|
||||
return dst;
|
||||
}
|
||||
|
||||
}
|
||||
65
Thirdparty/Pangolin/include/pangolin/image/image_io.h
vendored
Normal file
65
Thirdparty/Pangolin/include/pangolin/image/image_io.h
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2013 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
#include <pangolin/image/typed_image.h>
|
||||
#include <pangolin/utils/file_extension.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(std::istream& in, ImageFileType file_type);
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(const std::string& filename, ImageFileType file_type);
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(const std::string& filename);
|
||||
|
||||
PANGOLIN_EXPORT
|
||||
TypedImage LoadImage(const std::string& filename, const PixelFormat& raw_fmt, size_t raw_width, size_t raw_height, size_t raw_pitch);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, std::ostream& out, ImageFileType file_type, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, const std::string& filename, ImageFileType file_type, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const Image<unsigned char>& image, const pangolin::PixelFormat& fmt, const std::string& filename, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
/// Quality \in [0..100] for lossy formats
|
||||
PANGOLIN_EXPORT
|
||||
void SaveImage(const TypedImage& image, const std::string& filename, bool top_line_first = true, float quality = 100.0f);
|
||||
|
||||
}
|
||||
185
Thirdparty/Pangolin/include/pangolin/image/image_utils.h
vendored
Normal file
185
Thirdparty/Pangolin/include/pangolin/image/image_utils.h
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2013 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <utility>
|
||||
|
||||
#include <pangolin/image/image.h>
|
||||
#include <pangolin/plot/range.h>
|
||||
#include <pangolin/gl/gl.h>
|
||||
#include <pangolin/gl/glpixformat.h>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
std::pair<float, float> GetMinMax(const Image<T>& img, size_t channels)
|
||||
{
|
||||
const size_t max_channels = 3;
|
||||
const size_t colour_channels = std::min(channels, max_channels);
|
||||
std::pair<float, float> chan_mm[max_channels];
|
||||
for(size_t c = 0; c < max_channels; ++c)
|
||||
{
|
||||
chan_mm[c].first = +std::numeric_limits<float>::max();
|
||||
chan_mm[c].second = -std::numeric_limits<float>::max();
|
||||
}
|
||||
|
||||
for(size_t y = 0; y < img.h; ++y)
|
||||
{
|
||||
T* pix = (T*)((char*)img.ptr + y * img.pitch);
|
||||
for(size_t x = 0; x < img.w; ++x)
|
||||
{
|
||||
for(size_t c = 0; c < colour_channels; ++c)
|
||||
{
|
||||
if(pix[c] < chan_mm[c].first)
|
||||
chan_mm[c].first = (float)pix[c];
|
||||
if(pix[c] > chan_mm[c].second)
|
||||
chan_mm[c].second = (float)pix[c];
|
||||
}
|
||||
|
||||
pix += channels;
|
||||
}
|
||||
}
|
||||
|
||||
// Find min / max of all channels, ignoring 4th alpha channel
|
||||
std::pair<float, float> mm = chan_mm[0];
|
||||
for(size_t c = 1; c < colour_channels; ++c)
|
||||
{
|
||||
mm.first = std::min(mm.first, chan_mm[c].first);
|
||||
mm.second = std::max(mm.second, chan_mm[c].second);
|
||||
}
|
||||
|
||||
return mm;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
pangolin::Image<T> GetImageRoi( pangolin::Image<T> img, size_t channels, const pangolin::XYRangei& roi )
|
||||
{
|
||||
return pangolin::Image<T>(
|
||||
img.RowPtr(std::min(roi.y.min,roi.y.max)) + channels*std::min(roi.x.min,roi.x.max),
|
||||
roi.x.AbsSize(), roi.y.AbsSize(),
|
||||
img.pitch
|
||||
);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::pair<float,float> GetOffsetScale(const pangolin::Image<T>& img, size_t channels, float type_max, float format_max)
|
||||
{
|
||||
// Find min / max of all channels, ignoring 4th alpha channel
|
||||
const std::pair<float,float> mm = internal::GetMinMax<T>(img,channels);
|
||||
const float type_scale = format_max / type_max;
|
||||
const float offset = -type_scale* mm.first;
|
||||
const float scale = type_max / (mm.second - mm.first);
|
||||
return std::pair<float,float>(offset, scale);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
float GetScaleOnly(const pangolin::Image<T>& img, size_t channels, float type_max, float /*format_max*/)
|
||||
{
|
||||
// Find min / max of all channels, ignoring 4th alpha channel
|
||||
const std::pair<float,float> mm = internal::GetMinMax<T>(img,channels);
|
||||
const float scale = type_max / mm.second;
|
||||
return scale;
|
||||
}
|
||||
|
||||
} // internal
|
||||
|
||||
inline std::pair<float, float> GetMinMax(
|
||||
const Image<unsigned char>& img,
|
||||
XYRangei iroi, const GlPixFormat& glfmt
|
||||
) {
|
||||
using namespace internal;
|
||||
|
||||
iroi.Clamp(0, (int)img.w - 1, 0, (int)img.h - 1);
|
||||
|
||||
const size_t num_channels = pangolin::GlFormatChannels(glfmt.glformat);
|
||||
|
||||
if(glfmt.gltype == GL_UNSIGNED_BYTE) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<unsigned char>(), num_channels, iroi), num_channels);
|
||||
} else if(glfmt.gltype == GL_UNSIGNED_SHORT) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<unsigned short>(), num_channels, iroi), num_channels);
|
||||
} else if(glfmt.gltype == GL_FLOAT) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<float>(), num_channels, iroi), num_channels);
|
||||
} else if(glfmt.gltype == GL_DOUBLE) {
|
||||
return GetMinMax(GetImageRoi(img.template UnsafeReinterpret<double>(), num_channels, iroi), num_channels);
|
||||
} else {
|
||||
return std::pair<float, float>(std::numeric_limits<float>::max(), std::numeric_limits<float>::lowest());
|
||||
}
|
||||
}
|
||||
|
||||
inline std::pair<float,float> GetOffsetScale(
|
||||
const pangolin::Image<unsigned char>& img,
|
||||
pangolin::XYRangei iroi, const pangolin::GlPixFormat& glfmt
|
||||
) {
|
||||
using namespace internal;
|
||||
|
||||
iroi.Clamp(0, (int)img.w-1, 0, (int)img.h-1 );
|
||||
|
||||
const size_t num_channels = pangolin::GlFormatChannels(glfmt.glformat);
|
||||
|
||||
if(glfmt.gltype == GL_UNSIGNED_BYTE) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<unsigned char>(), num_channels, iroi), num_channels, 255.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_UNSIGNED_SHORT) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<unsigned short>(), num_channels, iroi), num_channels, 65535.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_FLOAT) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<float>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_DOUBLE) {
|
||||
return GetOffsetScale(GetImageRoi(img.template UnsafeReinterpret<double>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else{
|
||||
return std::pair<float,float>(0.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
inline float GetScaleOnly(
|
||||
const pangolin::Image<unsigned char>& img,
|
||||
pangolin::XYRangei iroi, const pangolin::GlPixFormat& glfmt
|
||||
) {
|
||||
using namespace internal;
|
||||
|
||||
iroi.Clamp(0, (int)img.w-1, 0, (int)img.h-1 );
|
||||
|
||||
const size_t num_channels = pangolin::GlFormatChannels(glfmt.glformat);
|
||||
|
||||
if(glfmt.gltype == GL_UNSIGNED_BYTE) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<unsigned char>(), num_channels, iroi), num_channels, 255.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_UNSIGNED_SHORT) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<unsigned short>(), num_channels, iroi), num_channels, 65535.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_FLOAT) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<float>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else if(glfmt.gltype == GL_DOUBLE) {
|
||||
return GetScaleOnly(GetImageRoi(img.template UnsafeReinterpret<double>(), num_channels, iroi), num_channels, 1.0f, 1.0f);
|
||||
}else{
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
175
Thirdparty/Pangolin/include/pangolin/image/managed_image.h
vendored
Normal file
175
Thirdparty/Pangolin/include/pangolin/image/managed_image.h
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/image/image.h>
|
||||
#include <pangolin/image/copy.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
template<class T> using DefaultImageAllocator = std::allocator<T>;
|
||||
|
||||
// Image that manages it's own memory, storing a strong pointer to it's memory
|
||||
template<typename T, class Allocator = DefaultImageAllocator<T> >
|
||||
class ManagedImage : public Image<T>
|
||||
{
|
||||
public:
|
||||
// Destructor
|
||||
inline
|
||||
~ManagedImage()
|
||||
{
|
||||
Deallocate();
|
||||
}
|
||||
|
||||
// Null image
|
||||
inline
|
||||
ManagedImage()
|
||||
{
|
||||
}
|
||||
|
||||
// Row image
|
||||
inline
|
||||
ManagedImage(size_t w)
|
||||
: Image<T>(
|
||||
Allocator().allocate(w),
|
||||
w, 1, w*sizeof(T)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ManagedImage(size_t w, size_t h)
|
||||
: Image<T>(
|
||||
Allocator().allocate(w*h),
|
||||
w, h, w*sizeof(T)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ManagedImage(size_t w, size_t h, size_t pitch_bytes)
|
||||
: Image<T>(
|
||||
Allocator().allocate( (h*pitch_bytes) / sizeof(T) + 1),
|
||||
w, h, pitch_bytes
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
// Not copy constructable
|
||||
inline
|
||||
ManagedImage( const ManagedImage<T>& other ) = delete;
|
||||
|
||||
// Move constructor
|
||||
inline
|
||||
ManagedImage(ManagedImage<T,Allocator>&& img)
|
||||
{
|
||||
*this = std::move(img);
|
||||
}
|
||||
|
||||
// Move asignment
|
||||
inline
|
||||
void operator=(ManagedImage<T,Allocator>&& img)
|
||||
{
|
||||
Deallocate();
|
||||
Image<T>::pitch = img.pitch;
|
||||
Image<T>::ptr = img.ptr;
|
||||
Image<T>::w = img.w;
|
||||
Image<T>::h = img.h;
|
||||
img.ptr = nullptr;
|
||||
}
|
||||
|
||||
// Explicit copy constructor
|
||||
template<typename TOther>
|
||||
ManagedImage( const CopyObject<TOther>& other )
|
||||
{
|
||||
CopyFrom(other.obj);
|
||||
}
|
||||
|
||||
// Explicit copy assignment
|
||||
template<typename TOther>
|
||||
void operator=(const CopyObject<TOther>& other)
|
||||
{
|
||||
CopyFrom(other.obj);
|
||||
}
|
||||
|
||||
inline
|
||||
void Swap(ManagedImage<T>& img)
|
||||
{
|
||||
std::swap(img.pitch, Image<T>::pitch);
|
||||
std::swap(img.ptr, Image<T>::ptr);
|
||||
std::swap(img.w, Image<T>::w);
|
||||
std::swap(img.h, Image<T>::h);
|
||||
}
|
||||
|
||||
inline
|
||||
void CopyFrom(const Image<T>& img)
|
||||
{
|
||||
if(!Image<T>::IsValid() || Image<T>::w != img.w || Image<T>::h != img.h) {
|
||||
Reinitialise(img.w,img.h);
|
||||
}
|
||||
Image<T>::CopyFrom(img);
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h)
|
||||
{
|
||||
if(!Image<T>::ptr || Image<T>::w != w || Image<T>::h != h) {
|
||||
*this = ManagedImage<T,Allocator>(w,h);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h, size_t pitch)
|
||||
{
|
||||
if(!Image<T>::ptr || Image<T>::w != w || Image<T>::h != h || Image<T>::pitch != pitch) {
|
||||
*this = ManagedImage<T,Allocator>(w,h,pitch);
|
||||
}
|
||||
}
|
||||
|
||||
inline void Deallocate()
|
||||
{
|
||||
if (Image<T>::ptr) {
|
||||
Allocator().deallocate(Image<T>::ptr, (Image<T>::h * Image<T>::pitch) / sizeof(T) );
|
||||
Image<T>::ptr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Move asignment
|
||||
template<typename TOther, typename AllocOther> inline
|
||||
void OwnAndReinterpret(ManagedImage<TOther,AllocOther>&& img)
|
||||
{
|
||||
Deallocate();
|
||||
Image<T>::pitch = img.pitch;
|
||||
Image<T>::ptr = (T*)img.ptr;
|
||||
Image<T>::w = img.w;
|
||||
Image<T>::h = img.h;
|
||||
img.ptr = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
110
Thirdparty/Pangolin/include/pangolin/image/memcpy.h
vendored
Normal file
110
Thirdparty/Pangolin/include/pangolin/image/memcpy.h
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
# include <cuda_runtime.h>
|
||||
#endif
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
template<typename T>
|
||||
PANGO_HOST_DEVICE inline
|
||||
bool IsDevicePtr(T* ptr)
|
||||
{
|
||||
#ifdef HAVE_CUDA
|
||||
cudaPointerAttributes attributes;
|
||||
cudaError_t res = cudaPointerGetAttributes(&attributes,ptr);
|
||||
|
||||
//Flushing the error flag for future CUDA error checks
|
||||
if(res != cudaSuccess)
|
||||
{
|
||||
cudaGetLastError();
|
||||
return false;
|
||||
}
|
||||
|
||||
return attributes.memoryType == cudaMemoryTypeDevice;
|
||||
#else
|
||||
PANGOLIN_UNUSED(ptr);
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void MemCopy(void *dst, const void *src, size_t size_bytes)
|
||||
{
|
||||
#ifdef HAVE_CUDA
|
||||
cudaMemcpy(dst,src, size_bytes, cudaMemcpyDefault);
|
||||
#else
|
||||
std::memcpy(dst, src, size_bytes);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline
|
||||
void PitchedCopy(char* dst, unsigned int dst_pitch_bytes, const char* src, unsigned int src_pitch_bytes, unsigned int width_bytes, unsigned int height)
|
||||
{
|
||||
#ifdef HAVE_CUDA
|
||||
cudaMemcpy2D(dst, dst_pitch_bytes, src, src_pitch_bytes, width_bytes, height, cudaMemcpyDefault);
|
||||
#else
|
||||
if(dst_pitch_bytes == width_bytes && src_pitch_bytes == width_bytes ) {
|
||||
std::memcpy(dst, src, height * width_bytes);
|
||||
}else{
|
||||
for(unsigned int row=0; row < height; ++row) {
|
||||
std::memcpy(dst, src, width_bytes);
|
||||
dst += dst_pitch_bytes;
|
||||
src += src_pitch_bytes;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
PANGO_HOST_DEVICE inline
|
||||
void Memset(char* ptr, unsigned char v, size_t size_bytes)
|
||||
{
|
||||
#ifdef __CUDA_ARCH__
|
||||
// Called in kernel
|
||||
char* end = ptr + size_bytes;
|
||||
for(char* p=ptr; p != end; ++p) *p = v;
|
||||
#else
|
||||
# ifdef HAVE_CUDA
|
||||
if(IsDevicePtr(ptr))
|
||||
{
|
||||
cudaMemset(ptr, v, size_bytes);
|
||||
}else
|
||||
# endif // HAVE_CUDA
|
||||
{
|
||||
std::memset(ptr, v, size_bytes);
|
||||
}
|
||||
#endif // __CUDA_ARCH__
|
||||
}
|
||||
|
||||
}
|
||||
66
Thirdparty/Pangolin/include/pangolin/image/pixel_format.h
vendored
Normal file
66
Thirdparty/Pangolin/include/pangolin/image/pixel_format.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2011-2013 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/platform.h>
|
||||
#include <string>
|
||||
|
||||
namespace pangolin
|
||||
{
|
||||
|
||||
struct PANGOLIN_EXPORT PixelFormat
|
||||
{
|
||||
// Previously, VideoInterface::PixFormat returned a string.
|
||||
// For compatibility, make this string convertable
|
||||
inline operator std::string() const { return format; }
|
||||
|
||||
std::string format;
|
||||
unsigned int channels;
|
||||
unsigned int channel_bits[4]; //Of the data type
|
||||
unsigned int bpp; //Of the data type
|
||||
unsigned int channel_bit_depth; //Of the data
|
||||
bool planar;
|
||||
};
|
||||
|
||||
|
||||
//! Return Pixel Format properties given string specification in
|
||||
//! FFMPEG notation.
|
||||
PANGOLIN_EXPORT
|
||||
PixelFormat PixelFormatFromString(const std::string& format);
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
/// Deprecated aliases for above
|
||||
|
||||
PANGOLIN_DEPRECATED
|
||||
typedef PixelFormat VideoPixelFormat;
|
||||
PANGOLIN_DEPRECATED
|
||||
inline PixelFormat VideoFormatFromString(const std::string& format) {
|
||||
return PixelFormatFromString(format);
|
||||
}
|
||||
|
||||
}
|
||||
91
Thirdparty/Pangolin/include/pangolin/image/typed_image.h
vendored
Normal file
91
Thirdparty/Pangolin/include/pangolin/image/typed_image.h
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/* This file is part of the Pangolin Project.
|
||||
* http://github.com/stevenlovegrove/Pangolin
|
||||
*
|
||||
* Copyright (c) 2013 Steven Lovegrove
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <pangolin/image/managed_image.h>
|
||||
#include <pangolin/image/pixel_format.h>
|
||||
|
||||
namespace pangolin {
|
||||
|
||||
struct TypedImage : public ManagedImage<unsigned char>
|
||||
{
|
||||
typedef ManagedImage<unsigned char> Base;
|
||||
|
||||
inline TypedImage()
|
||||
: Base()
|
||||
{
|
||||
}
|
||||
|
||||
inline TypedImage(size_t w, size_t h, const PixelFormat& fmt)
|
||||
: Base(w,h,w*fmt.bpp/8), fmt(fmt)
|
||||
{
|
||||
}
|
||||
|
||||
inline TypedImage(size_t w, size_t h, const PixelFormat& fmt, size_t pitch )
|
||||
: Base(w,h, pitch), fmt(fmt)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h, const PixelFormat& fmt)
|
||||
{
|
||||
Base::Reinitialise(w, h, w*fmt.bpp/8);
|
||||
this->fmt = fmt;
|
||||
}
|
||||
|
||||
inline
|
||||
void Reinitialise(size_t w, size_t h, const PixelFormat& fmt, size_t pitch)
|
||||
{
|
||||
Base::Reinitialise(w, h, pitch);
|
||||
this->fmt = fmt;
|
||||
}
|
||||
|
||||
// Not copy constructable
|
||||
inline
|
||||
TypedImage( const TypedImage& other ) = delete;
|
||||
|
||||
// Move constructor
|
||||
inline
|
||||
TypedImage(TypedImage&& img)
|
||||
{
|
||||
*this = std::move(img);
|
||||
}
|
||||
|
||||
// Move asignment
|
||||
inline
|
||||
void operator=(TypedImage&& img)
|
||||
{
|
||||
fmt = img.fmt;
|
||||
Base::operator =( std::move(img));
|
||||
}
|
||||
|
||||
|
||||
PixelFormat fmt;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user