Skip to content

Commit

Permalink
Develop (#42)
Browse files Browse the repository at this point in the history
* adding new image and duplicate image functionality (closes: #19)
* drawing eyedropper previews + other eyedropper improvements
* fixed a memory bug
* increasing size of some icons

* refactoring some code
* snake casing
* clang formatting the code
  • Loading branch information
wkjarosz authored Jun 8, 2021
1 parent 04ae357 commit ff17cd0
Show file tree
Hide file tree
Showing 58 changed files with 8,706 additions and 8,781 deletions.
26 changes: 26 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
BasedOnStyle: Microsoft
TabWidth: 4
IndentWidth: 4
ColumnLimit: 120
Standard: Cpp11

AlignAfterOpenBracket: Align
AlignConsecutiveMacros: 'true'
AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true'
AlignTrailingComments: 'true'

AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortBlocksOnASingleLine: Always
AllowShortLoopsOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'

AccessModifierOffset: -4
AlwaysBreakTemplateDeclarations: Yes
BreakConstructorInitializers: AfterColon

BreakBeforeBraces: Allman

...
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ project(hdrview)

set(HDRVIEW_VERSION "1.2.0")

# set(USE_SANITIZER "Address")
# set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/ext/cmake" ${CMAKE_MODULE_PATH})
# include(sanitizers)

# Set ourselves as the startup project in visual studio.
# Not available until cmake 3.6, but doesn't break older versions.
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT hdrview)
Expand Down
90 changes: 90 additions & 0 deletions ext/cmake/sanitizers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#
# Copyright (C) 2018 by George Cave - [email protected]
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

set(USE_SANITIZER
""
CACHE
STRING
"Compile with a sanitizer. Options are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'"
)

message(STATUS "CHECKING SANITIZERS: ${USE_SANITIZER}")

function(append value)
foreach(variable ${ARGN})
set(${variable}
"${${variable}} ${value}"
PARENT_SCOPE)
endforeach(variable)
endfunction()

if(USE_SANITIZER)
append("-fno-omit-frame-pointer" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

if(UNIX)

if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
append("-O1" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif()

if(USE_SANITIZER MATCHES "([Aa]ddress);([Uu]ndefined)"
OR USE_SANITIZER MATCHES "([Uu]ndefined);([Aa]ddress)")
message(STATUS "Building with Address, Undefined sanitizers")
append("-fsanitize=address,undefined" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif(USE_SANITIZER MATCHES "([Aa]ddress)")
# Optional: -fno-optimize-sibling-calls -fsanitize-address-use-after-scope
message(STATUS "Building with Address sanitizer")
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif(USE_SANITIZER MATCHES "([Mm]emory([Ww]ith[Oo]rigins)?)")
# Optional: -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2
append("-fsanitize=memory" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(USE_SANITIZER MATCHES "([Mm]emory[Ww]ith[Oo]rigins)")
message(STATUS "Building with MemoryWithOrigins sanitizer")
append("-fsanitize-memory-track-origins" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(STATUS "Building with Memory sanitizer")
endif()
elseif(USE_SANITIZER MATCHES "([Uu]ndefined)")
message(STATUS "Building with Undefined sanitizer")
append("-fsanitize=undefined" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(EXISTS "${BLACKLIST_FILE}")
append("-fsanitize-blacklist=${BLACKLIST_FILE}" CMAKE_C_FLAGS
CMAKE_CXX_FLAGS)
endif()
elseif(USE_SANITIZER MATCHES "([Tt]hread)")
message(STATUS "Building with Thread sanitizer")
append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
elseif(USE_SANITIZER MATCHES "([Ll]eak)")
message(STATUS "Building with Leak sanitizer")
append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(
FATAL_ERROR "Unsupported value of USE_SANITIZER: ${USE_SANITIZER}")
endif()
elseif(MSVC)
if(USE_SANITIZER MATCHES "([Aa]ddress)")
message(STATUS "Building with Address sanitizer")
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(
FATAL_ERROR
"This sanitizer not yet supported in the MSVC environment: ${USE_SANITIZER}"
)
endif()
else()
message(FATAL_ERROR "USE_SANITIZER is not supported on this platform.")
endif()

endif()
88 changes: 48 additions & 40 deletions src/array2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,65 @@ class Array2D
{
public:
//@{ \name Constructors and destructors
Array2D(); // empty array, 0 by 0 elements
Array2D(int size_x, int size_y, const T & value = T(0.)); // size_x by size_y elements

Array2D(const Array2D & o) { m_data = o.m_data; m_sizes[0] = o.m_sizes[0]; m_sizes[1] = o.m_sizes[1]; }
Array2D & operator=(const Array2D & o) {m_data = o.m_data; m_sizes[0] = o.m_sizes[0]; m_sizes[1] = o.m_sizes[1]; return *this;};
Array2D(); // empty array, 0 by 0 elements
Array2D(int size_x, int size_y, const T &value = T(0.)); // size_x by size_y elements

Array2D(const Array2D &o)
{
m_data = o.m_data;
m_sizes[0] = o.m_sizes[0];
m_sizes[1] = o.m_sizes[1];
}
Array2D &operator=(const Array2D &o)
{
m_data = o.m_data;
m_sizes[0] = o.m_sizes[0];
m_sizes[1] = o.m_sizes[1];
return *this;
};
//@}

//@{ \name Element access
T & operator()(int x, int y) {return m_data[y*m_sizes[0] + x];}
const T & operator()(int x, int y) const {return m_data[y*m_sizes[0] + x];}
T & operator()(int i) {return m_data[i];}
const T & operator()(int i) const {return m_data[i];}
const T * data() const {return &(m_data[0]);}
T * data() {return &(m_data[0]);}
T & operator()(int x, int y) { return m_data[y * m_sizes[0] + x]; }
const T &operator()(int x, int y) const { return m_data[y * m_sizes[0] + x]; }
T & operator()(int i) { return m_data[i]; }
const T &operator()(int i) const { return m_data[i]; }
const T *data() const { return &(m_data[0]); }
T * data() { return &(m_data[0]); }
//@}

//@{ \name Dimension sizes
int width() const { return m_sizes[0]; }
int width() const { return m_sizes[0]; }
int height() const { return m_sizes[1]; }

int size() const { return m_sizes[0]*m_sizes[1]; }
int size(int d) const { return m_sizes[d]; }
int size_x() const { return m_sizes[0]; }
int size_y() const { return m_sizes[1]; }
Array2D & swapped_dims() { std::swap(m_sizes[0], m_sizes[1]); return *this; }
int size() const { return m_sizes[0] * m_sizes[1]; }
int size(int d) const { return m_sizes[d]; }
int size_x() const { return m_sizes[0]; }
int size_y() const { return m_sizes[1]; }

Array2D &swapped_dims()
{
std::swap(m_sizes[0], m_sizes[1]);
return *this;
}
//@}

void resize(int size_x, int size_y, const T &value = T(0.));
void reset(const T& value = T(0.));
void operator=(const T&);
void reset(const T &value = T(0.));
void operator=(const T &);

protected:
std::vector<T> m_data;
int m_sizes[2];
std::vector<T> m_data;
int m_sizes[2];
};

template <typename T>
inline Array2D<T>::Array2D():
m_data()
inline Array2D<T>::Array2D() : m_data()
{
m_sizes[0] = m_sizes[1] = 0;
}


template <typename T>
inline Array2D<T>::Array2D(int size_x, int size_y, const T & value):
m_data(size_x * size_y, value)
inline Array2D<T>::Array2D(int size_x, int size_y, const T &value) : m_data(size_x * size_y, value)
{
m_sizes[0] = size_x;
m_sizes[1] = size_y;
Expand All @@ -73,26 +85,22 @@ inline void Array2D<T>::resize(int size_x, int size_y, const T &value)
return;

m_data.resize(size_x * size_y, value);
m_sizes[0] = size_x;
m_sizes[1] = size_y;
m_sizes[0] = size_x;
m_sizes[1] = size_y;
}


template <typename T>
inline void Array2D<T>::reset(const T& value)
inline void Array2D<T>::reset(const T &value)
{
for (int i = 0; i < size(); ++i)
m_data[i] = value;
for (int i = 0; i < size(); ++i) m_data[i] = value;
}


template <typename T>
inline void Array2D<T>::operator=(const T& value)
inline void Array2D<T>::operator=(const T &value)
{
reset(value);
}


using Array2Di = Array2D<int>;
using Array2Dd = Array2D<double>;
using Array2Df = Array2D<float>;
using Array2Di = Array2D<int>;
using Array2Dd = Array2D<double>;
using Array2Df = Array2D<float>;
Loading

0 comments on commit ff17cd0

Please sign in to comment.