mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2025-01-10 16:40:11 +00:00
remove libpng and use stb_image_write instead
This commit is contained in:
parent
b0188bf217
commit
b3da5d3fab
@ -22,14 +22,6 @@
|
||||
# language governing permissions and limitations under the Apache License.
|
||||
#
|
||||
|
||||
# optional dependency - enables screenshots in some examples
|
||||
find_package(PNG)
|
||||
if (PNG_FOUND)
|
||||
include_directories("${PNG_INCLUDE_DIRS}")
|
||||
list(APPEND PLATFORM_LIBRARIES "${PNG_LIBRARIES}")
|
||||
add_definitions(-DOPENSUBDIV_HAS_PNG)
|
||||
endif()
|
||||
|
||||
add_subdirectory(common)
|
||||
|
||||
if (NOT NO_OPENGL)
|
||||
|
@ -42,6 +42,7 @@ set(EXAMPLES_COMMON_HEADER_FILES
|
||||
objAnim.h
|
||||
patchColors.h
|
||||
simple_math.h
|
||||
stb_image_write.h
|
||||
stopwatch.h
|
||||
)
|
||||
|
||||
|
@ -30,11 +30,12 @@
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef OPENSUBDIV_HAS_PNG
|
||||
#include <zlib.h>
|
||||
#include <png.h>
|
||||
#endif
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION 1
|
||||
#include "stb_image_write.h"
|
||||
|
||||
#if _MSC_VER
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
GLFrameBuffer::GLFrameBuffer() :
|
||||
_width(0), _height(0),
|
||||
@ -303,12 +304,10 @@ private:
|
||||
void
|
||||
GLFrameBuffer::Screenshot() const {
|
||||
|
||||
#ifdef OPENSUBDIV_HAS_PNG
|
||||
|
||||
int width = GetWidth(),
|
||||
height = GetHeight();
|
||||
|
||||
void * buf = malloc(GetWidth() * GetHeight() * 4 /*RGBA*/);
|
||||
std::vector<unsigned char> data(width*height*4 /*RGBA*/);
|
||||
|
||||
PixelStoreState pixelStore;
|
||||
|
||||
@ -326,7 +325,7 @@ GLFrameBuffer::Screenshot() const {
|
||||
glActiveTexture( GL_TEXTURE0 );
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, _frameBufferColor );
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
|
||||
|
||||
glActiveTexture( restoreActiveTexture );
|
||||
glBindTexture( GL_TEXTURE_2D, restoreBinding );
|
||||
@ -339,44 +338,10 @@ GLFrameBuffer::Screenshot() const {
|
||||
char fname[64];
|
||||
snprintf(fname, 64, "screenshot.%d.png", counter++);
|
||||
|
||||
if (FILE * f = fopen( fname, "w" )) {
|
||||
// flip vertical
|
||||
stbi_write_png(fname, width, height, 4, &data[width*4*(height-1)], -width*4);
|
||||
|
||||
png_structp png_ptr =
|
||||
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
assert(png_ptr);
|
||||
|
||||
png_infop info_ptr =
|
||||
png_create_info_struct(png_ptr);
|
||||
assert(info_ptr);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height, 8,
|
||||
PNG_COLOR_TYPE_RGB_ALPHA,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT );
|
||||
|
||||
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
||||
|
||||
png_bytep rows_ptr[ height ];
|
||||
for(int i = 0; i<height; ++i ) {
|
||||
rows_ptr[height-i-1] = ((png_byte *)buf) + i*width*4;
|
||||
}
|
||||
|
||||
png_set_rows(png_ptr, info_ptr, rows_ptr);
|
||||
|
||||
png_init_io(png_ptr, f);
|
||||
|
||||
png_write_png( png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0 );
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
fclose(f);
|
||||
fprintf(stdout, "Saved %s\n", fname);
|
||||
} else {
|
||||
fprintf(stderr, "Error creating: %s\n", fname);
|
||||
}
|
||||
free(buf);
|
||||
#endif
|
||||
fprintf(stdout, "Saved %s\n", fname);
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,17 +58,6 @@ _stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# optional dependency - enables screenshots
|
||||
# XXX: this is actually unnecessary for this test since glImaging
|
||||
# use stb_image_write, however, examples_common_obj has libpng
|
||||
# dependency so we need to add here. We'll remove the libpng dependency soon.
|
||||
find_package(PNG)
|
||||
if (PNG_FOUND)
|
||||
include_directories("${PNG_INCLUDE_DIRS}")
|
||||
list(APPEND PLATFORM_LIBRARIES "${PNG_LIBRARIES}")
|
||||
add_definitions(-DOPENSUBDIV_HAS_PNG)
|
||||
endif()
|
||||
|
||||
_add_glfw_executable(glImaging
|
||||
"${SOURCE_FILES}"
|
||||
"${SHADER_FILES}"
|
||||
|
@ -103,11 +103,9 @@
|
||||
|
||||
#include <common/vtr_utils.h>
|
||||
#include "../common/patchColors.h"
|
||||
#include "../common/stb_image_write.h" // common.obj has an implementation.
|
||||
#include "init_shapes.h"
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION 1
|
||||
#include "stb_image_write.h"
|
||||
|
||||
using namespace OpenSubdiv;
|
||||
|
||||
static const char *shaderSource =
|
||||
|
@ -58,14 +58,6 @@ if( OPENCL_FOUND )
|
||||
include_directories("${OPENCL_INCLUDE_DIRS}")
|
||||
endif()
|
||||
|
||||
# optional dependency - enables screenshots
|
||||
find_package(PNG)
|
||||
if (PNG_FOUND)
|
||||
include_directories("${PNG_INCLUDE_DIRS}")
|
||||
list(APPEND PLATFORM_LIBRARIES "${PNG_LIBRARIES}")
|
||||
add_definitions(-DOPENSUBDIV_HAS_PNG)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
_stringify("${SHADER_FILES}" INC_FILES)
|
||||
|
@ -50,11 +50,6 @@ GLFWmonitor* g_primary = 0;
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef OPENSUBDIV_HAS_PNG
|
||||
#include <zlib.h>
|
||||
#include <png.h>
|
||||
#endif
|
||||
|
||||
#include <osd/glDrawContext.h>
|
||||
#include <osd/glDrawRegistry.h>
|
||||
#include <osd/glPtexMipmapTexture.h>
|
||||
@ -124,6 +119,7 @@ OpenSubdiv::Osd::GLMeshInterface *g_mesh;
|
||||
#include "../common/gl_hud.h"
|
||||
#include "../common/patchColors.h"
|
||||
#include "../common/hdr_reader.h"
|
||||
#include "../common/stb_image_write.h"
|
||||
|
||||
static const char *g_defaultShaderSource =
|
||||
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
||||
@ -1887,20 +1883,16 @@ display() {
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
screenshot(int multiplier=4) {
|
||||
#ifdef OPENSUBDIV_HAS_PNG
|
||||
|
||||
int oldwidth = g_width,
|
||||
oldheight = g_height,
|
||||
width = multiplier * g_width,
|
||||
height = multiplier * g_height;
|
||||
|
||||
|
||||
reshape(g_window, width, height);
|
||||
|
||||
display();
|
||||
|
||||
void * buf = malloc(width * height * 4);
|
||||
|
||||
glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
|
||||
std::vector<unsigned char> data(width*height*4 /*RGBA*/);
|
||||
|
||||
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
@ -1914,11 +1906,10 @@ screenshot(int multiplier=4) {
|
||||
glActiveTexture( GL_TEXTURE0 );
|
||||
|
||||
glBindTexture( GL_TEXTURE_2D, g_imageShader.frameBufferTexture );
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
|
||||
|
||||
glActiveTexture( restoreActiveTexture );
|
||||
glBindTexture( GL_TEXTURE_2D, restoreBinding );
|
||||
glPopClientAttrib();
|
||||
|
||||
reshape(g_window, oldwidth, oldheight);
|
||||
|
||||
@ -1928,43 +1919,10 @@ screenshot(int multiplier=4) {
|
||||
char fname[64];
|
||||
snprintf(fname, 64, "screenshot.%d.png", counter++);
|
||||
|
||||
if (FILE * f = fopen( fname, "w" )) {
|
||||
// flip vertical
|
||||
stbi_write_png(fname, width, height, 4, &data[width*4*(height-1)], -width*4);
|
||||
|
||||
png_structp png_ptr =
|
||||
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
assert(png_ptr);
|
||||
|
||||
png_infop info_ptr =
|
||||
png_create_info_struct(png_ptr);
|
||||
assert(info_ptr);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height, 8,
|
||||
PNG_COLOR_TYPE_RGB_ALPHA,
|
||||
PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT );
|
||||
|
||||
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
|
||||
|
||||
png_bytep rows_ptr[ height ];
|
||||
for(int i = 0; i<height; ++i ) {
|
||||
rows_ptr[height-i-1] = ((png_byte *)buf) + i*width*4;
|
||||
}
|
||||
|
||||
png_set_rows(png_ptr, info_ptr, rows_ptr);
|
||||
|
||||
png_init_io(png_ptr, f);
|
||||
|
||||
png_write_png( png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, 0 );
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
|
||||
fclose(f);
|
||||
fprintf(stdout, "Saved %s\n", fname);
|
||||
} else {
|
||||
fprintf(stderr, "Error creating: %s\n", fname);
|
||||
}
|
||||
#endif
|
||||
fprintf(stdout, "Saved %s\n", fname);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user