diff options
Diffstat (limited to 'xs/src/igl/png')
-rw-r--r-- | xs/src/igl/png/readPNG.cpp | 47 | ||||
-rw-r--r-- | xs/src/igl/png/readPNG.h | 39 | ||||
-rw-r--r-- | xs/src/igl/png/render_to_png.cpp | 45 | ||||
-rw-r--r-- | xs/src/igl/png/render_to_png.h | 41 | ||||
-rw-r--r-- | xs/src/igl/png/render_to_png_async.cpp | 54 | ||||
-rw-r--r-- | xs/src/igl/png/render_to_png_async.h | 45 | ||||
-rw-r--r-- | xs/src/igl/png/texture_from_file.cpp | 61 | ||||
-rw-r--r-- | xs/src/igl/png/texture_from_file.h | 39 | ||||
-rw-r--r-- | xs/src/igl/png/texture_from_png.cpp | 83 | ||||
-rw-r--r-- | xs/src/igl/png/texture_from_png.h | 54 | ||||
-rw-r--r-- | xs/src/igl/png/writePNG.cpp | 46 | ||||
-rw-r--r-- | xs/src/igl/png/writePNG.h | 41 |
12 files changed, 0 insertions, 595 deletions
diff --git a/xs/src/igl/png/readPNG.cpp b/xs/src/igl/png/readPNG.cpp deleted file mode 100644 index 8d42ad8d9..000000000 --- a/xs/src/igl/png/readPNG.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2016 Daniele Panozzo <daniele.panozzo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#include "readPNG.h" -#include <igl_stb_image.h> - -IGL_INLINE bool igl::png::readPNG( - const std::string png_file, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A -) -{ - int cols,rows,n; - unsigned char *data = stbi_load(png_file.c_str(), &cols, &rows, &n, 4); - if(data == NULL) { - return false; - } - - R.resize(cols,rows); - G.resize(cols,rows); - B.resize(cols,rows); - A.resize(cols,rows); - - for (unsigned i=0; i<rows; ++i) { - for (unsigned j=0; j<cols; ++j) { - R(j,rows-1-i) = data[4*(j + cols * i) + 0]; - G(j,rows-1-i) = data[4*(j + cols * i) + 1]; - B(j,rows-1-i) = data[4*(j + cols * i) + 2]; - A(j,rows-1-i) = data[4*(j + cols * i) + 3]; - } - } - - igl::stbi_image_free(data); - - return true; -} - -#ifdef IGL_STATIC_LIBRARY -// Explicit template instantiation -// generated by autoexplicit.sh -#endif diff --git a/xs/src/igl/png/readPNG.h b/xs/src/igl/png/readPNG.h deleted file mode 100644 index 65adf2c6c..000000000 --- a/xs/src/igl/png/readPNG.h +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2016 Daniele Panozzo <daniele.panozzo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_PNG_READ_PNG_H -#define IGL_PNG_READ_PNG_H -#include "../igl_inline.h" -#include <Eigen/Core> -#include <string> - -namespace igl -{ - namespace png - { - // Read an image from a .png file into 4 memory buffers - // - // Input: - // png_file path to .png file - // Output: - // R,G,B,A texture channels - // Returns true on success, false on failure - // - IGL_INLINE bool readPNG(const std::string png_file, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A - ); - } -} - -#ifndef IGL_STATIC_LIBRARY -# include "readPNG.cpp" -#endif - -#endif diff --git a/xs/src/igl/png/render_to_png.cpp b/xs/src/igl/png/render_to_png.cpp deleted file mode 100644 index 6533ad9ab..000000000 --- a/xs/src/igl/png/render_to_png.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#include "render_to_png.h" -#include <igl_stb_image.h> - -#include "../opengl/gl.h" - -IGL_INLINE bool igl::png::render_to_png( - const std::string png_file, - const int width, - const int height, - const bool alpha, - const bool fast) -{ - unsigned char * data = new unsigned char[4*width*height]; - glReadPixels( - 0, - 0, - width, - height, - GL_RGBA, - GL_UNSIGNED_BYTE, - data); - //img->flip(); - if(!alpha) - { - for(int i = 0;i<width;i++) - for(int j = 0;j<height;j++) - { - data[4*(i+j*width)+3] = 255; - } - } - bool ret = igl::stbi_write_png(png_file.c_str(), width, height, 4, data, 4*width*sizeof(unsigned char)); - delete [] data; - return ret; -} - -#ifdef IGL_STATIC_LIBRARY -// Explicit template instantiation -#endif diff --git a/xs/src/igl/png/render_to_png.h b/xs/src/igl/png/render_to_png.h deleted file mode 100644 index 508e12b1f..000000000 --- a/xs/src/igl/png/render_to_png.h +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_PNG_RENDER_TO_PNG_H -#define IGL_PNG_RENDER_TO_PNG_H -#include <igl/igl_inline.h> - -#include <string> -namespace igl -{ - namespace png - { - // - // Render current open GL image to .png file - // Inputs: - // png_file path to output .png file - // width width of scene and resulting image - // height height of scene and resulting image - // alpha whether to include alpha channel - // fast sacrifice compression ratio for speed - // Returns true only if no errors occurred - // - // See also: igl/render_to_tga which is faster but writes .tga files - IGL_INLINE bool render_to_png( - const std::string png_file, - const int width, - const int height, - const bool alpha = true, - const bool fast = false); - } -} - -#ifndef IGL_STATIC_LIBRARY -# include "render_to_png.cpp" -#endif - -#endif diff --git a/xs/src/igl/png/render_to_png_async.cpp b/xs/src/igl/png/render_to_png_async.cpp deleted file mode 100644 index 033701e63..000000000 --- a/xs/src/igl/png/render_to_png_async.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#include "render_to_png_async.h" -#include "../opengl/gl.h" -#include <igl_stb_image.h> - -static IGL_INLINE bool render_to_png_async_helper( - unsigned char * img, int width, int height, - const std::string png_file, - const bool alpha, - const bool fast) -{ - //img->flip(); - if(!alpha) - { - for(int i = 0;i<width;i++) - for(int j = 0;j<height;j++) - { - img[4*(i+j*width)+3] = 255; - } - } - - bool ret = igl::stbi_write_png(png_file.c_str(), width, height, 4, img, width*sizeof(unsigned char)); - delete [] img; - return ret; -} - -IGL_INLINE std::thread igl::png::render_to_png_async( - const std::string png_file, - const int width, - const int height, - const bool alpha, - const bool fast) -{ - // Part that should serial - unsigned char * data = new unsigned char[width*height]; - glReadPixels( - 0, - 0, - width, - height, - GL_RGBA, - GL_UNSIGNED_BYTE, - data); - // Part that should be asynchronous - std::thread t(render_to_png_async_helper,data,width,height,png_file,alpha,fast); - t.detach(); - return t; -} diff --git a/xs/src/igl/png/render_to_png_async.h b/xs/src/igl/png/render_to_png_async.h deleted file mode 100644 index c4ac07c64..000000000 --- a/xs/src/igl/png/render_to_png_async.h +++ /dev/null @@ -1,45 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_PNG_RENDER_TO_PNG_ASYNC_H -#define IGL_PNG_RENDER_TO_PNG_ASYNC_H -#include <igl/igl_inline.h> -#include <thread> -//#include <boost/thread/thread.hpp> - -#include <string> -namespace igl -{ - namespace png - { - // History: - // added multithreaded parameter and support, Alec Sept 3, 2012 - // - // Render current open GL image to .png file - // Inputs: - // png_file path to output .png file - // width width of scene and resulting image - // height height of scene and resulting image - // alpha whether to include alpha channel - // fast sacrifice compression ratio for speed - // Returns true only if no errors occurred - // - // See also: igl/render_to_tga which is faster but writes .tga files - IGL_INLINE std::thread render_to_png_async( - const std::string png_file, - const int width, - const int height, - const bool alpha = true, - const bool fast = false); - } -} - -#ifndef IGL_STATIC_LIBRARY -# include "render_to_png_async.cpp" -#endif - -#endif diff --git a/xs/src/igl/png/texture_from_file.cpp b/xs/src/igl/png/texture_from_file.cpp deleted file mode 100644 index 60e8c795c..000000000 --- a/xs/src/igl/png/texture_from_file.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#include "texture_from_file.h" - -#include "texture_from_png.h" -#include "../STR.h" -#include "../pathinfo.h" -#include "../opengl/report_gl_error.h" -//#include "../opengl2/texture_from_tga.h" -#include <string> -#include <algorithm> -#include <iostream> - -IGL_INLINE bool igl::png::texture_from_file(const std::string filename, GLuint & id) -{ - using namespace igl::opengl; - using namespace std; - // dirname, basename, extension and filename - string d,b,ext,f; - pathinfo(filename,d,b,ext,f); - // Convert extension to lower case - transform(ext.begin(), ext.end(), ext.begin(), ::tolower); - //if(ext == "tga") - //{ - // return texture_from_tga(filename,id); - //}else - if(ext == "png") - { - return texture_from_png(filename,id); - }else - { -#ifdef __APPLE__ - // Convert to a temporary png file - string tmp = "/var/tmp/.texture_from_file.png"; -#define PATH_TO_CONVERT "/opt/local/bin/convert" - string command = STR(PATH_TO_CONVERT<<" \""<<filename<<"\" \""<<tmp<<"\""); - try - { - if(system(command.c_str())==0) - { - return texture_from_file(tmp.c_str(),id); - }else - { - cerr<<"texture_from_file: calling to convert ('"<<command<<"') failed..."<<endl; - return false; - } - }catch(int e) - { - cerr<<"^"<<__FUNCTION__<<": Calling to convert crashed..."<<endl; - return false; - } -#else - return false; -#endif - } -} diff --git a/xs/src/igl/png/texture_from_file.h b/xs/src/igl/png/texture_from_file.h deleted file mode 100644 index 8852d101e..000000000 --- a/xs/src/igl/png/texture_from_file.h +++ /dev/null @@ -1,39 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_PNG_TEXTURE_FROM_FILE_H -#define IGL_PNG_TEXTURE_FROM_FILE_H -#include "../igl_inline.h" -#include "../opengl/gl.h" - -#include <string> - -namespace igl -{ - namespace png - { - // Read an image from an image file and use it as a texture. Officially, - // only <del>.tga and</del> .png are supported. Any filetype read by - // ImageMagick's `convert` will work via an unsafe system call. - // - // Input: - // filename path to image file - // Output: - // id of generated openGL texture - // Returns true on success, false on failure - IGL_INLINE bool texture_from_file(const std::string filename, GLuint & id); - } -} - -#ifndef IGL_STATIC_LIBRARY -# include "texture_from_file.cpp" -#endif - -#endif - - - diff --git a/xs/src/igl/png/texture_from_png.cpp b/xs/src/igl/png/texture_from_png.cpp deleted file mode 100644 index fde3c002c..000000000 --- a/xs/src/igl/png/texture_from_png.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#include "texture_from_png.h" - -#include "../opengl/report_gl_error.h" -#include <igl_stb_image.h> - -IGL_INLINE bool igl::png::texture_from_png(const std::string png_file, const bool flip, GLuint & id) -{ - int width,height,n; - unsigned char *data = igl::stbi_load(png_file.c_str(), &width, &height, &n, 4); - if(data == NULL) { - return false; - } - - // Why do I need to flip? - /*if(flip) - { - yimg.flip(); - }*/ - - glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, id); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGB, - width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - glBindTexture(GL_TEXTURE_2D, 0); - - igl::stbi_image_free(data); - - return true; -} - -IGL_INLINE bool igl::png::texture_from_png(const std::string png_file, GLuint & id) -{ - return texture_from_png(png_file,false,id); -} - - -IGL_INLINE bool igl::png::texture_from_png( - const std::string png_file, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A -) -{ - int width,height,n; - unsigned char *data = igl::stbi_load(png_file.c_str(), &width, &height, &n, 4); - if(data == NULL) { - return false; - } - - R.resize(height,width); - G.resize(height,width); - B.resize(height,width); - A.resize(height,width); - - for (unsigned j=0; j<height; ++j) { - for (unsigned i=0; i<width; ++i) { - // used to flip with libPNG, but I'm not sure if - // simply j*width + i wouldn't be better - // stb_image uses horizontal scanline an starts top-left corner - R(i,j) = data[4*( (width-1-i) + width * (height-1-j) )]; - G(i,j) = data[4*( (width-1-i) + width * (height-1-j) ) + 1]; - B(i,j) = data[4*( (width-1-i) + width * (height-1-j) ) + 2]; - //A(i,j) = data[4*( (width-1-i) + width * (height-1-j) ) + 3]; - } - } - - igl::stbi_image_free(data); - - return true; -} diff --git a/xs/src/igl/png/texture_from_png.h b/xs/src/igl/png/texture_from_png.h deleted file mode 100644 index db8c1988e..000000000 --- a/xs/src/igl/png/texture_from_png.h +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_PNG_TEXTURE_FROM_PNG_H -#define IGL_PNG_TEXTURE_FROM_PNG_H -#include "../igl_inline.h" -#include <Eigen/Core> -#include <string> - -#include "../opengl/gl.h" - -namespace igl -{ - namespace png - { - // Read an image from a .png file and use it as a texture - // - // Input: - // png_file path to .png file - // flip whether to flip the image vertically (A --> ∀) - // Output: - // id of generated openGL texture - // Returns true on success, false on failure - IGL_INLINE bool texture_from_png(const std::string png_file, const bool flip, GLuint & id); - IGL_INLINE bool texture_from_png(const std::string png_file, GLuint & id); - - // Read an image from a .png file and use it as a texture - // - // Input: - // png_file path to .png file - // Output: - // R,G,B,A texture channels - // Returns true on success, false on failure - // - // Todo: this is an inappropriate function name. This is really just - // reading a png.... Not necessarily as a texture. - IGL_INLINE bool texture_from_png(const std::string png_file, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B, - Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A - ); - } -} - -#ifndef IGL_STATIC_LIBRARY -# include "texture_from_png.cpp" -#endif - -#endif diff --git a/xs/src/igl/png/writePNG.cpp b/xs/src/igl/png/writePNG.cpp deleted file mode 100644 index 9ab68d775..000000000 --- a/xs/src/igl/png/writePNG.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2016 Daniele Panozzo <daniele.panozzo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#include "writePNG.h" -#include <igl_stb_image.h> -#include <vector> - -IGL_INLINE bool igl::png::writePNG( - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R, - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G, - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B, - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A, - const std::string png_file -) -{ - assert((R.rows() == G.rows()) && (G.rows() == B.rows()) && (B.rows() == A.rows())); - assert((R.cols() == G.cols()) && (G.cols() == B.cols()) && (B.cols() == A.cols())); - - const int comp = 4; // 4 Channels Red, Green, Blue, Alpha - const int stride_in_bytes = R.rows()*comp; // Length of one row in bytes - std::vector<unsigned char> data(R.size()*comp,0); // The image itself; - - for (unsigned i = 0; i<R.rows();++i) - { - for (unsigned j = 0; j < R.cols(); ++j) - { - data[(j * R.rows() * comp) + (i * comp) + 0] = R(i,R.cols()-1-j); - data[(j * R.rows() * comp) + (i * comp) + 1] = G(i,R.cols()-1-j); - data[(j * R.rows() * comp) + (i * comp) + 2] = B(i,R.cols()-1-j); - data[(j * R.rows() * comp) + (i * comp) + 3] = A(i,R.cols()-1-j); - } - } - - igl::stbi_write_png(png_file.c_str(), R.rows(), R.cols(), comp, data.data(), stride_in_bytes); - - return true; -} - -#ifdef IGL_STATIC_LIBRARY -// Explicit template instantiation -// generated by autoexplicit.sh -#endif diff --git a/xs/src/igl/png/writePNG.h b/xs/src/igl/png/writePNG.h deleted file mode 100644 index b0623249f..000000000 --- a/xs/src/igl/png/writePNG.h +++ /dev/null @@ -1,41 +0,0 @@ -// This file is part of libigl, a simple c++ geometry processing library. -// -// Copyright (C) 2016 Daniele Panozzo <daniele.panozzo@gmail.com> -// -// This Source Code Form is subject to the terms of the Mozilla Public License -// v. 2.0. If a copy of the MPL was not distributed with this file, You can -// obtain one at http://mozilla.org/MPL/2.0/. -#ifndef IGL_PNG_WRITE_PNG_H -#define IGL_PNG_WRITE_PNG_H -#include "../igl_inline.h" -#include <Eigen/Core> -#include <string> - -namespace igl -{ - namespace png - { - // Writes an image to a png file - // - // Input: - // R,G,B,A texture channels - // Output: - // png_file path to .png file - // Returns true on success, false on failure - // - IGL_INLINE bool writePNG - ( - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R, - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G, - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B, - const Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A, - const std::string png_file - ); - } -} - -#ifndef IGL_STATIC_LIBRARY -# include "writePNG.cpp" -#endif - -#endif |