├── bunny.jpg ├── zeta.A.0.jpg ├── zeta.A.5.jpg ├── zeta.B.0.jpg ├── zeta.B.5.jpg ├── Misha ├── Poly34.h ├── Poly34.inl ├── BMP.h ├── PBM.h ├── PNG.h ├── JPEG.h ├── SquaredEDT.h ├── IsoSurface3D.h ├── CmdLineParser.h ├── Rasterizer.h ├── JPEG.inl ├── MarchingCubes.h ├── PBM.inl └── Exceptions.h ├── bunny.saito.jpg ├── zeta.A.-2.jpg ├── zeta.B.-2.jpg ├── zeta.B.-5.jpg ├── zeta.B.10.jpg ├── bunny.danielsson.jpg ├── .gitignore ├── JPEG ├── jversion.h ├── jconfig.h ├── jchuff.h ├── jcinit.cpp ├── jmemnobs.cpp ├── jinclude.h ├── jcomapi.cpp ├── JPEG.vcxproj ├── jdtrans.cpp ├── jdatadst.cpp ├── jutils.cpp ├── jfdctflt.cpp ├── jcapistd.cpp └── jdct.h ├── ZLIB ├── inffast.h ├── infcodes.h ├── infblock.h ├── adler32.c ├── uncompr.c ├── infutil.c ├── compress.c ├── inftrees.h ├── infutil.h ├── ZLIB.vcxproj ├── zutil.c ├── inffast.c ├── zutil.h └── crc32.c ├── Makefile ├── EDTFromMesh ├── Makefile └── EDTFromMesh.cpp ├── MarchingCubes ├── Makefile └── MarchingCubes.cpp ├── EDTFromGrid ├── Makefile └── EDTFromGrid.cpp ├── PNG ├── Makefile ├── PNG.vcxproj ├── pngrio.c ├── pngdebug.h └── pngwio.c └── EDT.sln /bunny.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/bunny.jpg -------------------------------------------------------------------------------- /zeta.A.0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.A.0.jpg -------------------------------------------------------------------------------- /zeta.A.5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.A.5.jpg -------------------------------------------------------------------------------- /zeta.B.0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.B.0.jpg -------------------------------------------------------------------------------- /zeta.B.5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.B.5.jpg -------------------------------------------------------------------------------- /Misha/Poly34.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/Misha/Poly34.h -------------------------------------------------------------------------------- /bunny.saito.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/bunny.saito.jpg -------------------------------------------------------------------------------- /zeta.A.-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.A.-2.jpg -------------------------------------------------------------------------------- /zeta.B.-2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.B.-2.jpg -------------------------------------------------------------------------------- /zeta.B.-5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.B.-5.jpg -------------------------------------------------------------------------------- /zeta.B.10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/zeta.B.10.jpg -------------------------------------------------------------------------------- /Misha/Poly34.inl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/Misha/Poly34.inl -------------------------------------------------------------------------------- /bunny.danielsson.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mkazhdan/EDT/HEAD/bunny.danielsson.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | index.html 2 | *.zip 3 | .vs/* 4 | Bin/* 5 | *.o 6 | */x64/ 7 | *.filters 8 | */Documentation 9 | *.com 10 | */Release/ 11 | lpng1637 12 | PNG/V1 13 | PNG/V2 14 | *.user -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | programs = PNG EDTFromMesh EDTFromGrid MarchingCubes 2 | 3 | COMPILER ?= gcc 4 | 5 | # cd PNG && make COMPILER=$(COMPILER) 6 | 7 | # Allow "make -j" to operate in parallel over the programs. 8 | all: $(programs) 9 | $(programs): 10 | $(MAKE) -C $@ COMPILER=$(COMPILER) 11 | 12 | programs_debug = $(foreach n,$(programs),debug_$(n)) # pseudo-dependency to allow "make -j" parallelism 13 | debug: $(programs_debug) 14 | $(programs_debug): 15 | $(MAKE) -C $(@:debug_%:%) debug 16 | 17 | programs_clean = $(foreach n,$(programs),clean_$(n)) # pseudo-dependency to allow "make -j" parallelism 18 | clean: $(programs_clean) 19 | $(programs_clean): 20 | $(MAKE) -C $(@:clean_%=%) clean 21 | 22 | .PHONY: $(programs) $(programs_debug) $(programs_clean) 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /EDTFromMesh/Makefile: -------------------------------------------------------------------------------- 1 | TARGET=EDTFromMesh 2 | SOURCE=EDTFromMesh.cpp 3 | 4 | COMPILER ?= gcc 5 | 6 | CFLAGS += -fpermissive -fopenmp -Wno-deprecated -Wno-unused-result -Wno-format -msse2 -std=c++14 7 | LFLAGS += -lgomp 8 | 9 | CFLAGS_DEBUG = -DDEBUG -g3 10 | LFLAGS_DEBUG = 11 | 12 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -DNDEBUG 13 | LFLAGS_RELEASE = -O3 14 | 15 | SRC = ./ 16 | BIN = ./../Bin/Linux/ 17 | BIN = ./../Bin/Linux/ 18 | BIN_O = ./ 19 | INCLUDE = /usr/include/ -I../ 20 | 21 | ifeq ($(COMPILER),gcc) 22 | CC=gcc 23 | CXX=g++ 24 | else 25 | CC=clang 26 | CXX=clang++ 27 | endif 28 | 29 | MD=mkdir 30 | 31 | OBJECTS=$(addprefix $(BIN_O), $(addsuffix .o, $(basename $(SOURCE)))) 32 | 33 | all: CFLAGS += $(CFLAGS_RELEASE) 34 | all: LFLAGS += $(LFLAGS_RELEASE) 35 | all: $(BIN) 36 | all: $(BIN)$(TARGET) 37 | 38 | debug: CFLAGS += $(CFLAGS_DEBUG) 39 | debug: LFLAGS += $(LFLAGS_DEBUG) 40 | debug: $(BIN) 41 | debug: $(BIN)$(TARGET) 42 | 43 | clean: 44 | rm -f $(BIN)$(TARGET) 45 | rm -f $(OBJECTS) 46 | 47 | $(BIN): 48 | $(MD) -p $(BIN) 49 | 50 | $(BIN)$(TARGET): $(OBJECTS) 51 | $(CXX) -o $@ $(OBJECTS) $(LFLAGS) 52 | 53 | $(BIN_O)%.o: $(SRC)%.c 54 | $(CC) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 55 | 56 | $(BIN_O)%.o: $(SRC)%.cpp 57 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 58 | 59 | 60 | -------------------------------------------------------------------------------- /MarchingCubes/Makefile: -------------------------------------------------------------------------------- 1 | TARGET=MarchingCubes 2 | SOURCE=MarchingCubes.cpp 3 | 4 | COMPILER ?= gcc 5 | 6 | CFLAGS += -fpermissive -fopenmp -Wno-deprecated -Wno-unused-result -Wno-format -msse2 -std=c++14 7 | LFLAGS += -lgomp 8 | 9 | CFLAGS_DEBUG = -DDEBUG -g3 10 | LFLAGS_DEBUG = 11 | 12 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -DNDEBUG 13 | LFLAGS_RELEASE = -O3 14 | 15 | SRC = ./ 16 | BIN = ./../Bin/Linux/ 17 | BIN = ./../Bin/Linux/ 18 | BIN_O = ./ 19 | INCLUDE = /usr/include/ -I../ 20 | 21 | ifeq ($(COMPILER),gcc) 22 | CC=gcc 23 | CXX=g++ 24 | else 25 | CC=clang 26 | CXX=clang++ 27 | endif 28 | 29 | MD=mkdir 30 | 31 | OBJECTS=$(addprefix $(BIN_O), $(addsuffix .o, $(basename $(SOURCE)))) 32 | 33 | all: CFLAGS += $(CFLAGS_RELEASE) 34 | all: LFLAGS += $(LFLAGS_RELEASE) 35 | all: $(BIN) 36 | all: $(BIN)$(TARGET) 37 | 38 | debug: CFLAGS += $(CFLAGS_DEBUG) 39 | debug: LFLAGS += $(LFLAGS_DEBUG) 40 | debug: $(BIN) 41 | debug: $(BIN)$(TARGET) 42 | 43 | clean: 44 | rm -f $(BIN)$(TARGET) 45 | rm -f $(OBJECTS) 46 | 47 | $(BIN): 48 | $(MD) -p $(BIN) 49 | 50 | $(BIN)$(TARGET): $(OBJECTS) 51 | $(CXX) -o $@ $(OBJECTS) $(LFLAGS) 52 | 53 | $(BIN_O)%.o: $(SRC)%.c 54 | $(CC) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 55 | 56 | $(BIN_O)%.o: $(SRC)%.cpp 57 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 58 | 59 | 60 | -------------------------------------------------------------------------------- /EDTFromGrid/Makefile: -------------------------------------------------------------------------------- 1 | TARGET=EDTFromGrid 2 | SOURCE=EDTFromGrid.cpp 3 | 4 | COMPILER ?= gcc 5 | 6 | CFLAGS += -fpermissive -fopenmp -Wno-deprecated -Wno-unused-result -Wno-format -msse2 -std=c++14 7 | LFLAGS += -L$(BIN) -lgomp -ljpeg -lmypng -lz 8 | 9 | CFLAGS_DEBUG = -DDEBUG -g3 10 | LFLAGS_DEBUG = 11 | 12 | CFLAGS_RELEASE = -O3 -DRELEASE -funroll-loops -ffast-math -DNDEBUG 13 | LFLAGS_RELEASE = -O3 14 | 15 | SRC = ./ 16 | BIN = ./../Bin/Linux/ 17 | BIN = ./../Bin/Linux/ 18 | BIN_O = ./ 19 | INCLUDE = /usr/include/ -I../ 20 | 21 | ifeq ($(COMPILER),gcc) 22 | CC=gcc 23 | CXX=g++ 24 | else 25 | CC=clang 26 | CXX=clang++ 27 | endif 28 | 29 | MD=mkdir 30 | 31 | OBJECTS=$(addprefix $(BIN_O), $(addsuffix .o, $(basename $(SOURCE)))) 32 | 33 | all: CFLAGS += $(CFLAGS_RELEASE) 34 | all: LFLAGS += $(LFLAGS_RELEASE) 35 | all: $(BIN) 36 | all: $(BIN)$(TARGET) 37 | 38 | debug: CFLAGS += $(CFLAGS_DEBUG) 39 | debug: LFLAGS += $(LFLAGS_DEBUG) 40 | debug: $(BIN) 41 | debug: $(BIN)$(TARGET) 42 | 43 | clean: 44 | rm -f $(BIN)$(TARGET) 45 | rm -f $(OBJECTS) 46 | 47 | $(BIN): 48 | $(MD) -p $(BIN) 49 | 50 | $(BIN)$(TARGET): $(OBJECTS) 51 | $(CXX) -o $@ $(OBJECTS) $(LFLAGS) 52 | 53 | $(BIN_O)%.o: $(SRC)%.c 54 | $(CC) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 55 | 56 | $(BIN_O)%.o: $(SRC)%.cpp 57 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 58 | 59 | 60 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /PNG/Makefile: -------------------------------------------------------------------------------- 1 | PNG_TARGET=libmypng.a 2 | PNG_SOURCE=png.c pngerror.c pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c pngset.c pngwio.c pngwrite.c pngwtran.c pngwutil.c pngtrans.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 24 | CXX=clang++ 25 | endif 26 | 27 | MD=mkdir 28 | 29 | PNG_OBJECTS=$(addprefix $(BIN), $(addsuffix .o, $(basename $(PNG_SOURCE)))) 30 | 31 | 32 | all: CFLAGS += $(CFLAGS_RELEASE) 33 | all: LFLAGS += $(LFLAGS_RELEASE) 34 | all: make_dir 35 | all: $(BIN)$(PNG_TARGET) 36 | 37 | debug: CFLAGS += $(CFLAGS_DEBUG) 38 | debug: LFLAGS += $(LFLAGS_DEBUG) 39 | debug: make_dir 40 | debug: $(BIN)$(PNG_TARGET) 41 | 42 | png: CFLAGS += $(CFLAGS_RELEASE) 43 | png: LFLAGS += $(LFLAGS_RELEASE) 44 | png: make_dir 45 | png: $(BIN)$(PNG_TARGET) 46 | 47 | clean: 48 | rm -rf $(BIN)$(PNG_TARGET) 49 | rm -rf $(PNG_OBJECTS) 50 | 51 | make_dir: 52 | $(MD) -p $(BIN) 53 | 54 | $(BIN)$(PNG_TARGET): $(PNG_OBJECTS) 55 | ar rcs $(BIN)$(PNG_TARGET) $(PNG_OBJECTS) 56 | 57 | $(BIN)%.o: $(SRC)%.c 58 | $(CC) -c -o $@ -I$(INCLUDE) $< 59 | 60 | $(BIN)%.o: $(SRC)%.cpp 61 | $(CXX) -c -o $@ $(CFLAGS) -I$(INCLUDE) $< 62 | 63 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Misha/BMP.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 BMP_INCLUDED 29 | #define BMP_INCLUDED 30 | 31 | 32 | struct BMPInfo 33 | { 34 | unsigned char* data; 35 | FILE* fp; 36 | int width , lineLength; 37 | }; 38 | 39 | struct BMPReader : public ImageReader 40 | { 41 | BMPReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 42 | ~BMPReader( void ); 43 | unsigned int nextRow( unsigned char* row ); 44 | static bool GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 45 | protected: 46 | unsigned int _currentRow; 47 | BMPInfo _info; 48 | }; 49 | 50 | struct BMPWriter : public ImageWriter 51 | { 52 | BMPWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality=100 ); 53 | ~BMPWriter( void ); 54 | unsigned int nextRow( const unsigned char* row ); 55 | unsigned int nextRows( const unsigned char* row , unsigned int rowNum ); 56 | protected: 57 | BMPInfo _info; 58 | unsigned int _currentRow; 59 | }; 60 | 61 | #include "BMP.inl" 62 | #endif //BMP_INCLUDED 63 | -------------------------------------------------------------------------------- /Misha/PBM.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 PBM_INCLUDED 29 | #define PBM_INCLUDED 30 | 31 | 32 | struct PBMInfo 33 | { 34 | unsigned char *data; 35 | FILE *fp; 36 | bool binary; 37 | unsigned int width , lineLength; 38 | }; 39 | 40 | struct PBMReader : public ImageReader 41 | { 42 | PBMReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 43 | ~PBMReader( void ); 44 | unsigned int nextRow( unsigned char* row ); 45 | static bool GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 46 | protected: 47 | unsigned int _currentRow; 48 | PBMInfo _info; 49 | }; 50 | 51 | struct PBMWriter : public ImageWriter 52 | { 53 | PBMWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality=100 ); 54 | ~PBMWriter( void ); 55 | unsigned int nextRow( const unsigned char* row ); 56 | unsigned int nextRows( const unsigned char* row , unsigned int rowNum ); 57 | protected: 58 | PBMInfo _info; 59 | unsigned int _currentRow; 60 | }; 61 | 62 | #include "PBM.inl" 63 | #endif // PBM_INCLUDED 64 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Misha/PNG.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 PNG_INCLUDED 29 | #define PNG_INCLUDED 30 | 31 | #if 1 // Does not play well with newer versions of PNG 32 | #include "PNG/png.h" 33 | #else 34 | #ifdef _WIN32 35 | #include "PNG/png.h" 36 | #else // !_WIN32 37 | #include 38 | #endif // _WIN32 39 | #endif 40 | 41 | #if PNG_LIBPNG_VER_MAJOR>=1 && PNG_LIBPNG_VER_MINOR>=5 42 | #define NEW_PNG 43 | #endif 44 | 45 | struct PNGReader : public ImageReader 46 | { 47 | PNGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 48 | ~PNGReader( void ); 49 | unsigned int nextRow( unsigned char* row ); 50 | static bool GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 51 | protected: 52 | FILE* _fp; 53 | png_structp _png_ptr; 54 | png_infop _info_ptr; 55 | png_infop _end_info ; 56 | unsigned int _currentRow; 57 | }; 58 | 59 | struct PNGWriter : public ImageWriter 60 | { 61 | PNGWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality=100 ); 62 | ~PNGWriter( void ); 63 | unsigned int nextRow( const unsigned char* row ); 64 | unsigned int nextRows( const unsigned char* rows , unsigned int rowNum ); 65 | protected: 66 | FILE* _fp; 67 | #ifdef NEW_PNG 68 | unsigned int _width; 69 | #endif // NEW_ONG 70 | png_structp _png_ptr; 71 | png_infop _info_ptr; 72 | unsigned int _currentRow; 73 | }; 74 | 75 | #include "PNG.inl" 76 | #endif //PNG_INCLUDED 77 | -------------------------------------------------------------------------------- /Misha/JPEG.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 JPEG_INCLUDED 29 | #define JPEG_INCLUDED 30 | //#include "Image.h" 31 | 32 | #include 33 | 34 | #ifdef _WIN32 35 | #include 36 | #include "JPEG/jpeglib.h" 37 | #include "JPEG/jerror.h" 38 | #include "JPEG/jmorecfg.h" 39 | #else // !_WIN32 40 | #include 41 | #include 42 | #include 43 | #endif // _WIN32 44 | 45 | struct my_error_mgr 46 | { 47 | struct jpeg_error_mgr pub; // "public" fields 48 | jmp_buf setjmp_buffer; // for return to caller 49 | }; 50 | typedef struct my_error_mgr * my_error_ptr; 51 | 52 | struct JPEGReader : public ImageReader 53 | { 54 | JPEGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 55 | ~JPEGReader( void ); 56 | unsigned int nextRow( unsigned char* row ); 57 | static bool GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ); 58 | protected: 59 | FILE* _fp; 60 | struct jpeg_decompress_struct _cInfo; 61 | struct my_error_mgr _jErr; 62 | unsigned int _currentRow; 63 | }; 64 | 65 | struct JPEGWriter : public ImageWriter 66 | { 67 | JPEGWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality=100 ); 68 | ~JPEGWriter( void ); 69 | unsigned int nextRow( const unsigned char* row ); 70 | unsigned int nextRows( const unsigned char* rows , unsigned int rowNum ); 71 | protected: 72 | FILE* _fp; 73 | struct jpeg_compress_struct _cInfo; 74 | struct my_error_mgr _jErr; 75 | unsigned int _currentRow; 76 | }; 77 | 78 | #include "JPEG.inl" 79 | #endif //JPEG_INCLUDED 80 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Misha/SquaredEDT.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, 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 | #ifndef SQUARED_EDT_INCLUDED 30 | #define SQUARED_EDT_INCLUDED 31 | 32 | #include "Array.h" 33 | #include "Geometry.h" 34 | #include "RegularGrid.h" 35 | #include "Rasterizer.h" 36 | 37 | namespace Misha 38 | { 39 | template< typename Real , unsigned int Dim > 40 | struct SquaredEDT 41 | { 42 | // [Saito and Toriwaki, '94] 43 | // New algorithms for Euclidean Distance Transformation of an n-dimensional digitized picture with applications 44 | // {Returns the distance in voxel units} 45 | template< typename BinaryType > 46 | static RegularGrid< unsigned int , Dim > Saito( const RegularGrid< BinaryType , Dim > &binaryGrid , bool verbose=false ); 47 | template< typename BinaryType > 48 | static RegularGrid< std::pair< unsigned int , size_t > , Dim > FullSaito( const RegularGrid< BinaryType , Dim > &binaryGrid , bool verbose=false ); 49 | template< typename IndexType , unsigned int K > 50 | static RegularGrid< unsigned int , Dim > Saito( const SimplicialComplex< Real , Dim , K > &simplicialComplex , unsigned int depth , unsigned int lockDepth , XForm< Real , Dim+1 > &gridToModel , Real bBoxScale , bool verbose=false ); 51 | 52 | 53 | // [Danielsson, '90] 54 | // Euclidean distance mapping 55 | // {Returns the distance in unit-cube units} 56 | template< typename IndexType , unsigned int K > 57 | static RegularGrid< Real , Dim > Danielsson( const SimplicialComplex< Real , Dim , K > &simplicialComplex , unsigned int depth , unsigned int lockDepth , unsigned int radius , XForm< Real , Dim+1 > &gridToModel , Real bBoxScale , bool verbose=false ); 58 | protected: 59 | template< typename IndexType , unsigned int K , unsigned int SliceDim , bool MultiThreaded > 60 | static typename std::enable_if< SliceDim!=0 >::type _Danielsson( const std::vector< typename Simplex< Real , Dim , K >::NearestKey > &nearestKeys , Pointer( std::pair< Real , IndexType > ) sliceNearest , const unsigned int res[SliceDim] , Point< Real , Dim > center ); 61 | template< typename IndexType , unsigned int K , unsigned int SliceDim , bool MultiThreaded > 62 | static typename std::enable_if< SliceDim==0 >::type _Danielsson( const std::vector< typename Simplex< Real , Dim , K >::NearestKey > &nearestKeys , Pointer( std::pair< Real , IndexType > ) sliceNearest , const unsigned int res[] , Point< Real , Dim > center ){} 63 | }; 64 | } 65 | #include "SquaredEDT.inl" 66 | #endif // SQUARED_EDT_INCLUDED 67 | -------------------------------------------------------------------------------- /PNG/PNG.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release 6 | x64 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | {B5899B32-FAC2-477E-99AA-86736B97F2FC} 36 | PNG 37 | Win32Proj 38 | 10.0 39 | 40 | 41 | 42 | StaticLibrary 43 | Unicode 44 | true 45 | v142 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | <_ProjectFileVersion>10.0.40219.1 56 | $(SolutionDir)Bin\$(Platform) 57 | $(Platform)\$(Configuration)\ 58 | AllRules.ruleset 59 | 60 | 61 | 62 | 63 | 64 | X64 65 | 66 | 67 | ..;%(AdditionalIncludeDirectories) 68 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 69 | MultiThreadedDLL 70 | 71 | 72 | TurnOffAllWarnings 73 | ProgramDatabase 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /PNG/pngrio.c: -------------------------------------------------------------------------------- 1 | 2 | /* pngrio.c - functions for data input 3 | * 4 | * Copyright (c) 2018 Cosmin Truta 5 | * Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson 6 | * Copyright (c) 1996-1997 Andreas Dilger 7 | * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. 8 | * 9 | * This code is released under the libpng license. 10 | * For conditions of distribution and use, see the disclaimer 11 | * and license in png.h 12 | * 13 | * This file provides a location for all input. Users who need 14 | * special handling are expected to write a function that has the same 15 | * arguments as this and performs a similar function, but that possibly 16 | * has a different input method. Note that you shouldn't change this 17 | * function, but rather write a replacement function and then make 18 | * libpng use it at run time with png_set_read_fn(...). 19 | */ 20 | 21 | #include "pngpriv.h" 22 | 23 | #ifdef PNG_READ_SUPPORTED 24 | 25 | /* Read the data from whatever input you are using. The default routine 26 | * reads from a file pointer. Note that this routine sometimes gets called 27 | * with very small lengths, so you should implement some kind of simple 28 | * buffering if you are using unbuffered reads. This should never be asked 29 | * to read more than 64K on a 16-bit machine. 30 | */ 31 | void /* PRIVATE */ 32 | png_read_data(png_structrp png_ptr, png_bytep data, size_t length) 33 | { 34 | png_debug1(4, "reading %d bytes", (int)length); 35 | 36 | if (png_ptr->read_data_fn != NULL) 37 | (*(png_ptr->read_data_fn))(png_ptr, data, length); 38 | 39 | else 40 | png_error(png_ptr, "Call to NULL read function"); 41 | } 42 | 43 | #ifdef PNG_STDIO_SUPPORTED 44 | /* This is the function that does the actual reading of data. If you are 45 | * not reading from a standard C stream, you should create a replacement 46 | * read_data function and use it at run time with png_set_read_fn(), rather 47 | * than changing the library. 48 | */ 49 | void PNGCBAPI 50 | png_default_read_data(png_structp png_ptr, png_bytep data, size_t length) 51 | { 52 | size_t check; 53 | 54 | if (png_ptr == NULL) 55 | return; 56 | 57 | /* fread() returns 0 on error, so it is OK to store this in a size_t 58 | * instead of an int, which is what fread() actually returns. 59 | */ 60 | check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr)); 61 | 62 | if (check != length) 63 | png_error(png_ptr, "Read Error"); 64 | } 65 | #endif 66 | 67 | /* This function allows the application to supply a new input function 68 | * for libpng if standard C streams aren't being used. 69 | * 70 | * This function takes as its arguments: 71 | * 72 | * png_ptr - pointer to a png input data structure 73 | * 74 | * io_ptr - pointer to user supplied structure containing info about 75 | * the input functions. May be NULL. 76 | * 77 | * read_data_fn - pointer to a new input function that takes as its 78 | * arguments a pointer to a png_struct, a pointer to 79 | * a location where input data can be stored, and a 32-bit 80 | * unsigned int that is the number of bytes to be read. 81 | * To exit and output any fatal error messages the new write 82 | * function should call png_error(png_ptr, "Error msg"). 83 | * May be NULL, in which case libpng's default function will 84 | * be used. 85 | */ 86 | void PNGAPI 87 | png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr, 88 | png_rw_ptr read_data_fn) 89 | { 90 | if (png_ptr == NULL) 91 | return; 92 | 93 | png_ptr->io_ptr = io_ptr; 94 | 95 | #ifdef PNG_STDIO_SUPPORTED 96 | if (read_data_fn != NULL) 97 | png_ptr->read_data_fn = read_data_fn; 98 | 99 | else 100 | png_ptr->read_data_fn = png_default_read_data; 101 | #else 102 | png_ptr->read_data_fn = read_data_fn; 103 | #endif 104 | 105 | #ifdef PNG_WRITE_SUPPORTED 106 | /* It is an error to write to a read device */ 107 | if (png_ptr->write_data_fn != NULL) 108 | { 109 | png_ptr->write_data_fn = NULL; 110 | png_warning(png_ptr, 111 | "Can't set both read_data_fn and write_data_fn in the" 112 | " same structure"); 113 | } 114 | #endif 115 | 116 | #ifdef PNG_WRITE_FLUSH_SUPPORTED 117 | png_ptr->output_flush_fn = NULL; 118 | #endif 119 | } 120 | #endif /* READ */ 121 | -------------------------------------------------------------------------------- /MarchingCubes/MarchingCubes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 | #include 30 | #include 31 | #include 32 | #include "Misha/CmdLineParser.h" 33 | #include "Misha/Miscellany.h" 34 | #include "Misha/RegularGrid.h" 35 | #include "Misha/IsoSurface3D.h" 36 | #include "Misha/MarchingCubes.h" 37 | #include "Misha/IsoSurface3D.h" 38 | #include "Misha/Ply.h" 39 | #include "Misha/PlyVertexData.h" 40 | 41 | Misha::CmdLineParameter< std::string > In( "in" ) , Out( "out" ); 42 | Misha::CmdLineReadable FullCaseTable( "full" ) , Polygons( "polygons" ) , NonManifold( "nonManifold" ); 43 | Misha::CmdLineParameter< float > Value( "value" , 0.f ); 44 | Misha::CmdLineParameter< int > InterpolationType( "fit" , IsoSurface3D< float >::INTERPOLATE_LINEAR ); 45 | 46 | 47 | Misha::CmdLineReadable* params[] = 48 | { 49 | &In , &Out , &Value , &FullCaseTable , &InterpolationType , &Polygons , &NonManifold , NULL 50 | }; 51 | 52 | void ShowUsage( char* ex ) 53 | { 54 | std::cout << "Usage: " << std::string(ex) << std::endl; 55 | std::cout << "\t --" << In.name << " " << std::endl; 56 | std::cout << "\t[--" << Out.name << " ]" << std::endl; 57 | std::cout << "\t[--" << Value.name << " =" << Value.value << "]" << std::endl; 58 | std::cout << "\t[--" << InterpolationType.name << " =" << InterpolationType.value << "]" << std::endl; 59 | for( int i=0 ; i::INTERPOLATE_COUNT ; i++ ) std::cout << "\t\t" << i << "] " << IsoSurface3D< float >::InterpolationNames[i] << std::endl; 60 | std::cout << "\t[--" << Polygons.name << "]" << std::endl; 61 | std::cout << "\t[--" << FullCaseTable.name << "]" << std::endl; 62 | std::cout << "\t[--" << NonManifold.name << "]" << std::endl; 63 | } 64 | 65 | typedef VertexFactory::PositionFactory< float , 3 > Factory; 66 | typedef typename Factory::VertexType Vertex; 67 | 68 | int main( int argc , char* argv[] ) 69 | { 70 | Miscellany::Timer timer; 71 | 72 | Misha::CmdLineParse( argc-1 , &argv[1] , params ); 73 | if( !In.set ) 74 | { 75 | ShowUsage( argv[0] ); 76 | return EXIT_FAILURE; 77 | } 78 | 79 | XForm< float , 4 > gridToModel; 80 | RegularGrid< float , 3 > grid; 81 | grid.read( In.value , gridToModel ); 82 | 83 | 84 | std::vector< Vertex > vertices; 85 | std::vector< std::vector< int > > polygons; 86 | std::vector< TriangleIndex > triangles; 87 | if( Polygons.set ) IsoSurface3D< float >::Extract( grid , Value.value , vertices , polygons , FullCaseTable.set , InterpolationType.value ); 88 | else IsoSurface3D< float >::Extract( grid , Value.value , vertices , triangles , FullCaseTable.set , InterpolationType.value , !NonManifold.set ); 89 | 90 | for( int i=0 ; i 2 | 3 | 4 | 5 | Release 6 | x64 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | {0BE55595-4080-4265-82AF-51108EC956B2} 73 | Win32Proj 74 | JPEG 75 | 10.0 76 | 77 | 78 | 79 | StaticLibrary 80 | false 81 | true 82 | Unicode 83 | v142 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | $(SolutionDir)Bin\$(Platform) 94 | 95 | 96 | 97 | TurnOffAllWarnings 98 | 99 | 100 | MaxSpeed 101 | true 102 | true 103 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 104 | 105 | 106 | Windows 107 | true 108 | true 109 | true 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /Misha/IsoSurface3D.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015, 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 ISO_SURFACE_3D_INCLUDED 29 | #define ISO_SURFACE_3D_INCLUDED 30 | 31 | #include 32 | #include 33 | #include 34 | #include "Geometry.h" 35 | #include "MarchingCubes.h" 36 | #include "RegularGrid.h" 37 | #include "Array.h" 38 | #include "Polynomial.h" 39 | 40 | 41 | template< typename Real > 42 | struct IsoSurface3D 43 | { 44 | enum 45 | { 46 | INTERPOLATE_LINEAR , 47 | INTERPOLATE_QUADRATIC , 48 | INTERPOLATE_CUBIC , 49 | INTERPOLATE_CATMULL_ROM , 50 | INTERPOLATE_COUNT 51 | }; 52 | static const std::string InterpolationNames[]; 53 | 54 | static void Extract( const unsigned int res[3] , ConstPointer( Real ) values , Real isoValue , std::vector< Point3D< Real > >& vertices , std::vector< std::vector< int > >& polygons , bool fullCaseTable , int interpolationType ); 55 | static void Extract( const unsigned int res[3] , ConstPointer( Real ) values , Real isoValue , std::vector< Point3D< Real > >& vertices , std::vector< TriangleIndex >& triangles , bool fullCaseTable , int interpolationType , bool manifold ); 56 | 57 | static void Extract( const RegularGrid< Real , 3 > &voxelGrid , Real isoValue , std::vector< Point3D< Real > >& vertices , std::vector< std::vector< int > >& polygons , bool fullCaseTable , int interpolationType ); 58 | static void Extract( const RegularGrid< Real , 3 > &voxelGrid , Real isoValue , std::vector< Point3D< Real > >& vertices , std::vector< TriangleIndex >& triangles , bool fullCaseTable , int interpolationType , bool manifold ); 59 | 60 | protected: 61 | struct _Vertex 62 | { 63 | int dir , idx[3]; 64 | Point3D< Real > p; 65 | _Vertex( Point3D< Real > _p , int _dir , int x , int y , int z ) : p(_p) , dir(_dir) { idx[0] = x , idx[1] = y , idx[2] = z; } 66 | static bool CoFacial( const _Vertex &t1 , const _Vertex &t2 ); 67 | }; 68 | static void _Extract( const RegularGrid< Real , 3 > &voxelGrid , Real isoValue , std::vector< _Vertex >& vertices , std::vector< std::vector< int > >& polygons , bool fullCaseTable , int interpolationType ); 69 | static void _Extract( const unsigned int res[3] , ConstPointer( Real ) values , Real isoValue , std::vector< _Vertex >& vertices , std::vector< std::vector< int > >& polygons , bool fullCaseTable , int interpolationType ); 70 | 71 | static Real _LinearInterpolant( Real x1 , Real x2 , Real isoValue ); 72 | static Real _QuadraticInterpolant( Real x0 , Real x1 , Real x2 , Real x3 , Real isoValue ); 73 | static Real _CubicInterpolant( Real x0 , Real x1 , Real x2 , Real x3 , Real isoValue ); 74 | static Real _CatmullRomInterpolant( Real x0 , Real x1 , Real x2 , Real x3 , Real isoValue ); 75 | 76 | static void _SetFlags( int resX , int resY , ConstPointer( Real ) values , Real isoValue , Pointer( unsigned char ) flags ); 77 | static void _SetZVertices( int resX , int resY , int z , ConstPointer( Real ) values0 , ConstPointer( Real ) values1 , ConstPointer( Real ) values2 , ConstPointer( Real ) values3 , ConstPointer( unsigned char ) flags1 , ConstPointer( unsigned char ) flags2 , Real isoValue , int interpolationType , std::unordered_map< long long , int >& isoVertexMap , std::vector< _Vertex >& vertices ); 78 | static void _SetXYVertices( int resX , int resY , int z , ConstPointer( Real ) values , ConstPointer( unsigned char ) flags , Real isoValue , int interpolationType , std::unordered_map< long long , int >& xIsoVertexMap , std::unordered_map< long long , int >& yIsoVertexMap , std::vector< _Vertex >& vertices ); 79 | static void _SetPolygons( int resX , int resY , int z , ConstPointer( Real ) values1 , ConstPointer( Real ) values2 , Real isoValue , bool fullCaseTable , const std::unordered_map< long long , int >& xIsoVertexMap1 , const std::unordered_map< long long , int >& xIsoVertexMap2 , const std::unordered_map< long long , int >& yIsoVertexMap1 , const std::unordered_map< long long , int >& yIsoVertexMap2 , const std::unordered_map< long long , int >& zIsoVertexMap , const std::vector< _Vertex >& vertices , std::vector< std::vector< int > >& polygons ); 80 | }; 81 | 82 | #include "IsoSurface3D.inl" 83 | #endif // ISO_SURFACE_3D_INCLUDED -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /EDTFromMesh/EDTFromMesh.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 | #include 30 | #include 31 | #include 32 | #include "Misha/Geometry.h" 33 | #include "Misha/CmdLineParser.h" 34 | #include "Misha/Miscellany.h" 35 | #include "Misha/SquaredEDT.h" 36 | #include "Misha/RegularGrid.h" 37 | #include "Misha/Rasterizer.h" 38 | #include "Misha/PlyVertexData.h" 39 | #include "Misha/Ply.h" 40 | 41 | Misha::CmdLineParameter< std::string > In( "in" ) , Out( "out" ); 42 | Misha::CmdLineParameter< float > Scale( "scale" , 2.f ); 43 | Misha::CmdLineParameter< int > Depth( "depth" , 8 ) , Radius( "radius" , -1 ); 44 | Misha::CmdLineParameter< int > LockDepth( "lockDepth" , 4 ) , Threads( "threads" , omp_get_num_procs() ); 45 | Misha::CmdLineReadable Verbose( "verbose" ); 46 | 47 | Misha::CmdLineReadable* params[] = 48 | { 49 | &In , &Out , &Verbose , &Threads , &Scale , &Depth , &LockDepth , &Radius , NULL 50 | }; 51 | 52 | void ShowUsage( char* ex ) 53 | { 54 | std::cout << "Usage: " << std::string(ex) << std::endl; 55 | std::cout << "\t --" << In.name << " " << std::endl; 56 | std::cout << "\t[--" << Out.name << " ]" << std::endl; 57 | std::cout << "\t[--" << Depth.name << " =" << Depth.value << "]" << std::endl; 58 | std::cout << "\t[--" << Scale.name << " =" << Scale.value << "]" << std::endl; 59 | std::cout << "\t[--" << Radius.name << " =" << Threads.value << "]" << std::endl; 62 | std::cout << "\t[--" << LockDepth.name << " =" << LockDepth.value << "]" << std::endl; 63 | #endif // _OPENMP 64 | std::cout << "\t[--" << Verbose.name << "]" << std::endl; 65 | } 66 | 67 | 68 | RegularGrid< float , 3 > GetEDT( const SimplicialComplex< double , 3 , 2 > &sc , unsigned int depth , unsigned int lockDepth , int radius , double scale , XForm< float , 4 > &gridToModel , bool verbose ) 69 | { 70 | RegularGrid< float , 3 > edt; 71 | if( radius<0 ) 72 | { 73 | XForm< double , 4 > _gridToModel; 74 | RegularGrid< unsigned , 3 > _edt2 = Misha::SquaredEDT< double , 3 >::Saito< int , 2 >( sc , depth , lockDepth , _gridToModel , scale , verbose ); 75 | edt.resize( _edt2.res() ); 76 | for( unsigned int i=0 ; i _gridToModel; 83 | RegularGrid< double , 3 > _edt2 = Misha::SquaredEDT< double , 3 >::Danielsson< int , 2 >( sc , depth , lockDepth , radius , _gridToModel , scale , verbose ); 84 | edt.resize( _edt2.res() ); 85 | for( unsigned int i=0 ; i Factory; 108 | typedef typename Factory::VertexType Vertex; 109 | 110 | std::vector< Vertex > vertices; 111 | std::vector< TriangleIndex > triangles; 112 | 113 | int file_type; 114 | PLY::ReadTriangles( In.value , Factory() , vertices , triangles , NULL , file_type ); 115 | std::cout << "Vertices / Triangles: " << vertices.size() << " / " << triangles.size() << std::endl; 116 | 117 | IndexedSimplicialComplex< double , 3 , 2 , int > isc( vertices , triangles ); 118 | 119 | XForm< float , 4 > gridToModel; 120 | RegularGrid< float , 3 > EDT = GetEDT( isc , Depth.value , LockDepth.value , Radius.value , Scale.value , gridToModel, Verbose.set ); 121 | 122 | if( Out.set ) EDT.write( Out.value , gridToModel ); 123 | 124 | return EXIT_SUCCESS; 125 | } 126 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /PNG/pngdebug.h: -------------------------------------------------------------------------------- 1 | 2 | /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c 3 | * 4 | * Copyright (c) 2018 Cosmin Truta 5 | * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson 6 | * Copyright (c) 1996-1997 Andreas Dilger 7 | * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc. 8 | * 9 | * This code is released under the libpng license. 10 | * For conditions of distribution and use, see the disclaimer 11 | * and license in png.h 12 | */ 13 | 14 | /* Define PNG_DEBUG at compile time for debugging information. Higher 15 | * numbers for PNG_DEBUG mean more debugging information. This has 16 | * only been added since version 0.95 so it is not implemented throughout 17 | * libpng yet, but more support will be added as needed. 18 | * 19 | * png_debug[1-2]?(level, message ,arg{0-2}) 20 | * Expands to a statement (either a simple expression or a compound 21 | * do..while(0) statement) that outputs a message with parameter 22 | * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG 23 | * is undefined, 0 or 1 every png_debug expands to a simple expression 24 | * (actually ((void)0)). 25 | * 26 | * level: level of detail of message, starting at 0. A level 'n' 27 | * message is preceded by 'n' 3-space indentations (not implemented 28 | * on Microsoft compilers unless PNG_DEBUG_FILE is also 29 | * defined, to allow debug DLL compilation with no standard IO). 30 | * message: a printf(3) style text string. A trailing '\n' is added 31 | * to the message. 32 | * arg: 0 to 2 arguments for printf(3) style substitution in message. 33 | */ 34 | #ifndef PNGDEBUG_H 35 | #define PNGDEBUG_H 36 | /* These settings control the formatting of messages in png.c and pngerror.c */ 37 | /* Moved to pngdebug.h at 1.5.0 */ 38 | # ifndef PNG_LITERAL_SHARP 39 | # define PNG_LITERAL_SHARP 0x23 40 | # endif 41 | # ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET 42 | # define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b 43 | # endif 44 | # ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET 45 | # define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d 46 | # endif 47 | # ifndef PNG_STRING_NEWLINE 48 | # define PNG_STRING_NEWLINE "\n" 49 | # endif 50 | 51 | #ifdef PNG_DEBUG 52 | # if (PNG_DEBUG > 0) 53 | # if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER) 54 | # include 55 | # if (PNG_DEBUG > 1) 56 | # ifndef _DEBUG 57 | # define _DEBUG 58 | # endif 59 | # ifndef png_debug 60 | # define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE) 61 | # endif 62 | # ifndef png_debug1 63 | # define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1) 64 | # endif 65 | # ifndef png_debug2 66 | # define png_debug2(l,m,p1,p2) \ 67 | _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2) 68 | # endif 69 | # endif 70 | # else /* PNG_DEBUG_FILE || !_MSC_VER */ 71 | # ifndef PNG_STDIO_SUPPORTED 72 | # include /* not included yet */ 73 | # endif 74 | # ifndef PNG_DEBUG_FILE 75 | # define PNG_DEBUG_FILE stderr 76 | # endif /* PNG_DEBUG_FILE */ 77 | 78 | # if (PNG_DEBUG > 1) 79 | # ifdef __STDC__ 80 | # ifndef png_debug 81 | # define png_debug(l,m) \ 82 | do { \ 83 | int num_tabs=l; \ 84 | fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ 85 | (num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \ 86 | } while (0) 87 | # endif 88 | # ifndef png_debug1 89 | # define png_debug1(l,m,p1) \ 90 | do { \ 91 | int num_tabs=l; \ 92 | fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ 93 | (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \ 94 | } while (0) 95 | # endif 96 | # ifndef png_debug2 97 | # define png_debug2(l,m,p1,p2) \ 98 | do { \ 99 | int num_tabs=l; \ 100 | fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \ 101 | (num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\ 102 | } while (0) 103 | # endif 104 | # else /* __STDC __ */ 105 | # ifndef png_debug 106 | # define png_debug(l,m) \ 107 | do { \ 108 | int num_tabs=l; \ 109 | char format[256]; \ 110 | snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ 111 | (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ 112 | m,PNG_STRING_NEWLINE); \ 113 | fprintf(PNG_DEBUG_FILE,format); \ 114 | } while (0) 115 | # endif 116 | # ifndef png_debug1 117 | # define png_debug1(l,m,p1) \ 118 | do { \ 119 | int num_tabs=l; \ 120 | char format[256]; \ 121 | snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ 122 | (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ 123 | m,PNG_STRING_NEWLINE); \ 124 | fprintf(PNG_DEBUG_FILE,format,p1); \ 125 | } while (0) 126 | # endif 127 | # ifndef png_debug2 128 | # define png_debug2(l,m,p1,p2) \ 129 | do { \ 130 | int num_tabs=l; \ 131 | char format[256]; \ 132 | snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \ 133 | (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \ 134 | m,PNG_STRING_NEWLINE); \ 135 | fprintf(PNG_DEBUG_FILE,format,p1,p2); \ 136 | } while (0) 137 | # endif 138 | # endif /* __STDC __ */ 139 | # endif /* (PNG_DEBUG > 1) */ 140 | 141 | # endif /* _MSC_VER */ 142 | # endif /* (PNG_DEBUG > 0) */ 143 | #endif /* PNG_DEBUG */ 144 | #ifndef png_debug 145 | # define png_debug(l, m) ((void)0) 146 | #endif 147 | #ifndef png_debug1 148 | # define png_debug1(l, m, p1) ((void)0) 149 | #endif 150 | #ifndef png_debug2 151 | # define png_debug2(l, m, p1, p2) ((void)0) 152 | #endif 153 | #endif /* PNGDEBUG_H */ 154 | -------------------------------------------------------------------------------- /Misha/CmdLineParser.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 CMD_LINE_PARSER_INCLUDED 30 | #define CMD_LINE_PARSER_INCLUDED 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #define NEW_TYPE_CONVERSION 38 | 39 | 40 | namespace Misha 41 | { 42 | /** This class represents a named argument that can be read from the command line */ 43 | class CmdLineReadable 44 | { 45 | public: 46 | /** Has the argument been set */ 47 | bool set; 48 | 49 | /** The argument's name */ 50 | std::string name; 51 | 52 | /** Constructor with the name of the argument */ 53 | CmdLineReadable( const std::string &name ); 54 | 55 | /** Destructor */ 56 | virtual ~CmdLineReadable( void ); 57 | 58 | /** Try to set the argument from the list of command line arguments. 59 | *** Returns thenumber of arguments ingested.*/ 60 | virtual int read( char **argv , int argc ); 61 | 62 | #ifdef NEW_TYPE_CONVERSION 63 | /** Transforms a string into the prescribed type */ 64 | template< typename Type > 65 | static Type ToType( const std::string &str ); 66 | #endif // NEW_TYPE_CONVERSION 67 | }; 68 | 69 | /** This templated class represents a named argument of the prescribed type */ 70 | template< class Type > 71 | class CmdLineParameter : public CmdLineReadable 72 | { 73 | public: 74 | /** The value the parameter has been set to */ 75 | Type value; 76 | 77 | /** Constructor with the name of the argument */ 78 | CmdLineParameter( const std::string &name ); 79 | 80 | /** Constructor with the name of the argument and the default value */ 81 | CmdLineParameter( const std::string &name , Type v ); 82 | 83 | /** Try to set the argument from the list of command line arguments. 84 | *** Returns thenumber of arguments ingested.*/ 85 | int read( char **argv , int argc ); 86 | }; 87 | 88 | /** This templated class represents a named argument taking a fixed number of values of the prescribed type */ 89 | template< class Type , int Dim > 90 | class CmdLineParameterArray : public CmdLineReadable 91 | { 92 | public: 93 | /** The values the parameter has been set to */ 94 | Type values[Dim]; 95 | 96 | /** Constructor with the name of the argument and the default values */ 97 | CmdLineParameterArray( const std::string &name, const Type* v=NULL ); 98 | 99 | /** Try to set the argument from the list of command line arguments. 100 | *** Returns thenumber of arguments ingested.*/ 101 | int read( char **argv , int argc ); 102 | }; 103 | 104 | /** This templated class represents a named argument taking a variable number of values of of the prescribed type */ 105 | template< class Type > 106 | class CmdLineParameters : public CmdLineReadable 107 | { 108 | public: 109 | /** The number of values the argument takes */ 110 | unsigned int count; 111 | 112 | /** The values the parameter has been set to */ 113 | Type *values; 114 | 115 | /** Constructor with the name of the argument */ 116 | CmdLineParameters( const std::string &name ); 117 | 118 | /** Destructor deallocating the array of values */ 119 | ~CmdLineParameters( void ); 120 | 121 | /** Try to set the argument from the list of command line arguments. 122 | *** Returns thenumber of arguments ingested.*/ 123 | int read( char **argv , int argc ); 124 | 125 | /** Method for resizing the contents */ 126 | void resize( unsigned int sz ); 127 | }; 128 | 129 | /** This function takes a list of arguments and tries to set the parameters. 130 | *** The last parameter must be a NULL pointer. */ 131 | void CmdLineParse( int argc , char **argv, CmdLineReadable **params ); 132 | 133 | /** Converts a string to upper case*/ 134 | std::string ToUpper( const std::string &str ); 135 | 136 | /** Converts a string to lower case*/ 137 | std::string ToLower( const std::string &str ); 138 | 139 | /** Returns the file extension */ 140 | std::string GetFileExtension( const std::string &fileName ); 141 | 142 | /** Returns and array of individual lines read from a file */ 143 | std::vector< std::string > ReadLines( const std::string &fileName ); 144 | 145 | /** Returns and array of individual words pulled from a string */ 146 | std::vector< std::string > GetWords( const std::string &str ); 147 | 148 | /** Returns and array of individual words read from a file */ 149 | std::vector< std::string > ReadWords( const std::string &fileName ); 150 | } 151 | #include "CmdLineParser.inl" 152 | #endif // CMD_LINE_PARSER_INCLUDED 153 | -------------------------------------------------------------------------------- /Misha/Rasterizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2019, 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 | #ifndef RASTERIZER_INCLUDED 30 | #define RASTERIZER_INCLUDED 31 | 32 | #include "Array.h" 33 | #include "Geometry.h" 34 | #include "RegularGrid.h" 35 | 36 | namespace Misha 37 | { 38 | template< typename Real , unsigned int Dim > 39 | struct Rasterizer 40 | { 41 | template< typename IndexType , unsigned int K > using SimplexRasterizationGrid = RegularGrid< std::vector< std::pair< IndexType , Simplex< Real , Dim , K > > > , Dim >; 42 | 43 | // This templated function rasterizes a simplicial complex into the cube [0,1]^3. 44 | // Template parameters: 45 | // IndexType: specifies the storage for vertex/simplex indices 46 | // Input: 47 | // vertices: the vertices of the mesh 48 | // simplices: the connectivity of the mesh 49 | // depth: the depth of the voxel grid, generating a grid of size (2^depth) x (2^depth) x (2^depth) 50 | // lockDepth: the depth of the voxel grid storing the locks 51 | // bBoxScale: The ratio of unit-cube-size to bounding-box-size 52 | // Output: 53 | // A RegularGrid object where each cell stores the list of pairs containing the index into the original simplex list and the (clipped) simplex 54 | // gridToModel: the transformation taking the grid coordinates back to the model coordinates (composed of an isotropic scale and a translation) 55 | template< typename IndexType , unsigned int K > 56 | static SimplexRasterizationGrid< IndexType , K > Rasterize( const SimplicialComplex< Real , Dim , K > &simplicialComplex , unsigned int depth , unsigned int lockDepth , XForm< Real , Dim+1 > &unitCubeToModel , Real bBoxScale ); 57 | template< typename IndexType , unsigned int K > 58 | static SimplexRasterizationGrid< IndexType , K > Rasterize( const SimplicialComplex< Real , Dim , K > &simplicialComplex , unsigned int depth , unsigned int lockDepth , Real bBoxScale ); 59 | 60 | protected: 61 | struct _RegularGridIndex 62 | { 63 | unsigned int depth , index[Dim]; 64 | _RegularGridIndex( void ); 65 | _RegularGridIndex( unsigned int d , Point< Real , Dim > p ); 66 | template< unsigned int K > _RegularGridIndex( unsigned int maxDepth , Simplex< Real , Dim , K > simplex ); 67 | 68 | bool operator != ( const _RegularGridIndex &idx ) const; 69 | bool operator == ( const _RegularGridIndex &idx ) const { return !( (*this)!=idx ); } 70 | 71 | _RegularGridIndex child( unsigned int c ) const; 72 | }; 73 | 74 | struct _RegularGridLocks 75 | { 76 | _RegularGridLocks( unsigned int lockDepth , unsigned int maxDepth ) 77 | { 78 | if( lockDepth>maxDepth ) 79 | { 80 | WARN( "Lock depth exceeds max depth: " , lockDepth , " > " , maxDepth ); 81 | lockDepth = maxDepth; 82 | } 83 | _bitShift = maxDepth - lockDepth; 84 | unsigned int _res = 1<> _bitShift; 97 | return _locks( _idx ); 98 | } 99 | omp_lock_t &operator() ( unsigned int idx[Dim] ) 100 | { 101 | unsigned int _idx[Dim]; 102 | for( int d=0 ; d> _bitShift; 103 | return _locks( _idx ); 104 | } 105 | template< typename ... UnsignedInts > 106 | omp_lock_t &operator()( UnsignedInts ... idx ) 107 | { 108 | unsigned int _idx[] = { idx ... }; 109 | for( int d=0 ; d> _bitShift; 110 | return _locks( _idx ); 111 | } 112 | 113 | protected: 114 | RegularGrid< omp_lock_t , Dim > _locks; 115 | size_t _bitShift; 116 | }; 117 | 118 | template< typename IndexType , unsigned int K > 119 | static size_t _Rasterize( _RegularGridLocks &locks , SimplexRasterizationGrid< IndexType , K > &raster , IndexType simplexIndex , Simplex< Real , Dim , K > simplex , unsigned int depth , _RegularGridIndex idx ); 120 | 121 | template< unsigned int K > 122 | static XForm< Real , Dim+1 > _ModelToUnitCube( const SimplicialComplex< Real , Dim , K > &simplicialComplex , Real bBoxScale ); 123 | }; 124 | } 125 | 126 | #include "Rasterizer.inl" 127 | #endif // RASTERIZER_INCLUDED -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ZLIB/ZLIB.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | {D3D173AB-D306-4179-BEC4-95CE1B14E647} 44 | ZLIB 45 | Win32Proj 46 | 10.0 47 | 48 | 49 | 50 | StaticLibrary 51 | Unicode 52 | true 53 | v142 54 | 55 | 56 | StaticLibrary 57 | Unicode 58 | v142 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | <_ProjectFileVersion>10.0.40219.1 72 | $(SolutionDir)$(Platform)\$(Configuration)\ 73 | $(Platform)\$(Configuration)\ 74 | $(SolutionDir)Bin\$(Platform) 75 | $(Platform)\$(Configuration)\ 76 | AllRules.ruleset 77 | 78 | 79 | AllRules.ruleset 80 | 81 | 82 | 83 | 84 | 85 | X64 86 | 87 | 88 | Disabled 89 | WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) 90 | true 91 | EnableFastChecks 92 | MultiThreadedDebugDLL 93 | 94 | 95 | Level3 96 | ProgramDatabase 97 | 98 | 99 | 100 | 101 | X64 102 | 103 | 104 | _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) 105 | MultiThreadedDLL 106 | 107 | 108 | TurnOffAllWarnings 109 | ProgramDatabase 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Misha/JPEG.inl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 | #include 29 | #include 30 | #include 31 | 32 | #ifdef _WIN32 33 | #include 34 | #include "JPEG/jpeglib.h" 35 | #include "JPEG/jerror.h" 36 | #include "JPEG/jmorecfg.h" 37 | #else // !_WIN32 38 | #include 39 | #include 40 | #include 41 | #endif // _WIN32 42 | 43 | 44 | 45 | inline METHODDEF( void ) 46 | my_error_exit (j_common_ptr cinfo) 47 | { 48 | // cinfo->err really points to a my_error_mgr struct, so coerce pointer 49 | my_error_ptr myerr = (my_error_ptr) cinfo->err; 50 | 51 | // Always display the message. 52 | // We could postpone this until after returning, if we chose. 53 | (*cinfo->err->output_message) (cinfo); 54 | 55 | // Return control to the setjmp point 56 | longjmp(myerr->setjmp_buffer, 1); 57 | } 58 | 59 | inline bool JPEGReader::GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 60 | { 61 | FILE* fp = fopen( fileName , "rb" ); 62 | if( !fp ) fprintf( stderr , "[ERROR] JPEGReader: Failed to open: %s\n" , fileName ) , exit(0); 63 | 64 | struct jpeg_decompress_struct cInfo; 65 | struct my_error_mgr jErr; 66 | 67 | cInfo.err = jpeg_std_error( &jErr.pub ); 68 | jErr.pub.error_exit = my_error_exit; 69 | if( setjmp( jErr.setjmp_buffer ) ) 70 | { 71 | jpeg_destroy_decompress( &cInfo ); 72 | fprintf( stderr , "[ERROR] JPEGReader: JPEG error occured\n" ); 73 | exit( 0 ); 74 | } 75 | 76 | jpeg_create_decompress( &cInfo ); 77 | jpeg_stdio_src( &cInfo , fp ); 78 | 79 | (void) jpeg_read_header( &cInfo , TRUE ); 80 | 81 | channels = cInfo.num_components; 82 | width = cInfo.image_width; 83 | height = cInfo.image_height; 84 | jpeg_destroy_decompress( &cInfo ); 85 | 86 | fclose( fp ); 87 | return true; 88 | } 89 | 90 | inline JPEGReader::JPEGReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 91 | { 92 | _currentRow = 0; 93 | _fp = fopen( fileName , "rb" ); 94 | if( !_fp ) fprintf( stderr , "[ERROR] JPEGReader: Failed to open: %s\n" , fileName ) , exit(0); 95 | 96 | _cInfo.err = jpeg_std_error( &_jErr.pub ); 97 | _jErr.pub.error_exit = my_error_exit; 98 | if( setjmp( _jErr.setjmp_buffer ) ) 99 | { 100 | jpeg_destroy_decompress( &_cInfo ); 101 | fprintf( stderr , "[ERROR] JPEGReader: JPEG error occured\n" ); 102 | exit( 0 ); 103 | } 104 | 105 | jpeg_create_decompress( &_cInfo ); 106 | jpeg_stdio_src( &_cInfo , _fp ); 107 | 108 | (void) jpeg_read_header( &_cInfo , TRUE ); 109 | (void) jpeg_start_decompress( &_cInfo ); 110 | 111 | channels = _cInfo.output_components; 112 | width = _cInfo.output_width; 113 | height = _cInfo.output_height; 114 | } 115 | inline JPEGReader::~JPEGReader( void ) 116 | { 117 | (void) jpeg_finish_decompress( &_cInfo ); 118 | jpeg_destroy_decompress( &_cInfo ); 119 | fclose( _fp ); 120 | } 121 | inline unsigned int JPEGReader::nextRow( unsigned char* row ) 122 | { 123 | JSAMPROW row_pointers[1]; 124 | row_pointers[0] = row; 125 | jpeg_read_scanlines( &_cInfo , row_pointers, 1 ); 126 | return _currentRow++; 127 | } 128 | 129 | inline JPEGWriter::JPEGWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int quality ) 130 | { 131 | _currentRow = 0; 132 | _fp = fopen( fileName , "wb" ); 133 | if( !_fp ) fprintf( stderr , "[ERROR] JPEGWriter: Failed to open: %s\n" , fileName ) , exit(0); 134 | 135 | _cInfo.err = jpeg_std_error( &_jErr.pub ); 136 | jpeg_create_compress( &_cInfo ); 137 | 138 | jpeg_stdio_dest( &_cInfo , _fp ); 139 | 140 | _cInfo.image_width = width; 141 | _cInfo.image_height = height; 142 | _cInfo.input_components = channels; 143 | _cInfo.in_color_space = JCS_RGB; /* colorspace of input image */ 144 | 145 | jpeg_set_defaults( &_cInfo ); 146 | jpeg_set_quality( &_cInfo , quality , TRUE ); 147 | 148 | jpeg_start_compress( &_cInfo , TRUE ); 149 | } 150 | inline JPEGWriter::~JPEGWriter( void ) 151 | { 152 | jpeg_finish_compress( &_cInfo ); 153 | jpeg_destroy_compress( &_cInfo ); 154 | fclose( _fp ); 155 | } 156 | inline unsigned int JPEGWriter::nextRow( const unsigned char* row ) 157 | { 158 | JSAMPROW row_pointer[1]; 159 | row_pointer[0] = ( unsigned char* )row; 160 | (void) jpeg_write_scanlines( &_cInfo , row_pointer , 1 ); 161 | return _currentRow++; 162 | } 163 | 164 | inline unsigned int JPEGWriter::nextRows( const unsigned char* rows , unsigned int rowNum ) 165 | { 166 | JSAMPROW* row_pointers = new JSAMPROW[ rowNum ]; 167 | for( unsigned int r=0 ; rwrite_data_fn != NULL ) 37 | (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data), 38 | length); 39 | 40 | else 41 | png_error(png_ptr, "Call to NULL write function"); 42 | } 43 | 44 | #ifdef PNG_STDIO_SUPPORTED 45 | /* This is the function that does the actual writing of data. If you are 46 | * not writing to a standard C stream, you should create a replacement 47 | * write_data function and use it at run time with png_set_write_fn(), rather 48 | * than changing the library. 49 | */ 50 | void PNGCBAPI 51 | png_default_write_data(png_structp png_ptr, png_bytep data, size_t length) 52 | { 53 | size_t check; 54 | 55 | if (png_ptr == NULL) 56 | return; 57 | 58 | check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); 59 | 60 | if (check != length) 61 | png_error(png_ptr, "Write Error"); 62 | } 63 | #endif 64 | 65 | /* This function is called to output any data pending writing (normally 66 | * to disk). After png_flush is called, there should be no data pending 67 | * writing in any buffers. 68 | */ 69 | #ifdef PNG_WRITE_FLUSH_SUPPORTED 70 | void /* PRIVATE */ 71 | png_flush(png_structrp png_ptr) 72 | { 73 | if (png_ptr->output_flush_fn != NULL) 74 | (*(png_ptr->output_flush_fn))(png_ptr); 75 | } 76 | 77 | # ifdef PNG_STDIO_SUPPORTED 78 | void PNGCBAPI 79 | png_default_flush(png_structp png_ptr) 80 | { 81 | png_FILE_p io_ptr; 82 | 83 | if (png_ptr == NULL) 84 | return; 85 | 86 | io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr)); 87 | fflush(io_ptr); 88 | } 89 | # endif 90 | #endif 91 | 92 | /* This function allows the application to supply new output functions for 93 | * libpng if standard C streams aren't being used. 94 | * 95 | * This function takes as its arguments: 96 | * png_ptr - pointer to a png output data structure 97 | * io_ptr - pointer to user supplied structure containing info about 98 | * the output functions. May be NULL. 99 | * write_data_fn - pointer to a new output function that takes as its 100 | * arguments a pointer to a png_struct, a pointer to 101 | * data to be written, and a 32-bit unsigned int that is 102 | * the number of bytes to be written. The new write 103 | * function should call png_error(png_ptr, "Error msg") 104 | * to exit and output any fatal error messages. May be 105 | * NULL, in which case libpng's default function will 106 | * be used. 107 | * flush_data_fn - pointer to a new flush function that takes as its 108 | * arguments a pointer to a png_struct. After a call to 109 | * the flush function, there should be no data in any buffers 110 | * or pending transmission. If the output method doesn't do 111 | * any buffering of output, a function prototype must still be 112 | * supplied although it doesn't have to do anything. If 113 | * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile 114 | * time, output_flush_fn will be ignored, although it must be 115 | * supplied for compatibility. May be NULL, in which case 116 | * libpng's default function will be used, if 117 | * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not 118 | * a good idea if io_ptr does not point to a standard 119 | * *FILE structure. 120 | */ 121 | void PNGAPI 122 | png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, 123 | png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) 124 | { 125 | if (png_ptr == NULL) 126 | return; 127 | 128 | png_ptr->io_ptr = io_ptr; 129 | 130 | #ifdef PNG_STDIO_SUPPORTED 131 | if (write_data_fn != NULL) 132 | png_ptr->write_data_fn = write_data_fn; 133 | 134 | else 135 | png_ptr->write_data_fn = png_default_write_data; 136 | #else 137 | png_ptr->write_data_fn = write_data_fn; 138 | #endif 139 | 140 | #ifdef PNG_WRITE_FLUSH_SUPPORTED 141 | # ifdef PNG_STDIO_SUPPORTED 142 | 143 | if (output_flush_fn != NULL) 144 | png_ptr->output_flush_fn = output_flush_fn; 145 | 146 | else 147 | png_ptr->output_flush_fn = png_default_flush; 148 | 149 | # else 150 | png_ptr->output_flush_fn = output_flush_fn; 151 | # endif 152 | #else 153 | PNG_UNUSED(output_flush_fn) 154 | #endif /* WRITE_FLUSH */ 155 | 156 | #ifdef PNG_READ_SUPPORTED 157 | /* It is an error to read while writing a png file */ 158 | if (png_ptr->read_data_fn != NULL) 159 | { 160 | png_ptr->read_data_fn = NULL; 161 | 162 | png_warning(png_ptr, 163 | "Can't set both read_data_fn and write_data_fn in the" 164 | " same structure"); 165 | } 166 | #endif 167 | } 168 | #endif /* WRITE */ 169 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Misha/MarchingCubes.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 MARCHING_CUBES_INCLUDED 29 | #define MARCHING_CUBES_INCLUDED 30 | #include 31 | 32 | class Square 33 | { 34 | public: 35 | const static int CORNERS=4,EDGES=4; 36 | static int CornerIndex (const int& x,const int& y); 37 | static void FactorCornerIndex (const int& idx,int& x,int& y); 38 | static int EdgeIndex (const int& orientation,const int& i); 39 | static void FactorEdgeIndex (const int& idx,int& orientation,int& i); 40 | 41 | static int ReflectCornerIndex (const int& idx,const int& edgeIndex); 42 | static int ReflectEdgeIndex (const int& idx,const int& edgeIndex); 43 | 44 | static void EdgeCorners(const int& idx,int& c1,int &c2); 45 | static void OrientedEdgeCorners(const int& idx,int& c1,int &c2); 46 | }; 47 | 48 | class Cube 49 | { 50 | public: 51 | const static int CORNERS=8,EDGES=12,FACES=6; 52 | 53 | static int CornerIndex (const int& x,const int& y,const int& z); 54 | static void FactorCornerIndex (const int& idx,int& x,int& y,int& z); 55 | static int EdgeIndex (const int& orientation,const int& i,const int& j); 56 | static void FactorEdgeIndex (const int& idx,int& orientation,int& i,int &j); 57 | static int FaceIndex (const int& dir,const int& offSet); 58 | static int FaceIndex (const int& x,const int& y,const int& z); 59 | static void FactorFaceIndex (const int& idx,int& x,int &y,int& z); 60 | static void FactorFaceIndex (const int& idx,int& dir,int& offSet); 61 | 62 | static int AntipodalCornerIndex (const int& idx); 63 | static int FaceReflectCornerIndex (const int& idx,const int& faceIndex); 64 | static int FaceReflectEdgeIndex (const int& idx,const int& faceIndex); 65 | static int FaceReflectFaceIndex (const int& idx,const int& faceIndex); 66 | static int EdgeReflectCornerIndex (const int& idx,const int& edgeIndex); 67 | static int EdgeReflectEdgeIndex (const int& edgeIndex); 68 | 69 | static int FaceAdjacentToEdges (const int& eIndex1,const int& eIndex2); 70 | static void FacesAdjacentToEdge (const int& eIndex,int& f1Index,int& f2Index); 71 | 72 | static void EdgeCorners(const int& idx,int& c1,int &c2); 73 | static void FaceCorners(const int& idx,int& c1,int &c2,int& c3,int& c4); 74 | 75 | static int SquareToCubeCorner(const int& fIndex,const int& cIndex); 76 | static int SquareToCubeEdge(const int& fIndex,const int& eIndex); 77 | }; 78 | 79 | class MarchingEdges 80 | { 81 | public: 82 | template< class Real > inline static int ValueLabel( Real value , Real isoValue ){ return value edge[2]; 93 | std::pair< int , int > &operator[] ( int idx ) { return edge[idx]; } 94 | const std::pair< int , int > &operator[] ( int idx ) const { return edge[idx]; } 95 | }; 96 | private: 97 | static FaceEdges __caseTable [1<<(Square::CORNERS )]; 98 | static FaceEdges __fullCaseTable[1<<(Square::CORNERS+1)]; 99 | public: 100 | template< class Real > inline static int ValueLabel( Real value , Real isoValue ){ return MarchingEdges::ValueLabel< Real >( value , isoValue ); } 101 | static void SetCaseTable(void); 102 | static void SetFullCaseTable(void); 103 | 104 | static const FaceEdges& caseTable(const int& idx); 105 | static const FaceEdges& fullCaseTable(const int& idx); 106 | template< class Real > static int GetFullIndex( const Real values[Square::CORNERS] , Real iso ); 107 | template< class Real > static int GetIndex( const Real values[Square::CORNERS] , Real iso ); 108 | }; 109 | 110 | class MarchingCubes 111 | { 112 | static void GetEdgeLoops( std::vector< typename std::pair< int , int > >& edges , std::vector< typename std::vector< int > >& loops ); 113 | static std::vector< std::vector > __caseTable[1< > > __fullCaseTable; 116 | public: 117 | template< class Real > inline static int ValueLabel( Real value , Real isoValue ){ return MarchingEdges::ValueLabel< Real >( value , isoValue ); } 118 | static void SetCaseTable(void); 119 | static void SetFullCaseTable(void); 120 | 121 | template< class Real > static int GetFullIndex( const Real values[Cube::CORNERS] , Real iso ); 122 | template< class Real > static int GetIndex( const Real values[Cube::CORNERS] , Real iso ); 123 | static const std::vector< std::vector >& caseTable(const int& idx); 124 | static const std::vector< std::vector >& fullCaseTable(const int& idx); 125 | static const std::vector< std::vector >& caseTable(const int& idx,const int& useFull); 126 | 127 | static int IsAmbiguous(const int& idx); 128 | static int IsAmbiguous(const int& idx,const int& f); 129 | static int HasRoots(const int& mcIndex); 130 | static int HasEdgeRoots(const int& mcIndex,const int& edgeIndex); 131 | }; 132 | #include "MarchingCubes.inl" 133 | #endif //MARCHING_CUBES_INCLUDED 134 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /ZLIB/inffast.c: -------------------------------------------------------------------------------- 1 | /* inffast.c -- process literals and length/distance pairs fast 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 "inftrees.h" 8 | #include "infblock.h" 9 | #include "infcodes.h" 10 | #include "infutil.h" 11 | #include "inffast.h" 12 | 13 | struct inflate_codes_state {int dummy;}; /* for buggy compilers */ 14 | 15 | /* simplify the use of the inflate_huft type with some defines */ 16 | #define exop word.what.Exop 17 | #define bits word.what.Bits 18 | 19 | /* macros for bit input with no checking and for returning unused bytes */ 20 | #define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<avail_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 | -------------------------------------------------------------------------------- /EDTFromGrid/EDTFromGrid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 | #include 30 | #include 31 | #include 32 | #include 33 | #include "Misha/CmdLineParser.h" 34 | #include "Misha/Miscellany.h" 35 | #include "Misha/SquaredEDT.h" 36 | #include "Misha/RegularGrid.h" 37 | #include "Misha/Image.h" 38 | 39 | Misha::CmdLineParameter< std::string > In( "in" ) , Out( "out" ); 40 | Misha::CmdLineReadable Verbose( "verbose" ); 41 | Misha::CmdLineParameter< int > Threads( "threads" , omp_get_num_procs() ); 42 | Misha::CmdLineParameterArray< unsigned int , 3 > ID( "id" ); 43 | 44 | Misha::CmdLineReadable* params[] = 45 | { 46 | &In , &Out , &Verbose , &Threads , &ID , NULL 47 | }; 48 | 49 | void ShowUsage( char* ex ) 50 | { 51 | std::cout << "Usage: " << std::string(ex) << std::endl; 52 | std::cout << "\t --" << In.name << " " << std::endl; 53 | std::cout << "\t --" << ID.name << " " << std::endl; 54 | std::cout << "\t[--" << Out.name << " ]" << std::endl; 55 | #ifdef _OPENMP 56 | std::cout << "\t[--" << Threads.name << " =" << Threads.value << "]" << std::endl; 57 | #endif // _OPENMP 58 | std::cout << "\t[--" << Verbose.name << "]" << std::endl; 59 | } 60 | 61 | template< typename InputType > 62 | RegularGrid< float , 3 > GetSignedEDT( const RegularGrid< InputType , 3 > &grid , InputType id , bool verbose ) 63 | { 64 | Miscellany::Timer timer; 65 | 66 | RegularGrid< unsigned char , 3 > mask; 67 | mask.resize( grid.res() ); 68 | 69 | bool foundID = false; 70 | #pragma omp parallel for 71 | for( int i=0 ; i<(int)grid.res(0) ; i++ ) for( int j=0 ; j<(int)grid.res(1) ; j++ ) for( int k=0 ; k<(int)grid.res(2) ; k++ ) 72 | { 73 | bool boundary = false; 74 | if( grid(i,j,k)==id ) 75 | { 76 | for( int ii=-1 ; ii<=1 ; ii++ ) for( int jj=-1 ; jj<=1 ; jj++ ) for( int kk=-1 ; kk<=1 ; kk++ ) 77 | if( !ii && !jj && !kk ) continue; 78 | else if( i+ii<0 || i+ii>=(int)grid.res(0) || j+jj<0 || j+jj>=(int)grid.res(1) || k+kk<0 || k+kk>=(int)grid.res(2) ) continue; 79 | else if( grid( i+ii , j+jj , k+kk )!=id ) boundary = true; 80 | foundID = true; 81 | } 82 | if( boundary ) mask(i,j,k) = 1; 83 | else mask(i,j,k) = 0; 84 | } 85 | if( !foundID ) ERROR_OUT( "Could not find voxel with target id" ); 86 | std::cout << "Got mask: " << timer.elapsed() << std::endl; 87 | 88 | RegularGrid< unsigned int , 3 > EDT = Misha::SquaredEDT< double , 3 >::Saito( mask , verbose ); 89 | RegularGrid< float , 3 > signedEDT; 90 | signedEDT.resize( grid.res() ); 91 | 92 | #pragma omp parallel for 93 | for( int i=0 ; i<(int)grid.res(0) ; i++ ) for( int j=0 ; j<(int)grid.res(1) ; j++ ) for( int k=0 ; k<(int)grid.res(2) ; k++ ) 94 | if( grid(i,j,k)!=id ) signedEDT(i,j,k) = (float)sqrt( EDT(i,j,k) ); 95 | else signedEDT(i,j,k) = -(float)sqrt( EDT(i,j,k) ); 96 | 97 | return signedEDT; 98 | } 99 | 100 | int main( int argc , char* argv[] ) 101 | { 102 | double t = Miscellany::Time(); 103 | 104 | Misha::CmdLineParse( argc-1 , &argv[1] , params ); 105 | if( !In.set || !ID.set ) 106 | { 107 | ShowUsage( argv[0] ); 108 | return EXIT_FAILURE; 109 | } 110 | omp_set_num_threads( Threads.value ); 111 | 112 | RegularGrid< unsigned int , 3 > grid; 113 | 114 | auto RGBToInt = []( const unsigned char *rgb ){ return (unsigned int)rgb[0] <<16 | (unsigned int)rgb[1]<<8 | (unsigned int)rgb[2]<<0; }; 115 | 116 | std::unordered_map< unsigned int , Point3D< unsigned int > > ids; 117 | 118 | Miscellany::Timer timer; 119 | { 120 | 121 | std::vector< std::string > images = Misha::ReadLines( In.value ); 122 | 123 | for( unsigned int k=0 ; k<(unsigned int)images.size() ; k++ ) 124 | { 125 | unsigned int width , height; 126 | unsigned char *rgb = ImageReader::ReadColor( images[k].c_str() , width , height ); 127 | if( !k ) 128 | { 129 | grid.resize( width , height , (unsigned int)images.size() ); 130 | for( unsigned int i=0 ; i( (int)rgb[ 3 *( j*width+i ) + 0 ] , (int)rgb[ 3 *( j*width+i ) + 1 ] , (int)rgb[ 3 *( j*width+i ) + 2 ] ); 144 | } 145 | 146 | delete[] rgb; 147 | } 148 | } 149 | 150 | if( Verbose.set ) std::cout << "Read grid: " << grid.res(0) << " x " << grid.res(1) << " x " << grid.res(2) << " in " << timer.elapsed() << std::endl; 151 | 152 | if( ID.set ) 153 | { 154 | RegularGrid< float , 3 > signedEDT = GetSignedEDT< unsigned int >( grid , ID.values[0]<<16 | ID.values[1]<<8 | ID.values[2] , Verbose.set ); 155 | 156 | if( Out.set ) signedEDT.template write< float >( Out.value , XForm< float , 4 >::Identity() ); 157 | } 158 | else for( auto i=ids.begin() ; i!=ids.end() ; i++ ) std::cout << i->second << " -> " << i->first << std::endl; 159 | 160 | return EXIT_SUCCESS; 161 | } 162 | -------------------------------------------------------------------------------- /Misha/PBM.inl: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2021, 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 | #include 29 | #include 30 | 31 | inline bool PBMReader::GetInfo( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 32 | { 33 | PBMInfo _info; 34 | _info.fp = fopen( fileName , "rb" ); 35 | if( !_info.fp ) return false; 36 | 37 | static const unsigned int COMMENT_SIZE = 4096; 38 | char comment[COMMENT_SIZE]; 39 | char temp[512]; 40 | bool haveMagicNumber=false , haveWidth=false , haveHeight=false; 41 | while( !haveMagicNumber || !haveWidth || !haveHeight ) 42 | { 43 | if( fscanf( _info.fp , " %s " , temp )!=1 ){ fclose(_info.fp) ; return false; } 44 | else 45 | { 46 | if( temp[0]=='#' ) fgets( comment , COMMENT_SIZE , _info.fp ); 47 | else if( !haveMagicNumber ) 48 | { 49 | if( temp[0]!='P' ){ fclose(_info.fp) ; return false; } 50 | else if( temp[1]=='1' ) _info.binary = false; 51 | else if( temp[1]=='4' ) _info.binary = true; 52 | else{ fclose(_info.fp) ; return false; } 53 | haveMagicNumber = true; 54 | } 55 | if( !haveWidth ) 56 | { 57 | int w; 58 | if( fscanf( _info.fp , " %d " , &w )!=1 ){ fclose(_info.fp) ; return false; } 59 | width = w; 60 | haveWidth = true; 61 | } 62 | if( !haveHeight ) 63 | { 64 | int h; 65 | if( fscanf( _info.fp , " %d " , &h )!=1 ){ fclose(_info.fp) ; return false; } 66 | height = h; 67 | haveHeight = true; 68 | } 69 | } 70 | } 71 | fclose( _info.fp ); 72 | channels = 1; 73 | return true; 74 | } 75 | 76 | inline PBMReader::PBMReader( const char* fileName , unsigned int& width , unsigned int& height , unsigned int& channels ) 77 | { 78 | _currentRow = 0; 79 | _info.data = NULL; 80 | _info.fp = fopen( fileName , "rb" ); 81 | if( !_info.fp ) ERROR_OUT( "PBMInitRead: Failed to open: " , fileName ); 82 | 83 | static const unsigned int COMMENT_SIZE = 4096; 84 | char comment[COMMENT_SIZE]; 85 | char temp[512]; 86 | bool haveMagicNumber=false , haveWidth=false , haveHeight=false; 87 | while( !haveMagicNumber || !haveWidth || !haveHeight ) 88 | { 89 | 90 | if( fscanf( _info.fp , " %s " , temp )!=1 ) ERROR_OUT( "Failed to read next string" ); 91 | else 92 | { 93 | if( temp[0]=='#' ) fgets( comment , COMMENT_SIZE , _info.fp ); 94 | else if( !haveMagicNumber ) 95 | { 96 | if( temp[0]!='P' ) ERROR_OUT( "Failed to read magic number: " , temp ); 97 | else if( temp[1]=='1' ) _info.binary = false; 98 | else if( temp[1]=='4' ) _info.binary = true; 99 | else ERROR_OUT( "Failed to read magic number: " , temp ); 100 | haveMagicNumber = true; 101 | } 102 | if( !haveWidth ) 103 | { 104 | int w; 105 | if( fscanf( _info.fp , " %d " , &w )!=1 ) ERROR_OUT( "Failed to read width" ); 106 | width = w; 107 | haveWidth = true; 108 | } 109 | if( !haveHeight ) 110 | { 111 | int h; 112 | if( fscanf( _info.fp , " %d " , &h )!=1 ) ERROR_OUT( "Failed to read height" ); 113 | height = h; 114 | haveHeight = true; 115 | } 116 | } 117 | } 118 | channels = 1; 119 | 120 | _info.width = width; 121 | if( _info.binary ) 122 | { 123 | _info.lineLength = (width+7)/8; 124 | _info.data = new unsigned char[ _info.lineLength ]; 125 | } 126 | else _info.data = NULL; 127 | } 128 | 129 | inline PBMReader::~PBMReader( void ){ fclose( _info.fp ) ; delete[] _info.data; } 130 | 131 | inline unsigned int PBMReader::nextRow( unsigned char* row ) 132 | { 133 | if( _info.binary ) 134 | { 135 | fread( _info.data , sizeof(unsigned char) , _info.lineLength , _info.fp ); 136 | for( unsigned int i=0 ; i<_info.width ; i++ ) 137 | { 138 | unsigned int _i = i/8; 139 | if( _info.data[i/8] & ( 1<<( 7 - (i%8) ) ) ) row[i] = 255; 140 | else row[i] = 0; 141 | } 142 | } 143 | else for( unsigned int i=0 ; i<_info.width ; i++ ) if( fscanf( _info.fp , " %c" , row+i )!=1 ) ERROR_OUT( "Failed to read " , i , "-th character from line" ); 144 | return ++_currentRow; 145 | } 146 | 147 | inline PBMWriter::PBMWriter( const char* fileName , unsigned int width , unsigned int height , unsigned int channels , unsigned int ) 148 | { 149 | if( channels!=1 ) ERROR_OUT( "Only single-channel output supported: " , channels ); 150 | _currentRow = 0; 151 | 152 | _info.fp = fopen( fileName , "wb" ); 153 | if( !_info.fp ) ERROR_OUT( "Failed to open: " , fileName ); 154 | 155 | _info.width = width; 156 | _info.lineLength = (width+7)/8; 157 | _info.data = new unsigned char[ _info.lineLength ]; 158 | _info.binary = true; 159 | 160 | fprintf( _info.fp , "P4\n" ); 161 | fprintf( _info.fp , "%d %d\n" , width , height ); 162 | } 163 | inline PBMWriter::~PBMWriter( void ){ fclose(_info.fp) ; delete[] _info.data; } 164 | 165 | inline unsigned int PBMWriter::nextRow( const unsigned char* row ) 166 | { 167 | if( _info.binary ) 168 | { 169 | memset( _info.data , 0 , sizeof(unsigned char) * _info.lineLength ); 170 | for( unsigned int i=0 ; i<_info.width ; i++ ) if( row[i] ) _info.data[i/8] |= 1<<( 7 - (i%8) ); 171 | fwrite( _info.data , sizeof(unsigned char) , _info.lineLength , _info.fp ); 172 | } 173 | else 174 | { 175 | for( unsigned int i=0 ; i<_info.width ; i++ ) fprintf( _info.fp , " %d" , row[i] ? 1 : 0 ); 176 | fprintf( _info.fp , "\n" ); 177 | } 178 | return ++_currentRow; 179 | } 180 | inline unsigned int PBMWriter::nextRows( const unsigned char* rows , unsigned int rowNum ) 181 | { 182 | for( unsigned int i=0 ; i 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | 41 | namespace Misha 42 | { 43 | template< typename ... Arguments > void _AddToMessageStream( std::stringstream &stream , Arguments ... arguments ); 44 | inline void _AddToMessageStream( std::stringstream &stream ){ return; } 45 | template< typename Argument , typename ... Arguments > void _AddToMessageStream( std::stringstream &stream , Argument argument , Arguments ... arguments ) 46 | { 47 | stream << argument; 48 | _AddToMessageStream( stream , arguments ... ); 49 | } 50 | 51 | #ifdef VERBOSE_MESSAGING 52 | template< typename ... Arguments > 53 | std::string MakeMessageString( std::string header , std::string fileName , int line , std::string functionName , Arguments ... arguments ) 54 | { 55 | size_t headerSize = header.size(); 56 | std::stringstream stream; 57 | 58 | // The first line is the header, the file name , and the line number 59 | stream << header << " " << fileName << " (Line " << line << ")" << std::endl; 60 | 61 | // Inset the second line by the size of the header and write the function name 62 | for( size_t i=0 ; i<=headerSize ; i++ ) stream << " "; 63 | stream << functionName << std::endl; 64 | 65 | // Inset the third line by the size of the header and write the rest 66 | for( size_t i=0 ; i<=headerSize ; i++ ) stream << " "; 67 | _AddToMessageStream( stream , arguments ... ); 68 | 69 | return stream.str(); 70 | } 71 | struct Exception : public std::exception 72 | { 73 | const char *what( void ) const noexcept { return _message.c_str(); } 74 | template< typename ... Args > 75 | Exception( const char *fileName , int line , const char *functionName , const char *format , Args ... args ) 76 | { 77 | _message = MakeMessageString( "[EXCEPTION]" , fileName , line , functionName , format , args ... ); 78 | } 79 | private: 80 | std::string _message; 81 | }; 82 | 83 | template< typename ... Args > void Throw( const char *fileName , int line , const char *functionName , const char *format , Args ... args ){ throw Exception( fileName , line , functionName , format , args ... ); } 84 | template< typename ... Args > 85 | void Warn( const char *fileName , int line , const char *functionName , const char *format , Args ... args ) 86 | { 87 | #pragma omp critical 88 | std::cerr << MakeMessageString( "[WARNING]" , fileName , line , functionName , format , args ... ) << std::endl; 89 | } 90 | template< typename ... Args > 91 | void ErrorOut( const char *fileName , int line , const char *functionName , const char *format , Args ... args ) 92 | { 93 | #pragma omp critical 94 | std::cerr << MakeMessageString( "[ERROR]" , fileName , line , functionName , format , args ... ) << std::endl; 95 | exit( 0 ); 96 | } 97 | #else // !VERBOSE_MESSAGING 98 | template< typename ... Arguments > 99 | std::string MakeMessageString( std::string header , std::string functionName , Arguments ... arguments ) 100 | { 101 | std::stringstream stream; 102 | 103 | // The first line is the header, the file name , and the line number 104 | stream << header << " " << functionName << ": "; 105 | 106 | _AddToMessageStream( stream , arguments ... ); 107 | 108 | return stream.str(); 109 | } 110 | 111 | struct Exception : public std::exception 112 | { 113 | const char *what( void ) const noexcept { return _message.c_str(); } 114 | template< typename ... Args > 115 | Exception( const char *functionName , const char *format , Args ... args ) 116 | { 117 | _message = MakeMessageString( "[EXCEPTION]" , functionName , format , args ... ); 118 | } 119 | private: 120 | std::string _message; 121 | }; 122 | template< typename ... Args > void Throw( const char *functionName , const char *format , Args ... args ){ throw Exception( functionName , format , args ... ); } 123 | template< typename ... Args > 124 | void Warn( const char *functionName , const char *format , Args ... args ) 125 | { 126 | #pragma omp critical 127 | std::cerr << MakeMessageString( "[WARNING]" , functionName , format , args ... ) << std::endl; 128 | } 129 | template< typename ... Args > 130 | void ErrorOut( const char *functionName , const char *format , Args ... args ) 131 | { 132 | #pragma omp critical 133 | std::cerr << MakeMessageString( "[WARNING]" , functionName , format , args ... ) << std::endl; 134 | exit( 0 ); 135 | } 136 | #endif // VERBOSE_MESSAGING 137 | } 138 | #ifdef VERBOSE_MESSAGING 139 | #ifndef WARN 140 | #define WARN( ... ) Misha::Warn( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ ) 141 | #endif // WARN 142 | #ifndef WARN_ONCE 143 | #define WARN_ONCE( ... ) { static bool firstTime = true ; if( firstTime ) Misha::Warn( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ ) ; firstTime = false; } 144 | #endif // WARN_ONCE 145 | #ifndef THROW 146 | #define THROW( ... ) Misha::Throw( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ ) 147 | #endif // THROW 148 | #ifndef ERROR_OUT 149 | #define ERROR_OUT( ... ) Misha::ErrorOut( __FILE__ , __LINE__ , __FUNCTION__ , __VA_ARGS__ ) 150 | #endif // ERROR_OUT 151 | #else // !VERBOSE_MESSAGING 152 | #ifndef WARN 153 | #define WARN( ... ) Misha::Warn( __FUNCTION__ , __VA_ARGS__ ) 154 | #endif // WARN 155 | #ifndef WARN_ONCE 156 | #define WARN_ONCE( ... ) { static bool firstTime = true ; if( firstTime ) Misha::Warn( __FUNCTION__ , __VA_ARGS__ ) ; firstTime = false; } 157 | #endif // WARN_ONCE 158 | #ifndef THROW 159 | #define THROW( ... ) Misha::Throw( __FUNCTION__ , __VA_ARGS__ ) 160 | #endif // THROW 161 | #ifndef ERROR_OUT 162 | #define ERROR_OUT( ... ) Misha::ErrorOut( __FUNCTION__ , __VA_ARGS__ ) 163 | #endif // ERROR_OUT 164 | #endif // VERBOSE_MESSAGING 165 | 166 | #endif // EXCEPTIONS_INCLUDED 167 | -------------------------------------------------------------------------------- /ZLIB/crc32.c: -------------------------------------------------------------------------------- 1 | /* crc32.c -- compute the CRC-32 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: crc32.c,v 1.1 2014/03/04 21:20:43 uid42406 Exp $ */ 7 | 8 | #include "zlib.h" 9 | 10 | #define local static 11 | 12 | #ifdef DYNAMIC_CRC_TABLE 13 | 14 | local int crc_table_empty = 1; 15 | local uLongf crc_table[256]; 16 | local void make_crc_table OF((void)); 17 | 18 | /* 19 | Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: 20 | x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. 21 | 22 | Polynomials over GF(2) are represented in binary, one bit per coefficient, 23 | with the lowest powers in the most significant bit. Then adding polynomials 24 | is just exclusive-or, and multiplying a polynomial by x is a right shift by 25 | one. If we call the above polynomial p, and represent a byte as the 26 | polynomial q, also with the lowest power in the most significant bit (so the 27 | byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, 28 | where a mod b means the remainder after dividing a by b. 29 | 30 | This calculation is done using the shift-register method of multiplying and 31 | taking the remainder. The register is initialized to zero, and for each 32 | incoming bit, x^32 is added mod p to the register if the bit is a one (where 33 | x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by 34 | x (which is shifting right by one and adding x^32 mod p if the bit shifted 35 | out is a one). We start with the highest power (least significant bit) of 36 | q and repeat for all eight bits of q. 37 | 38 | The table is simply the CRC of all possible eight bit values. This is all 39 | the information needed to generate CRC's on data a byte at a time for all 40 | combinations of CRC register values and incoming bytes. 41 | */ 42 | local void make_crc_table() 43 | { 44 | uLong c; 45 | int n, k; 46 | uLong poly; /* polynomial exclusive-or pattern */ 47 | /* terms of polynomial defining this crc (except x^32): */ 48 | static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; 49 | 50 | /* make exclusive-or pattern from polynomial (0xedb88320L) */ 51 | poly = 0L; 52 | for (n = 0; n < sizeof(p)/sizeof(Byte); n++) 53 | poly |= 1L << (31 - p[n]); 54 | 55 | for (n = 0; n < 256; n++) 56 | { 57 | c = (uLong)n; 58 | for (k = 0; k < 8; k++) 59 | c = c & 1 ? poly ^ (c >> 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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------