├── PNG ├── pngvcrd.c ├── pngasmrd.h ├── Makefile ├── pnggccrd.c └── pngrio.c ├── .gitignore ├── JPEG ├── jversion.h ├── jconfig.h ├── jchuff.h ├── Makefile ├── jcinit.cpp ├── jmemnobs.cpp ├── jinclude.h ├── jcomapi.cpp ├── jdtrans.cpp ├── jdatadst.cpp ├── jutils.cpp ├── jfdctflt.cpp ├── jcapistd.cpp └── jdct.h ├── ZLIB ├── inffast.h ├── infcodes.h ├── infblock.h ├── adler32.c ├── Makefile ├── uncompr.c ├── infutil.c ├── compress.c ├── inftrees.h ├── infutil.h ├── Make_vms.com ├── zutil.c ├── inffast.c ├── zutil.h └── crc32.c ├── PoissonRecon.pro ├── Src ├── PNG.h ├── JPEG.h ├── PreProcessor.h ├── MAT.h ├── BinaryNode.h ├── CmdLineParser.h ├── JPEG.inl ├── PPolynomial.h ├── Polynomial.h ├── FEMTree.SortedTreeNodes.inl ├── SparseMatrixInterface.h ├── FunctionData.h ├── PNG.inl ├── Factor.h ├── Allocator.h ├── BlockedVector.h ├── MAT.inl └── Array.h ├── LICENSE ├── Src_CC_wrap ├── PointData.cpp ├── PointData.h └── PoissonReconLib.h ├── CMakeLists.txt └── Makefile /PNG/pngvcrd.c: -------------------------------------------------------------------------------- 1 | /* pnggvrd.c was removed from libpng-1.2.20. */ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.sdf 2 | *.suo 3 | /Obj/ 4 | /Debug/ 5 | /Bin/ 6 | *.opensdf 7 | *.bat 8 | *.zip 9 | .vs/* -------------------------------------------------------------------------------- /PNG/pngasmrd.h: -------------------------------------------------------------------------------- 1 | /* pngasmrd.h - assembler version of utilities to read a PNG file 2 | * 3 | * libpng 1.2.5 - October 3, 2002 4 | * For conditions of distribution and use, see copyright notice in png.h 5 | * Copyright (c) 2002 Glenn Randers-Pehrson 6 | * 7 | */ 8 | 9 | /* This file is obsolete in libpng-1.0.9 and later; its contents now appear 10 | * at the end of pngconf.h. 11 | */ 12 | -------------------------------------------------------------------------------- /JPEG/jversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jversion.h 3 | * 4 | * Copyright (C) 1991-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains software version identification. 9 | */ 10 | 11 | 12 | #define JVERSION "6b 27-Mar-1998" 13 | 14 | #define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane" 15 | -------------------------------------------------------------------------------- /ZLIB/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | extern int inflate_fast OF(( 12 | uInt, 13 | uInt, 14 | inflate_huft *, 15 | inflate_huft *, 16 | inflate_blocks_statef *, 17 | z_streamp )); 18 | -------------------------------------------------------------------------------- /ZLIB/infcodes.h: -------------------------------------------------------------------------------- 1 | /* infcodes.h -- header to use infcodes.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | struct inflate_codes_state; 12 | typedef struct inflate_codes_state FAR inflate_codes_statef; 13 | 14 | extern inflate_codes_statef *inflate_codes_new OF(( 15 | uInt, uInt, 16 | inflate_huft *, inflate_huft *, 17 | z_streamp )); 18 | 19 | extern int inflate_codes OF(( 20 | inflate_blocks_statef *, 21 | z_streamp , 22 | int)); 23 | 24 | extern void inflate_codes_free OF(( 25 | inflate_codes_statef *, 26 | z_streamp )); 27 | 28 | -------------------------------------------------------------------------------- /PoissonRecon.pro: -------------------------------------------------------------------------------- 1 | QT -= core gui 2 | INCLUDEPATH -= . 3 | 4 | ### begin mac specific part ################# 5 | # On OSX xcode clang does NOT support OpenMP. 6 | # Use these two lines if you installed an alternative clang with macport 7 | # (something like 'sudo port install clang-3.9') 8 | macx:QMAKE_CXX = clang++-mp-3.9 9 | macx:QMAKE_LFLAGS += -L/opt/local/lib/libomp -lomp 10 | 11 | # Use this if you want to use the standard clang distributed with xcode 12 | # macx:QMAKE_CXXFLAGS-= -fopenmp 13 | 14 | # Mac specific Config required to avoid to make application bundles 15 | CONFIG -= app_bundle 16 | ### end of mac specific part ################# 17 | 18 | QMAKE_CXXFLAGS+=-fopenmp -Wsign-compare -O3 -DRELEASE -funroll-loops -ffast-math 19 | 20 | CONFIG += console warn_off 21 | TEMPLATE = app 22 | 23 | SOURCES += Src/PoissonRecon.cpp \ 24 | Src/MarchingCubes.cpp \ 25 | Src/PlyFile.cpp \ 26 | Src/CmdLineParser.cpp \ 27 | Src/Factor.cpp \ 28 | Src/Geometry.cpp 29 | 30 | 31 | TARGET=PoissonRecon 32 | 33 | -------------------------------------------------------------------------------- /Src/PNG.h: -------------------------------------------------------------------------------- 1 | #ifndef PNG_INCLUDED 2 | #define PNG_INCLUDED 3 | 4 | #include "PNG/png.h" 5 | 6 | struct PNGReader : public ImageReader 7 | { 8 | PNGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 9 | ~PNGReader( void ); 10 | unsigned int nextRow( unsigned char* row ); 11 | static bool GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 12 | protected: 13 | png_structp _png_ptr; 14 | png_infop _info_ptr; 15 | png_infop _end_info ; 16 | FILE* _fp; 17 | unsigned char* _scratchRow; 18 | unsigned int _currentRow; 19 | }; 20 | 21 | struct PNGWriter : public ImageWriter 22 | { 23 | PNGWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality=100 ); 24 | ~PNGWriter( void ); 25 | unsigned int nextRow( const unsigned char* row ); 26 | unsigned int nextRows( const unsigned char* rows , unsigned int rowNum ); 27 | protected: 28 | FILE* _fp; 29 | png_structp _png_ptr; 30 | png_infop _info_ptr; 31 | unsigned int _currentRow; 32 | }; 33 | 34 | #include "PNG.inl" 35 | #endif //PNG_INCLUDED 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 mkazhdan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /JPEG/jconfig.h: -------------------------------------------------------------------------------- 1 | /* jconfig.h --- generated by ckconfig.c */ 2 | /* see jconfig.doc for explanations */ 3 | 4 | #define HAVE_PROTOTYPES 5 | #define HAVE_UNSIGNED_CHAR 6 | #define HAVE_UNSIGNED_SHORT 7 | /* #define void char */ 8 | /* #define const */ 9 | #undef CHAR_IS_UNSIGNED 10 | #define HAVE_STDDEF_H 11 | #define HAVE_STDLIB_H 12 | #undef NEED_BSD_STRINGS 13 | #undef NEED_SYS_TYPES_H 14 | #undef NEED_FAR_POINTERS 15 | #undef NEED_SHORT_EXTERNAL_NAMES 16 | #undef INCOMPLETE_TYPES_BROKEN 17 | 18 | #ifdef JPEG_INTERNALS 19 | 20 | #undef RIGHT_SHIFT_IS_UNSIGNED 21 | 22 | #endif /* JPEG_INTERNALS */ 23 | 24 | #ifdef JPEG_CJPEG_DJPEG 25 | 26 | #define BMP_SUPPORTED /* BMP image file format */ 27 | #define GIF_SUPPORTED /* GIF image file format */ 28 | #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ 29 | #undef RLE_SUPPORTED /* Utah RLE image file format */ 30 | #define TARGA_SUPPORTED /* Targa image file format */ 31 | 32 | #undef TWO_FILE_COMMANDLINE /* You may need this on non-Unix systems */ 33 | #undef NEED_SIGNAL_CATCHER /* Define this if you use jmemname.c */ 34 | #undef DONT_USE_B_MODE 35 | /* #define PROGRESS_REPORT */ /* optional */ 36 | 37 | #endif /* JPEG_CJPEG_DJPEG */ 38 | -------------------------------------------------------------------------------- /ZLIB/infblock.h: -------------------------------------------------------------------------------- 1 | /* infblock.h -- header to use infblock.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | struct inflate_blocks_state; 12 | typedef struct inflate_blocks_state FAR inflate_blocks_statef; 13 | 14 | extern inflate_blocks_statef * inflate_blocks_new OF(( 15 | z_streamp z, 16 | check_func c, /* check function */ 17 | uInt w)); /* window size */ 18 | 19 | extern int inflate_blocks OF(( 20 | inflate_blocks_statef *, 21 | z_streamp , 22 | int)); /* initial return code */ 23 | 24 | extern void inflate_blocks_reset OF(( 25 | inflate_blocks_statef *, 26 | z_streamp , 27 | uLongf *)); /* check value on output */ 28 | 29 | extern int inflate_blocks_free OF(( 30 | inflate_blocks_statef *, 31 | z_streamp)); 32 | 33 | extern void inflate_set_dictionary OF(( 34 | inflate_blocks_statef *s, 35 | const Bytef *d, /* dictionary */ 36 | uInt n)); /* dictionary length */ 37 | 38 | extern int inflate_blocks_sync_point OF(( 39 | inflate_blocks_statef *s)); 40 | -------------------------------------------------------------------------------- /Src_CC_wrap/PointData.cpp: -------------------------------------------------------------------------------- 1 | //########################################################################## 2 | //# # 3 | //# CLOUDCOMPARE WRAPPER: PoissonReconLib # 4 | //# # 5 | //# This program is free software; you can redistribute it and/or modify # 6 | //# it under the terms of the GNU General Public License as published by # 7 | //# the Free Software Foundation; version 2 or later of the License. # 8 | //# # 9 | //# This program is distributed in the hope that it will be useful, # 10 | //# but WITHOUT ANY WARRANTY; without even the implied warranty of # 11 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 12 | //# GNU General Public License for more details. # 13 | //# # 14 | //# COPYRIGHT: CloudCompare Project # 15 | //# # 16 | //########################################################################## 17 | 18 | #include "PointData.h" 19 | 20 | template class PointData; 21 | template class PointData; 22 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.10 ) 2 | 3 | project( QPOISSON_RECON_LIB ) 4 | 5 | add_library( ${PROJECT_NAME} STATIC ) 6 | 7 | # To remove very annoying "NO ARGUMENTS THAT DEPEND ON A TEMPLATE PARAMETER" errors with G++! 8 | if( UNIX OR MINGW ) 9 | target_compile_options( ${PROJECT_NAME} PRIVATE $<$:-fpermissive -w> ) 10 | elseif( MSVC ) 11 | target_compile_options( ${PROJECT_NAME} PRIVATE $<$:/bigobj> ) 12 | endif() 13 | 14 | target_sources( ${PROJECT_NAME} 15 | PUBLIC 16 | ${CMAKE_CURRENT_SOURCE_DIR}/Src_CC_wrap/PoissonReconLib.h 17 | ${CMAKE_CURRENT_SOURCE_DIR}/Src_CC_wrap/PointData.h 18 | PRIVATE 19 | ${CMAKE_CURRENT_SOURCE_DIR}/Src_CC_wrap/PoissonReconLib.cpp 20 | ${CMAKE_CURRENT_SOURCE_DIR}/Src_CC_wrap/PointData.cpp 21 | ) 22 | 23 | target_include_directories( ${PROJECT_NAME} 24 | PUBLIC 25 | ${CMAKE_CURRENT_SOURCE_DIR}/Src_CC_wrap 26 | PRIVATE 27 | ${CMAKE_CURRENT_SOURCE_DIR}/Src 28 | ) 29 | 30 | target_compile_definitions( ${PROJECT_NAME} 31 | PRIVATE 32 | _CRT_SECURE_NO_DEPRECATE 33 | _CRT_SECURE_NO_WARNINGS 34 | NOMINMAX 35 | ) 36 | 37 | option( POISSON_RECON_WITH_OPEN_MP "Compile PoissonRecon plugin with OpenMP support" OFF ) 38 | if( POISSON_RECON_WITH_OPEN_MP ) 39 | find_package( OpenMP ) 40 | 41 | if( OpenMP_CXX_FOUND ) 42 | target_link_libraries( ${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX ) 43 | target_compile_definitions( ${PROJECT_NAME} PRIVATE WITH_OPENMP ) 44 | endif() 45 | endif () 46 | -------------------------------------------------------------------------------- /ZLIB/adler32.c: -------------------------------------------------------------------------------- 1 | /* adler32.c -- compute the Adler-32 checksum of a data stream 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: adler32.c,v 1.1 2014/03/04 21:20:43 uid42406 Exp $ */ 7 | 8 | #include "zlib.h" 9 | 10 | #define BASE 65521L /* largest prime smaller than 65536 */ 11 | #define NMAX 5552 12 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ 13 | 14 | #define DO1(buf,i) {s1 += buf[i]; s2 += s1;} 15 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 16 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 17 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 18 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 19 | 20 | /* ========================================================================= */ 21 | uLong ZEXPORT adler32(adler, buf, len) 22 | uLong adler; 23 | const Bytef *buf; 24 | uInt len; 25 | { 26 | unsigned long s1 = adler & 0xffff; 27 | unsigned long s2 = (adler >> 16) & 0xffff; 28 | int k; 29 | 30 | if (buf == Z_NULL) return 1L; 31 | 32 | while (len > 0) { 33 | k = len < NMAX ? len : NMAX; 34 | len -= k; 35 | while (k >= 16) { 36 | DO16(buf); 37 | buf += 16; 38 | k -= 16; 39 | } 40 | if (k != 0) do { 41 | s1 += *buf++; 42 | s2 += s1; 43 | } while (--k); 44 | s1 %= BASE; 45 | s2 %= BASE; 46 | } 47 | return (s2 << 16) | s1; 48 | } 49 | -------------------------------------------------------------------------------- /ZLIB/Makefile: -------------------------------------------------------------------------------- 1 | ZLIB_TARGET=libmyz.a 2 | ZLIB_SOURCE=adler32.c compress.c crc32.c deflate.c gzio.c infblock.c infcodes.c inffast.c inflate.c inftrees.c infutil.c trees.c uncompr.c zutil.c 3 | 4 | COMPILER = gcc 5 | #COMPILER = clang 6 | 7 | CFLAGS += -Wno-deprecated -Wno-write-strings 8 | 9 | CFLAGS_DEBUG = -DDEBUG -g3 10 | LFLAGS_DEBUG = 11 | 12 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -g 13 | LFLAGS_RELEASE = -O3 -g 14 | 15 | SRC = ./ 16 | BIN = ../Bin/Linux/ 17 | INCLUDE = ../ 18 | 19 | ifeq ($(COMPILER),gcc) 20 | CC=gcc 21 | CXX=g++ 22 | else 23 | CC=clang-3.8 24 | CXX=clang++-3.8 25 | # CC=clang-3.5 26 | # CXX=clang++-3.5 27 | endif 28 | 29 | MD=mkdir 30 | 31 | ZLIB_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(ZLIB_SOURCE)))) 32 | 33 | all: CFLAGS += $(CFLAGS_RELEASE) 34 | all: LFLAGS += $(LFLAGS_RELEASE) 35 | all: make_dir 36 | all: $(BIN)$(ZLIB_TARGET) 37 | 38 | debug: CFLAGS += $(CFLAGS_DEBUG) 39 | debug: LFLAGS += $(LFLAGS_DEBUG) 40 | debug: make_dir 41 | debug: $(BIN)$(ZLIB_TARGET) 42 | 43 | zlib: CFLAGS += $(CFLAGS_RELEASE) 44 | zlib: LFLAGS += $(LFLAGS_RELEASE) 45 | zlib: make_dir 46 | zlib: $(BIN)$(ZLIB_TARGET) 47 | 48 | clean: 49 | rm -rf $(BIN)$(ZLIB_TARGET) 50 | rm -rf $(ZLIB_OBJECTS) 51 | 52 | make_dir: 53 | $(MD) -p $(BIN) 54 | 55 | $(BIN)$(ZLIB_TARGET): $(ZLIB_OBJECTS) 56 | ar rcs $(BIN)$(ZLIB_TARGET) $(ZLIB_OBJECTS) 57 | 58 | $(BIN)%.o: $(SRC)%.c 59 | $(CC) -c -o $@ -I$(INCLUDE) $< 60 | 61 | $(BIN)%.o: $(SRC)%.cpp 62 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 63 | 64 | -------------------------------------------------------------------------------- /PNG/Makefile: -------------------------------------------------------------------------------- 1 | PNG_TARGET=libmypng.a 2 | PNG_SOURCE=png.c pngerror.c pnggccrd.c pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c pngset.c pngtest.c pngtrans.c pngvcrd.c pngwio.c pngwrite.c pngwtran.c pngwutil.c 3 | 4 | COMPILER = gcc 5 | #COMPILER = clang 6 | 7 | CFLAGS += -Wno-deprecated -Wno-write-strings 8 | 9 | CFLAGS_DEBUG = -DDEBUG -g3 10 | LFLAGS_DEBUG = 11 | 12 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -g 13 | LFLAGS_RELEASE = -O3 -g 14 | 15 | SRC = ./ 16 | BIN = ../Bin/Linux/ 17 | INCLUDE = ../ 18 | 19 | ifeq ($(COMPILER),gcc) 20 | CC=gcc 21 | CXX=g++ 22 | else 23 | CC=clang-3.8 24 | CXX=clang++-3.8 25 | # CC=clang-3.5 26 | # CXX=clang++-3.5 27 | endif 28 | 29 | MD=mkdir 30 | 31 | PNG_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(PNG_SOURCE)))) 32 | 33 | 34 | all: CFLAGS += $(CFLAGS_RELEASE) 35 | all: LFLAGS += $(LFLAGS_RELEASE) 36 | all: make_dir 37 | all: $(BIN)$(PNG_TARGET) 38 | 39 | debug: CFLAGS += $(CFLAGS_DEBUG) 40 | debug: LFLAGS += $(LFLAGS_DEBUG) 41 | debug: make_dir 42 | debug: $(BIN)$(PNG_TARGET) 43 | 44 | png: CFLAGS += $(CFLAGS_RELEASE) 45 | png: LFLAGS += $(LFLAGS_RELEASE) 46 | png: make_dir 47 | png: $(BIN)$(PNG_TARGET) 48 | 49 | clean: 50 | rm -rf $(BIN)$(PNG_TARGET) 51 | rm -rf $(PNG_OBJECTS) 52 | 53 | make_dir: 54 | $(MD) -p $(BIN) 55 | 56 | $(BIN)$(PNG_TARGET): $(PNG_OBJECTS) 57 | ar rcs $(BIN)$(PNG_TARGET) $(PNG_OBJECTS) 58 | 59 | $(BIN)%.o: $(SRC)%.c 60 | $(CC) -c -o $@ -I$(INCLUDE) $< 61 | 62 | $(BIN)%.o: $(SRC)%.cpp 63 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 64 | 65 | -------------------------------------------------------------------------------- /Src/JPEG.h: -------------------------------------------------------------------------------- 1 | #ifndef JPEG_INCLUDED 2 | #define JPEG_INCLUDED 3 | #include "Image.h" 4 | 5 | #include 6 | 7 | #ifdef _WIN32 8 | #include 9 | #include "JPEG/jpeglib.h" 10 | #include "JPEG/jerror.h" 11 | #include "JPEG/jmorecfg.h" 12 | #else // !_WIN32 13 | #include 14 | #include 15 | #include 16 | #endif // _WIN32 17 | 18 | struct my_error_mgr 19 | { 20 | struct jpeg_error_mgr pub; // "public" fields 21 | jmp_buf setjmp_buffer; // for return to caller 22 | }; 23 | typedef struct my_error_mgr * my_error_ptr; 24 | 25 | struct JPEGReader : public ImageReader 26 | { 27 | JPEGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 28 | ~JPEGReader( void ); 29 | unsigned int nextRow( unsigned char* row ); 30 | static bool GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 31 | protected: 32 | FILE* _fp; 33 | struct jpeg_decompress_struct _cInfo; 34 | struct my_error_mgr _jErr; 35 | unsigned int _currentRow; 36 | }; 37 | 38 | struct JPEGWriter : public ImageWriter 39 | { 40 | JPEGWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality=100 ); 41 | ~JPEGWriter( void ); 42 | unsigned int nextRow( const unsigned char* row ); 43 | unsigned int nextRows( const unsigned char* rows , unsigned int rowNum ); 44 | protected: 45 | FILE* _fp; 46 | struct jpeg_compress_struct _cInfo; 47 | struct my_error_mgr _jErr; 48 | unsigned int _currentRow; 49 | }; 50 | 51 | #include "JPEG.inl" 52 | #endif //JPEG_INCLUDED 53 | -------------------------------------------------------------------------------- /JPEG/jchuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jchuff.h 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains declarations for Huffman entropy encoding routines 9 | * that are shared between the sequential encoder (jchuff.c) and the 10 | * progressive encoder (jcphuff.c). No other modules need to see these. 11 | */ 12 | 13 | /* The legal range of a DCT coefficient is 14 | * -1024 .. +1023 for 8-bit data; 15 | * -16384 .. +16383 for 12-bit data. 16 | * Hence the magnitude should always fit in 10 or 14 bits respectively. 17 | */ 18 | 19 | #if BITS_IN_JSAMPLE == 8 20 | #define MAX_COEF_BITS 10 21 | #else 22 | #define MAX_COEF_BITS 14 23 | #endif 24 | 25 | /* Derived data constructed for each Huffman table */ 26 | 27 | typedef struct { 28 | unsigned int ehufco[256]; /* code for each symbol */ 29 | char ehufsi[256]; /* length of code for each symbol */ 30 | /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */ 31 | } c_derived_tbl; 32 | 33 | /* Short forms of external names for systems with brain-damaged linkers. */ 34 | 35 | #ifdef NEED_SHORT_EXTERNAL_NAMES 36 | #define jpeg_make_c_derived_tbl jMkCDerived 37 | #define jpeg_gen_optimal_table jGenOptTbl 38 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 39 | 40 | /* Expand a Huffman table definition into the derived format */ 41 | EXTERN(void) jpeg_make_c_derived_tbl 42 | JPP((j_compress_ptr cinfo, boolean isDC, int tblno, 43 | c_derived_tbl ** pdtbl)); 44 | 45 | /* Generate an optimal table definition given the specified counts */ 46 | EXTERN(void) jpeg_gen_optimal_table 47 | JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])); 48 | -------------------------------------------------------------------------------- /JPEG/Makefile: -------------------------------------------------------------------------------- 1 | JPG_TARGET=libmyjpg.a 2 | JPG_SOURCE=ckconfig.cpp jccolor.cpp jcmainct.cpp jcparam.cpp jctrans.cpp jdatasrc.cpp jdhuff.cpp jdmaster.cpp jdsample.cpp jfdctfst.cpp jidctint.cpp jquant1.cpp jcapimin.cpp jcdctmgr.cpp jcmarker.cpp jcphuff.cpp jdapimin.cpp jdcoefct.cpp jdinput.cpp jdmerge.cpp jdtrans.cpp jfdctint.cpp jidctred.cpp jquant2.cpp jcapistd.cpp jchuff.cpp jcmaster.cpp jcprepct.cpp jdapistd.cpp jdcolor.cpp jdmainct.cpp jdphuff.cpp jerror.cpp jidctflt.cpp jmemmgr.cpp jutils.cpp jccoefct.cpp jcinit.cpp jcomapi.cpp jcsample.cpp jdatadst.cpp jddctmgr.cpp jdmarker.cpp jdpostct.cpp jfdctflt.cpp jidctfst.cpp jmemnobs.cpp 3 | 4 | COMPILER = gcc 5 | #COMPILER = clang 6 | 7 | CFLAGS += -Wno-deprecated -Wno-write-strings 8 | 9 | CFLAGS_DEBUG = -DDEBUG -g3 10 | LFLAGS_DEBUG = 11 | 12 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -g 13 | LFLAGS_RELEASE = -O3 -g 14 | 15 | SRC = ./ 16 | BIN = ../Bin/Linux/ 17 | INCLUDE = ../ 18 | 19 | ifeq ($(COMPILER),gcc) 20 | CC=gcc 21 | CXX=g++ 22 | else 23 | CC=clang-3.8 24 | CXX=clang++-3.8 25 | # CC=clang-3.5 26 | # CXX=clang++-3.5 27 | endif 28 | 29 | MD=mkdir 30 | 31 | JPG_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(JPG_SOURCE)))) 32 | 33 | all: CFLAGS += $(CFLAGS_RELEASE) 34 | all: LFLAGS += $(LFLAGS_RELEASE) 35 | all: make_dir 36 | all: $(BIN) 37 | all: $(BIN)$(JPG_TARGET) 38 | 39 | debug: CFLAGS += $(CFLAGS_DEBUG) 40 | debug: LFLAGS += $(LFLAGS_DEBUG) 41 | debug: $(BIN) 42 | debug: $(BIN)$(JPG_TARGET) 43 | 44 | jpeg: CFLAGS += $(CFLAGS_RELEASE) 45 | jpeg: LFLAGS += $(LFLAGS_RELEASE) 46 | jpeg: $(BIN) 47 | jpeg: $(BIN)$(JPG_TARGET) 48 | 49 | clean: 50 | rm -rf $(BIN)$(JPG_TARGET) 51 | rm -rf $(JPG_OBJECTS) 52 | 53 | make_dir: 54 | $(MD) -p $(BIN) 55 | 56 | $(BIN): 57 | $(MD) -p $(BIN) 58 | 59 | $(BIN)$(JPG_TARGET): $(JPG_OBJECTS) 60 | ar rcs $(BIN)$(JPG_TARGET) $(JPG_OBJECTS) 61 | 62 | $(BIN)%.o: $(SRC)%.c 63 | $(CC) -c -o $@ -I$(INCLUDE) $< 64 | 65 | $(BIN)%.o: $(SRC)%.cpp 66 | $(CC) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 67 | 68 | -------------------------------------------------------------------------------- /ZLIB/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: uncompr.c,v 1.1 2014/03/04 21:20:44 uid42406 Exp $ */ 7 | 8 | #include "zlib.h" 9 | 10 | /* =========================================================================== 11 | Decompresses the source buffer into the destination buffer. sourceLen is 12 | the byte length of the source buffer. Upon entry, destLen is the total 13 | size of the destination buffer, which must be large enough to hold the 14 | entire uncompressed data. (The size of the uncompressed data must have 15 | been saved previously by the compressor and transmitted to the decompressor 16 | by some mechanism outside the scope of this compression library.) 17 | Upon exit, destLen is the actual size of the compressed buffer. 18 | This function can be used to decompress a whole file at once if the 19 | input file is mmap'ed. 20 | 21 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 22 | enough memory, Z_BUF_ERROR if there was not enough room in the output 23 | buffer, or Z_DATA_ERROR if the input data was corrupted. 24 | */ 25 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 26 | Bytef *dest; 27 | uLongf *destLen; 28 | const Bytef *source; 29 | uLong sourceLen; 30 | { 31 | z_stream stream; 32 | int err; 33 | 34 | stream.next_in = (Bytef*)source; 35 | stream.avail_in = (uInt)sourceLen; 36 | /* Check for source > 64K on 16-bit machine: */ 37 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 38 | 39 | stream.next_out = dest; 40 | stream.avail_out = (uInt)*destLen; 41 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 42 | 43 | stream.zalloc = (alloc_func)0; 44 | stream.zfree = (free_func)0; 45 | 46 | err = inflateInit(&stream); 47 | if (err != Z_OK) return err; 48 | 49 | err = inflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | inflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = inflateEnd(&stream); 57 | return err; 58 | } 59 | -------------------------------------------------------------------------------- /ZLIB/infutil.c: -------------------------------------------------------------------------------- 1 | /* inflate_util.c -- data and routines common to blocks and codes 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "zutil.h" 7 | #include "infblock.h" 8 | #include "inftrees.h" 9 | #include "infcodes.h" 10 | #include "infutil.h" 11 | 12 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ 13 | 14 | /* And'ing with mask[n] masks the lower n bits */ 15 | uInt inflate_mask[17] = { 16 | 0x0000, 17 | 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, 18 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff 19 | }; 20 | 21 | 22 | /* copy as much as possible from the sliding window to the output area */ 23 | int inflate_flush(s, z, r) 24 | inflate_blocks_statef *s; 25 | z_streamp z; 26 | int r; 27 | { 28 | uInt n; 29 | Bytef *p; 30 | Bytef *q; 31 | 32 | /* local copies of source and destination pointers */ 33 | p = z->next_out; 34 | q = s->read; 35 | 36 | /* compute number of bytes to copy as far as end of window */ 37 | n = (uInt)((q <= s->write ? s->write : s->end) - q); 38 | if (n > z->avail_out) n = z->avail_out; 39 | if (n && r == Z_BUF_ERROR) r = Z_OK; 40 | 41 | /* update counters */ 42 | z->avail_out -= n; 43 | z->total_out += n; 44 | 45 | /* update check information */ 46 | if (s->checkfn != Z_NULL) 47 | z->adler = s->check = (*s->checkfn)(s->check, q, n); 48 | 49 | /* copy as far as end of window */ 50 | zmemcpy(p, q, n); 51 | p += n; 52 | q += n; 53 | 54 | /* see if more to copy at beginning of window */ 55 | if (q == s->end) 56 | { 57 | /* wrap pointers */ 58 | q = s->window; 59 | if (s->write == s->end) 60 | s->write = s->window; 61 | 62 | /* compute bytes to copy */ 63 | n = (uInt)(s->write - q); 64 | if (n > z->avail_out) n = z->avail_out; 65 | if (n && r == Z_BUF_ERROR) r = Z_OK; 66 | 67 | /* update counters */ 68 | z->avail_out -= n; 69 | z->total_out += n; 70 | 71 | /* update check information */ 72 | if (s->checkfn != Z_NULL) 73 | z->adler = s->check = (*s->checkfn)(s->check, q, n); 74 | 75 | /* copy */ 76 | zmemcpy(p, q, n); 77 | p += n; 78 | q += n; 79 | } 80 | 81 | /* update pointers */ 82 | z->next_out = p; 83 | s->read = q; 84 | 85 | /* done */ 86 | return r; 87 | } 88 | -------------------------------------------------------------------------------- /ZLIB/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: compress.c,v 1.1 2014/03/04 21:20:43 uid42406 Exp $ */ 7 | 8 | #include "zlib.h" 9 | 10 | /* =========================================================================== 11 | Compresses the source buffer into the destination buffer. The level 12 | parameter has the same meaning as in deflateInit. sourceLen is the byte 13 | length of the source buffer. Upon entry, destLen is the total size of the 14 | destination buffer, which must be at least 0.1% larger than sourceLen plus 15 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 16 | 17 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 18 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 19 | Z_STREAM_ERROR if the level parameter is invalid. 20 | */ 21 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 22 | Bytef *dest; 23 | uLongf *destLen; 24 | const Bytef *source; 25 | uLong sourceLen; 26 | int level; 27 | { 28 | z_stream stream; 29 | int err; 30 | 31 | stream.next_in = (Bytef*)source; 32 | stream.avail_in = (uInt)sourceLen; 33 | #ifdef MAXSEG_64K 34 | /* Check for source > 64K on 16-bit machine: */ 35 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 36 | #endif 37 | stream.next_out = dest; 38 | stream.avail_out = (uInt)*destLen; 39 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 40 | 41 | stream.zalloc = (alloc_func)0; 42 | stream.zfree = (free_func)0; 43 | stream.opaque = (voidpf)0; 44 | 45 | err = deflateInit(&stream, level); 46 | if (err != Z_OK) return err; 47 | 48 | err = deflate(&stream, Z_FINISH); 49 | if (err != Z_STREAM_END) { 50 | deflateEnd(&stream); 51 | return err == Z_OK ? Z_BUF_ERROR : err; 52 | } 53 | *destLen = stream.total_out; 54 | 55 | err = deflateEnd(&stream); 56 | return err; 57 | } 58 | 59 | /* =========================================================================== 60 | */ 61 | int ZEXPORT compress (dest, destLen, source, sourceLen) 62 | Bytef *dest; 63 | uLongf *destLen; 64 | const Bytef *source; 65 | uLong sourceLen; 66 | { 67 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 68 | } 69 | -------------------------------------------------------------------------------- /JPEG/jcinit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jcinit.c 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains initialization logic for the JPEG compressor. 9 | * This routine is in charge of selecting the modules to be executed and 10 | * making an initialization call to each one. 11 | * 12 | * Logically, this code belongs in jcmaster.c. It's split out because 13 | * linking this routine implies linking the entire compression library. 14 | * For a transcoding-only application, we want to be able to use jcmaster.c 15 | * without linking in the whole library. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | 22 | 23 | /* 24 | * Master selection of compression modules. 25 | * This is done once at the start of processing an image. We determine 26 | * which modules will be used and give them appropriate initialization calls. 27 | */ 28 | 29 | GLOBAL(void) 30 | jinit_compress_master (j_compress_ptr cinfo) 31 | { 32 | /* Initialize master control (includes parameter checking/processing) */ 33 | jinit_c_master_control(cinfo, FALSE /* full compression */); 34 | 35 | /* Preprocessing */ 36 | if (! cinfo->raw_data_in) { 37 | jinit_color_converter(cinfo); 38 | jinit_downsampler(cinfo); 39 | jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); 40 | } 41 | /* Forward DCT */ 42 | jinit_forward_dct(cinfo); 43 | /* Entropy encoding: either Huffman or arithmetic coding. */ 44 | if (cinfo->arith_code) { 45 | ERREXIT(cinfo, JERR_ARITH_NOTIMPL); 46 | } else { 47 | if (cinfo->progressive_mode) { 48 | #ifdef C_PROGRESSIVE_SUPPORTED 49 | jinit_phuff_encoder(cinfo); 50 | #else 51 | ERREXIT(cinfo, JERR_NOT_COMPILED); 52 | #endif 53 | } else 54 | jinit_huff_encoder(cinfo); 55 | } 56 | 57 | /* Need a full-image coefficient buffer in any multi-pass mode. */ 58 | jinit_c_coef_controller(cinfo, 59 | (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding)); 60 | jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); 61 | 62 | jinit_marker_writer(cinfo); 63 | 64 | /* We can now tell the memory manager to allocate virtual arrays. */ 65 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); 66 | 67 | /* Write the datastream header (SOI) immediately. 68 | * Frame and scan headers are postponed till later. 69 | * This lets application insert special markers after the SOI. 70 | */ 71 | (*cinfo->marker->write_file_header) (cinfo); 72 | } 73 | -------------------------------------------------------------------------------- /Src_CC_wrap/PointData.h: -------------------------------------------------------------------------------- 1 | //########################################################################## 2 | //# # 3 | //# CLOUDCOMPARE WRAPPER: PoissonReconLib # 4 | //# # 5 | //# This program is free software; you can redistribute it and/or modify # 6 | //# it under the terms of the GNU General Public License as published by # 7 | //# the Free Software Foundation; version 2 or later of the License. # 8 | //# # 9 | //# This program is distributed in the hope that it will be useful, # 10 | //# but WITHOUT ANY WARRANTY; without even the implied warranty of # 11 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 12 | //# GNU General Public License for more details. # 13 | //# # 14 | //# COPYRIGHT: Daniel Girardeau-Montaut # 15 | //# # 16 | //########################################################################## 17 | 18 | #ifndef POINTDATA_H 19 | #define POINTDATA_H 20 | 21 | template 22 | class PointData { 23 | public: 24 | PointData() : normal{ 0, 0, 0 }, color{ 0, 0, 0 } {} 25 | PointData(const Real _normal[3], const Real _color[3], Real scale = 1.0) 26 | { 27 | normal[0] = scale * _normal[0]; 28 | normal[1] = scale * _normal[1]; 29 | normal[2] = scale * _normal[2]; 30 | color[0] = scale * _color[0]; 31 | color[1] = scale * _color[1]; 32 | color[2] = scale * _color[2]; 33 | } 34 | 35 | PointData operator * (Real s) const 36 | { 37 | return PointData(normal, color, s); 38 | } 39 | 40 | PointData operator / (Real s) const 41 | { 42 | return PointData(normal, color, 1 / s); 43 | } 44 | 45 | PointData& operator += (const PointData& d) 46 | { 47 | normal[0] += d.normal[0]; 48 | normal[1] += d.normal[1]; 49 | normal[2] += d.normal[2]; 50 | color[0] += d.color[0]; 51 | color[1] += d.color[1]; 52 | color[2] += d.color[2]; 53 | return *this; 54 | } 55 | PointData& operator *= (Real s) 56 | { 57 | normal[0] *= s; 58 | normal[1] *= s; 59 | normal[2] *= s; 60 | color[0] *= s; 61 | color[1] *= s; 62 | color[2] *= s; 63 | return *this; 64 | } 65 | 66 | public: 67 | Real normal[3]; 68 | Real color[3]; 69 | }; 70 | 71 | extern template class PointData; 72 | extern template class PointData; 73 | 74 | #endif // POINTDATA_H 75 | -------------------------------------------------------------------------------- /ZLIB/inftrees.h: -------------------------------------------------------------------------------- 1 | /* inftrees.h -- header to use inftrees.c 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* Huffman code lookup table entry--this entry is four bytes for machines 12 | that have 16-bit pointers (e.g. PC's in the small or medium model). */ 13 | 14 | typedef struct inflate_huft_s FAR inflate_huft; 15 | 16 | struct inflate_huft_s { 17 | union { 18 | struct { 19 | Byte Exop; /* number of extra bits or operation */ 20 | Byte Bits; /* number of bits in this code or subcode */ 21 | } what; 22 | uInt pad; /* pad structure to a power of 2 (4 bytes for */ 23 | } word; /* 16-bit, 8 bytes for 32-bit int's) */ 24 | uInt base; /* literal, length base, distance base, 25 | or table offset */ 26 | }; 27 | 28 | /* Maximum size of dynamic tree. The maximum found in a long but non- 29 | exhaustive search was 1004 huft structures (850 for length/literals 30 | and 154 for distances, the latter actually the result of an 31 | exhaustive search). The actual maximum is not known, but the 32 | value below is more than safe. */ 33 | #define MANY 1440 34 | 35 | extern int inflate_trees_bits OF(( 36 | uIntf *, /* 19 code lengths */ 37 | uIntf *, /* bits tree desired/actual depth */ 38 | inflate_huft * FAR *, /* bits tree result */ 39 | inflate_huft *, /* space for trees */ 40 | z_streamp)); /* for messages */ 41 | 42 | extern int inflate_trees_dynamic OF(( 43 | uInt, /* number of literal/length codes */ 44 | uInt, /* number of distance codes */ 45 | uIntf *, /* that many (total) code lengths */ 46 | uIntf *, /* literal desired/actual bit depth */ 47 | uIntf *, /* distance desired/actual bit depth */ 48 | inflate_huft * FAR *, /* literal/length tree result */ 49 | inflate_huft * FAR *, /* distance tree result */ 50 | inflate_huft *, /* space for trees */ 51 | z_streamp)); /* for messages */ 52 | 53 | extern int inflate_trees_fixed OF(( 54 | uIntf *, /* literal desired/actual bit depth */ 55 | uIntf *, /* distance desired/actual bit depth */ 56 | inflate_huft * FAR *, /* literal/length tree result */ 57 | inflate_huft * FAR *, /* distance tree result */ 58 | z_streamp)); /* for memory allocation */ 59 | -------------------------------------------------------------------------------- /Src/PreProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef PRE_PROCESSOR_INCLUDED 30 | #define PRE_PROCESSOR_INCLUDED 31 | 32 | #undef BIG_DATA // Supports processing requiring more than 32-bit integers for indexing 33 | // Note: enabling BIG_DATA can generate .ply files using "longlong" for vertex indices instead of "int". 34 | // These are not standardly supported by .ply reading/writing applications. 35 | // The executable ChunkPLY can help by partitioning the mesh into more manageable chunks 36 | // (each of which is small enough to be represented using 32-bit indexing.) 37 | 38 | #undef FAST_COMPILE // If enabled, only a single version of the code is compiled 39 | #undef SHOW_WARNINGS // Display compilation warnings 40 | #undef ARRAY_DEBUG // If enabled, array access is tested for validity 41 | #undef USE_SEG_FAULT_HANDLER // Tries to dump a stack trace in the case of a segfault (gcc only) 42 | 43 | #ifdef BIG_DATA 44 | #define USE_DEEP_TREE_NODES // Chances are that if you are using big data, you want to support a tree with depth>15. 45 | #endif // BIG_DATA 46 | 47 | #define VERSION "12.00" // The version of the code 48 | #define MEMORY_ALLOCATOR_BLOCK_SIZE 1<<12 // The chunk size for memory allocation 49 | 50 | #endif // PRE_PROCESSOR_INCLUDED -------------------------------------------------------------------------------- /Src/MAT.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007, Michael Kazhdan 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | #ifndef MAT_INCLUDED 29 | #define MAT_INCLUDED 30 | #include "Geometry.h" 31 | #include "Array.h" 32 | 33 | template< typename Index , class Real , unsigned int Dim > 34 | std::vector< TriangleIndex< Index > > MinimalAreaTriangulation( ConstPointer( Point< Real , Dim > ) vertices , size_t vCount ); 35 | 36 | template< typename Index , class Real , unsigned int Dim > 37 | class _MinimalAreaTriangulation 38 | { 39 | Pointer( Real ) _bestTriangulation; 40 | Pointer( Index ) _midpoint; 41 | size_t _vCount; 42 | ConstPointer( Point< Real , Dim > ) _vertices; 43 | 44 | void _set( void ); 45 | Real _subPolygonArea( Index i , Index j ); 46 | void _addTriangles( Index i , Index j , std::vector< TriangleIndex< Index > >& triangles ) const; 47 | Index _subPolygonIndex( Index i , Index j ) const; 48 | 49 | _MinimalAreaTriangulation( ConstPointer( Point< Real , Dim > ) vertices , size_t vCount ); 50 | ~_MinimalAreaTriangulation( void ); 51 | std::vector< TriangleIndex< Index > > getTriangulation( void ); 52 | friend std::vector< TriangleIndex< Index > > MinimalAreaTriangulation< Index , Real , Dim >( ConstPointer( Point< Real , Dim > ) vertices , size_t vCount ); 53 | }; 54 | template< typename Index , class Real , unsigned int Dim > 55 | std::vector< TriangleIndex< Index > > MinimalAreaTriangulation( ConstPointer( Point< Real , Dim > ) vertices , size_t vCount ) 56 | { 57 | _MinimalAreaTriangulation< Index , Real , Dim > MAT( vertices , vCount ); 58 | return MAT.getTriangulation(); 59 | } 60 | #include "MAT.inl" 61 | 62 | #endif // MAT_INCLUDED 63 | -------------------------------------------------------------------------------- /JPEG/jmemnobs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemnobs.c 3 | * 4 | * Copyright (C) 1992-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a really simple implementation of the system- 9 | * dependent portion of the JPEG memory manager. This implementation 10 | * assumes that no backing-store files are needed: all required space 11 | * can be obtained from malloc(). 12 | * This is very portable in the sense that it'll compile on almost anything, 13 | * but you'd better have lots of main memory (or virtual memory) if you want 14 | * to process big images. 15 | * Note that the max_memory_to_use option is ignored by this implementation. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | #include "jmemsys.h" /* import the system-dependent declarations */ 22 | 23 | #ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ 24 | extern void * malloc JPP((size_t size)); 25 | extern void free JPP((void *ptr)); 26 | #endif 27 | 28 | 29 | /* 30 | * Memory allocation and freeing are controlled by the regular library 31 | * routines malloc() and free(). 32 | */ 33 | 34 | GLOBAL(void *) 35 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 36 | { 37 | return (void *) malloc(sizeofobject); 38 | } 39 | 40 | GLOBAL(void) 41 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 42 | { 43 | free(object); 44 | } 45 | 46 | 47 | /* 48 | * "Large" objects are treated the same as "small" ones. 49 | * NB: although we include FAR keywords in the routine declarations, 50 | * this file won't actually work in 80x86 small/medium model; at least, 51 | * you probably won't be able to process useful-size images in only 64KB. 52 | */ 53 | 54 | GLOBAL(void FAR *) 55 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 56 | { 57 | return (void FAR *) malloc(sizeofobject); 58 | } 59 | 60 | GLOBAL(void) 61 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 62 | { 63 | free(object); 64 | } 65 | 66 | 67 | /* 68 | * This routine computes the total memory space available for allocation. 69 | * Here we always say, "we got all you want bud!" 70 | */ 71 | 72 | GLOBAL(long) 73 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 74 | long max_bytes_needed, long already_allocated) 75 | { 76 | return max_bytes_needed; 77 | } 78 | 79 | 80 | /* 81 | * Backing store (temporary file) management. 82 | * Since jpeg_mem_available always promised the moon, 83 | * this should never be called and we can just error out. 84 | */ 85 | 86 | GLOBAL(void) 87 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 88 | long total_bytes_needed) 89 | { 90 | ERREXIT(cinfo, JERR_NO_BACKING_STORE); 91 | } 92 | 93 | 94 | /* 95 | * These routines take care of any system-dependent initialization and 96 | * cleanup required. Here, there isn't any. 97 | */ 98 | 99 | GLOBAL(long) 100 | jpeg_mem_init (j_common_ptr cinfo) 101 | { 102 | return 0; /* just set max_memory_to_use to 0 */ 103 | } 104 | 105 | GLOBAL(void) 106 | jpeg_mem_term (j_common_ptr cinfo) 107 | { 108 | /* no work */ 109 | } 110 | -------------------------------------------------------------------------------- /JPEG/jinclude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jinclude.h 3 | * 4 | * Copyright (C) 1991-1994, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file exists to provide a single place to fix any problems with 9 | * including the wrong system include files. (Common problems are taken 10 | * care of by the standard jconfig symbols, but on really weird systems 11 | * you may have to edit this file.) 12 | * 13 | * NOTE: this file is NOT intended to be included by applications using the 14 | * JPEG library. Most applications need only include jpeglib.h. 15 | */ 16 | 17 | 18 | /* Include auto-config file to find out which system include files we need. */ 19 | 20 | #include "jconfig.h" /* auto configuration options */ 21 | #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ 22 | 23 | /* 24 | * We need the NULL macro and size_t typedef. 25 | * On an ANSI-conforming system it is sufficient to include . 26 | * Otherwise, we get them from or ; we may have to 27 | * pull in as well. 28 | * Note that the core JPEG library does not require ; 29 | * only the default error handler and data source/destination modules do. 30 | * But we must pull it in because of the references to FILE in jpeglib.h. 31 | * You can remove those references if you want to compile without . 32 | */ 33 | 34 | #ifdef HAVE_STDDEF_H 35 | #include 36 | #endif 37 | 38 | #ifdef HAVE_STDLIB_H 39 | #include 40 | #endif 41 | 42 | #ifdef NEED_SYS_TYPES_H 43 | #include 44 | #endif 45 | 46 | #include 47 | 48 | /* 49 | * We need memory copying and zeroing functions, plus strncpy(). 50 | * ANSI and System V implementations declare these in . 51 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). 52 | * Some systems may declare memset and memcpy in . 53 | * 54 | * NOTE: we assume the size parameters to these functions are of type size_t. 55 | * Change the casts in these macros if not! 56 | */ 57 | 58 | #ifdef NEED_BSD_STRINGS 59 | 60 | #include 61 | #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) 62 | #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) 63 | 64 | #else /* not BSD, assume ANSI/SysV string lib */ 65 | 66 | #include 67 | #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) 68 | #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) 69 | 70 | #endif 71 | 72 | /* 73 | * In ANSI C, and indeed any rational implementation, size_t is also the 74 | * type returned by sizeof(). However, it seems there are some irrational 75 | * implementations out there, in which sizeof() returns an int even though 76 | * size_t is defined as long or unsigned long. To ensure consistent results 77 | * we always use this SIZEOF() macro in place of using sizeof() directly. 78 | */ 79 | 80 | #define SIZEOF(object) ((size_t) sizeof(object)) 81 | 82 | /* 83 | * The modules that use fread() and fwrite() always invoke them through 84 | * these macros. On some systems you may need to twiddle the argument casts. 85 | * CAUTION: argument order is different from underlying functions! 86 | */ 87 | 88 | #define JFREAD(file,buf,sizeofbuf) \ 89 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 90 | #define JFWRITE(file,buf,sizeofbuf) \ 91 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 92 | -------------------------------------------------------------------------------- /JPEG/jcomapi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jcomapi.c 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface routines that are used for both 9 | * compression and decompression. 10 | */ 11 | 12 | #define JPEG_INTERNALS 13 | #include "jinclude.h" 14 | #include "jpeglib.h" 15 | 16 | 17 | /* 18 | * Abort processing of a JPEG compression or decompression operation, 19 | * but don't destroy the object itself. 20 | * 21 | * For this, we merely clean up all the nonpermanent memory pools. 22 | * Note that temp files (virtual arrays) are not allowed to belong to 23 | * the permanent pool, so we will be able to close all temp files here. 24 | * Closing a data source or destination, if necessary, is the application's 25 | * responsibility. 26 | */ 27 | 28 | GLOBAL(void) 29 | jpeg_abort (j_common_ptr cinfo) 30 | { 31 | int pool; 32 | 33 | /* Do nothing if called on a not-initialized or destroyed JPEG object. */ 34 | if (cinfo->mem == NULL) 35 | return; 36 | 37 | /* Releasing pools in reverse order might help avoid fragmentation 38 | * with some (brain-damaged) malloc libraries. 39 | */ 40 | for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { 41 | (*cinfo->mem->free_pool) (cinfo, pool); 42 | } 43 | 44 | /* Reset overall state for possible reuse of object */ 45 | if (cinfo->is_decompressor) { 46 | cinfo->global_state = DSTATE_START; 47 | /* Try to keep application from accessing now-deleted marker list. 48 | * A bit kludgy to do it here, but this is the most central place. 49 | */ 50 | ((j_decompress_ptr) cinfo)->marker_list = NULL; 51 | } else { 52 | cinfo->global_state = CSTATE_START; 53 | } 54 | } 55 | 56 | 57 | /* 58 | * Destruction of a JPEG object. 59 | * 60 | * Everything gets deallocated except the master jpeg_compress_struct itself 61 | * and the error manager struct. Both of these are supplied by the application 62 | * and must be freed, if necessary, by the application. (Often they are on 63 | * the stack and so don't need to be freed anyway.) 64 | * Closing a data source or destination, if necessary, is the application's 65 | * responsibility. 66 | */ 67 | 68 | GLOBAL(void) 69 | jpeg_destroy (j_common_ptr cinfo) 70 | { 71 | /* We need only tell the memory manager to release everything. */ 72 | /* NB: mem pointer is NULL if memory mgr failed to initialize. */ 73 | if (cinfo->mem != NULL) 74 | (*cinfo->mem->self_destruct) (cinfo); 75 | cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ 76 | cinfo->global_state = 0; /* mark it destroyed */ 77 | } 78 | 79 | 80 | /* 81 | * Convenience routines for allocating quantization and Huffman tables. 82 | * (Would jutils.c be a more reasonable place to put these?) 83 | */ 84 | 85 | GLOBAL(JQUANT_TBL *) 86 | jpeg_alloc_quant_table (j_common_ptr cinfo) 87 | { 88 | JQUANT_TBL *tbl; 89 | 90 | tbl = (JQUANT_TBL *) 91 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); 92 | tbl->sent_table = FALSE; /* make sure this is false in any new table */ 93 | return tbl; 94 | } 95 | 96 | 97 | GLOBAL(JHUFF_TBL *) 98 | jpeg_alloc_huff_table (j_common_ptr cinfo) 99 | { 100 | JHUFF_TBL *tbl; 101 | 102 | tbl = (JHUFF_TBL *) 103 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); 104 | tbl->sent_table = FALSE; /* make sure this is false in any new table */ 105 | return tbl; 106 | } 107 | -------------------------------------------------------------------------------- /ZLIB/infutil.h: -------------------------------------------------------------------------------- 1 | /* infutil.h -- types and macros common to blocks and codes 2 | * Copyright (C) 1995-2002 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | #ifndef _INFUTIL_H 12 | #define _INFUTIL_H 13 | 14 | typedef enum { 15 | TYPE, /* get type bits (3, including end bit) */ 16 | LENS, /* get lengths for stored */ 17 | STORED, /* processing stored block */ 18 | TABLE, /* get table lengths */ 19 | BTREE, /* get bit lengths tree for a dynamic block */ 20 | DTREE, /* get length, distance trees for a dynamic block */ 21 | CODES, /* processing fixed or dynamic block */ 22 | DRY, /* output remaining window bytes */ 23 | DONE, /* finished last block, done */ 24 | BAD} /* got a data error--stuck here */ 25 | inflate_block_mode; 26 | 27 | /* inflate blocks semi-private state */ 28 | struct inflate_blocks_state { 29 | 30 | /* mode */ 31 | inflate_block_mode mode; /* current inflate_block mode */ 32 | 33 | /* mode dependent information */ 34 | union { 35 | uInt left; /* if STORED, bytes left to copy */ 36 | struct { 37 | uInt table; /* table lengths (14 bits) */ 38 | uInt index; /* index into blens (or border) */ 39 | uIntf *blens; /* bit lengths of codes */ 40 | uInt bb; /* bit length tree depth */ 41 | inflate_huft *tb; /* bit length decoding tree */ 42 | } trees; /* if DTREE, decoding info for trees */ 43 | struct { 44 | inflate_codes_statef 45 | *codes; 46 | } decode; /* if CODES, current state */ 47 | } sub; /* submode */ 48 | uInt last; /* true if this block is the last block */ 49 | 50 | /* mode independent information */ 51 | uInt bitk; /* bits in bit buffer */ 52 | uLong bitb; /* bit buffer */ 53 | inflate_huft *hufts; /* single malloc for tree space */ 54 | Bytef *window; /* sliding window */ 55 | Bytef *end; /* one byte after sliding window */ 56 | Bytef *read; /* window read pointer */ 57 | Bytef *write; /* window write pointer */ 58 | check_func checkfn; /* check function */ 59 | uLong check; /* check on output */ 60 | 61 | }; 62 | 63 | 64 | /* defines for inflate input/output */ 65 | /* update pointers and return */ 66 | #define UPDBITS {s->bitb=b;s->bitk=k;} 67 | #define UPDIN {z->avail_in=n;z->total_in+=p-z->next_in;z->next_in=p;} 68 | #define UPDOUT {s->write=q;} 69 | #define UPDATE {UPDBITS UPDIN UPDOUT} 70 | #define LEAVE {UPDATE return inflate_flush(s,z,r);} 71 | /* get bytes and bits */ 72 | #define LOADIN {p=z->next_in;n=z->avail_in;b=s->bitb;k=s->bitk;} 73 | #define NEEDBYTE {if(n)r=Z_OK;else LEAVE} 74 | #define NEXTBYTE (n--,*p++) 75 | #define NEEDBITS(j) {while(k<(j)){NEEDBYTE;b|=((uLong)NEXTBYTE)<>=(j);k-=(j);} 77 | /* output bytes */ 78 | #define WAVAIL (uInt)(qread?s->read-q-1:s->end-q) 79 | #define LOADOUT {q=s->write;m=(uInt)WAVAIL;} 80 | #define WRAP {if(q==s->end&&s->read!=s->window){q=s->window;m=(uInt)WAVAIL;}} 81 | #define FLUSH {UPDOUT r=inflate_flush(s,z,r); LOADOUT} 82 | #define NEEDOUT {if(m==0){WRAP if(m==0){FLUSH WRAP if(m==0) LEAVE}}r=Z_OK;} 83 | #define OUTBYTE(a) {*q++=(Byte)(a);m--;} 84 | /* load local pointers */ 85 | #define LOAD {LOADIN LOADOUT} 86 | 87 | /* masks for lower bits (size given to avoid silly warnings with Visual C++) */ 88 | extern uInt inflate_mask[17]; 89 | 90 | /* copy as much as possible from the sliding window to the output area */ 91 | extern int inflate_flush OF(( 92 | inflate_blocks_statef *, 93 | z_streamp , 94 | int)); 95 | 96 | struct internal_state {int dummy;}; /* for buggy compilers */ 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /Src/BinaryNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef BINARY_NODE_INCLUDED 30 | #define BINARY_NODE_INCLUDED 31 | 32 | class BinaryNode 33 | { 34 | public: 35 | static inline size_t CenterCount( unsigned int depth ) { return (size_t)1< static inline Real Width( unsigned int depth ){ return Real(1.0/((size_t)1< static inline void CenterAndWidth( unsigned int depth , size_t offset , Real& center , Real& width ){ width = Real (1.0/((size_t)1< static inline void CornerAndWidth( unsigned int depth , size_t offset , Real& corner , Real& width ){ width = Real(1.0/((size_t)1< static inline void CenterAndWidth( size_t idx , Real& center , Real& width ) 47 | { 48 | unsigned int depth; 49 | size_t offset; 50 | CenterDepthAndOffset( idx , depth , offset ); 51 | CenterAndWidth( depth , offset , center , width ); 52 | } 53 | template< class Real > static inline void CornerAndWidth( size_t idx , Real& corner , Real& width ) 54 | { 55 | unsigned int depth; 56 | size_t offset; 57 | CornerDepthAndOffset( idx , depth , offset ); 58 | CornerAndWidth( depth , offset , corner , width ); 59 | } 60 | static inline void CenterDepthAndOffset( size_t idx , unsigned int &depth , size_t &offset ) 61 | { 62 | offset = idx , depth = 0; 63 | while( offset>=((size_t)1<=( ((size_t)1< 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #ifdef WIN32 39 | int strcasecmp( const char* c1 , const char* c2 ); 40 | #endif // WIN32 41 | 42 | class cmdLineReadable 43 | { 44 | public: 45 | bool set; 46 | char *name; 47 | cmdLineReadable( const char *name ); 48 | virtual ~cmdLineReadable( void ); 49 | virtual int read( char** argv , int argc ); 50 | virtual void writeValue( char* str ) const; 51 | }; 52 | 53 | template< class Type > void cmdLineWriteValue( Type t , char* str ); 54 | template< class Type > void cmdLineCleanUp( Type* t ); 55 | template< class Type > Type cmdLineInitialize( void ); 56 | template< class Type > Type cmdLineCopy( Type t ); 57 | template< class Type > Type cmdLineStringToType( const char* str ); 58 | 59 | template< class Type > 60 | class cmdLineParameter : public cmdLineReadable 61 | { 62 | public: 63 | Type value; 64 | cmdLineParameter( const char *name ); 65 | cmdLineParameter( const char *name , Type v ); 66 | ~cmdLineParameter( void ); 67 | int read( char** argv , int argc ); 68 | void writeValue( char* str ) const; 69 | bool expectsArg( void ) const { return true; } 70 | }; 71 | 72 | template< class Type , int Dim > 73 | class cmdLineParameterArray : public cmdLineReadable 74 | { 75 | public: 76 | Type values[Dim]; 77 | cmdLineParameterArray( const char *name, const Type* v=NULL ); 78 | ~cmdLineParameterArray( void ); 79 | int read( char** argv , int argc ); 80 | void writeValue( char* str ) const; 81 | bool expectsArg( void ) const { return true; } 82 | }; 83 | 84 | template< class Type > 85 | class cmdLineParameters : public cmdLineReadable 86 | { 87 | public: 88 | int count; 89 | Type *values; 90 | cmdLineParameters( const char* name ); 91 | ~cmdLineParameters( void ); 92 | int read( char** argv , int argc ); 93 | void writeValue( char* str ) const; 94 | bool expectsArg( void ) const { return true; } 95 | }; 96 | 97 | void cmdLineParse( int argc , char **argv, cmdLineReadable** params ); 98 | char* FileExtension( char* fileName ); 99 | char* LocalFileName( char* fileName ); 100 | char* DirectoryName( char* fileName ); 101 | char* GetFileExtension( const char* fileName ); 102 | char* GetLocalFileName( const char* fileName ); 103 | char** ReadWords( const char* fileName , int& cnt ); 104 | 105 | #include "CmdLineParser.inl" 106 | #endif // CMD_LINE_PARSER_INCLUDED 107 | -------------------------------------------------------------------------------- /Src/JPEG.inl: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | inline METHODDEF( void ) 6 | my_error_exit (j_common_ptr cinfo) 7 | { 8 | // cinfo->err really points to a my_error_mgr struct, so coerce pointer 9 | my_error_ptr myerr = (my_error_ptr) cinfo->err; 10 | 11 | // Always display the message. 12 | // We could postpone this until after returning, if we chose. 13 | (*cinfo->err->output_message) (cinfo); 14 | 15 | // Return control to the setjmp point 16 | longjmp(myerr->setjmp_buffer, 1); 17 | } 18 | 19 | inline bool JPEGReader::GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 20 | { 21 | FILE* fp = fopen( fileName , "rb" ); 22 | if( !fp ) ERROR_OUT( "Failed to open: " , fileName ); 23 | 24 | struct jpeg_decompress_struct cInfo; 25 | struct my_error_mgr jErr; 26 | 27 | cInfo.err = jpeg_std_error( &jErr.pub ); 28 | jErr.pub.error_exit = my_error_exit; 29 | if( setjmp( jErr.setjmp_buffer ) ) 30 | { 31 | jpeg_destroy_decompress( &cInfo ); 32 | ERROR_OUT( "JPEG error occured" ); 33 | } 34 | 35 | jpeg_create_decompress( &cInfo ); 36 | jpeg_stdio_src( &cInfo , fp ); 37 | 38 | (void) jpeg_read_header( &cInfo , TRUE ); 39 | 40 | channels = cInfo.num_components; 41 | width = cInfo.image_width; 42 | height = cInfo.image_height; 43 | jpeg_destroy_decompress( &cInfo ); 44 | 45 | fclose( fp ); 46 | return true; 47 | } 48 | 49 | inline JPEGReader::JPEGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 50 | { 51 | _currentRow = 0; 52 | _fp = fopen( fileName , "rb" ); 53 | if( !_fp ) ERROR_OUT( "Failed to open: " , fileName ); 54 | 55 | _cInfo.err = jpeg_std_error( &_jErr.pub ); 56 | _jErr.pub.error_exit = my_error_exit; 57 | if( setjmp( _jErr.setjmp_buffer ) ) 58 | { 59 | jpeg_destroy_decompress( &_cInfo ); 60 | ERROR_OUT( "JPEG error occured" ); 61 | } 62 | 63 | jpeg_create_decompress( &_cInfo ); 64 | jpeg_stdio_src( &_cInfo , _fp ); 65 | 66 | (void) jpeg_read_header( &_cInfo , TRUE ); 67 | (void) jpeg_start_decompress( &_cInfo ); 68 | 69 | channels = _cInfo.output_components; 70 | width = _cInfo.output_width; 71 | height = _cInfo.output_height; 72 | } 73 | inline JPEGReader::~JPEGReader( void ) 74 | { 75 | (void) jpeg_finish_decompress( &_cInfo ); 76 | jpeg_destroy_decompress( &_cInfo ); 77 | fclose( _fp ); 78 | } 79 | inline unsigned int JPEGReader::nextRow( unsigned char* row ) 80 | { 81 | JSAMPROW row_pointers[1]; 82 | row_pointers[0] = row; 83 | jpeg_read_scanlines( &_cInfo , row_pointers, 1 ); 84 | return _currentRow++; 85 | } 86 | 87 | inline JPEGWriter::JPEGWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality ) 88 | { 89 | _currentRow = 0; 90 | _fp = fopen( fileName , "wb" ); 91 | if( !_fp ) ERROR_OUT( "Failed to open: " , fileName ); 92 | 93 | _cInfo.err = jpeg_std_error( &_jErr.pub ); 94 | jpeg_create_compress( &_cInfo ); 95 | 96 | jpeg_stdio_dest( &_cInfo , _fp ); 97 | 98 | _cInfo.image_width = width; 99 | _cInfo.image_height = height; 100 | _cInfo.input_components = channels; 101 | _cInfo.in_color_space = JCS_RGB; /* colorspace of input image */ 102 | 103 | jpeg_set_defaults( &_cInfo ); 104 | jpeg_set_quality( &_cInfo , quality , TRUE ); 105 | 106 | jpeg_start_compress( &_cInfo , TRUE ); 107 | } 108 | inline JPEGWriter::~JPEGWriter( void ) 109 | { 110 | jpeg_finish_compress( &_cInfo ); 111 | jpeg_destroy_compress( &_cInfo ); 112 | fclose( _fp ); 113 | } 114 | inline unsigned int JPEGWriter::nextRow( const unsigned char* row ) 115 | { 116 | JSAMPROW row_pointer[1]; 117 | row_pointer[0] = ( unsigned char* )row; 118 | (void) jpeg_write_scanlines( &_cInfo , row_pointer , 1 ); 119 | return _currentRow++; 120 | } 121 | 122 | inline unsigned int JPEGWriter::nextRows( const unsigned char* rows , unsigned int rowNum ) 123 | { 124 | JSAMPROW* row_pointers = new JSAMPROW[ rowNum ]; 125 | for( unsigned int r=0 ; r 3 | $! 4 | $! Look for the compiler used 5 | $! 6 | $ ccopt = "" 7 | $ if f$getsyi("HW_MODEL").ge.1024 8 | $ then 9 | $ ccopt = "/prefix=all"+ccopt 10 | $ comp = "__decc__=1" 11 | $ if f$trnlnm("SYS").eqs."" then define sys sys$library: 12 | $ else 13 | $ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" 14 | $ then 15 | $ comp = "__vaxc__=1" 16 | $ if f$trnlnm("SYS").eqs."" then define sys sys$library: 17 | $ else 18 | $ if f$trnlnm("SYS").eqs."" then define sys decc$library_include: 19 | $ ccopt = "/decc/prefix=all"+ccopt 20 | $ comp = "__decc__=1" 21 | $ endif 22 | $ endif 23 | $! 24 | $! Build the thing plain or with mms 25 | $! 26 | $ write sys$output "Compiling Zlib sources ..." 27 | $ if f$search("SYS$SYSTEM:MMS.EXE").eqs."" 28 | $ then 29 | $ dele example.obj;*,minigzip.obj;* 30 | $ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" - 31 | adler32.c zlib.h zconf.h 32 | $ CALL MAKE compress.OBJ "CC ''CCOPT' compress" - 33 | compress.c zlib.h zconf.h 34 | $ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" - 35 | crc32.c zlib.h zconf.h 36 | $ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - 37 | deflate.c deflate.h zutil.h zlib.h zconf.h 38 | $ CALL MAKE gzio.OBJ "CC ''CCOPT' gzio" - 39 | gzio.c zutil.h zlib.h zconf.h 40 | $ CALL MAKE infblock.OBJ "CC ''CCOPT' infblock" - 41 | infblock.c zutil.h zlib.h zconf.h infblock.h 42 | $ CALL MAKE infcodes.OBJ "CC ''CCOPT' infcodes" - 43 | infcodes.c zutil.h zlib.h zconf.h inftrees.h 44 | $ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - 45 | inffast.c zutil.h zlib.h zconf.h inffast.h 46 | $ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" - 47 | inflate.c zutil.h zlib.h zconf.h infblock.h 48 | $ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" - 49 | inftrees.c zutil.h zlib.h zconf.h inftrees.h 50 | $ CALL MAKE infutil.OBJ "CC ''CCOPT' infutil" - 51 | infutil.c zutil.h zlib.h zconf.h inftrees.h infutil.h 52 | $ CALL MAKE trees.OBJ "CC ''CCOPT' trees" - 53 | trees.c deflate.h zutil.h zlib.h zconf.h 54 | $ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" - 55 | uncompr.c zlib.h zconf.h 56 | $ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" - 57 | zutil.c zutil.h zlib.h zconf.h 58 | $ write sys$output "Building Zlib ..." 59 | $ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ 60 | $ write sys$output "Building example..." 61 | $ CALL MAKE example.OBJ "CC ''CCOPT' example" - 62 | example.c zlib.h zconf.h 63 | $ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb 64 | $ write sys$output "Building minigzip..." 65 | $ CALL MAKE minigzip.OBJ "CC ''CCOPT' minigzip" - 66 | minigzip.c zlib.h zconf.h 67 | $ call make minigzip.exe - 68 | "LINK minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib" - 69 | minigzip.obj libz.olb 70 | $ else 71 | $ mms/macro=('comp') 72 | $ endif 73 | $ write sys$output "Zlib build completed" 74 | $ exit 75 | $! 76 | $! 77 | $MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES 78 | $ V = 'F$Verify(0) 79 | $! P1 = What we are trying to make 80 | $! P2 = Command to make it 81 | $! P3 - P8 What it depends on 82 | $ 83 | $ If F$Search(P1) .Eqs. "" Then Goto Makeit 84 | $ Time = F$CvTime(F$File(P1,"RDT")) 85 | $arg=3 86 | $Loop: 87 | $ Argument = P'arg 88 | $ If Argument .Eqs. "" Then Goto Exit 89 | $ El=0 90 | $Loop2: 91 | $ File = F$Element(El," ",Argument) 92 | $ If File .Eqs. " " Then Goto Endl 93 | $ AFile = "" 94 | $Loop3: 95 | $ OFile = AFile 96 | $ AFile = F$Search(File) 97 | $ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl 98 | $ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit 99 | $ Goto Loop3 100 | $NextEL: 101 | $ El = El + 1 102 | $ Goto Loop2 103 | $EndL: 104 | $ arg=arg+1 105 | $ If arg .Le. 8 Then Goto Loop 106 | $ Goto Exit 107 | $ 108 | $Makeit: 109 | $ VV=F$VERIFY(0) 110 | $ write sys$output P2 111 | $ 'P2 112 | $ VV='F$Verify(VV) 113 | $Exit: 114 | $ If V Then Set Verify 115 | $ENDSUBROUTINE 116 | -------------------------------------------------------------------------------- /Src/PPolynomial.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef P_POLYNOMIAL_INCLUDED 30 | #define P_POLYNOMIAL_INCLUDED 31 | #include 32 | #include "Polynomial.h" 33 | #include "Array.h" 34 | 35 | template< int Degree > 36 | class StartingPolynomial 37 | { 38 | public: 39 | Polynomial< Degree > p; 40 | double start; 41 | 42 | template< int Degree2 > 43 | StartingPolynomial< Degree+Degree2 > operator * ( const StartingPolynomial< Degree2 >& p ) const; 44 | StartingPolynomial scale( double s ) const; 45 | StartingPolynomial shift( double t ) const; 46 | int operator < ( const StartingPolynomial& sp ) const; 47 | static int Compare( const void* v1 , const void* v2 ); 48 | }; 49 | 50 | template< int Degree > 51 | class PPolynomial 52 | { 53 | public: 54 | size_t polyCount; 55 | Pointer( StartingPolynomial< Degree > ) polys; 56 | 57 | PPolynomial( void ); 58 | PPolynomial( const PPolynomial& p ); 59 | ~PPolynomial( void ); 60 | 61 | PPolynomial& operator = ( const PPolynomial& p ); 62 | 63 | int size( void ) const; 64 | 65 | void set( size_t size ); 66 | // Note: this method will sort the elements in sps 67 | void set( Pointer( StartingPolynomial ) sps , int count ); 68 | void reset( size_t newSize ); 69 | PPolynomial& compress( double delta=0. ); 70 | 71 | 72 | double operator()( double t ) const; 73 | double integral( double tMin , double tMax ) const; 74 | double Integral( void ) const; 75 | 76 | template< int Degree2 > PPolynomial< Degree >& operator = ( const PPolynomial< Degree2 >& p ); 77 | 78 | PPolynomial operator + ( const PPolynomial& p ) const; 79 | PPolynomial operator - ( const PPolynomial& p ) const; 80 | 81 | template< int Degree2 > PPolynomial< Degree+Degree2 > operator * ( const Polynomial< Degree2 >& p ) const; 82 | template< int Degree2 > PPolynomial< Degree+Degree2 > operator * ( const PPolynomial< Degree2 >& p) const; 83 | 84 | 85 | PPolynomial& operator += ( double s ); 86 | PPolynomial& operator -= ( double s ); 87 | PPolynomial& operator *= ( double s ); 88 | PPolynomial& operator /= ( double s ); 89 | PPolynomial operator + ( double s ) const; 90 | PPolynomial operator - ( double s ) const; 91 | PPolynomial operator * ( double s ) const; 92 | PPolynomial operator / ( double s ) const; 93 | 94 | PPolynomial& addScaled( const PPolynomial& poly , double scale ); 95 | 96 | PPolynomial scale( double s ) const; 97 | PPolynomial shift( double t ) const; 98 | PPolynomial reflect( double r=0. ) const; 99 | 100 | PPolynomial< Degree-1 > derivative(void) const; 101 | PPolynomial< Degree+1 > integral(void) const; 102 | 103 | void getSolutions( double c , std::vector< double >& roots , double EPS , double min=-DBL_MAX , double max=DBL_MAX ) const; 104 | 105 | void printnl( void ) const; 106 | 107 | PPolynomial< Degree+1 > MovingAverage( double radius ) const; 108 | static PPolynomial BSpline( double radius=0.5 ); 109 | 110 | void write( FILE* fp , int samples , double min , double max ) const; 111 | }; 112 | #include "PPolynomial.inl" 113 | #endif // P_POLYNOMIAL_INCLUDED 114 | -------------------------------------------------------------------------------- /Src/Polynomial.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef POLYNOMIAL_INCLUDED 30 | #define POLYNOMIAL_INCLUDED 31 | 32 | template< int Degree > 33 | class Polynomial 34 | { 35 | public: 36 | double coefficients[Degree+1]; 37 | 38 | Polynomial( void ); 39 | template< int Degree2 > Polynomial( const Polynomial< Degree2 >& P ); 40 | double operator()( double t ) const; 41 | double integral( double tMin , double tMax ) const; 42 | 43 | int operator == (const Polynomial& p) const; 44 | int operator != (const Polynomial& p) const; 45 | int isZero(void) const; 46 | void setZero(void); 47 | 48 | template 49 | Polynomial& operator = (const Polynomial &p); 50 | Polynomial& operator += (const Polynomial& p); 51 | Polynomial& operator -= (const Polynomial& p); 52 | Polynomial operator - (void) const; 53 | Polynomial operator + (const Polynomial& p) const; 54 | Polynomial operator - (const Polynomial& p) const; 55 | template 56 | Polynomial operator * (const Polynomial& p) const; 57 | 58 | Polynomial& operator += ( double s ); 59 | Polynomial& operator -= ( double s ); 60 | Polynomial& operator *= ( double s ); 61 | Polynomial& operator /= ( double s ); 62 | Polynomial operator + ( double s ) const; 63 | Polynomial operator - ( double s ) const; 64 | Polynomial operator * ( double s ) const; 65 | Polynomial operator / ( double s ) const; 66 | 67 | Polynomial scale( double s ) const; 68 | Polynomial shift( double t ) const; 69 | 70 | template< int _Degree=Degree > 71 | typename std::enable_if< (_Degree==0) , Polynomial< Degree > >::type derivative( void ) const { return Polynomial< Degree >(); } 72 | template< int _Degree=Degree > 73 | typename std::enable_if< (_Degree> 0) , Polynomial< Degree-1 > >::type derivative( void ) const 74 | { 75 | Polynomial< Degree-1 > p; 76 | for( int i=0 ; i integral(void) const; 80 | 81 | void printnl( void ) const; 82 | 83 | Polynomial& addScaled(const Polynomial& p,double scale); 84 | static void Negate(const Polynomial& in,Polynomial& out); 85 | static void Subtract(const Polynomial& p1,const Polynomial& p2,Polynomial& q); 86 | static void Scale(const Polynomial& p,double w,Polynomial& q); 87 | static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,double w2,Polynomial& q); 88 | static void AddScaled(const Polynomial& p1,const Polynomial& p2,double w2,Polynomial& q); 89 | static void AddScaled(const Polynomial& p1,double w1,const Polynomial& p2,Polynomial& q); 90 | 91 | int getSolutions( double c , double* roots , double EPS ) const; 92 | 93 | // [NOTE] Both of these methods define the indexing according to DeBoor's algorithm, so that 94 | // Polynomial< Degree >BSplineComponent( 0 )( 1.0 )=0 for all Degree>0. 95 | static Polynomial BSplineComponent( int i ); 96 | static void BSplineComponentValues( double x , double* values ); 97 | static void BinomialCoefficients( int bCoefficients[Degree+1] ); 98 | }; 99 | 100 | #include "Polynomial.inl" 101 | #endif // POLYNOMIAL_INCLUDED 102 | -------------------------------------------------------------------------------- /Src/FEMTree.SortedTreeNodes.inl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | ///////////////////// 30 | // SortedTreeNodes // 31 | ///////////////////// 32 | template< unsigned int Dim > 33 | SortedTreeNodes< Dim >::SortedTreeNodes( void ) 34 | { 35 | _sliceStart = NullPointer( Pointer( node_index_type ) ); 36 | treeNodes = NullPointer( TreeNode* ); 37 | _levels = 0; 38 | } 39 | template< unsigned int Dim > 40 | SortedTreeNodes< Dim >::~SortedTreeNodes( void ) 41 | { 42 | if( _sliceStart ) for( int d=0 ; d<_levels ; d++ ) FreePointer( _sliceStart[d] ); 43 | FreePointer( _sliceStart ); 44 | DeletePointer( treeNodes ); 45 | } 46 | template< unsigned int Dim > 47 | void SortedTreeNodes< Dim >::set( TreeNode& root , std::vector< node_index_type >* map ) 48 | { 49 | size_t sz = set( root ); 50 | 51 | if( map ) 52 | { 53 | map->resize( sz , -1 ); 54 | for( node_index_type i=0 ; i<_sliceStart[_levels-1][(size_t)1<<(_levels-1)] ; i++ ) if( treeNodes[i]->nodeData.nodeIndex>=0 ) (*map)[ treeNodes[i]->nodeData.nodeIndex ] = i; 55 | } 56 | for( node_index_type i=0 ; i<_sliceStart[_levels-1][(size_t)1<<(_levels-1)] ; i++ ) treeNodes[i]->nodeData.nodeIndex = i; 57 | } 58 | template< unsigned int Dim > 59 | size_t SortedTreeNodes< Dim >::set( TreeNode& root ) 60 | { 61 | size_t sz = 0; 62 | _levels = root.maxDepth()+1; 63 | 64 | if( _sliceStart ) for( int d=0 ; d<_levels ; d++ ) FreePointer( _sliceStart[d] ); 65 | FreePointer( _sliceStart ); 66 | DeletePointer( treeNodes ); 67 | 68 | _sliceStart = AllocPointer< Pointer( node_index_type ) >( _levels ); 69 | for( int l=0 ; l<_levels ; l++ ) 70 | { 71 | _sliceStart[l] = AllocPointer< node_index_type >( ((size_t)1<nodeData.nodeIndex>=0 ) sz = std::max< size_t >( node->nodeData.nodeIndex+1 , sz ); 79 | if( !GetGhostFlag< Dim >( node ) ) 80 | { 81 | int d , off[Dim]; 82 | node->depthAndOffset( d , off ); 83 | _sliceStart[d][ off[Dim-1]+1 ]++; 84 | } 85 | } 86 | 87 | // Get the start index for each slice 88 | { 89 | node_index_type levelOffset = 0; 90 | for( int l=0 ; l<_levels ; l++ ) 91 | { 92 | _sliceStart[l][0] = levelOffset; 93 | for( int s=0 ; s<((size_t)1<( _sliceStart[_levels-1][(size_t)1<<(_levels-1)] ); 99 | 100 | // Add the tree nodes 101 | for( TreeNode* node=root.nextNode() ; node ; node=root.nextNode( node ) ) if( !GetGhostFlag< Dim >( node ) ) 102 | { 103 | int d , off[Dim]; 104 | node->depthAndOffset( d , off ); 105 | treeNodes[ _sliceStart[d][ off[Dim-1] ]++ ] = node; 106 | } 107 | 108 | // Shift the slice offsets up since we incremented as we added 109 | for( int l=0 ; l<_levels ; l++ ) 110 | { 111 | for( int s=(1<0 ; s-- ) _sliceStart[l][s] = _sliceStart[l][s-1]; 112 | _sliceStart[l][0] = l>0 ? _sliceStart[l-1][(size_t)1<<(l-1)] : 0; 113 | } 114 | return sz; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Src/SparseMatrixInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef SPARSE_MATRIX_INTERFACE_INCLUDED 30 | #define SPARSE_MATRIX_INTERFACE_INCLUDED 31 | 32 | #define FORCE_TWO_BYTE_ALIGNMENT 1 33 | #include "MyMiscellany.h" 34 | #include "Array.h" 35 | 36 | #if FORCE_TWO_BYTE_ALIGNMENT 37 | #pragma pack(push) 38 | #pragma pack(2) 39 | #endif // FORCE_TWO_BYTE_ALIGNMENT 40 | template< class T , class IndexType > 41 | struct MatrixEntry 42 | { 43 | MatrixEntry( void ) { N =-1 , Value = 0; } 44 | MatrixEntry( IndexType i ) { N = i , Value = 0; } 45 | MatrixEntry( IndexType n , T v ){ N = n , Value = v; } 46 | IndexType N; 47 | T Value; 48 | }; 49 | 50 | #if FORCE_TWO_BYTE_ALIGNMENT 51 | #pragma pack(pop) 52 | #endif // FORCE_TWO_BYTE_ALIGNMENT 53 | 54 | enum 55 | { 56 | MULTIPLY_ADD = 1 , 57 | MULTIPLY_NEGATE = 2 58 | }; 59 | 60 | //#pragma message( "[WARNING] make me templated off of IndexType as well" ) 61 | template< class T , class const_iterator > class SparseMatrixInterface 62 | { 63 | public: 64 | virtual const_iterator begin( size_t row ) const = 0; 65 | virtual const_iterator end ( size_t row ) const = 0; 66 | virtual size_t rows ( void ) const = 0; 67 | virtual size_t rowSize( size_t idx ) const = 0; 68 | 69 | size_t entries( void ) const; 70 | 71 | double squareNorm( void ) const; 72 | double squareASymmetricNorm( void ) const; 73 | double squareASymmetricNorm( size_t &idx1 , size_t &idx2 ) const; 74 | 75 | template< class T2 > void multiply ( ConstPointer( T2 ) In , Pointer( T2 ) Out , char multiplyFlag=0 ) const; 76 | template< class T2 > void multiplyScaled( T scale , ConstPointer( T2 ) In , Pointer( T2 ) Out , char multiplyFlag=0 ) const; 77 | template< class T2 > void multiply ( Pointer( T2 ) In , Pointer( T2 ) Out , char multiplyFlag=0 ) const { multiply ( ( ConstPointer(T2) )( In ) , Out , multiplyFlag ); } 78 | template< class T2 > void multiplyScaled( T scale , Pointer( T2 ) In , Pointer( T2 ) Out , char multiplyFlag=0 ) const { multiplyScaled( scale , ( ConstPointer(T2) )( In ) , Out , multiplyFlag ); } 79 | 80 | void setDiagonal( Pointer( T ) diagonal ) const; 81 | void setDiagonalR( Pointer( T ) diagonal ) const; 82 | template< class T2 > void jacobiIteration( ConstPointer( T ) diagonal , ConstPointer( T2 ) b , ConstPointer( T2 ) in , Pointer( T2 ) out , bool dReciprocal ) const; 83 | template< class T2 > void gsIteration( const std::vector< size_t > & multiColorIndices , ConstPointer( T ) diagonal , ConstPointer( T2 ) b , Pointer( T2 ) x , bool dReciprocal ) const; 84 | template< class T2 > void gsIteration( const std::vector< std::vector< size_t > >& multiColorIndices , ConstPointer( T ) diagonal , ConstPointer( T2 ) b , Pointer( T2 ) x , bool forward , bool dReciprocal ) const; 85 | template< class T2 > void gsIteration( ConstPointer( T ) diagonal , ConstPointer( T2 ) b , Pointer( T2 ) x , bool forward , bool dReciprocal ) const; 86 | }; 87 | 88 | // Assuming that the SPDOperator class defines: 89 | // auto SPDOperator::()( ConstPointer( T ) , Pointer( T ) ) const 90 | template< class SPDFunctor , class T , typename Real , class TDotTFunctor > size_t SolveCG( const SPDFunctor& M , size_t dim , ConstPointer( T ) b , size_t iters , Pointer( T ) x , double eps , TDotTFunctor Dot ); 91 | template< class SPDFunctor , class Preconditioner , class T , typename Real , class TDotTFunctor > size_t SolveCG( const SPDFunctor& M , const Preconditioner& P , size_t dim , ConstPointer( T ) b , size_t iters , Pointer( T ) x , double eps , TDotTFunctor Dot ); 92 | 93 | #include "SparseMatrixInterface.inl" 94 | #endif // SPARSE_MATRIX_INTERFACE_INCLUDED 95 | -------------------------------------------------------------------------------- /PNG/pnggccrd.c: -------------------------------------------------------------------------------- 1 | /* pnggccrd.c was removed from libpng-1.2.20. */ 2 | 3 | /* This code snippet is for use by configure's compilation test. */ 4 | 5 | #if (!defined _MSC_VER) && \ 6 | defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ 7 | defined(PNG_MMX_CODE_SUPPORTED) 8 | 9 | int PNGAPI png_dummy_mmx_support(void); 10 | 11 | static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested 12 | 13 | int PNGAPI 14 | png_dummy_mmx_support(void) __attribute__((noinline)); 15 | 16 | int PNGAPI 17 | png_dummy_mmx_support(void) 18 | { 19 | int result; 20 | #if defined(PNG_MMX_CODE_SUPPORTED) // superfluous, but what the heck 21 | __asm__ __volatile__ ( 22 | #if defined(__x86_64__) 23 | "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction 24 | "pushq %%rcx \n\t" // so does rcx... 25 | "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux) 26 | "pushfq \n\t" // save Eflag to stack 27 | "popq %%rax \n\t" // get Eflag from stack into rax 28 | "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx 29 | "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) 30 | "pushq %%rax \n\t" // save modified Eflag back to stack 31 | "popfq \n\t" // restore modified value to Eflag reg 32 | "pushfq \n\t" // save Eflag to stack 33 | "popq %%rax \n\t" // get Eflag from stack 34 | "pushq %%rcx \n\t" // save original Eflag to stack 35 | "popfq \n\t" // restore original Eflag 36 | #else 37 | "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction 38 | "pushl %%ecx \n\t" // so does ecx... 39 | "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux) 40 | "pushfl \n\t" // save Eflag to stack 41 | "popl %%eax \n\t" // get Eflag from stack into eax 42 | "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx 43 | "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21) 44 | "pushl %%eax \n\t" // save modified Eflag back to stack 45 | "popfl \n\t" // restore modified value to Eflag reg 46 | "pushfl \n\t" // save Eflag to stack 47 | "popl %%eax \n\t" // get Eflag from stack 48 | "pushl %%ecx \n\t" // save original Eflag to stack 49 | "popfl \n\t" // restore original Eflag 50 | #endif 51 | "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag 52 | "jz 0f \n\t" // if same, CPUID instr. is not supported 53 | 54 | "xorl %%eax, %%eax \n\t" // set eax to zero 55 | // ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode) 56 | "cpuid \n\t" // get the CPU identification info 57 | "cmpl $1, %%eax \n\t" // make sure eax return non-zero value 58 | "jl 0f \n\t" // if eax is zero, MMX is not supported 59 | 60 | "xorl %%eax, %%eax \n\t" // set eax to zero and... 61 | "incl %%eax \n\t" // ...increment eax to 1. This pair is 62 | // faster than the instruction "mov eax, 1" 63 | "cpuid \n\t" // get the CPU identification info again 64 | "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23) 65 | "cmpl $0, %%edx \n\t" // 0 = MMX not supported 66 | "jz 0f \n\t" // non-zero = yes, MMX IS supported 67 | 68 | "movl $1, %%eax \n\t" // set return value to 1 69 | "jmp 1f \n\t" // DONE: have MMX support 70 | 71 | "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions 72 | "movl $0, %%eax \n\t" // set return value to 0 73 | "1: \n\t" // .RETURN: target label for jump instructions 74 | #if defined(__x86_64__) 75 | "popq %%rdx \n\t" // restore rdx 76 | "popq %%rcx \n\t" // restore rcx 77 | "popq %%rbx \n\t" // restore rbx 78 | #else 79 | "popl %%edx \n\t" // restore edx 80 | "popl %%ecx \n\t" // restore ecx 81 | "popl %%ebx \n\t" // restore ebx 82 | #endif 83 | 84 | // "ret \n\t" // DONE: no MMX support 85 | // (fall through to standard C "ret") 86 | 87 | : "=a" (result) // output list 88 | 89 | : // any variables used on input (none) 90 | 91 | // no clobber list 92 | // , "%ebx", "%ecx", "%edx" // GRR: we handle these manually 93 | // , "memory" // if write to a variable gcc thought was in a reg 94 | // , "cc" // "condition codes" (flag bits) 95 | ); 96 | _mmx_supported = result; 97 | #else 98 | _mmx_supported = 0; 99 | #endif /* PNG_MMX_CODE_SUPPORTED */ 100 | 101 | return _mmx_supported; 102 | } 103 | #endif 104 | -------------------------------------------------------------------------------- /Src/FunctionData.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef FUNCTION_DATA_INCLUDED 30 | #define FUNCTION_DATA_INCLUDED 31 | 32 | #define BOUNDARY_CONDITIONS 1 33 | 34 | 35 | #include "PPolynomial.h" 36 | 37 | template 38 | class FunctionData{ 39 | bool useDotRatios; 40 | int normalize; 41 | #if BOUNDARY_CONDITIONS 42 | bool reflectBoundary; 43 | #endif // BOUNDARY_CONDITIONS 44 | public: 45 | const static int DOT_FLAG = 1; 46 | const static int D_DOT_FLAG = 2; 47 | const static int D2_DOT_FLAG = 4; 48 | const static int VALUE_FLAG = 1; 49 | const static int D_VALUE_FLAG = 2; 50 | 51 | int depth , res , res2; 52 | Real *dotTable , *dDotTable , *d2DotTable; 53 | Real *valueTables , *dValueTables; 54 | #if BOUNDARY_CONDITIONS 55 | PPolynomial baseFunction , leftBaseFunction , rightBaseFunction; 56 | PPolynomial dBaseFunction , dLeftBaseFunction , dRightBaseFunction; 57 | #else // !BOUNDARY_CONDITIONS 58 | PPolynomial baseFunction; 59 | PPolynomial dBaseFunction; 60 | #endif // BOUNDARY_CONDITIONS 61 | PPolynomial* baseFunctions; 62 | 63 | FunctionData(void); 64 | ~FunctionData(void); 65 | 66 | virtual void setDotTables(const int& flags); 67 | virtual void clearDotTables(const int& flags); 68 | 69 | virtual void setValueTables(const int& flags,const double& smooth=0); 70 | virtual void setValueTables(const int& flags,const double& valueSmooth,const double& normalSmooth); 71 | virtual void clearValueTables(void); 72 | 73 | /******************************************************** 74 | * Sets the translates and scales of the basis function 75 | * up to the prescribed depth 76 | * the maximum depth 77 | * the basis function 78 | * how the functions should be scaled 79 | * 0] Value at zero equals 1 80 | * 1] Integral equals 1 81 | * 2] L2-norm equals 1 82 | * specifies if dot-products of derivatives 83 | * should be pre-divided by function integrals 84 | * spcifies if function space should be 85 | * forced to be reflectively symmetric across the boundary 86 | ********************************************************/ 87 | #if BOUNDARY_CONDITIONS 88 | void set( const int& maxDepth , const PPolynomial& F , const int& normalize , bool useDotRatios=true , bool reflectBoundary=false ); 89 | #else // !BOUNDARY_CONDITIONS 90 | void set(const int& maxDepth,const PPolynomial& F,const int& normalize , bool useDotRatios=true ); 91 | #endif // BOUNDARY_CONDITIONS 92 | 93 | #if BOUNDARY_CONDITIONS 94 | Real dotProduct( const double& center1 , const double& width1 , const double& center2 , const double& width2 , int boundary1 , int boundary2 ) const; 95 | Real dDotProduct( const double& center1 , const double& width1 , const double& center2 , const double& width2 , int boundary1 , int boundary2 ) const; 96 | Real d2DotProduct( const double& center1 , const double& width1 , const double& center2 , const double& width2 , int boundary1 , int boundary2 ) const; 97 | #else // !BOUNDARY_CONDITIONS 98 | Real dotProduct( const double& center1 , const double& width1 , const double& center2 , const double& width2 ) const; 99 | Real dDotProduct( const double& center1 , const double& width1 , const double& center2 , const double& width2 ) const; 100 | Real d2DotProduct( const double& center1 , const double& width1 , const double& center2 , const double& width2 ) const; 101 | #endif // BOUNDARY_CONDITIONS 102 | 103 | static inline int SymmetricIndex( const int& i1 , const int& i2 ); 104 | static inline int SymmetricIndex( const int& i1 , const int& i2 , int& index ); 105 | }; 106 | 107 | 108 | #include "FunctionData.inl" 109 | #endif // FUNCTION_DATA_INCLUDED -------------------------------------------------------------------------------- /Src/PNG.inl: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #ifdef _WIN32 4 | #include "PNG/png.h" 5 | #else // !_WIN32 6 | #include 7 | #endif // _WIN32 8 | 9 | inline PNGReader::PNGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 10 | { 11 | _currentRow = 0; 12 | 13 | _png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING , 0 , 0 , 0); 14 | if( !_png_ptr ) ERROR_OUT( "Failed to create png pointer" ); 15 | _info_ptr = png_create_info_struct( _png_ptr ); 16 | if( !_info_ptr ) ERROR_OUT( "Failed to create info pointer" ); 17 | 18 | _end_info = png_create_info_struct( _png_ptr ); 19 | if( !_end_info ) ERROR_OUT( "Failed to create end pointer" ); 20 | 21 | 22 | _fp = fopen( fileName , "rb" ); 23 | if( !_fp ) ERROR_OUT( "Failed to open file for reading: " , fileName ); 24 | png_init_io( _png_ptr , _fp ); 25 | 26 | png_read_info( _png_ptr, _info_ptr ); 27 | 28 | width = png_get_image_width( _png_ptr , _info_ptr ); 29 | height = png_get_image_height( _png_ptr, _info_ptr ); 30 | channels = png_get_channels( _png_ptr , _info_ptr ); 31 | int bit_depth=png_get_bit_depth( _png_ptr , _info_ptr ); 32 | int color_type = png_get_color_type( _png_ptr , _info_ptr ); 33 | if( bit_depth==16 ) 34 | { 35 | WARN( "Converting 16-bit image to 8-bit image" ); 36 | _scratchRow = new unsigned char[ channels*width*2 ]; 37 | } 38 | else 39 | { 40 | if( bit_depth!=8 ) ERROR_OUT( "Expected 8 bits per channel" ); 41 | _scratchRow = NULL; 42 | } 43 | if( color_type==PNG_COLOR_TYPE_PALETTE ) png_set_expand( _png_ptr ) , printf( "Expanding PNG color pallette\n" ); 44 | 45 | { 46 | long int a = 1; 47 | int swap = (*((unsigned char *) &a) == 1); 48 | if( swap ) png_set_swap( _png_ptr ); 49 | } 50 | } 51 | inline unsigned int PNGReader::nextRow( unsigned char* row ) 52 | { 53 | if( _scratchRow ) 54 | { 55 | int width = png_get_image_width( _png_ptr , _info_ptr ); 56 | int channels = png_get_channels( _png_ptr , _info_ptr ); 57 | 58 | png_read_row( _png_ptr , (png_bytep)_scratchRow , NULL ); 59 | #pragma omp parallel for 60 | for( int i=0 ; iwidth ) ); 148 | return _currentRow += rowNum; 149 | } 150 | -------------------------------------------------------------------------------- /JPEG/jdtrans.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jdtrans.c 3 | * 4 | * Copyright (C) 1995-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains library routines for transcoding decompression, 9 | * that is, reading raw DCT coefficient arrays from an input JPEG file. 10 | * The routines in jdapimin.c will also be needed by a transcoder. 11 | */ 12 | 13 | #define JPEG_INTERNALS 14 | #include "jinclude.h" 15 | #include "jpeglib.h" 16 | 17 | 18 | /* Forward declarations */ 19 | LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo)); 20 | 21 | 22 | /* 23 | * Read the coefficient arrays from a JPEG file. 24 | * jpeg_read_header must be completed before calling this. 25 | * 26 | * The entire image is read into a set of virtual coefficient-block arrays, 27 | * one per component. The return value is a pointer to the array of 28 | * virtual-array descriptors. These can be manipulated directly via the 29 | * JPEG memory manager, or handed off to jpeg_write_coefficients(). 30 | * To release the memory occupied by the virtual arrays, call 31 | * jpeg_finish_decompress() when done with the data. 32 | * 33 | * An alternative usage is to simply obtain access to the coefficient arrays 34 | * during a buffered-image-mode decompression operation. This is allowed 35 | * after any jpeg_finish_output() call. The arrays can be accessed until 36 | * jpeg_finish_decompress() is called. (Note that any call to the library 37 | * may reposition the arrays, so don't rely on access_virt_barray() results 38 | * to stay valid across library calls.) 39 | * 40 | * Returns NULL if suspended. This case need be checked only if 41 | * a suspending data source is used. 42 | */ 43 | 44 | GLOBAL(jvirt_barray_ptr *) 45 | jpeg_read_coefficients (j_decompress_ptr cinfo) 46 | { 47 | if (cinfo->global_state == DSTATE_READY) { 48 | /* First call: initialize active modules */ 49 | transdecode_master_selection(cinfo); 50 | cinfo->global_state = DSTATE_RDCOEFS; 51 | } 52 | if (cinfo->global_state == DSTATE_RDCOEFS) { 53 | /* Absorb whole file into the coef buffer */ 54 | for (;;) { 55 | int retcode; 56 | /* Call progress monitor hook if present */ 57 | if (cinfo->progress != NULL) 58 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 59 | /* Absorb some more input */ 60 | retcode = (*cinfo->inputctl->consume_input) (cinfo); 61 | if (retcode == JPEG_SUSPENDED) 62 | return NULL; 63 | if (retcode == JPEG_REACHED_EOI) 64 | break; 65 | /* Advance progress counter if appropriate */ 66 | if (cinfo->progress != NULL && 67 | (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { 68 | if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { 69 | /* startup underestimated number of scans; ratchet up one scan */ 70 | cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; 71 | } 72 | } 73 | } 74 | /* Set state so that jpeg_finish_decompress does the right thing */ 75 | cinfo->global_state = DSTATE_STOPPING; 76 | } 77 | /* At this point we should be in state DSTATE_STOPPING if being used 78 | * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access 79 | * to the coefficients during a full buffered-image-mode decompression. 80 | */ 81 | if ((cinfo->global_state == DSTATE_STOPPING || 82 | cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) { 83 | return cinfo->coef->coef_arrays; 84 | } 85 | /* Oops, improper usage */ 86 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 87 | return NULL; /* keep compiler happy */ 88 | } 89 | 90 | 91 | /* 92 | * Master selection of decompression modules for transcoding. 93 | * This substitutes for jdmaster.c's initialization of the full decompressor. 94 | */ 95 | 96 | LOCAL(void) 97 | transdecode_master_selection (j_decompress_ptr cinfo) 98 | { 99 | /* This is effectively a buffered-image operation. */ 100 | cinfo->buffered_image = TRUE; 101 | 102 | /* Entropy decoding: either Huffman or arithmetic coding. */ 103 | if (cinfo->arith_code) { 104 | ERREXIT(cinfo, JERR_ARITH_NOTIMPL); 105 | } else { 106 | if (cinfo->progressive_mode) { 107 | #ifdef D_PROGRESSIVE_SUPPORTED 108 | jinit_phuff_decoder(cinfo); 109 | #else 110 | ERREXIT(cinfo, JERR_NOT_COMPILED); 111 | #endif 112 | } else 113 | jinit_huff_decoder(cinfo); 114 | } 115 | 116 | /* Always get a full-image coefficient buffer. */ 117 | jinit_d_coef_controller(cinfo, TRUE); 118 | 119 | /* We can now tell the memory manager to allocate virtual arrays. */ 120 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); 121 | 122 | /* Initialize input side of decompressor to consume first scan. */ 123 | (*cinfo->inputctl->start_input_pass) (cinfo); 124 | 125 | /* Initialize progress monitoring. */ 126 | if (cinfo->progress != NULL) { 127 | int nscans; 128 | /* Estimate number of scans to set pass_limit. */ 129 | if (cinfo->progressive_mode) { 130 | /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */ 131 | nscans = 2 + 3 * cinfo->num_components; 132 | } else if (cinfo->inputctl->has_multiple_scans) { 133 | /* For a nonprogressive multiscan file, estimate 1 scan per component. */ 134 | nscans = cinfo->num_components; 135 | } else { 136 | nscans = 1; 137 | } 138 | cinfo->progress->pass_counter = 0L; 139 | cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans; 140 | cinfo->progress->completed_passes = 0; 141 | cinfo->progress->total_passes = 1; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /Src/Factor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef FACTOR_INCLUDED 30 | #define FACTOR_INCLUDED 31 | 32 | #include 33 | #include 34 | #ifndef SQRT_3 35 | #define SQRT_3 1.7320508075688772935 36 | #endif // SQRT_3 37 | inline int Factor( double a1 , double a0 , std::complex< double > roots[1] , double EPS ) 38 | { 39 | if( fabs(a1)<=EPS ) return 0; 40 | roots[0] = std::complex< double >( -a0/a1 , 0 ); 41 | return 1; 42 | } 43 | inline int Factor( double a2 , double a1 , double a0 , std::complex< double > roots[2] , double EPS ) 44 | { 45 | double d; 46 | if( fabs(a2)<=EPS ) return Factor( a1 , a0 , roots , EPS ); 47 | 48 | d = a1*a1 - 4*a0*a2; 49 | a1 /= (2*a2); 50 | if( d<0 ) 51 | { 52 | d=sqrt(-d)/(2*a2); 53 | roots[0] = std::complex< double >( -a1 , -d ); 54 | roots[1] = std::complex< double >( -a1 , d ); 55 | } 56 | else 57 | { 58 | d = sqrt(d)/(2*a2); 59 | roots[0] = std::complex< double >( -a1-d , 0 ); 60 | roots[1] = std::complex< double >( -a1+d , 0 ); 61 | } 62 | return 2; 63 | } 64 | // Solution taken from: http://mathworld.wolfram.com/CubicFormula.html 65 | // and http://www.csit.fsu.edu/~burkardt/f_src/subpak/subpak.f90 66 | inline int Factor( double a3 , double a2 , double a1 , double a0 , std::complex< double > roots[3] , double EPS ) 67 | { 68 | double q,r,r2,q3; 69 | 70 | if( fabs(a3)<=EPS ) return Factor( a2 , a1 , a0 , roots , EPS ); 71 | a2 /= a3 , a1 /= a3 , a0 /= a3; 72 | 73 | q = -(3*a1-a2*a2)/9; 74 | r = -(9*a2*a1-27*a0-2*a2*a2*a2)/54; 75 | r2 = r*r; 76 | q3 = q*q*q; 77 | 78 | if(r2( -2*cTheta , 0 ); 85 | roots[1] = std::complex< double >( -2*(-cTheta*0.5-sTheta) , 0 ); 86 | roots[2] = std::complex< double >( -2*(-cTheta*0.5+sTheta) , 0 ); 87 | } 88 | else 89 | { 90 | double t , s1 , s2 , sqr=sqrt(r2-q3); 91 | t = -r+sqr; 92 | if(t<0) s1 = -pow( -t , 1.0/3 ); 93 | else s1 = pow( t , 1.0/3 ); 94 | t = -r-sqr; 95 | if( t<0 ) s2 = -pow( -t , 1.0/3 ); 96 | else s2 = pow( t , 1.0/3 ); 97 | roots[0] = std::complex< double >( s1+s2 , 0 ); 98 | s1 /= 2 , s2 /= 2; 99 | roots[1] = std::complex< double >( -s1-s2 , SQRT_3*(s1-s2) ); 100 | roots[2] = std::complex< double >( -s1-s2 , -SQRT_3*(s1-s2) ); 101 | } 102 | roots[0] -= a2/3; 103 | roots[1] -= a2/3; 104 | roots[2] -= a2/3; 105 | return 3; 106 | } 107 | // Solution taken from: http://mathworld.wolfram.com/QuarticEquation.html 108 | // and http://www.csit.fsu.edu/~burkardt/f_src/subpak/subpak.f90 109 | inline int Factor( double a4 , double a3 , double a2 , double a1 , double a0 , std::complex< double > roots[4] , double EPS ) 110 | { 111 | std::complex< double > R , D , E , R2; 112 | 113 | if( fabs(a4)( a3*a3/4.0-a2+roots[0].real() , 0 ); 119 | R = sqrt( R2 ); 120 | if( fabs( R.real() )>10e-8 ) 121 | { 122 | std::complex< double > temp1 , temp2 , p1 , p2; 123 | 124 | p1 = std::complex< double >( a3*a3*0.75-2.0*a2-R2.real() , 0 ); 125 | 126 | temp2 = std::complex< double >( (4.0*a3*a2-8.0*a1-a3*a3*a3)/4.0 , 0 ); 127 | p2 = temp2 / R; 128 | temp1 = p1+p2; 129 | temp2 = p1-p2; 130 | D = sqrt( temp1 ); 131 | E = sqrt( temp2 ); 132 | } 133 | else 134 | { 135 | R = std::complex< double >( 0 , 0 ); 136 | std::complex< double > temp1 , temp2; 137 | temp1 = std::complex< double >( roots[0].real()*roots[0].real()-4.0*a0 , 0 ); 138 | temp2 = sqrt( temp1 ); 139 | 140 | temp1 = std::complex< double >( a3*a3*0.75-2.0*a2+2.0*temp2.real() , 2.0*temp2.imag() ); 141 | D = sqrt( temp1 ); 142 | 143 | temp1 = std::complex< double >( a3*a3*0.75-2.0*a2-2.0*temp2.real() , -2.0*temp2.imag() ); 144 | E = sqrt( temp1 ); 145 | } 146 | 147 | roots[0] = R/2. + D/2. - a3/4; 148 | roots[1] = R/2. - D/2. - a3/4; 149 | roots[2] = -R/2. + E/2. - a3/4; 150 | roots[3] = -R/2. - E/2. - a3/4; 151 | 152 | return 4; 153 | } 154 | #endif // FACTOR_INCLUDED -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PR_TARGET=PoissonRecon 2 | SR_TARGET=SSDRecon 3 | PI_TARGET=PointInterpolant 4 | ST_TARGET=SurfaceTrimmer 5 | EH_TARGET=EDTInHeat 6 | IS_TARGET=ImageStitching 7 | AV_TARGET=AdaptiveTreeVisualization 8 | CP_TARGET=ChunkPLY 9 | PR_SOURCE=PoissonRecon.cpp 10 | SR_SOURCE=SSDRecon.cpp 11 | PI_SOURCE=PointInterpolant.cpp 12 | ST_SOURCE=SurfaceTrimmer.cpp 13 | EH_SOURCE=EDTInHeat.cpp 14 | IS_SOURCE=ImageStitching.cpp 15 | AV_SOURCE=AdaptiveTreeVisualization.cpp 16 | CP_SOURCE=ChunkPLY.cpp 17 | 18 | COMPILER = gcc 19 | #COMPILER = clang 20 | 21 | ifeq ($(COMPILER),gcc) 22 | CFLAGS += -fopenmp -Wno-deprecated -std=c++11 -pthread -Wno-invalid-offsetof 23 | LFLAGS += -lgomp -lstdc++ -lpthread 24 | else 25 | # CFLAGS += -fopenmp=libiomp5 -Wno-deprecated -Wno-write-strings -std=c++11 -Wno-invalid-offsetof 26 | # LFLAGS += -liomp5 -lstdc++ 27 | CFLAGS += -Wno-deprecated -std=c++11 -pthread -Wno-invalid-offsetof 28 | LFLAGS += -lstdc++ 29 | endif 30 | #LFLAGS += -lz -lpng -ljpeg 31 | 32 | CFLAGS_DEBUG = -DDEBUG -g3 33 | LFLAGS_DEBUG = 34 | 35 | #CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -g 36 | #LFLAGS_RELEASE = -O3 -g 37 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -g 38 | LFLAGS_RELEASE = -O3 -g 39 | 40 | SRC = Src/ 41 | BIN = Bin/Linux/ 42 | #INCLUDE = /usr/include/ 43 | INCLUDE = . 44 | 45 | ifeq ($(COMPILER),gcc) 46 | CC=gcc 47 | CXX=g++ 48 | else 49 | CC=clang-3.8 50 | CXX=clang++-3.8 51 | # CC=clang-3.5 52 | # CXX=clang++-3.5 53 | endif 54 | 55 | MD=mkdir 56 | 57 | PR_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(PR_SOURCE)))) 58 | SR_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(SR_SOURCE)))) 59 | PI_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(PI_SOURCE)))) 60 | ST_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(ST_SOURCE)))) 61 | EH_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(EH_SOURCE)))) 62 | IS_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(IS_SOURCE)))) 63 | AV_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(AV_SOURCE)))) 64 | CP_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(CP_SOURCE)))) 65 | 66 | 67 | all: CFLAGS += $(CFLAGS_RELEASE) 68 | all: LFLAGS += $(LFLAGS_RELEASE) 69 | all: make_dir 70 | all: $(BIN)$(PR_TARGET) 71 | all: $(BIN)$(SR_TARGET) 72 | all: $(BIN)$(PI_TARGET) 73 | all: $(BIN)$(ST_TARGET) 74 | all: $(BIN)$(EH_TARGET) 75 | all: $(BIN)$(IS_TARGET) 76 | all: $(BIN)$(AV_TARGET) 77 | all: $(BIN)$(CP_TARGET) 78 | 79 | debug: CFLAGS += $(CFLAGS_DEBUG) 80 | debug: LFLAGS += $(LFLAGS_DEBUG) 81 | debug: make_dir 82 | debug: $(BIN)$(PR_TARGET) 83 | debug: $(BIN)$(SR_TARGET) 84 | debug: $(BIN)$(PI_TARGET) 85 | debug: $(BIN)$(ST_TARGET) 86 | debug: $(BIN)$(EH_TARGET) 87 | debug: $(BIN)$(IS_TARGET) 88 | debug: $(BIN)$(AV_TARGET) 89 | debug: $(BIN)$(CP_TARGET) 90 | 91 | poissonrecon: CFLAGS += $(CFLAGS_RELEASE) 92 | poissonrecon: LFLAGS += $(LFLAGS_RELEASE) 93 | poissonrecon: make_dir 94 | poissonrecon: $(BIN)$(PR_TARGET) 95 | 96 | ssdrecon: CFLAGS += $(CFLAGS_RELEASE) 97 | ssdrecon: LFLAGS += $(LFLAGS_RELEASE) 98 | ssdrecon: make_dir 99 | ssdrecon: $(BIN)$(SR_TARGET) 100 | 101 | pointinterpolant: CFLAGS += $(CFLAGS_RELEASE) 102 | pointinterpolant: LFLAGS += $(LFLAGS_RELEASE) 103 | pointinterpolant: make_dir 104 | pointinterpolant: $(BIN)$(PI_TARGET) 105 | 106 | surfacetrimmer: CFLAGS += $(CFLAGS_RELEASE) 107 | surfacetrimmer: LFLAGS += $(LFLAGS_RELEASE) 108 | surfacetrimmer: make_dir 109 | surfacetrimmer: $(BIN)$(ST_TARGET) 110 | 111 | edtinheat: CFLAGS += $(CFLAGS_RELEASE) 112 | edtinheat: LFLAGS += $(LFLAGS_RELEASE) 113 | edtinheat: make_dir 114 | edtinheat: $(BIN)$(EH_TARGET) 115 | 116 | imagestitching: CFLAGS += $(CFLAGS_RELEASE) 117 | imagestitching: LFLAGS += $(LFLAGS_RELEASE) 118 | imagestitching: make_dir 119 | imagestitching: $(BIN)$(IS_TARGET) 120 | 121 | octreevisualization: CFLAGS += $(CFLAGS_RELEASE) 122 | octreevisualization: LFLAGS += $(LFLAGS_RELEASE) 123 | octreevisualization: make_dir 124 | octreevisualization: $(BIN)$(AV_TARGET) 125 | 126 | chunkply: CFLAGS += $(CFLAGS_RELEASE) 127 | chunkply: LFLAGS += $(LFLAGS_RELEASE) 128 | chunkply: make_dir 129 | chunkply: $(BIN)$(CP_TARGET) 130 | 131 | clean: 132 | rm -rf $(BIN)$(PR_TARGET) 133 | rm -rf $(BIN)$(SR_TARGET) 134 | rm -rf $(BIN)$(PI_TARGET) 135 | rm -rf $(BIN)$(ST_TARGET) 136 | rm -rf $(BIN)$(EH_TARGET) 137 | rm -rf $(BIN)$(IS_TARGET) 138 | rm -rf $(BIN)$(AV_TARGET) 139 | rm -rf $(BIN)$(CP_TARGET) 140 | rm -rf $(PR_OBJECTS) 141 | rm -rf $(SR_OBJECTS) 142 | rm -rf $(PI_OBJECTS) 143 | rm -rf $(ST_OBJECTS) 144 | rm -rf $(EH_OBJECTS) 145 | rm -rf $(IS_OBJECTS) 146 | rm -rf $(AV_OBJECTS) 147 | rm -rf $(CP_OBJECTS) 148 | cd PNG && make clean 149 | 150 | 151 | make_dir: 152 | $(MD) -p $(BIN) 153 | 154 | $(BIN)$(PR_TARGET): $(PR_OBJECTS) 155 | cd PNG && make 156 | $(CXX) -o $@ $(PR_OBJECTS) -L$(BIN) $(LFLAGS) -ljpeg -lmypng -lz 157 | 158 | $(BIN)$(SR_TARGET): $(SR_OBJECTS) 159 | cd PNG && make 160 | $(CXX) -o $@ $(SR_OBJECTS) -L$(BIN) $(LFLAGS) -ljpeg -lmypng -lz 161 | 162 | $(BIN)$(PI_TARGET): $(PI_OBJECTS) 163 | cd PNG && make 164 | $(CXX) -o $@ $(PI_OBJECTS) -L$(BIN) $(LFLAGS) -ljpeg -lmypng -lz 165 | 166 | $(BIN)$(ST_TARGET): $(ST_OBJECTS) 167 | $(CXX) -o $@ $(ST_OBJECTS) $(LFLAGS) 168 | 169 | $(BIN)$(EH_TARGET): $(EH_OBJECTS) 170 | $(CXX) -o $@ $(EH_OBJECTS) $(LFLAGS) 171 | 172 | $(BIN)$(IS_TARGET): $(IS_OBJECTS) 173 | cd PNG && make 174 | $(CXX) -o $@ $(IS_OBJECTS) -L$(BIN) $(LFLAGS) -ljpeg -lmypng -lz 175 | 176 | $(BIN)$(AV_TARGET): $(AV_OBJECTS) 177 | cd PNG && make 178 | $(CXX) -o $@ $(AV_OBJECTS) -L$(BIN) $(LFLAGS) -ljpeg -lmypng -lz 179 | 180 | $(BIN)$(CP_TARGET): $(CP_OBJECTS) 181 | cd PNG && make 182 | $(CXX) -o $@ $(CP_OBJECTS) -L$(BIN) $(LFLAGS) -ljpeg -lmypng -lz 183 | 184 | $(BIN)%.o: $(SRC)%.c 185 | $(CC) -c -o $@ -I$(INCLUDE) $< 186 | 187 | $(BIN)%.o: $(SRC)%.cpp 188 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 189 | 190 | -------------------------------------------------------------------------------- /JPEG/jdatadst.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jdatadst.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains compression data destination routines for the case of 9 | * emitting JPEG data to a file (or any stdio stream). While these routines 10 | * are sufficient for most applications, some will want to use a different 11 | * destination manager. 12 | * IMPORTANT: we assume that fwrite() will correctly transcribe an array of 13 | * JOCTETs into 8-bit-wide elements on external storage. If char is wider 14 | * than 8 bits on your machine, you may need to do some tweaking. 15 | */ 16 | 17 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ 18 | #include "jinclude.h" 19 | #include "jpeglib.h" 20 | #include "jerror.h" 21 | 22 | 23 | /* Expanded data destination object for stdio output */ 24 | 25 | typedef struct { 26 | struct jpeg_destination_mgr pub; /* public fields */ 27 | 28 | FILE * outfile; /* target stream */ 29 | JOCTET * buffer; /* start of buffer */ 30 | } my_destination_mgr; 31 | 32 | typedef my_destination_mgr * my_dest_ptr; 33 | 34 | #if 1 35 | #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */ 36 | #else 37 | // Misha modified for bigger block I/O 38 | #define OUTPUT_BUF_SIZE 1<<16 /* choose an efficiently fwrite'able size */ 39 | #endif 40 | 41 | 42 | /* 43 | * Initialize destination --- called by jpeg_start_compress 44 | * before any data is actually written. 45 | */ 46 | 47 | METHODDEF(void) 48 | init_destination (j_compress_ptr cinfo) 49 | { 50 | my_dest_ptr dest = (my_dest_ptr) cinfo->dest; 51 | 52 | /* Allocate the output buffer --- it will be released when done with image */ 53 | dest->buffer = (JOCTET *) 54 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 55 | OUTPUT_BUF_SIZE * SIZEOF(JOCTET)); 56 | 57 | dest->pub.next_output_byte = dest->buffer; 58 | dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; 59 | } 60 | 61 | 62 | /* 63 | * Empty the output buffer --- called whenever buffer fills up. 64 | * 65 | * In typical applications, this should write the entire output buffer 66 | * (ignoring the current state of next_output_byte & free_in_buffer), 67 | * reset the pointer & count to the start of the buffer, and return TRUE 68 | * indicating that the buffer has been dumped. 69 | * 70 | * In applications that need to be able to suspend compression due to output 71 | * overrun, a FALSE return indicates that the buffer cannot be emptied now. 72 | * In this situation, the compressor will return to its caller (possibly with 73 | * an indication that it has not accepted all the supplied scanlines). The 74 | * application should resume compression after it has made more room in the 75 | * output buffer. Note that there are substantial restrictions on the use of 76 | * suspension --- see the documentation. 77 | * 78 | * When suspending, the compressor will back up to a convenient restart point 79 | * (typically the start of the current MCU). next_output_byte & free_in_buffer 80 | * indicate where the restart point will be if the current call returns FALSE. 81 | * Data beyond this point will be regenerated after resumption, so do not 82 | * write it out when emptying the buffer externally. 83 | */ 84 | 85 | METHODDEF(boolean) 86 | empty_output_buffer (j_compress_ptr cinfo) 87 | { 88 | my_dest_ptr dest = (my_dest_ptr) cinfo->dest; 89 | 90 | if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != 91 | (size_t) OUTPUT_BUF_SIZE) 92 | ERREXIT(cinfo, JERR_FILE_WRITE); 93 | 94 | dest->pub.next_output_byte = dest->buffer; 95 | dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; 96 | 97 | return TRUE; 98 | } 99 | 100 | 101 | /* 102 | * Terminate destination --- called by jpeg_finish_compress 103 | * after all data has been written. Usually needs to flush buffer. 104 | * 105 | * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding 106 | * application must deal with any cleanup that should happen even 107 | * for error exit. 108 | */ 109 | 110 | METHODDEF(void) 111 | term_destination (j_compress_ptr cinfo) 112 | { 113 | my_dest_ptr dest = (my_dest_ptr) cinfo->dest; 114 | size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; 115 | 116 | /* Write any data remaining in the buffer */ 117 | if (datacount > 0) { 118 | if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount) 119 | ERREXIT(cinfo, JERR_FILE_WRITE); 120 | } 121 | fflush(dest->outfile); 122 | /* Make sure we wrote the output file OK */ 123 | if (ferror(dest->outfile)) 124 | ERREXIT(cinfo, JERR_FILE_WRITE); 125 | } 126 | 127 | 128 | /* 129 | * Prepare for output to a stdio stream. 130 | * The caller must have already opened the stream, and is responsible 131 | * for closing it after finishing compression. 132 | */ 133 | 134 | GLOBAL(void) 135 | jpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile) 136 | { 137 | my_dest_ptr dest; 138 | 139 | /* The destination object is made permanent so that multiple JPEG images 140 | * can be written to the same file without re-executing jpeg_stdio_dest. 141 | * This makes it dangerous to use this manager and a different destination 142 | * manager serially with the same JPEG object, because their private object 143 | * sizes may be different. Caveat programmer. 144 | */ 145 | if (cinfo->dest == NULL) { /* first time for this JPEG object? */ 146 | cinfo->dest = (struct jpeg_destination_mgr *) 147 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 148 | SIZEOF(my_destination_mgr)); 149 | } 150 | 151 | dest = (my_dest_ptr) cinfo->dest; 152 | dest->pub.init_destination = init_destination; 153 | dest->pub.empty_output_buffer = empty_output_buffer; 154 | dest->pub.term_destination = term_destination; 155 | dest->outfile = outfile; 156 | } 157 | -------------------------------------------------------------------------------- /JPEG/jutils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jutils.c 3 | * 4 | * Copyright (C) 1991-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains tables and miscellaneous utility routines needed 9 | * for both compression and decompression. 10 | * Note we prefix all global names with "j" to minimize conflicts with 11 | * a surrounding application. 12 | */ 13 | 14 | #define JPEG_INTERNALS 15 | #include "jinclude.h" 16 | #include "jpeglib.h" 17 | 18 | 19 | /* 20 | * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element 21 | * of a DCT block read in natural order (left to right, top to bottom). 22 | */ 23 | 24 | #if 0 /* This table is not actually needed in v6a */ 25 | 26 | const int jpeg_zigzag_order[DCTSIZE2] = { 27 | 0, 1, 5, 6, 14, 15, 27, 28, 28 | 2, 4, 7, 13, 16, 26, 29, 42, 29 | 3, 8, 12, 17, 25, 30, 41, 43, 30 | 9, 11, 18, 24, 31, 40, 44, 53, 31 | 10, 19, 23, 32, 39, 45, 52, 54, 32 | 20, 22, 33, 38, 46, 51, 55, 60, 33 | 21, 34, 37, 47, 50, 56, 59, 61, 34 | 35, 36, 48, 49, 57, 58, 62, 63 35 | }; 36 | 37 | #endif 38 | 39 | /* 40 | * jpeg_natural_order[i] is the natural-order position of the i'th element 41 | * of zigzag order. 42 | * 43 | * When reading corrupted data, the Huffman decoders could attempt 44 | * to reference an entry beyond the end of this array (if the decoded 45 | * zero run length reaches past the end of the block). To prevent 46 | * wild stores without adding an inner-loop test, we put some extra 47 | * "63"s after the real entries. This will cause the extra coefficient 48 | * to be stored in location 63 of the block, not somewhere random. 49 | * The worst case would be a run-length of 15, which means we need 16 50 | * fake entries. 51 | */ 52 | 53 | const int jpeg_natural_order[DCTSIZE2+16] = { 54 | 0, 1, 8, 16, 9, 2, 3, 10, 55 | 17, 24, 32, 25, 18, 11, 4, 5, 56 | 12, 19, 26, 33, 40, 48, 41, 34, 57 | 27, 20, 13, 6, 7, 14, 21, 28, 58 | 35, 42, 49, 56, 57, 50, 43, 36, 59 | 29, 22, 15, 23, 30, 37, 44, 51, 60 | 58, 59, 52, 45, 38, 31, 39, 46, 61 | 53, 60, 61, 54, 47, 55, 62, 63, 62 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 63 | 63, 63, 63, 63, 63, 63, 63, 63 64 | }; 65 | 66 | 67 | /* 68 | * Arithmetic utilities 69 | */ 70 | 71 | GLOBAL(long) 72 | jdiv_round_up (long a, long b) 73 | /* Compute a/b rounded up to next integer, ie, ceil(a/b) */ 74 | /* Assumes a >= 0, b > 0 */ 75 | { 76 | return (a + b - 1L) / b; 77 | } 78 | 79 | 80 | GLOBAL(long) 81 | jround_up (long a, long b) 82 | /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ 83 | /* Assumes a >= 0, b > 0 */ 84 | { 85 | a += b - 1L; 86 | return a - (a % b); 87 | } 88 | 89 | 90 | /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays 91 | * and coefficient-block arrays. This won't work on 80x86 because the arrays 92 | * are FAR and we're assuming a small-pointer memory model. However, some 93 | * DOS compilers provide far-pointer versions of memcpy() and memset() even 94 | * in the small-model libraries. These will be used if USE_FMEM is defined. 95 | * Otherwise, the routines below do it the hard way. (The performance cost 96 | * is not all that great, because these routines aren't very heavily used.) 97 | */ 98 | 99 | #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ 100 | #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) 101 | #define FMEMZERO(target,size) MEMZERO(target,size) 102 | #else /* 80x86 case, define if we can */ 103 | #ifdef USE_FMEM 104 | #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) 105 | #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) 106 | #endif 107 | #endif 108 | 109 | 110 | GLOBAL(void) 111 | jcopy_sample_rows (JSAMPARRAY input_array, int source_row, 112 | JSAMPARRAY output_array, int dest_row, 113 | int num_rows, JDIMENSION num_cols) 114 | /* Copy some rows of samples from one place to another. 115 | * num_rows rows are copied from input_array[source_row++] 116 | * to output_array[dest_row++]; these areas may overlap for duplication. 117 | * The source and destination arrays must be at least as wide as num_cols. 118 | */ 119 | { 120 | register JSAMPROW inptr, outptr; 121 | #ifdef FMEMCOPY 122 | register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); 123 | #else 124 | register JDIMENSION count; 125 | #endif 126 | register int row; 127 | 128 | input_array += source_row; 129 | output_array += dest_row; 130 | 131 | for (row = num_rows; row > 0; row--) { 132 | inptr = *input_array++; 133 | outptr = *output_array++; 134 | #ifdef FMEMCOPY 135 | FMEMCOPY(outptr, inptr, count); 136 | #else 137 | for (count = num_cols; count > 0; count--) 138 | *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ 139 | #endif 140 | } 141 | } 142 | 143 | 144 | GLOBAL(void) 145 | jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, 146 | JDIMENSION num_blocks) 147 | /* Copy a row of coefficient blocks from one place to another. */ 148 | { 149 | #ifdef FMEMCOPY 150 | FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); 151 | #else 152 | register JCOEFPTR inptr, outptr; 153 | register long count; 154 | 155 | inptr = (JCOEFPTR) input_row; 156 | outptr = (JCOEFPTR) output_row; 157 | for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { 158 | *outptr++ = *inptr++; 159 | } 160 | #endif 161 | } 162 | 163 | 164 | GLOBAL(void) 165 | jzero_far (void FAR * target, size_t bytestozero) 166 | /* Zero out a chunk of FAR memory. */ 167 | /* This might be sample-array data, block-array data, or alloc_large data. */ 168 | { 169 | #ifdef FMEMZERO 170 | FMEMZERO(target, bytestozero); 171 | #else 172 | register char FAR * ptr = (char FAR *) target; 173 | register size_t count; 174 | 175 | for (count = bytestozero; count > 0; count--) { 176 | *ptr++ = 0; 177 | } 178 | #endif 179 | } 180 | -------------------------------------------------------------------------------- /JPEG/jfdctflt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jfdctflt.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains a floating-point implementation of the 9 | * forward DCT (Discrete Cosine Transform). 10 | * 11 | * This implementation should be more accurate than either of the integer 12 | * DCT implementations. However, it may not give the same results on all 13 | * machines because of differences in roundoff behavior. Speed will depend 14 | * on the hardware's floating point capacity. 15 | * 16 | * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT 17 | * on each column. Direct algorithms are also available, but they are 18 | * much more complex and seem not to be any faster when reduced to code. 19 | * 20 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for 21 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 22 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell 23 | * JPEG textbook (see REFERENCES section in file README). The following code 24 | * is based directly on figure 4-8 in P&M. 25 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is 26 | * possible to arrange the computation so that many of the multiplies are 27 | * simple scalings of the final outputs. These multiplies can then be 28 | * folded into the multiplications or divisions by the JPEG quantization 29 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds 30 | * to be done in the DCT itself. 31 | * The primary disadvantage of this method is that with a fixed-point 32 | * implementation, accuracy is lost due to imprecise representation of the 33 | * scaled quantization values. However, that problem does not arise if 34 | * we use floating point arithmetic. 35 | */ 36 | 37 | #define JPEG_INTERNALS 38 | #include "jinclude.h" 39 | #include "jpeglib.h" 40 | #include "jdct.h" /* Private declarations for DCT subsystem */ 41 | 42 | #ifdef DCT_FLOAT_SUPPORTED 43 | 44 | 45 | /* 46 | * This module is specialized to the case DCTSIZE = 8. 47 | */ 48 | 49 | #if DCTSIZE != 8 50 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 51 | #endif 52 | 53 | 54 | /* 55 | * Perform the forward DCT on one block of samples. 56 | */ 57 | 58 | GLOBAL(void) 59 | jpeg_fdct_float (FAST_FLOAT * data) 60 | { 61 | FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 62 | FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 63 | FAST_FLOAT z1, z2, z3, z4, z5, z11, z13; 64 | FAST_FLOAT *dataptr; 65 | int ctr; 66 | 67 | /* Pass 1: process rows. */ 68 | 69 | dataptr = data; 70 | for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { 71 | tmp0 = dataptr[0] + dataptr[7]; 72 | tmp7 = dataptr[0] - dataptr[7]; 73 | tmp1 = dataptr[1] + dataptr[6]; 74 | tmp6 = dataptr[1] - dataptr[6]; 75 | tmp2 = dataptr[2] + dataptr[5]; 76 | tmp5 = dataptr[2] - dataptr[5]; 77 | tmp3 = dataptr[3] + dataptr[4]; 78 | tmp4 = dataptr[3] - dataptr[4]; 79 | 80 | /* Even part */ 81 | 82 | tmp10 = tmp0 + tmp3; /* phase 2 */ 83 | tmp13 = tmp0 - tmp3; 84 | tmp11 = tmp1 + tmp2; 85 | tmp12 = tmp1 - tmp2; 86 | 87 | dataptr[0] = tmp10 + tmp11; /* phase 3 */ 88 | dataptr[4] = tmp10 - tmp11; 89 | 90 | z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ 91 | dataptr[2] = tmp13 + z1; /* phase 5 */ 92 | dataptr[6] = tmp13 - z1; 93 | 94 | /* Odd part */ 95 | 96 | tmp10 = tmp4 + tmp5; /* phase 2 */ 97 | tmp11 = tmp5 + tmp6; 98 | tmp12 = tmp6 + tmp7; 99 | 100 | /* The rotator is modified from fig 4-8 to avoid extra negations. */ 101 | z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ 102 | z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ 103 | z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ 104 | z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ 105 | 106 | z11 = tmp7 + z3; /* phase 5 */ 107 | z13 = tmp7 - z3; 108 | 109 | dataptr[5] = z13 + z2; /* phase 6 */ 110 | dataptr[3] = z13 - z2; 111 | dataptr[1] = z11 + z4; 112 | dataptr[7] = z11 - z4; 113 | 114 | dataptr += DCTSIZE; /* advance pointer to next row */ 115 | } 116 | 117 | /* Pass 2: process columns. */ 118 | 119 | dataptr = data; 120 | for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { 121 | tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; 122 | tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; 123 | tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; 124 | tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; 125 | tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; 126 | tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; 127 | tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; 128 | tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; 129 | 130 | /* Even part */ 131 | 132 | tmp10 = tmp0 + tmp3; /* phase 2 */ 133 | tmp13 = tmp0 - tmp3; 134 | tmp11 = tmp1 + tmp2; 135 | tmp12 = tmp1 - tmp2; 136 | 137 | dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */ 138 | dataptr[DCTSIZE*4] = tmp10 - tmp11; 139 | 140 | z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */ 141 | dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */ 142 | dataptr[DCTSIZE*6] = tmp13 - z1; 143 | 144 | /* Odd part */ 145 | 146 | tmp10 = tmp4 + tmp5; /* phase 2 */ 147 | tmp11 = tmp5 + tmp6; 148 | tmp12 = tmp6 + tmp7; 149 | 150 | /* The rotator is modified from fig 4-8 to avoid extra negations. */ 151 | z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */ 152 | z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */ 153 | z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */ 154 | z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */ 155 | 156 | z11 = tmp7 + z3; /* phase 5 */ 157 | z13 = tmp7 - z3; 158 | 159 | dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */ 160 | dataptr[DCTSIZE*3] = z13 - z2; 161 | dataptr[DCTSIZE*1] = z11 + z4; 162 | dataptr[DCTSIZE*7] = z11 - z4; 163 | 164 | dataptr++; /* advance pointer to next column */ 165 | } 166 | } 167 | 168 | #endif /* DCT_FLOAT_SUPPORTED */ 169 | -------------------------------------------------------------------------------- /PNG/pngrio.c: -------------------------------------------------------------------------------- 1 | 2 | /* pngrio.c - functions for data input 3 | * 4 | * Last changed in libpng 1.2.13 November 13, 2006 5 | * For conditions of distribution and use, see copyright notice in png.h 6 | * Copyright (c) 1998-2006 Glenn Randers-Pehrson 7 | * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 8 | * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 9 | * 10 | * This file provides a location for all input. Users who need 11 | * special handling are expected to write a function that has the same 12 | * arguments as this and performs a similar function, but that possibly 13 | * has a different input method. Note that you shouldn't change this 14 | * function, but rather write a replacement function and then make 15 | * libpng use it at run time with png_set_read_fn(...). 16 | */ 17 | 18 | #define PNG_INTERNAL 19 | #include "png.h" 20 | 21 | #if defined(PNG_READ_SUPPORTED) 22 | 23 | /* Read the data from whatever input you are using. The default routine 24 | reads from a file pointer. Note that this routine sometimes gets called 25 | with very small lengths, so you should implement some kind of simple 26 | buffering if you are using unbuffered reads. This should never be asked 27 | to read more then 64K on a 16 bit machine. */ 28 | void /* PRIVATE */ 29 | png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 30 | { 31 | png_debug1(4,"reading %d bytes\n", (int)length); 32 | if (png_ptr->read_data_fn != NULL) 33 | (*(png_ptr->read_data_fn))(png_ptr, data, length); 34 | else 35 | png_error(png_ptr, "Call to NULL read function"); 36 | } 37 | 38 | #if !defined(PNG_NO_STDIO) 39 | /* This is the function that does the actual reading of data. If you are 40 | not reading from a standard C stream, you should create a replacement 41 | read_data function and use it at run time with png_set_read_fn(), rather 42 | than changing the library. */ 43 | #ifndef USE_FAR_KEYWORD 44 | void PNGAPI 45 | png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 46 | { 47 | png_size_t check; 48 | 49 | if(png_ptr == NULL) return; 50 | /* fread() returns 0 on error, so it is OK to store this in a png_size_t 51 | * instead of an int, which is what fread() actually returns. 52 | */ 53 | #if defined(_WIN32_WCE) 54 | if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 55 | check = 0; 56 | #else 57 | check = (png_size_t)fread(data, (png_size_t)1, length, 58 | (png_FILE_p)png_ptr->io_ptr); 59 | #endif 60 | 61 | if (check != length) 62 | png_error(png_ptr, "Read Error"); 63 | } 64 | #else 65 | /* this is the model-independent version. Since the standard I/O library 66 | can't handle far buffers in the medium and small models, we have to copy 67 | the data. 68 | */ 69 | 70 | #define NEAR_BUF_SIZE 1024 71 | #define MIN(a,b) (a <= b ? a : b) 72 | 73 | static void PNGAPI 74 | png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) 75 | { 76 | int check; 77 | png_byte *n_data; 78 | png_FILE_p io_ptr; 79 | 80 | if(png_ptr == NULL) return; 81 | /* Check if data really is near. If so, use usual code. */ 82 | n_data = (png_byte *)CVT_PTR_NOCHECK(data); 83 | io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); 84 | if ((png_bytep)n_data == data) 85 | { 86 | #if defined(_WIN32_WCE) 87 | if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 88 | check = 0; 89 | #else 90 | check = fread(n_data, 1, length, io_ptr); 91 | #endif 92 | } 93 | else 94 | { 95 | png_byte buf[NEAR_BUF_SIZE]; 96 | png_size_t read, remaining, err; 97 | check = 0; 98 | remaining = length; 99 | do 100 | { 101 | read = MIN(NEAR_BUF_SIZE, remaining); 102 | #if defined(_WIN32_WCE) 103 | if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) ) 104 | err = 0; 105 | #else 106 | err = fread(buf, (png_size_t)1, read, io_ptr); 107 | #endif 108 | png_memcpy(data, buf, read); /* copy far buffer to near buffer */ 109 | if(err != read) 110 | break; 111 | else 112 | check += err; 113 | data += read; 114 | remaining -= read; 115 | } 116 | while (remaining != 0); 117 | } 118 | if ((png_uint_32)check != (png_uint_32)length) 119 | png_error(png_ptr, "read Error"); 120 | } 121 | #endif 122 | #endif 123 | 124 | /* This function allows the application to supply a new input function 125 | for libpng if standard C streams aren't being used. 126 | 127 | This function takes as its arguments: 128 | png_ptr - pointer to a png input data structure 129 | io_ptr - pointer to user supplied structure containing info about 130 | the input functions. May be NULL. 131 | read_data_fn - pointer to a new input function that takes as its 132 | arguments a pointer to a png_struct, a pointer to 133 | a location where input data can be stored, and a 32-bit 134 | unsigned int that is the number of bytes to be read. 135 | To exit and output any fatal error messages the new write 136 | function should call png_error(png_ptr, "Error msg"). */ 137 | void PNGAPI 138 | png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, 139 | png_rw_ptr read_data_fn) 140 | { 141 | if(png_ptr == NULL) return; 142 | png_ptr->io_ptr = io_ptr; 143 | 144 | #if !defined(PNG_NO_STDIO) 145 | if (read_data_fn != NULL) 146 | png_ptr->read_data_fn = read_data_fn; 147 | else 148 | png_ptr->read_data_fn = png_default_read_data; 149 | #else 150 | png_ptr->read_data_fn = read_data_fn; 151 | #endif 152 | 153 | /* It is an error to write to a read device */ 154 | if (png_ptr->write_data_fn != NULL) 155 | { 156 | png_ptr->write_data_fn = NULL; 157 | png_warning(png_ptr, 158 | "It's an error to set both read_data_fn and write_data_fn in the "); 159 | png_warning(png_ptr, 160 | "same structure. Resetting write_data_fn to NULL."); 161 | } 162 | 163 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) 164 | png_ptr->output_flush_fn = NULL; 165 | #endif 166 | } 167 | #endif /* PNG_READ_SUPPORTED */ 168 | -------------------------------------------------------------------------------- /ZLIB/zutil.c: -------------------------------------------------------------------------------- 1 | /* zutil.c -- target dependent utility functions for the compression library 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id: zutil.c,v 1.1 2014/03/04 21:20:44 uid42406 Exp $ */ 7 | 8 | #include "zutil.h" 9 | 10 | struct internal_state {int dummy;}; /* for buggy compilers */ 11 | 12 | #ifndef STDC 13 | extern void exit OF((int)); 14 | #endif 15 | 16 | const char *z_errmsg[10] = { 17 | "need dictionary", /* Z_NEED_DICT 2 */ 18 | "stream end", /* Z_STREAM_END 1 */ 19 | "", /* Z_OK 0 */ 20 | "file error", /* Z_ERRNO (-1) */ 21 | "stream error", /* Z_STREAM_ERROR (-2) */ 22 | "data error", /* Z_DATA_ERROR (-3) */ 23 | "insufficient memory", /* Z_MEM_ERROR (-4) */ 24 | "buffer error", /* Z_BUF_ERROR (-5) */ 25 | "incompatible version",/* Z_VERSION_ERROR (-6) */ 26 | ""}; 27 | 28 | 29 | const char * ZEXPORT zlibVersion() 30 | { 31 | return ZLIB_VERSION; 32 | } 33 | 34 | #ifdef DEBUG 35 | 36 | # ifndef verbose 37 | # define verbose 0 38 | # endif 39 | int z_verbose = verbose; 40 | 41 | void z_error (m) 42 | char *m; 43 | { 44 | fprintf(stderr, "%s\n", m); 45 | exit(1); 46 | } 47 | #endif 48 | 49 | /* exported to allow conversion of error code to string for compress() and 50 | * uncompress() 51 | */ 52 | const char * ZEXPORT zError(err) 53 | int err; 54 | { 55 | return ERR_MSG(err); 56 | } 57 | 58 | 59 | #ifndef HAVE_MEMCPY 60 | 61 | void zmemcpy(dest, source, len) 62 | Bytef* dest; 63 | const Bytef* source; 64 | uInt len; 65 | { 66 | if (len == 0) return; 67 | do { 68 | *dest++ = *source++; /* ??? to be unrolled */ 69 | } while (--len != 0); 70 | } 71 | 72 | int zmemcmp(s1, s2, len) 73 | const Bytef* s1; 74 | const Bytef* s2; 75 | uInt len; 76 | { 77 | uInt j; 78 | 79 | for (j = 0; j < len; j++) { 80 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 81 | } 82 | return 0; 83 | } 84 | 85 | void zmemzero(dest, len) 86 | Bytef* dest; 87 | uInt len; 88 | { 89 | if (len == 0) return; 90 | do { 91 | *dest++ = 0; /* ??? to be unrolled */ 92 | } while (--len != 0); 93 | } 94 | #endif 95 | 96 | #ifdef __TURBOC__ 97 | #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__) 98 | /* Small and medium model in Turbo C are for now limited to near allocation 99 | * with reduced MAX_WBITS and MAX_MEM_LEVEL 100 | */ 101 | # define MY_ZCALLOC 102 | 103 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 104 | * and farmalloc(64K) returns a pointer with an offset of 8, so we 105 | * must fix the pointer. Warning: the pointer must be put back to its 106 | * original form in order to free it, use zcfree(). 107 | */ 108 | 109 | #define MAX_PTR 10 110 | /* 10*64K = 640K */ 111 | 112 | local int next_ptr = 0; 113 | 114 | typedef struct ptr_table_s { 115 | voidpf org_ptr; 116 | voidpf new_ptr; 117 | } ptr_table; 118 | 119 | local ptr_table table[MAX_PTR]; 120 | /* This table is used to remember the original form of pointers 121 | * to large buffers (64K). Such pointers are normalized with a zero offset. 122 | * Since MSDOS is not a preemptive multitasking OS, this table is not 123 | * protected from concurrent access. This hack doesn't work anyway on 124 | * a protected system like OS/2. Use Microsoft C instead. 125 | */ 126 | 127 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 128 | { 129 | voidpf buf = opaque; /* just to make some compilers happy */ 130 | ulg bsize = (ulg)items*size; 131 | 132 | /* If we allocate less than 65520 bytes, we assume that farmalloc 133 | * will return a usable pointer which doesn't have to be normalized. 134 | */ 135 | if (bsize < 65520L) { 136 | buf = farmalloc(bsize); 137 | if (*(ush*)&buf != 0) return buf; 138 | } else { 139 | buf = farmalloc(bsize + 16L); 140 | } 141 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 142 | table[next_ptr].org_ptr = buf; 143 | 144 | /* Normalize the pointer to seg:0 */ 145 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 146 | *(ush*)&buf = 0; 147 | table[next_ptr++].new_ptr = buf; 148 | return buf; 149 | } 150 | 151 | void zcfree (voidpf opaque, voidpf ptr) 152 | { 153 | int n; 154 | if (*(ush*)&ptr != 0) { /* object < 64K */ 155 | farfree(ptr); 156 | return; 157 | } 158 | /* Find the original pointer */ 159 | for (n = 0; n < next_ptr; n++) { 160 | if (ptr != table[n].new_ptr) continue; 161 | 162 | farfree(table[n].org_ptr); 163 | while (++n < next_ptr) { 164 | table[n-1] = table[n]; 165 | } 166 | next_ptr--; 167 | return; 168 | } 169 | ptr = opaque; /* just to make some compilers happy */ 170 | Assert(0, "zcfree: ptr not found"); 171 | } 172 | #endif 173 | #endif /* __TURBOC__ */ 174 | 175 | 176 | #if defined(M_I86) && !defined(__32BIT__) 177 | /* Microsoft C in 16-bit mode */ 178 | 179 | # define MY_ZCALLOC 180 | 181 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 182 | # define _halloc halloc 183 | # define _hfree hfree 184 | #endif 185 | 186 | voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 187 | { 188 | if (opaque) opaque = 0; /* to make compiler happy */ 189 | return _halloc((long)items, size); 190 | } 191 | 192 | void zcfree (voidpf opaque, voidpf ptr) 193 | { 194 | if (opaque) opaque = 0; /* to make compiler happy */ 195 | _hfree(ptr); 196 | } 197 | 198 | #endif /* MSC */ 199 | 200 | 201 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 202 | 203 | #ifndef STDC 204 | extern voidp calloc OF((uInt items, uInt size)); 205 | extern void free OF((voidpf ptr)); 206 | #endif 207 | 208 | voidpf zcalloc (opaque, items, size) 209 | voidpf opaque; 210 | unsigned items; 211 | unsigned size; 212 | { 213 | if (opaque) items += size - size; /* make compiler happy */ 214 | return (voidpf)calloc(items, size); 215 | } 216 | 217 | void zcfree (opaque, ptr) 218 | voidpf opaque; 219 | voidpf ptr; 220 | { 221 | free(ptr); 222 | if (opaque) return; /* make compiler happy */ 223 | } 224 | 225 | #endif /* MY_ZCALLOC */ 226 | -------------------------------------------------------------------------------- /JPEG/jcapistd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * jcapistd.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface code for the compression half 9 | * of the JPEG library. These are the "standard" API routines that are 10 | * used in the normal full-compression case. They are not used by a 11 | * transcoding-only application. Note that if an application links in 12 | * jpeg_start_compress, it will end up linking in the entire compressor. 13 | * We thus must separate this file from jcapimin.c to avoid linking the 14 | * whole compression library into a transcoder. 15 | */ 16 | 17 | #define JPEG_INTERNALS 18 | #include "jinclude.h" 19 | #include "jpeglib.h" 20 | 21 | 22 | /* 23 | * Compression initialization. 24 | * Before calling this, all parameters and a data destination must be set up. 25 | * 26 | * We require a write_all_tables parameter as a failsafe check when writing 27 | * multiple datastreams from the same compression object. Since prior runs 28 | * will have left all the tables marked sent_table=TRUE, a subsequent run 29 | * would emit an abbreviated stream (no tables) by default. This may be what 30 | * is wanted, but for safety's sake it should not be the default behavior: 31 | * programmers should have to make a deliberate choice to emit abbreviated 32 | * images. Therefore the documentation and examples should encourage people 33 | * to pass write_all_tables=TRUE; then it will take active thought to do the 34 | * wrong thing. 35 | */ 36 | 37 | GLOBAL(void) 38 | jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables) 39 | { 40 | if (cinfo->global_state != CSTATE_START) 41 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 42 | 43 | if (write_all_tables) 44 | jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */ 45 | 46 | /* (Re)initialize error mgr and destination modules */ 47 | (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); 48 | (*cinfo->dest->init_destination) (cinfo); 49 | /* Perform master selection of active modules */ 50 | jinit_compress_master(cinfo); 51 | /* Set up for the first pass */ 52 | (*cinfo->master->prepare_for_pass) (cinfo); 53 | /* Ready for application to drive first pass through jpeg_write_scanlines 54 | * or jpeg_write_raw_data. 55 | */ 56 | cinfo->next_scanline = 0; 57 | cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING); 58 | } 59 | 60 | 61 | /* 62 | * Write some scanlines of data to the JPEG compressor. 63 | * 64 | * The return value will be the number of lines actually written. 65 | * This should be less than the supplied num_lines only in case that 66 | * the data destination module has requested suspension of the compressor, 67 | * or if more than image_height scanlines are passed in. 68 | * 69 | * Note: we warn about excess calls to jpeg_write_scanlines() since 70 | * this likely signals an application programmer error. However, 71 | * excess scanlines passed in the last valid call are *silently* ignored, 72 | * so that the application need not adjust num_lines for end-of-image 73 | * when using a multiple-scanline buffer. 74 | */ 75 | 76 | GLOBAL(JDIMENSION) 77 | jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines, 78 | JDIMENSION num_lines) 79 | { 80 | JDIMENSION row_ctr, rows_left; 81 | 82 | if (cinfo->global_state != CSTATE_SCANNING) 83 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 84 | if (cinfo->next_scanline >= cinfo->image_height) 85 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 86 | 87 | /* Call progress monitor hook if present */ 88 | if (cinfo->progress != NULL) { 89 | cinfo->progress->pass_counter = (long) cinfo->next_scanline; 90 | cinfo->progress->pass_limit = (long) cinfo->image_height; 91 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 92 | } 93 | 94 | /* Give master control module another chance if this is first call to 95 | * jpeg_write_scanlines. This lets output of the frame/scan headers be 96 | * delayed so that application can write COM, etc, markers between 97 | * jpeg_start_compress and jpeg_write_scanlines. 98 | */ 99 | if (cinfo->master->call_pass_startup) 100 | (*cinfo->master->pass_startup) (cinfo); 101 | 102 | /* Ignore any extra scanlines at bottom of image. */ 103 | rows_left = cinfo->image_height - cinfo->next_scanline; 104 | if (num_lines > rows_left) 105 | num_lines = rows_left; 106 | 107 | row_ctr = 0; 108 | (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines); 109 | cinfo->next_scanline += row_ctr; 110 | return row_ctr; 111 | } 112 | 113 | 114 | /* 115 | * Alternate entry point to write raw data. 116 | * Processes exactly one iMCU row per call, unless suspended. 117 | */ 118 | 119 | GLOBAL(JDIMENSION) 120 | jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data, 121 | JDIMENSION num_lines) 122 | { 123 | JDIMENSION lines_per_iMCU_row; 124 | 125 | if (cinfo->global_state != CSTATE_RAW_OK) 126 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 127 | if (cinfo->next_scanline >= cinfo->image_height) { 128 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 129 | return 0; 130 | } 131 | 132 | /* Call progress monitor hook if present */ 133 | if (cinfo->progress != NULL) { 134 | cinfo->progress->pass_counter = (long) cinfo->next_scanline; 135 | cinfo->progress->pass_limit = (long) cinfo->image_height; 136 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 137 | } 138 | 139 | /* Give master control module another chance if this is first call to 140 | * jpeg_write_raw_data. This lets output of the frame/scan headers be 141 | * delayed so that application can write COM, etc, markers between 142 | * jpeg_start_compress and jpeg_write_raw_data. 143 | */ 144 | if (cinfo->master->call_pass_startup) 145 | (*cinfo->master->pass_startup) (cinfo); 146 | 147 | /* Verify that at least one iMCU row has been passed. */ 148 | lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE; 149 | if (num_lines < lines_per_iMCU_row) 150 | ERREXIT(cinfo, JERR_BUFFER_SIZE); 151 | 152 | /* Directly compress the row. */ 153 | if (! (*cinfo->coef->compress_data) (cinfo, data)) { 154 | /* If compressor did not consume the whole row, suspend processing. */ 155 | return 0; 156 | } 157 | 158 | /* OK, we processed one iMCU row. */ 159 | cinfo->next_scanline += lines_per_iMCU_row; 160 | return lines_per_iMCU_row; 161 | } 162 | -------------------------------------------------------------------------------- /Src/Allocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef ALLOCATOR_INCLUDED 30 | #define ALLOCATOR_INCLUDED 31 | #include 32 | 33 | struct AllocatorState 34 | { 35 | size_t index , remains; 36 | AllocatorState( void ) : index(0) , remains(0) {} 37 | }; 38 | 39 | /** This templated class assists in memory allocation and is well suited for instances 40 | * when it is known that the sequence of memory allocations is performed in a stack-based 41 | * manner, so that memory allocated last is released first. It also preallocates memory 42 | * in chunks so that multiple requests for small chunks of memory do not require separate 43 | * system calls to the memory manager. 44 | * The allocator is templated off of the class of objects that we would like it to allocate, 45 | * ensuring that appropriate constructors and destructors are called as necessary. 46 | */ 47 | template< class T > 48 | class Allocator 49 | { 50 | size_t _blockSize; 51 | AllocatorState _state; 52 | std::vector< T* > _memory; 53 | public: 54 | Allocator( void ) : _blockSize(0) {} 55 | ~Allocator( void ){ reset(); } 56 | 57 | /** This method is the allocators destructor. It frees up any of the memory that 58 | * it has allocated. */ 59 | void reset( void ) 60 | { 61 | for( size_t i=0 ; i<_memory.size() ; i++ ) delete[] _memory[i]; 62 | _memory.clear(); 63 | _blockSize = 0; 64 | _state = AllocatorState(); 65 | } 66 | /** This method returns the memory state of the allocator. */ 67 | AllocatorState getState( void ) const { return _state; } 68 | 69 | 70 | /** This method rolls back the allocator so that it makes all of the memory previously 71 | * allocated available for re-allocation. Note that it does it not call the constructor 72 | * again, so after this method has been called, assumptions about the state of the values 73 | * in memory are no longer valid. */ 74 | void rollBack( void ) 75 | { 76 | if( _memory.size() ) 77 | { 78 | for( size_t i=0 ; i<_memory.size() ; i++ ) for( size_t j=0 ; j<_blockSize ; j++ ) 79 | { 80 | _memory[i][j].~T(); 81 | new( &_memory[i][j] ) T(); 82 | } 83 | _state = AllocatorState(); 84 | } 85 | } 86 | /** This method rolls back the allocator to the previous memory state and makes all of the memory previously 87 | * allocated available for re-allocation. Note that it does it not call the constructor 88 | * again, so after this method has been called, assumptions about the state of the values 89 | * in memory are no longer valid. */ 90 | void rollBack( const AllocatorState& state ) 91 | { 92 | if( state.index<_state.index || ( state.index==_state.index && state.remains<_state.remains ) ) 93 | { 94 | if( state.index<_state.index ) 95 | { 96 | for( size_t j=state.remains ; j<_blockSize ; j++ ) 97 | { 98 | _memory[ state.index ][j].~T(); 99 | new( &_memory[ state.index ][j] ) T(); 100 | } 101 | for( size_t i=state.index+1 ; i<_state.index-1 ; i++ ) for( size_t j=0 ; j<_blockSize ; j++ ) 102 | { 103 | _memory[i][j].~T(); 104 | new( &_memory[i][j] ) T(); 105 | } 106 | for( size_t j=0 ; j<_state.remains ; j++ ) 107 | { 108 | _memory[ _state.index ][j].~T(); 109 | new( &_memory[ _state.index ][j] ) T(); 110 | } 111 | _state = state; 112 | } 113 | else 114 | { 115 | for( size_t j=0 ; j_blockSize ) ERROR_OUT( "elements bigger than block-size: " , elements , " > " , _blockSize ); 145 | if( _state.remainsavail_in-n;c=(k>>3)>3:c;n+=c;p-=c;k-=c<<3;} 22 | 23 | /* Called with number of bytes left to write in window at least 258 24 | (the maximum string length) and number of input bytes available 25 | at least ten. The ten bytes are six bytes for the longest length/ 26 | distance pair plus four bytes for overloading the bit buffer. */ 27 | 28 | int inflate_fast(bl, bd, tl, td, s, z) 29 | uInt bl, bd; 30 | inflate_huft *tl; 31 | inflate_huft *td; /* need separate declaration for Borland C++ */ 32 | inflate_blocks_statef *s; 33 | z_streamp z; 34 | { 35 | inflate_huft *t; /* temporary pointer */ 36 | uInt e; /* extra bits or operation */ 37 | uLong b; /* bit buffer */ 38 | uInt k; /* bits in bit buffer */ 39 | Bytef *p; /* input data pointer */ 40 | uInt n; /* bytes available there */ 41 | Bytef *q; /* output window write pointer */ 42 | uInt m; /* bytes to end of window or read pointer */ 43 | uInt ml; /* mask for literal/length tree */ 44 | uInt md; /* mask for distance tree */ 45 | uInt c; /* bytes to copy */ 46 | uInt d; /* distance back to copy from */ 47 | Bytef *r; /* copy source pointer */ 48 | 49 | /* load input, output, bit values */ 50 | LOAD 51 | 52 | /* initialize masks */ 53 | ml = inflate_mask[bl]; 54 | md = inflate_mask[bd]; 55 | 56 | /* do until not enough input or output space for fast loop */ 57 | do { /* assume called with m >= 258 && n >= 10 */ 58 | /* get literal/length code */ 59 | GRABBITS(20) /* max bits for literal/length code */ 60 | if ((e = (t = tl + ((uInt)b & ml))->exop) == 0) 61 | { 62 | DUMPBITS(t->bits) 63 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? 64 | "inflate: * literal '%c'\n" : 65 | "inflate: * literal 0x%02x\n", t->base)); 66 | *q++ = (Byte)t->base; 67 | m--; 68 | continue; 69 | } 70 | do { 71 | DUMPBITS(t->bits) 72 | if (e & 16) 73 | { 74 | /* get extra bits for length */ 75 | e &= 15; 76 | c = t->base + ((uInt)b & inflate_mask[e]); 77 | DUMPBITS(e) 78 | Tracevv((stderr, "inflate: * length %u\n", c)); 79 | 80 | /* decode distance base of block to copy */ 81 | GRABBITS(15); /* max bits for distance code */ 82 | e = (t = td + ((uInt)b & md))->exop; 83 | do { 84 | DUMPBITS(t->bits) 85 | if (e & 16) 86 | { 87 | /* get extra bits to add to distance base */ 88 | e &= 15; 89 | GRABBITS(e) /* get extra bits (up to 13) */ 90 | d = t->base + ((uInt)b & inflate_mask[e]); 91 | DUMPBITS(e) 92 | Tracevv((stderr, "inflate: * distance %u\n", d)); 93 | 94 | /* do the copy */ 95 | m -= c; 96 | r = q - d; 97 | if (r < s->window) /* wrap if needed */ 98 | { 99 | do { 100 | r += s->end - s->window; /* force pointer in window */ 101 | } while (r < s->window); /* covers invalid distances */ 102 | e = s->end - r; 103 | if (c > e) 104 | { 105 | c -= e; /* wrapped copy */ 106 | do { 107 | *q++ = *r++; 108 | } while (--e); 109 | r = s->window; 110 | do { 111 | *q++ = *r++; 112 | } while (--c); 113 | } 114 | else /* normal copy */ 115 | { 116 | *q++ = *r++; c--; 117 | *q++ = *r++; c--; 118 | do { 119 | *q++ = *r++; 120 | } while (--c); 121 | } 122 | } 123 | else /* normal copy */ 124 | { 125 | *q++ = *r++; c--; 126 | *q++ = *r++; c--; 127 | do { 128 | *q++ = *r++; 129 | } while (--c); 130 | } 131 | break; 132 | } 133 | else if ((e & 64) == 0) 134 | { 135 | t += t->base; 136 | e = (t += ((uInt)b & inflate_mask[e]))->exop; 137 | } 138 | else 139 | { 140 | z->msg = (char*)"invalid distance code"; 141 | UNGRAB 142 | UPDATE 143 | return Z_DATA_ERROR; 144 | } 145 | } while (1); 146 | break; 147 | } 148 | if ((e & 64) == 0) 149 | { 150 | t += t->base; 151 | if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0) 152 | { 153 | DUMPBITS(t->bits) 154 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? 155 | "inflate: * literal '%c'\n" : 156 | "inflate: * literal 0x%02x\n", t->base)); 157 | *q++ = (Byte)t->base; 158 | m--; 159 | break; 160 | } 161 | } 162 | else if (e & 32) 163 | { 164 | Tracevv((stderr, "inflate: * end of block\n")); 165 | UNGRAB 166 | UPDATE 167 | return Z_STREAM_END; 168 | } 169 | else 170 | { 171 | z->msg = (char*)"invalid literal/length code"; 172 | UNGRAB 173 | UPDATE 174 | return Z_DATA_ERROR; 175 | } 176 | } while (1); 177 | } while (m >= 258 && n >= 10); 178 | 179 | /* not enough input or output--restore pointers and return */ 180 | UNGRAB 181 | UPDATE 182 | return Z_OK; 183 | } 184 | -------------------------------------------------------------------------------- /ZLIB/zutil.h: -------------------------------------------------------------------------------- 1 | /* zutil.h -- internal interface and configuration of the compression library 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | /* @(#) $Id: zutil.h,v 1.1 2014/03/04 21:20:44 uid42406 Exp $ */ 12 | 13 | #ifndef _Z_UTIL_H 14 | #define _Z_UTIL_H 15 | 16 | #include "zlib.h" 17 | 18 | #ifdef STDC 19 | # include 20 | # include 21 | # include 22 | #endif 23 | #ifdef NO_ERRNO_H 24 | extern int errno; 25 | #else 26 | # include 27 | #endif 28 | 29 | #ifndef local 30 | # define local static 31 | #endif 32 | /* compile with -Dlocal if your debugger can't find static symbols */ 33 | 34 | typedef unsigned char uch; 35 | typedef uch FAR uchf; 36 | typedef unsigned short ush; 37 | typedef ush FAR ushf; 38 | typedef unsigned long ulg; 39 | 40 | extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */ 41 | /* (size given to avoid silly warnings with Visual C++) */ 42 | 43 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] 44 | 45 | #define ERR_RETURN(strm,err) \ 46 | return (strm->msg = (char*)ERR_MSG(err), (err)) 47 | /* To be used only when the state is known to be valid */ 48 | 49 | /* common constants */ 50 | 51 | #ifndef DEF_WBITS 52 | # define DEF_WBITS MAX_WBITS 53 | #endif 54 | /* default windowBits for decompression. MAX_WBITS is for compression only */ 55 | 56 | #if MAX_MEM_LEVEL >= 8 57 | # define DEF_MEM_LEVEL 8 58 | #else 59 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 60 | #endif 61 | /* default memLevel */ 62 | 63 | #define STORED_BLOCK 0 64 | #define STATIC_TREES 1 65 | #define DYN_TREES 2 66 | /* The three kinds of block type */ 67 | 68 | #define MIN_MATCH 3 69 | #define MAX_MATCH 258 70 | /* The minimum and maximum match lengths */ 71 | 72 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ 73 | 74 | /* target dependencies */ 75 | 76 | #ifdef MSDOS 77 | # define OS_CODE 0x00 78 | # if defined(__TURBOC__) || defined(__BORLANDC__) 79 | # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) 80 | /* Allow compilation with ANSI keywords only enabled */ 81 | void _Cdecl farfree( void *block ); 82 | void *_Cdecl farmalloc( unsigned long nbytes ); 83 | # else 84 | # include 85 | # endif 86 | # else /* MSC or DJGPP */ 87 | # include 88 | # endif 89 | #endif 90 | 91 | #ifdef OS2 92 | # define OS_CODE 0x06 93 | #endif 94 | 95 | #ifdef WIN32 /* Window 95 & Windows NT */ 96 | # define OS_CODE 0x0b 97 | #endif 98 | 99 | #if defined(VAXC) || defined(VMS) 100 | # define OS_CODE 0x02 101 | # define F_OPEN(name, mode) \ 102 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") 103 | #endif 104 | 105 | #ifdef AMIGA 106 | # define OS_CODE 0x01 107 | #endif 108 | 109 | #if defined(ATARI) || defined(atarist) 110 | # define OS_CODE 0x05 111 | #endif 112 | 113 | #if defined(MACOS) || defined(TARGET_OS_MAC) 114 | # define OS_CODE 0x07 115 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 116 | # include /* for fdopen */ 117 | # else 118 | # ifndef fdopen 119 | # define fdopen(fd,mode) NULL /* No fdopen() */ 120 | # endif 121 | # endif 122 | #endif 123 | 124 | #ifdef __50SERIES /* Prime/PRIMOS */ 125 | # define OS_CODE 0x0F 126 | #endif 127 | 128 | #ifdef TOPS20 129 | # define OS_CODE 0x0a 130 | #endif 131 | 132 | #if defined(_BEOS_) || defined(RISCOS) 133 | # define fdopen(fd,mode) NULL /* No fdopen() */ 134 | #endif 135 | 136 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) 137 | # define fdopen(fd,type) _fdopen(fd,type) 138 | #endif 139 | 140 | 141 | /* Common defaults */ 142 | 143 | #ifndef OS_CODE 144 | # define OS_CODE 0x03 /* assume Unix */ 145 | #endif 146 | 147 | #ifndef F_OPEN 148 | # define F_OPEN(name, mode) fopen((name), (mode)) 149 | #endif 150 | 151 | /* functions */ 152 | 153 | #ifdef HAVE_STRERROR 154 | extern char *strerror OF((int)); 155 | # define zstrerror(errnum) strerror(errnum) 156 | #else 157 | # define zstrerror(errnum) "" 158 | #endif 159 | 160 | #if defined(pyr) 161 | # define NO_MEMCPY 162 | #endif 163 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) 164 | /* Use our own functions for small and medium model with MSC <= 5.0. 165 | * You may have to use the same strategy for Borland C (untested). 166 | * The __SC__ check is for Symantec. 167 | */ 168 | # define NO_MEMCPY 169 | #endif 170 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) 171 | # define HAVE_MEMCPY 172 | #endif 173 | #ifdef HAVE_MEMCPY 174 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */ 175 | # define zmemcpy _fmemcpy 176 | # define zmemcmp _fmemcmp 177 | # define zmemzero(dest, len) _fmemset(dest, 0, len) 178 | # else 179 | # define zmemcpy memcpy 180 | # define zmemcmp memcmp 181 | # define zmemzero(dest, len) memset(dest, 0, len) 182 | # endif 183 | #else 184 | extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); 185 | extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); 186 | extern void zmemzero OF((Bytef* dest, uInt len)); 187 | #endif 188 | 189 | /* Diagnostic functions */ 190 | #ifdef DEBUG 191 | # include 192 | extern int z_verbose; 193 | extern void z_error OF((char *m)); 194 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);} 195 | # define Trace(x) {if (z_verbose>=0) fprintf x ;} 196 | # define Tracev(x) {if (z_verbose>0) fprintf x ;} 197 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;} 198 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} 199 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} 200 | #else 201 | # define Assert(cond,msg) 202 | # define Trace(x) 203 | # define Tracev(x) 204 | # define Tracevv(x) 205 | # define Tracec(c,x) 206 | # define Tracecv(c,x) 207 | #endif 208 | 209 | 210 | typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, 211 | uInt len)); 212 | voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size)); 213 | void zcfree OF((voidpf opaque, voidpf ptr)); 214 | 215 | #define ZALLOC(strm, items, size) \ 216 | (*((strm)->zalloc))((strm)->opaque, (items), (size)) 217 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) 218 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);} 219 | 220 | #endif /* _Z_UTIL_H */ 221 | -------------------------------------------------------------------------------- /Src/BlockedVector.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | 30 | #ifndef BLOCKED_VECTOR_INCLUDED 31 | #define BLOCKED_VECTOR_INCLUDED 32 | 33 | #include "MyMiscellany.h" 34 | 35 | // This represents a vector that can only grow in size. 36 | // It has the property that once a reference to an element is returned, that reference remains valid until the vector is destroyed. 37 | template< typename T , unsigned int LogBlockSize=10 , unsigned int InitialBlocks=10 , unsigned int AllocationMultiplier=2 > 38 | struct BlockedVector 39 | { 40 | BlockedVector( T defaultValue=T() ) : _defaultValue( defaultValue ) 41 | { 42 | _reservedBlocks = InitialBlocks; 43 | _blocks = NewPointer< Pointer( T ) >( _reservedBlocks ); 44 | for( size_t i=0 ; i<_reservedBlocks ; i++ ) _blocks[i] = NullPointer( T ); 45 | _allocatedBlocks = _size = 0; 46 | } 47 | ~BlockedVector( void ) 48 | { 49 | for( size_t i=0 ; i<_allocatedBlocks ; i++ ) DeletePointer( _blocks[i] ); 50 | DeletePointer( _blocks ); 51 | } 52 | BlockedVector( const BlockedVector& v ) 53 | { 54 | _reservedBlocks = v._reservedBlocks , _allocatedBlocks = v._allocatedBlocks , _size = v._size , _defaultValue = v._defaultValue; 55 | _blocks = NewPointer< Pointer( T ) >( _reservedBlocks ); 56 | for( size_t i=0 ; i<_allocatedBlocks ; i++ ) 57 | { 58 | _blocks[i] = NewPointer< T >( _BlockSize ); 59 | memcpy( _blocks[i] , v._blocks[i] , sizeof(T)*_BlockSize ); 60 | } 61 | for( size_t i=_allocatedBlocks ; i<_reservedBlocks ; i++ ) _blocks[i] = NullPointer( Pointer ( T ) ); 62 | } 63 | BlockedVector& operator = ( const BlockedVector& v ) 64 | { 65 | for( size_t i=0 ; i<_allocatedBlocks ; i++ ) DeletePointer( _blocks[i] ); 66 | DeletePointer( _blocks ); 67 | _reservedBlocks = v._reservedBlocks , _blocks = v._blocks , _allocatedBlocks = v._allocatedBlocks , _size = v._size , _defaultValue = v._defaultValue; 68 | _blocks = NewPointer< Pointer( T ) >( _reservedBlocks ); 69 | for( size_t i=0 ; i<_allocatedBlocks ; i++ ) 70 | { 71 | _blocks[i] = NewPointer< T >( _BlockSize ); 72 | memcpy( _blocks[i] , v._blocks[i] , sizeof(T)*_BlockSize ); 73 | } 74 | for( size_t i=_allocatedBlocks ; i<_reservedBlocks ; i++ ) _blocks[i] = NullPointer( T ); 75 | return *this; 76 | } 77 | BlockedVector( BlockedVector&& v ) 78 | { 79 | _reservedBlocks = v._reservedBlocks , _allocatedBlocks = v._allocatedBlocks , _size = v._size , _defaultValue = v._defaultValue , _blocks = v._blocks; 80 | v._reservedBlocks = v._allocatedBlocks = v._size = 0 , v._blocks = NullPointer( Pointer( T ) ); 81 | } 82 | BlockedVector& operator = ( BlockedVector&& v ) 83 | { 84 | for( size_t i=0 ; i<_allocatedBlocks ; i++ ) DeletePointer( _blocks[i] ); 85 | DeletePointer( _blocks ); 86 | _reservedBlocks = v._reservedBlocks , _allocatedBlocks = v._allocatedBlocks , _size = v._size , _defaultValue = v._defaultValue , _blocks = v._blocks; 87 | v._reservedBlocks = v._allocatedBlocks = v._size = 0 , v._blocks = NullPointer( Pointer( T ) ); 88 | return *this; 89 | } 90 | 91 | size_t size( void ) const { return _size; } 92 | const T& operator[]( size_t idx ) const { return _blocks[idx>>LogBlockSize][idx&_Mask]; } 93 | T& operator[]( size_t idx ){ return _blocks[idx>>LogBlockSize][idx&_Mask]; } 94 | 95 | size_t resize( size_t size ){ return resize( size , _defaultValue ); } 96 | size_t resize( size_t size , const T& defaultValue ) 97 | { 98 | if( size<=_size ) 99 | { 100 | #ifdef _MSC_VER 101 | WARN( "BlockedVector::resize: new size must be greater than old size: " , size , " > " , _size ); 102 | #else // !MSC_VER 103 | WARN( "BlockedVector::resize: new size must be greater than old size: " , size , " > ", _size ); 104 | #endif // _MSC_VER 105 | return _size; 106 | } 107 | size_t index = size-1; 108 | size_t block = index >> LogBlockSize; 109 | size_t blockIndex = index & _Mask; 110 | 111 | // If there are insufficiently many blocks 112 | if( block>=_reservedBlocks ) 113 | { 114 | size_t newReservedSize = std::max< size_t >( _reservedBlocks * AllocationMultiplier , block+1 ); 115 | Pointer( Pointer( T ) ) __blocks = NewPointer< Pointer( T ) >( newReservedSize ); 116 | memcpy( __blocks , _blocks , sizeof( Pointer( T ) ) * _reservedBlocks ); 117 | for( size_t i=_reservedBlocks ; i=_allocatedBlocks ) 126 | { 127 | for( size_t b=_allocatedBlocks ; b<=block ; b++ ) 128 | { 129 | _blocks[b] = NewPointer< T >( _BlockSize ); 130 | for( size_t i=0 ; i<_BlockSize ; i++ ) _blocks[b][i] = defaultValue; 131 | } 132 | _allocatedBlocks = block+1; 133 | } 134 | _size = index+1; 135 | return index; 136 | } 137 | size_t push( void ){ return resize( _size+1 ); } 138 | 139 | protected: 140 | static const size_t _BlockSize = 1< 22 | 23 | //! Wrapper to use PoissonRecon (Kazhdan et. al) as a library 24 | class PoissonReconLib 25 | { 26 | public: 27 | 28 | //! Algorithm parameters 29 | struct Parameters 30 | { 31 | //! Default initializer 32 | Parameters(); 33 | 34 | //! Returns the maximum number of threads 35 | static int GetMaxThreadCount(); 36 | 37 | //! Boundary types 38 | enum BoundaryType { FREE, DIRICHLET, NEUMANN }; 39 | 40 | //! Boundary type for the finite elements 41 | BoundaryType boundary = NEUMANN; 42 | 43 | //! The maximum depth of the tree that will be used for surface reconstruction 44 | /** Running at depth d corresponds to solving on a 2^d x 2^d x 2^d. 45 | Note that since the reconstructor adapts the octree to the sampling density, 46 | the specified reconstruction depth is only an upper bound. 47 | **/ 48 | int depth = 8; 49 | 50 | //! The target width of the finest level octree cells (ignored if depth is specified) 51 | float finestCellWidth = 0.0f; 52 | 53 | //! The ratio between the diameter of the cube used for reconstruction and the diameter of the samples' bounding cube. 54 | /** Specifies the factor of the bounding cube that the input samples should fit into. 55 | **/ 56 | float scale = 1.1f; 57 | 58 | //! The minimum number of sample points that should fall within an octree node as the octree construction is adapted to sampling density. 59 | /** This parameter specifies the minimum number of points that should fall within an octree node. 60 | For noise-free samples, small values in the range [1.0 - 5.0] can be used. For more noisy samples, larger values 61 | in the range [15.0 - 20.0] may be needed to provide a smoother, noise-reduced, reconstruction. 62 | **/ 63 | float samplesPerNode = 1.5f; 64 | 65 | //! The importance that interpolation of the point samples is given in the formulation of the screened Poisson equation. 66 | /** The results of the original (unscreened) Poisson Reconstruction can be obtained by setting this value to 0. 67 | **/ 68 | float pointWeight = 2.0f; 69 | 70 | //! The number of solver iterations 71 | /** Number of Gauss-Seidel relaxations to be performed at each level of the octree hierarchy. 72 | **/ 73 | int iters = 8; 74 | 75 | //! If this flag is enabled, the sampling density is written out with the vertices 76 | bool density = false; 77 | 78 | //! This flag tells the reconstructor to read in color values with the input points and extrapolate those to the vertices of the output. 79 | bool withColors = true; 80 | 81 | //! Data pull factor 82 | /** If withColors is rue, this floating point value specifies the relative importance of finer color estimates over lower ones. 83 | **/ 84 | float colorPullFactor = 32.0f; 85 | 86 | //! Normal confidence exponent 87 | /** Exponent to be applied to a point's confidence to adjust its weight. (A point's confidence is defined by the magnitude of its normal.) 88 | **/ 89 | float normalConfidence = 0.0; 90 | 91 | //! Normal confidence bias exponent 92 | /** Exponent to be applied to a point's confidence to bias the resolution at which the sample contributes to the linear system. (Points with lower confidence are biased to contribute at coarser resolutions.) 93 | **/ 94 | float normalConfidenceBias = 0.0; 95 | 96 | //! Enabling this flag has the reconstructor use linear interpolation to estimate the positions of iso-vertices. 97 | bool linearFit = false; 98 | 99 | //! This parameter specifies the number of threads across which the solver should be parallelized 100 | int threads = 1; 101 | 102 | /** The parameters below are accessible via the command line but are not described in the official documentation **/ 103 | 104 | //! The depth beyond which the octree will be adapted. 105 | /** At coarser depths, the octree will be complete, containing all 2^d x 2^d x 2^d nodes. 106 | **/ 107 | int fullDepth = 5; 108 | 109 | //! Coarse MG solver depth 110 | int baseDepth = 0; 111 | 112 | //! Coarse MG solver v-cycles 113 | int baseVCycles = 1; 114 | 115 | //! This flag specifies the accuracy cut-off to be used for CG 116 | float cgAccuracy = 1.0e-3f; 117 | 118 | }; 119 | 120 | //! Input cloud interface 121 | template class ICloud 122 | { 123 | public: 124 | virtual size_t size() const = 0; 125 | virtual bool hasNormals() const = 0; 126 | virtual bool hasColors() const = 0; 127 | virtual void getPoint(size_t index, Real* coords) const = 0; 128 | virtual void getNormal(size_t index, Real* coords) const = 0; 129 | virtual void getColor(size_t index, Real* rgb) const = 0; 130 | }; 131 | 132 | //! Output mesh interface 133 | template class IMesh 134 | { 135 | public: 136 | virtual void addVertex(const Real* coords) = 0; 137 | virtual void addNormal(const Real* coords) = 0; 138 | virtual void addColor(const Real* rgb) = 0; 139 | virtual void addDensity(double d) = 0; 140 | virtual void addTriangle(size_t i1, size_t i2, size_t i3) = 0; 141 | }; 142 | 143 | //! Reconstruct a mesh from a point cloud (float version) 144 | static bool Reconstruct(const Parameters& params, 145 | const PoissonReconLib::ICloud& inCloud, 146 | PoissonReconLib::IMesh& ouMesh); 147 | 148 | //! Reconstruct a mesh from a point cloud (double version) 149 | static bool Reconstruct(const Parameters& params, 150 | const PoissonReconLib::ICloud& inCloud, 151 | PoissonReconLib::IMesh& ouMesh); 152 | 153 | }; 154 | 155 | #endif // CC_POISSON_RECON_LIB_12_0_WRAPPER 156 | -------------------------------------------------------------------------------- /Src/MAT.inl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007, Michael Kazhdan 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | ////////////////////////////// 30 | // MinimalAreaTriangulation // 31 | ////////////////////////////// 32 | template< typename Index , class Real , unsigned int Dim > 33 | _MinimalAreaTriangulation< Index , Real , Dim >::_MinimalAreaTriangulation( ConstPointer( Point< Real , Dim > ) vertices , size_t vCount ) : _vertices( vertices ) , _vCount( vCount ) 34 | { 35 | _bestTriangulation = NullPointer( Real ); 36 | _midpoint = NullPointer( Index ); 37 | } 38 | template< typename Index , class Real , unsigned int Dim > 39 | _MinimalAreaTriangulation< Index , Real , Dim >::~_MinimalAreaTriangulation( void ) 40 | { 41 | FreePointer( _bestTriangulation ); 42 | FreePointer( _midpoint ); 43 | } 44 | template< typename Index , class Real , unsigned int Dim > 45 | std::vector< TriangleIndex< Index > > _MinimalAreaTriangulation< Index , Real , Dim >::getTriangulation( void ) 46 | { 47 | std::vector< TriangleIndex< Index > > triangles; 48 | if( _vCount==3 ) 49 | { 50 | triangles.resize(1); 51 | triangles[0].idx[0] = 0; 52 | triangles[0].idx[1] = 1; 53 | triangles[0].idx[2] = 2; 54 | return triangles; 55 | } 56 | else if( _vCount==4 ) 57 | { 58 | TriangleIndex< Index > tIndex[2][2]; 59 | Real area[] = { 0 , 0 }; 60 | 61 | triangles.resize(2); 62 | 63 | tIndex[0][0].idx[0]=0; 64 | tIndex[0][0].idx[1]=1; 65 | tIndex[0][0].idx[2]=2; 66 | tIndex[0][1].idx[0]=2; 67 | tIndex[0][1].idx[1]=3; 68 | tIndex[0][1].idx[2]=0; 69 | 70 | tIndex[1][0].idx[0]=0; 71 | tIndex[1][0].idx[1]=1; 72 | tIndex[1][0].idx[2]=3; 73 | tIndex[1][1].idx[0]=3; 74 | tIndex[1][1].idx[1]=1; 75 | tIndex[1][1].idx[2]=2; 76 | 77 | Point< Real , Dim > p1 , p2; 78 | for( int i=0 ; i<2 ; i++ ) for( int j=0 ; j<2 ; j++ ) area[i] = SquareArea( _vertices[ tIndex[i][j].idx[0] ] , _vertices[ tIndex[i][j].idx[1] ] , _vertices[ tIndex[i][j].idx[2] ] ); 79 | if( area[0]>area[1] ) triangles[0] = tIndex[1][0] , triangles[1] = tIndex[1][1]; 80 | else triangles[0] = tIndex[0][0] , triangles[1] = tIndex[0][1]; 81 | return triangles; 82 | } 83 | _set(); 84 | _addTriangles( 1 , 0 , triangles ); 85 | return triangles; 86 | } 87 | template< typename Index , class Real , unsigned int Dim > 88 | void _MinimalAreaTriangulation< Index , Real , Dim >::_set( void ) 89 | { 90 | FreePointer( _bestTriangulation ); 91 | FreePointer( _midpoint ); 92 | _bestTriangulation = AllocPointer< Real >( _vCount * _vCount ); 93 | _midpoint = AllocPointer< Index >( _vCount * _vCount ); 94 | for( int i=0 ; i<_vCount*_vCount ; i++ ) _bestTriangulation[i] = -1 , _midpoint[i] = -1; 95 | _subPolygonArea( 1 , 0 ); 96 | } 97 | 98 | template< typename Index , class Real , unsigned int Dim > 99 | Index _MinimalAreaTriangulation< Index , Real , Dim >::_subPolygonIndex( Index i , Index j ) const { return (Index)( i*_vCount+j ); } 100 | 101 | template< typename Index , class Real , unsigned int Dim > 102 | void _MinimalAreaTriangulation< Index , Real , Dim >::_addTriangles( Index i , Index j , std::vector< TriangleIndex< Index > >& triangles ) const 103 | { 104 | TriangleIndex< Index > tIndex; 105 | if( j 121 | Real _MinimalAreaTriangulation< Index , Real , Dim >::_subPolygonArea( Index i , Index j ) 122 | { 123 | Index idx = _subPolygonIndex( i , j ); 124 | if( _midpoint[idx]!=-1 ) return _bestTriangulation[idx]; 125 | Real a = FLT_MAX , temp; 126 | if( j=0 ) 149 | { 150 | temp += _bestTriangulation[idx1]; 151 | // If the partial area is already too large, terminate 152 | if( temp>a ) continue; // Terminate early 153 | // Otherwise, compute the total area 154 | temp += _subPolygonArea( r%_vCount , j%_vCount ); 155 | } 156 | else 157 | { 158 | // Otherwise, compute it now 159 | temp += _subPolygonArea( r%_vCount , j%_vCount ); 160 | // If the partial area is already too large, terminate 161 | if( temp>a ) continue; 162 | // Otherwise, compute the total area 163 | temp += _subPolygonArea( i , r%_vCount ); 164 | } 165 | 166 | if( temp> 1) : c >> 1; 60 | crc_table[n] = c; 61 | } 62 | crc_table_empty = 0; 63 | } 64 | #else 65 | /* ======================================================================== 66 | * Table of CRC-32's of all single-byte values (made by make_crc_table) 67 | */ 68 | local const uLongf crc_table[256] = { 69 | 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 70 | 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L, 71 | 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 72 | 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 73 | 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L, 74 | 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 75 | 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 76 | 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL, 77 | 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 78 | 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL, 79 | 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 80 | 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 81 | 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L, 82 | 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 83 | 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 84 | 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L, 85 | 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 86 | 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L, 87 | 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 88 | 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 89 | 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL, 90 | 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 91 | 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 92 | 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL, 93 | 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 94 | 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L, 95 | 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 96 | 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 97 | 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L, 98 | 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 99 | 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 100 | 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L, 101 | 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 102 | 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL, 103 | 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 104 | 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 105 | 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL, 106 | 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 107 | 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 108 | 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L, 109 | 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 110 | 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L, 111 | 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 112 | 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 113 | 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L, 114 | 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 115 | 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 116 | 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L, 117 | 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 118 | 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L, 119 | 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 120 | 0x2d02ef8dL 121 | }; 122 | #endif 123 | 124 | /* ========================================================================= 125 | * This function can be used by asm versions of crc32() 126 | */ 127 | const uLongf * ZEXPORT get_crc_table() 128 | { 129 | #ifdef DYNAMIC_CRC_TABLE 130 | if (crc_table_empty) make_crc_table(); 131 | #endif 132 | return (const uLongf *)crc_table; 133 | } 134 | 135 | /* ========================================================================= */ 136 | #define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8); 137 | #define DO2(buf) DO1(buf); DO1(buf); 138 | #define DO4(buf) DO2(buf); DO2(buf); 139 | #define DO8(buf) DO4(buf); DO4(buf); 140 | 141 | /* ========================================================================= */ 142 | uLong ZEXPORT crc32(crc, buf, len) 143 | uLong crc; 144 | const Bytef *buf; 145 | uInt len; 146 | { 147 | if (buf == Z_NULL) return 0L; 148 | #ifdef DYNAMIC_CRC_TABLE 149 | if (crc_table_empty) 150 | make_crc_table(); 151 | #endif 152 | crc = crc ^ 0xffffffffL; 153 | while (len >= 8) 154 | { 155 | DO8(buf); 156 | len -= 8; 157 | } 158 | if (len) do { 159 | DO1(buf); 160 | } while (--len); 161 | return crc ^ 0xffffffffL; 162 | } 163 | -------------------------------------------------------------------------------- /Src/Array.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Michael Kazhdan and Ming Chuang 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. Redistributions in binary form must reproduce 10 | the above copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the distribution. 12 | 13 | Neither the name of the Johns Hopkins University nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without specific 15 | prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES 19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 20 | SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 22 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 25 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 | DAMAGE. 27 | */ 28 | 29 | #ifndef ARRAY_INCLUDED 30 | #define ARRAY_INCLUDED 31 | 32 | #include 33 | 34 | #ifdef _WIN64 35 | #define ASSERT( x ) { if( !( x ) ) __debugbreak(); } 36 | #else // !_WIN64 37 | #ifdef _WIN32 38 | #define ASSERT( x ) { if( !( x ) ) _asm{ int 0x03 } } 39 | #else // !_WIN32 40 | #define ASSERT( x ) { if( !( x ) ) exit(0); } 41 | #endif // _WIN32 42 | #endif // _WIN64 43 | 44 | // Code from http://stackoverflow.com 45 | inline void* aligned_malloc( size_t size , size_t align ) 46 | { 47 | // Align enough for the data, the alignment padding, and room to store a pointer to the actual start of the memory 48 | void* mem = malloc( size + align + sizeof( void* ) ); 49 | // The position at which we could potentially start addressing 50 | char* amem = ( (char*)mem ) + sizeof( void* ); 51 | // Add align-1 to the start of the address and then zero out at most of the first align-1 bits. 52 | amem = ( char* )( ( (size_t)( ( (char*)amem ) + (align-1) ) ) & ~( align-1 ) ); 53 | // Pre-write the actual address 54 | ( ( void** ) amem )[-1] = mem; 55 | return amem; 56 | } 57 | inline void aligned_free( void* mem ) { free( ( ( void** )mem )[-1] ); } 58 | 59 | #ifdef ARRAY_DEBUG 60 | #ifdef SHOW_WARNINGS 61 | #pragma message ( "[WARNING] Array debugging is enabled" ) 62 | #endif // SHOW_WARNINGS 63 | #include "Array.inl" 64 | #define Pointer( ... ) Array< __VA_ARGS__ > 65 | #define ConstPointer( ... ) ConstArray< __VA_ARGS__ > 66 | #define NullPointer( ... ) Array< __VA_ARGS__ >() 67 | template< class C > void FreePointer( Array< C >& a ){ a.Free( ); } 68 | template< class C > void AlignedFreePointer( Array< C >& a ){ a.Free( ); } 69 | template< class C > void VFreePointer( Array< C >& a ){ a.Free( ); } 70 | template< class C > void DeletePointer( Array< C >& a ){ a.Delete( ); } 71 | 72 | template< class C > Array< C > NewPointer( size_t size , const char* name=NULL ){ return Array< C >::New ( size , name ); } 73 | template< class C > Array< C > AllocPointer( size_t size , const char* name=NULL ){ return Array< C >::Alloc ( size , false , name ); } 74 | template< class C > Array< C > AlignedAllocPointer( size_t size , size_t alignment , const char* name=NULL ){ return Array< C >::AlignedAlloc( size , alignment , false , name ); } 75 | template< class C > Array< C > ReAllocPointer( Array< C >& a , size_t size , const char* name=NULL ){ return Array< C >::ReAlloc ( a , size , false , name ); } 76 | 77 | template< class C > C* PointerAddress( Array< C >& a ) { return a.pointer(); } 78 | template< class C > const C* PointerAddress( ConstArray< C >& a ) { return a.pointer(); } 79 | template< class C > Array< C > GetPointer( C& c ) { return Array< C >::FromPointer( &c , 1 ); } 80 | template< class C > ConstArray< C > GetPointer( const C& c ) { return ConstArray< C >::FromPointer( &c , 1 ); } 81 | template< class C > Array< C > GetPointer( std::vector< C >& v ){ return Array< C >::FromPointer( &v[0] , v.size() ); } 82 | template< class C > ConstArray< C > GetPointer( const std::vector< C >& v ){ return ConstArray< C >::FromPointer( &v[0] , v.size() ); } 83 | 84 | template< class C > Array< C > GetPointer( C* c , size_t sz ) { return Array< C >::FromPointer( c , sz ); } 85 | template< class C > ConstArray< C > GetPointer( const C* c , size_t sz ) { return ConstArray< C >::FromPointer( c , sz ); } 86 | template< class C > Array< C > GetPointer( C* c , std::ptrdiff_t start , std::ptrdiff_t end ) { return Array< C >::FromPointer( c , start , end ); } 87 | template< class C > ConstArray< C > GetPointer( const C* c , std::ptrdiff_t start , std::ptrdiff_t end ) { return ConstArray< C >::FromPointer( c , start , end ); } 88 | 89 | #else // !ARRAY_DEBUG 90 | #define Pointer( ... ) __VA_ARGS__* 91 | #define ConstPointer( ... ) const __VA_ARGS__* 92 | #define NullPointer( ... ) NULL 93 | 94 | #define FreePointer( ... ) { if( __VA_ARGS__ ) free( __VA_ARGS__ ) , __VA_ARGS__ = NULL; } 95 | #define AlignedFreePointer( ... ) { if( __VA_ARGS__ ) aligned_free( __VA_ARGS__ ) , __VA_ARGS__ = NULL; } 96 | #define DeletePointer( ... ) { if( __VA_ARGS__ ) delete[] __VA_ARGS__ , __VA_ARGS__ = NULL; } 97 | 98 | template< class C > C* NewPointer( size_t size , const char* name=NULL ){ return new C[size]; } 99 | template< class C > C* AllocPointer( size_t size , const char* name=NULL ){ return (C*) malloc( sizeof(C) * size ); } 100 | template< class C > C* AlignedAllocPointer( size_t size , size_t alignment , const char* name=NULL ){ return (C*)aligned_malloc( sizeof(C) * size , alignment ); } 101 | template< class C > C* ReAllocPointer( C* c , size_t size , const char* name=NULL ){ return (C*) realloc( c , sizeof(C) * size ); } 102 | 103 | //template< class C > C* NullPointer( void ){ return NULL; } 104 | 105 | template< class C > C* PointerAddress( C* c ){ return c; } 106 | template< class C > const C* PointerAddress( const C* c ){ return c; } 107 | template< class C > C* GetPointer( C& c ){ return &c; } 108 | template< class C > const C* GetPointer( const C& c ){ return &c; } 109 | template< class C > C* GetPointer( std::vector< C >& v ){ return &v[0]; } 110 | template< class C > const C* GetPointer( const std::vector< C >& v ){ return &v[0]; } 111 | 112 | template< class C > C* GetPointer( C* c , size_t sz ) { return c; } 113 | template< class C > const C* GetPointer( const C* c , size_t sz ) { return c; } 114 | template< class C > C* GetPointer( C* c , std::ptrdiff_t start , std::ptrdiff_t end ) { return c; } 115 | template< class C > const C* GetPointer( const C* c , std::ptrdiff_t start , std::ptrdiff_t end ) { return c; } 116 | #endif // ARRAY_DEBUG 117 | #endif // ARRAY_INCLUDED 118 | -------------------------------------------------------------------------------- /JPEG/jdct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jdct.h 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This include file contains common declarations for the forward and 9 | * inverse DCT modules. These declarations are private to the DCT managers 10 | * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms. 11 | * The individual DCT algorithms are kept in separate files to ease 12 | * machine-dependent tuning (e.g., assembly coding). 13 | */ 14 | 15 | 16 | /* 17 | * A forward DCT routine is given a pointer to a work area of type DCTELEM[]; 18 | * the DCT is to be performed in-place in that buffer. Type DCTELEM is int 19 | * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT 20 | * implementations use an array of type FAST_FLOAT, instead.) 21 | * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE). 22 | * The DCT outputs are returned scaled up by a factor of 8; they therefore 23 | * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This 24 | * convention improves accuracy in integer implementations and saves some 25 | * work in floating-point ones. 26 | * Quantization of the output coefficients is done by jcdctmgr.c. 27 | */ 28 | 29 | #if BITS_IN_JSAMPLE == 8 30 | typedef int DCTELEM; /* 16 or 32 bits is fine */ 31 | #else 32 | typedef INT32 DCTELEM; /* must have 32 bits */ 33 | #endif 34 | 35 | typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data)); 36 | typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data)); 37 | 38 | 39 | /* 40 | * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer 41 | * to an output sample array. The routine must dequantize the input data as 42 | * well as perform the IDCT; for dequantization, it uses the multiplier table 43 | * pointed to by compptr->dct_table. The output data is to be placed into the 44 | * sample array starting at a specified column. (Any row offset needed will 45 | * be applied to the array pointer before it is passed to the IDCT code.) 46 | * Note that the number of samples emitted by the IDCT routine is 47 | * DCT_scaled_size * DCT_scaled_size. 48 | */ 49 | 50 | /* typedef inverse_DCT_method_ptr is declared in jpegint.h */ 51 | 52 | /* 53 | * Each IDCT routine has its own ideas about the best dct_table element type. 54 | */ 55 | 56 | typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ 57 | #if BITS_IN_JSAMPLE == 8 58 | typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ 59 | #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ 60 | #else 61 | typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ 62 | #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ 63 | #endif 64 | typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ 65 | 66 | 67 | /* 68 | * Each IDCT routine is responsible for range-limiting its results and 69 | * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could 70 | * be quite far out of range if the input data is corrupt, so a bulletproof 71 | * range-limiting step is required. We use a mask-and-table-lookup method 72 | * to do the combined operations quickly. See the comments with 73 | * prepare_range_limit_table (in jdmaster.c) for more info. 74 | */ 75 | 76 | #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE) 77 | 78 | #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ 79 | 80 | 81 | /* Short forms of external names for systems with brain-damaged linkers. */ 82 | 83 | #ifdef NEED_SHORT_EXTERNAL_NAMES 84 | #define jpeg_fdct_islow jFDislow 85 | #define jpeg_fdct_ifast jFDifast 86 | #define jpeg_fdct_float jFDfloat 87 | #define jpeg_idct_islow jRDislow 88 | #define jpeg_idct_ifast jRDifast 89 | #define jpeg_idct_float jRDfloat 90 | #define jpeg_idct_4x4 jRD4x4 91 | #define jpeg_idct_2x2 jRD2x2 92 | #define jpeg_idct_1x1 jRD1x1 93 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 94 | 95 | /* Extern declarations for the forward and inverse DCT routines. */ 96 | 97 | EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data)); 98 | EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data)); 99 | EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data)); 100 | 101 | EXTERN(void) jpeg_idct_islow 102 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 103 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 104 | EXTERN(void) jpeg_idct_ifast 105 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 106 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 107 | EXTERN(void) jpeg_idct_float 108 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 109 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 110 | EXTERN(void) jpeg_idct_4x4 111 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 112 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 113 | EXTERN(void) jpeg_idct_2x2 114 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 115 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 116 | EXTERN(void) jpeg_idct_1x1 117 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 118 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 119 | 120 | 121 | /* 122 | * Macros for handling fixed-point arithmetic; these are used by many 123 | * but not all of the DCT/IDCT modules. 124 | * 125 | * All values are expected to be of type INT32. 126 | * Fractional constants are scaled left by CONST_BITS bits. 127 | * CONST_BITS is defined within each module using these macros, 128 | * and may differ from one module to the next. 129 | */ 130 | 131 | #define ONE ((INT32) 1) 132 | #define CONST_SCALE (ONE << CONST_BITS) 133 | 134 | /* Convert a positive real constant to an integer scaled by CONST_SCALE. 135 | * Caution: some C compilers fail to reduce "FIX(constant)" at compile time, 136 | * thus causing a lot of useless floating-point operations at run time. 137 | */ 138 | 139 | #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) 140 | 141 | /* Descale and correctly round an INT32 value that's scaled by N bits. 142 | * We assume RIGHT_SHIFT rounds towards minus infinity, so adding 143 | * the fudge factor is correct for either sign of X. 144 | */ 145 | 146 | #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) 147 | 148 | /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. 149 | * This macro is used only when the two inputs will actually be no more than 150 | * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a 151 | * full 32x32 multiply. This provides a useful speedup on many machines. 152 | * Unfortunately there is no way to specify a 16x16->32 multiply portably 153 | * in C, but some C compilers will do the right thing if you provide the 154 | * correct combination of casts. 155 | */ 156 | 157 | #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ 158 | #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) 159 | #endif 160 | #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ 161 | #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const))) 162 | #endif 163 | 164 | #ifndef MULTIPLY16C16 /* default definition */ 165 | #define MULTIPLY16C16(var,const) ((var) * (const)) 166 | #endif 167 | 168 | /* Same except both inputs are variables. */ 169 | 170 | #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ 171 | #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) 172 | #endif 173 | 174 | #ifndef MULTIPLY16V16 /* default definition */ 175 | #define MULTIPLY16V16(var1,var2) ((var1) * (var2)) 176 | #endif 177 | --------------------------------------------------------------------------------