Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows portability edits #46

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libdvid/DVIDNodeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <json/value.h>
#include <vector>
#include <random>
#include <fstream>
#include <string>

Expand Down Expand Up @@ -64,6 +65,10 @@ class NodeBuffer {
* Class that helps access different DVID version node actions.
*/
class DVIDNodeService {
protected:
//! Random number generator
std::default_random_engine rng;

public:
/*!
* Constructor sets up a http connection and checks
Expand Down
18 changes: 8 additions & 10 deletions load_tests/ScopeTime.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#ifndef SCOPETIME_H
#define SCOPETIME_H

#include <sys/time.h>
#include <chrono>
#include <iostream>

class ScopeTime {
using clock = std::chrono::high_resolution_clock;

public:
ScopeTime(bool debug_ = true) : debug(debug_)
ScopeTime(bool debug_ = true) : debug(debug_), initial_time(clock::now())
{
struct timeval tv;
gettimeofday(&tv, NULL);
initial_time = tv.tv_sec + tv.tv_usec / 1000000.0;
}
~ScopeTime()
{
Expand All @@ -20,13 +19,12 @@ class ScopeTime {
}
double getElapsed()
{
struct timeval tv;
gettimeofday(&tv, NULL);
double final_time = tv.tv_sec + tv.tv_usec / 1000000.0;
return (final_time - initial_time);
auto final_time = clock::now();
std::chrono::duration<double> diff = (final_time - initial_time);
return diff.count();
}
private:
double initial_time;
std::chrono::time_point<clock> initial_time;
bool debug;
};

Expand Down
4 changes: 2 additions & 2 deletions load_tests/loadtest_labelblk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int SMALLFETCH = 128;
int main(int argc, char** argv)
{
if (argc != 3) {
cout << "Usage: <program> <server_name>" << endl;
cout << "Usage: <program> <server_name> <segmentation_binary_lz4_file>" << endl;
return -1;
}
try {
Expand All @@ -67,7 +67,7 @@ int main(int argc, char** argv)
dims.push_back(VOLDIM); dims.push_back(VOLDIM); dims.push_back(VOLDIM);

// read a representative segmentation
ifstream fin(argv[2]);
ifstream fin(argv[2], std::ios_base::in | std::ios_base::binary);
BinaryDataPtr binary = BinaryData::create_binary_data(fin);
binary = BinaryData::decompress_lz4(binary, VOLDIM*VOLDIM*VOLDIM*sizeof(uint64));
Labels3D labelbin = Labels3D(binary, dims);
Expand Down
60 changes: 60 additions & 0 deletions png++/NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
Version 0.2.7:

- Added solid_pixel_buffer (patch by Andrey Potapov).

- Fixed some compilation problems on Win32.

Version 0.2.5:

- Fixed compatibility with newer libpng versions (>= 1.4)

- Fixed compilation on FreeBSD.

- Fixed tRNS handling with transformations.

- Added IO transformation debugging facility.

- Better organized test suite.

Version 0.2.3:

- Fixed numerous `already defined' errors due to require_color_space
implementation.

- Added `config.hpp'.

- Fixed `strerror' usage.

- Minor docs fixes.


Version 0.2.1:

- Added support for tRNS chunk.

- Added non-std IO streams support.

- Fixed 16-bit endianness problems.

- Improved test script.


Version 0.2.0:

- Added support for 16-bit data (RGB, RGBA, Grayscale and Gray+Alpha
color types)

- Added support for packed 1-, 2- or 4-bit pixels (Grayscale and
Indexed colors)

- Fixed interlace handling code which was severely broken

- Added possibility to process images without reading the entire
image into memory

- Internals are refactored while the client interface is mostly
unchanged

- Added intensive test suite

- Added documentation
37 changes: 36 additions & 1 deletion png++/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include <endian.h>

#elif defined(__WIN32)
#elif defined(_WIN32)

#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
Expand All @@ -52,10 +52,45 @@
#include <machine/endian.h>
#include <sys/endian.h>

#elif defined(__sun)

#include <sys/isa_defs.h>

#else

#error Byte-order could not be detected.

#endif

// Determine C++11 features
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && defined(__GXX_EXPERIMENTAL_CXX0X__)

#define PNGPP_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
// gcc c++11 support list
// http://gcc.gnu.org/projects/cxx0x.html

// gcc supports static_assert since 4.3
#if (PNGPP_GCC_VERSION >= 40300)
#define PNGPP_HAS_STATIC_ASSERT
#endif

// gcc supports std::move since 4.6
#if (PNGPP_GCC_VERSION >= 40600)
#define PNGPP_HAS_STD_MOVE
#endif

#undef PNGPP_GCC_VERSION

#elif defined(_MSC_VER)

// MS Visual C++ compiler supports static_assert and std::move since VS2010
// http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx
#if (_MSC_VER >= 1600)
#define PNGPP_HAS_STATIC_ASSERT
#define PNGPP_HAS_STD_MOVE
#endif

#endif


#endif // PNGPP_CONFIG_HPP_INCLUDED
6 changes: 2 additions & 4 deletions png++/consumer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ namespace png
#ifdef PNG_READ_SWAP_SUPPORTED
rd.set_swap();
#else
throw error("Cannot read 16-bit image:"
" recompile with PNG_READ_SWAP_SUPPORTED.");
throw error("Cannot read 16-bit image: recompile with PNG_READ_SWAP_SUPPORTED.");
#endif
}
#endif
Expand All @@ -180,8 +179,7 @@ namespace png
#ifdef PNG_READ_INTERLACING_SUPPORTED
pass_count = rd.set_interlace_handling();
#else
throw error("Cannot read interlaced image:"
" interlace handling disabled.");
throw error("Cannot read interlaced image: interlace handling disabled.");
#endif
}
else
Expand Down
70 changes: 42 additions & 28 deletions png++/convert_color_space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ namespace png
#ifdef PNG_READ_16_TO_8_SUPPORTED
io.set_strip_16();
#else
throw error("expected 8-bit data but found 16-bit;"
" recompile with PNG_READ_16_TO_8_SUPPORTED");
throw error("expected 8-bit data but found 16-bit; recompile with PNG_READ_16_TO_8_SUPPORTED");
#endif
}
if (io.get_bit_depth() != 16 && traits::get_bit_depth() == 16)
Expand All @@ -122,9 +121,7 @@ namespace png
io.set_user_transform_info(NULL, 16,
traits::get_channels());
#else
throw error("expected 16-bit data but found 8-bit;"
" recompile with"
" PNG_READ_USER_TRANSFORM_SUPPORTED");
throw error("expected 16-bit data but found 8-bit; recompile with PNG_READ_USER_TRANSFORM_SUPPORTED");
#endif
}
}
Expand All @@ -140,9 +137,7 @@ namespace png
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
io.set_strip_alpha();
#else
throw error("alpha channel unexpected;"
" recompile with"
" PNG_READ_STRIP_ALPHA_SUPPORTED");
throw error("alpha channel unexpected; recompile with PNG_READ_STRIP_ALPHA_SUPPORTED");
#endif
}
if (!src_alpha && dst_alpha)
Expand All @@ -157,30 +152,45 @@ namespace png
#if defined(PNG_READ_FILLER_SUPPORTED) && !defined(PNG_1_0_X)
io.set_add_alpha(filler, filler_after);
#else
throw error("expected alpha channel but none found;"
" recompile with PNG_READ_FILLER_SUPPORTED"
" and be sure to use libpng > 1.0.x");
throw error("expected alpha channel but none found; recompile with PNG_READ_FILLER_SUPPORTED and be sure to use libpng > 1.0.x");
#endif
}
}

template< class reader >
static void handle_palette(reader& io)
{
if (io.get_color_type() == color_type_palette)
bool src_palette =
io.get_color_type() == color_type_palette;
bool dst_palette =
traits::get_color_type() == color_type_palette;
if (src_palette && !dst_palette)
{
#ifdef PNG_READ_EXPAND_SUPPORTED
io.set_palette_to_rgb();

if (traits::get_color_type() != color_type_palette)
{
io.get_info().drop_palette();
}
io.get_info().drop_palette();
#else
throw error("indexed colors unexpected;"
" recompile with PNG_READ_EXPAND_SUPPORTED");
throw error("indexed colors unexpected; recompile with PNG_READ_EXPAND_SUPPORTED");
#endif
}
else if (!src_palette && dst_palette)
{
throw error("conversion to indexed colors is unsupported (yet)");
}
else if (src_palette && dst_palette
&& io.get_bit_depth() != traits::get_bit_depth())
{
if (traits::get_bit_depth() == 8)
{
#ifdef PNG_READ_PACK_SUPPORTED
io.set_packing();
#endif
}
else
{
throw error("cannot convert to indexed colors with bit-depth < 8");
}
}
}

template< class reader >
Expand All @@ -194,19 +204,15 @@ namespace png
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
io.set_rgb_to_gray(/*rgb_to_gray_error*/);
#else
throw error("grayscale data expected;"
" recompile with"
" PNG_READ_RGB_TO_GRAY_SUPPORTED");
throw error("grayscale data expected; recompile with PNG_READ_RGB_TO_GRAY_SUPPORTED");
#endif
}
if (!src_rgb && dst_rgb)
{
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
io.set_gray_to_rgb();
#else
throw error("expected RGB data;"
" recompile with"
" PNG_READ_GRAY_TO_RGB_SUPPORTED");
throw error("expected RGB data; recompile with PNG_READ_GRAY_TO_RGB_SUPPORTED");
#endif
}
}
Expand All @@ -222,9 +228,7 @@ namespace png
#ifdef PNG_READ_EXPAND_SUPPORTED
io.set_gray_1_2_4_to_8();
#else
throw error("convert_color_space: expected 8-bit data;"
" recompile with"
" PNG_READ_EXPAND_SUPPORTED");
throw error("convert_color_space: expected 8-bit data; recompile with PNG_READ_EXPAND_SUPPORTED");
#endif
}
}
Expand Down Expand Up @@ -333,6 +337,16 @@ namespace png
{
};

/**
* \brief Converts %image %color space. A specialization for
* index_pixel type.
*/
template<>
struct convert_color_space< index_pixel >
: detail::convert_color_space_impl< index_pixel >
{
};

} // namespace png

#endif // PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED
1 change: 1 addition & 0 deletions png++/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef PNGPP_ERROR_HPP_INCLUDED
#define PNGPP_ERROR_HPP_INCLUDED

#include <string>
#include <stdexcept>
#include <cerrno>
#include <cstdlib>
Expand Down
9 changes: 3 additions & 6 deletions png++/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ namespace png
#ifdef PNG_WRITE_SWAP_SUPPORTED
wr.set_swap();
#else
throw error("Cannot write 16-bit image:"
" recompile with PNG_WRITE_SWAP_SUPPORTED.");
throw error("Cannot write 16-bit image: recompile with PNG_WRITE_SWAP_SUPPORTED.");
#endif
}
#endif
Expand All @@ -154,12 +153,10 @@ namespace png
}
else
{
throw std::logic_error("Cannot write interlaced image:"
" generator does not support it.");
throw std::logic_error("Cannot write interlaced image: generator does not support it.");
}
#else
throw error("Cannot write interlaced image:"
" interlace handling disabled.");
throw error("Cannot write interlaced image: interlace handling disabled.");
#endif
}
else
Expand Down
Loading