mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-28 03:01:17 -06:00
Building igl statically and moving to the dep scripts
Fixing dep build script on Windows and removing some warnings. Use bundled igl by default. Not building with the dependency scripts if not explicitly stated. This way, it will stay in Fix the libigl patch to include C source files in header only mode.
This commit is contained in:
parent
89e39e3895
commit
2ae2672ee9
1095 changed files with 181 additions and 5 deletions
47
src/libigl/igl/png/readPNG.cpp
Normal file
47
src/libigl/igl/png/readPNG.cpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// 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
|
||||
39
src/libigl/igl/png/readPNG.h
Normal file
39
src/libigl/igl/png/readPNG.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// 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
|
||||
45
src/libigl/igl/png/render_to_png.cpp
Normal file
45
src/libigl/igl/png/render_to_png.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// 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
|
||||
41
src/libigl/igl/png/render_to_png.h
Normal file
41
src/libigl/igl/png/render_to_png.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// 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
|
||||
54
src/libigl/igl/png/render_to_png_async.cpp
Normal file
54
src/libigl/igl/png/render_to_png_async.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// 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;
|
||||
}
|
||||
45
src/libigl/igl/png/render_to_png_async.h
Normal file
45
src/libigl/igl/png/render_to_png_async.h
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// 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
|
||||
61
src/libigl/igl/png/texture_from_file.cpp
Normal file
61
src/libigl/igl/png/texture_from_file.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// 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
|
||||
}
|
||||
}
|
||||
39
src/libigl/igl/png/texture_from_file.h
Normal file
39
src/libigl/igl/png/texture_from_file.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// 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
|
||||
|
||||
|
||||
|
||||
83
src/libigl/igl/png/texture_from_png.cpp
Normal file
83
src/libigl/igl/png/texture_from_png.cpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// 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;
|
||||
}
|
||||
54
src/libigl/igl/png/texture_from_png.h
Normal file
54
src/libigl/igl/png/texture_from_png.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// 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
|
||||
46
src/libigl/igl/png/writePNG.cpp
Normal file
46
src/libigl/igl/png/writePNG.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// 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
|
||||
41
src/libigl/igl/png/writePNG.h
Normal file
41
src/libigl/igl/png/writePNG.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue