Merge branch 'fix_out_of_files_in_encoding' into release-1.36

This commit is contained in:
Isaac Connor 2021-05-21 10:39:58 -04:00
commit d218d81f87
40 changed files with 1080 additions and 806 deletions

View File

@ -3,7 +3,8 @@ target_compile_options(zm-warning-interface
-Wall
-Wextra
-Wimplicit-fallthrough
-Wno-unused-parameter)
-Wno-unused-parameter
-Wvla)
if(ENABLE_WERROR)
target_compile_options(zm-warning-interface

View File

@ -7,7 +7,8 @@ target_compile_options(zm-warning-interface
-Wno-cast-function-type
$<$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>:-Wno-clobbered>
-Wno-unused-parameter
-Woverloaded-virtual)
-Woverloaded-virtual
-Wvla)
if(ENABLE_WERROR)
target_compile_options(zm-warning-interface

View File

@ -31,7 +31,7 @@
%global _hardened_build 1
Name: zoneminder
Version: 1.36.0
Version: 1.37.0
Release: 1%{?dist}
Summary: A camera monitoring and analysis tool
Group: System Environment/Daemons

View File

@ -6,12 +6,10 @@ configure_file(zm_config_data.h.in "${CMAKE_BINARY_DIR}/zm_config_data.h" @ONLY)
# Group together all the source files that are used by all the binaries (zmc, zmu, zms etc)
set(ZM_BIN_SRC_FILES
zm_analysis_thread.cpp
zm_box.cpp
zm_buffer.cpp
zm_camera.cpp
zm_comms.cpp
zm_config.cpp
zm_coord.cpp
zm_curl_camera.cpp
zm_crypt.cpp
zm.cpp

View File

@ -1,22 +0,0 @@
//
// ZoneMinder Box Class Implementation, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "zm_box.h"
// This section deliberately left blank

View File

@ -20,49 +20,59 @@
#ifndef ZM_BOX_H
#define ZM_BOX_H
#include "zm_coord.h"
#include "zm_line.h"
#include "zm_vector2.h"
#include <cmath>
#include <vector>
//
// Class used for storing a box, which is defined as a region
// defined by two coordinates
//
class Box {
private:
Coord lo, hi;
Coord size;
public:
inline Box() : lo(0,0), hi(0,0), size(0,0) { }
explicit inline Box(unsigned int p_size) : lo(0, 0), hi(p_size-1, p_size-1), size(Coord::Range(hi, lo)) { }
inline Box( int p_x_size, int p_y_size ) : lo( 0, 0 ), hi ( p_x_size-1, p_y_size-1 ), size( Coord::Range( hi, lo ) ) { }
inline Box( int lo_x, int lo_y, int hi_x, int hi_y ) : lo( lo_x, lo_y ), hi( hi_x, hi_y ), size( Coord::Range( hi, lo ) ) { }
inline Box( const Coord &p_lo, const Coord &p_hi ) : lo( p_lo ), hi( p_hi ), size( Coord::Range( hi, lo ) ) { }
Box() = default;
Box(Vector2 lo, Vector2 hi) : lo_(lo), hi_(hi), size_(hi - lo) {}
inline const Coord &Lo() const { return lo; }
inline int LoX() const { return lo.X(); }
inline int LoX(int p_lo_x) { return lo.X(p_lo_x); }
inline int LoY() const { return lo.Y(); }
inline int LoY(int p_lo_y) { return lo.Y(p_lo_y); }
inline const Coord &Hi() const { return hi; }
inline int HiX() const { return hi.X(); }
inline int HiX(int p_hi_x) { return hi.X(p_hi_x); }
inline int HiY() const { return hi.Y(); }
inline int HiY(int p_hi_y) { return hi.Y(p_hi_y); }
inline const Coord &Size() const { return size; }
inline int Width() const { return size.X(); }
inline int Height() const { return size.Y(); }
inline int Area() const { return size.X()*size.Y(); }
const Vector2 &Lo() const { return lo_; }
const Vector2 &Hi() const { return hi_; }
inline const Coord Centre() const {
int mid_x = int(std::round(lo.X()+(size.X()/2.0)));
int mid_y = int(std::round(lo.Y()+(size.Y()/2.0)));
return Coord( mid_x, mid_y );
const Vector2 &Size() const { return size_; }
int32 Area() const { return size_.x_ * size_.y_; }
Vector2 Centre() const {
int32 mid_x = static_cast<int32>(std::lround(lo_.x_ + (size_.x_ / 2.0)));
int32 mid_y = static_cast<int32>(std::lround(lo_.y_ + (size_.y_ / 2.0)));
return {mid_x, mid_y};
}
inline bool Inside( const Coord &coord ) const
{
return( coord.X() >= lo.X() && coord.X() <= hi.X() && coord.Y() >= lo.Y() && coord.Y() <= hi.Y() );
// Get vertices of the box in a counter-clockwise order
std::vector<Vector2> Vertices() const {
return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}};
}
// Get edges of the box in a counter-clockwise order
std::vector<LineSegment> Edges() const {
std::vector<LineSegment> edges;
edges.reserve(4);
std::vector<Vector2> v = Vertices();
edges.emplace_back(v[0], v[1]);
edges.emplace_back(v[1], v[2]);
edges.emplace_back(v[2], v[3]);
edges.emplace_back(v[3], v[0]);
return edges;
}
bool Contains(const Vector2 &coord) const {
return (coord.x_ >= lo_.x_ && coord.x_ <= hi_.x_ && coord.y_ >= lo_.y_ && coord.y_ <= hi_.y_);
}
private:
Vector2 lo_;
Vector2 hi_;
Vector2 size_;
};
#endif // ZM_BOX_H

View File

@ -36,7 +36,7 @@
int ZM::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) {
va_list arg_ptr;
iovec iov[iovcnt];
std::vector<iovec> iov(iovcnt);
va_start(arg_ptr, iovcnt);
for (int i = 0; i < iovcnt; i++) {
@ -45,7 +45,7 @@ int ZM::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) {
}
va_end(arg_ptr);
int nBytes = ::readv(mRd, iov, iovcnt);
int nBytes = ::readv(mRd, iov.data(), iovcnt);
if (nBytes < 0) {
Debug(1, "Readv of %d buffers max on rd %d failed: %s", iovcnt, mRd, strerror(errno));
}
@ -54,7 +54,7 @@ int ZM::CommsBase::readV(int iovcnt, /* const void *, int, */ ...) {
int ZM::CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) {
va_list arg_ptr;
iovec iov[iovcnt];
std::vector<iovec> iov(iovcnt);
va_start(arg_ptr, iovcnt);
for (int i = 0; i < iovcnt; i++) {
@ -63,7 +63,7 @@ int ZM::CommsBase::writeV(int iovcnt, /* const void *, int, */ ...) {
}
va_end(arg_ptr);
ssize_t nBytes = ::writev(mWd, iov, iovcnt);
ssize_t nBytes = ::writev(mWd, iov.data(), iovcnt);
if (nBytes < 0) {
Debug(1, "Writev of %d buffers on wd %d failed: %s", iovcnt, mWd, strerror(errno));
}

View File

@ -243,27 +243,27 @@ class Socket : public CommsBase {
return nBytes;
}
virtual int recv(std::string &msg) const {
char buffer[msg.capacity()];
int nBytes = 0;
if ((nBytes = ::recv(mSd, buffer, sizeof(buffer), 0)) < 0) {
Debug(1, "Recv of %zd bytes max to string on sd %d failed: %s", sizeof(buffer), mSd, strerror(errno));
virtual ssize_t recv(std::string &msg) const {
std::vector<char> buffer(msg.capacity());
ssize_t nBytes;
if ((nBytes = ::recv(mSd, buffer.data(), buffer.size(), 0)) < 0) {
Debug(1, "Recv of %zd bytes max to string on sd %d failed: %s", msg.size(), mSd, strerror(errno));
return nBytes;
}
buffer[nBytes] = '\0';
msg = buffer;
msg = {buffer.begin(), buffer.begin() + nBytes};
return nBytes;
}
virtual int recv(std::string &msg, size_t maxLen) const {
char buffer[maxLen];
int nBytes = 0;
if ((nBytes = ::recv(mSd, buffer, sizeof(buffer), 0)) < 0) {
virtual ssize_t recv(std::string &msg, size_t maxLen) const {
std::vector<char> buffer(maxLen);
ssize_t nBytes;
if ((nBytes = ::recv(mSd, buffer.data(), buffer.size(), 0)) < 0) {
Debug(1, "Recv of %zd bytes max to string on sd %d failed: %s", maxLen, mSd, strerror(errno));
return nBytes;
}
buffer[nBytes] = '\0';
msg = buffer;
msg = {buffer.begin(), buffer.begin() + nBytes};
return nBytes;
}

View File

@ -1,22 +0,0 @@
//
// ZoneMinder Coordinate Class Implementation, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "zm_coord.h"
// This section deliberately left blank

View File

@ -1,64 +0,0 @@
//
// ZoneMinder Coordinate Class Interface, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#ifndef ZM_COORD_H
#define ZM_COORD_H
#include "zm_define.h"
//
// Class used for storing an x,y pair, i.e. a coordinate
//
class Coord {
private:
int x, y;
public:
inline Coord() : x(0), y(0) { }
inline Coord( int p_x, int p_y ) : x(p_x), y(p_y) { }
inline Coord( const Coord &p_coord ) : x(p_coord.x), y(p_coord.y) { }
inline Coord &operator =( const Coord &coord ) {
x = coord.x;
y = coord.y;
return *this;
}
inline int &X(int p_x) { x=p_x; return x; }
inline const int &X() const { return x; }
inline int &Y(int p_y) { y=p_y; return y; }
inline const int &Y() const { return y; }
inline static Coord Range( const Coord &coord1, const Coord &coord2 ) {
Coord result( (coord1.x-coord2.x)+1, (coord1.y-coord2.y)+1 );
return result;
}
inline bool operator==( const Coord &coord ) const { return( x == coord.x && y == coord.y ); }
inline bool operator!=( const Coord &coord ) const { return( x != coord.x || y != coord.y ); }
inline bool operator>( const Coord &coord ) const { return( x > coord.x && y > coord.y ); }
inline bool operator>=( const Coord &coord ) const { return( !(operator<(coord)) ); }
inline bool operator<( const Coord &coord ) const { return( x < coord.x && y < coord.y ); }
inline bool operator<=( const Coord &coord ) const { return( !(operator>(coord)) ); }
inline Coord &operator+=( const Coord &coord ) { x += coord.x; y += coord.y; return( *this ); }
inline Coord &operator-=( const Coord &coord ) { x -= coord.x; y -= coord.y; return( *this ); }
inline friend Coord operator+( const Coord &coord1, const Coord &coord2 ) { Coord result( coord1 ); result += coord2; return( result ); }
inline friend Coord operator-( const Coord &coord1, const Coord &coord2 ) { Coord result( coord1 ); result -= coord2; return( result ); }
};
#endif // ZM_COORD_H

View File

@ -29,6 +29,7 @@
#endif
#include <cinttypes>
#include <cstddef>
typedef std::int64_t int64;
typedef std::int32_t int32;

View File

@ -473,10 +473,10 @@ void Event::WriteDbFrames() {
stats.alarm_blobs_,
stats.min_blob_size_,
stats.max_blob_size_,
stats.alarm_box_.LoX(),
stats.alarm_box_.LoY(),
stats.alarm_box_.HiX(),
stats.alarm_box_.HiY(),
stats.alarm_box_.Lo().x_,
stats.alarm_box_.Lo().y_,
stats.alarm_box_.Hi().x_,
stats.alarm_box_.Hi().y_,
stats.score_);
} // end foreach zone stats
} // end if recording stats

View File

@ -820,10 +820,10 @@ Image *Image::HighlightEdges(
/* Set image to all black */
high_image->Clear();
unsigned int lo_x = limits ? limits->Lo().X() : 0;
unsigned int lo_y = limits ? limits->Lo().Y() : 0;
unsigned int hi_x = limits ? limits->Hi().X() : width-1;
unsigned int hi_y = limits ? limits->Hi().Y() : height-1;
unsigned int lo_x = limits ? limits->Lo().x_ : 0;
unsigned int lo_y = limits ? limits->Lo().y_ : 0;
unsigned int hi_x = limits ? limits->Hi().x_ : width - 1;
unsigned int hi_y = limits ? limits->Hi().y_ : height - 1;
if ( p_colours == ZM_COLOUR_GRAY8 ) {
for ( unsigned int y = lo_y; y <= hi_y; y++ ) {
@ -1508,7 +1508,7 @@ bool Image::Crop( unsigned int lo_x, unsigned int lo_y, unsigned int hi_x, unsig
}
bool Image::Crop(const Box &limits) {
return Crop(limits.LoX(), limits.LoY(), limits.HiX(), limits.HiY());
return Crop(limits.Lo().x_, limits.Lo().y_, limits.Hi().x_, limits.Hi().y_);
}
/* Far from complete */
@ -1932,7 +1932,7 @@ void Image::Delta(const Image &image, Image* targetimage) const {
#endif
}
const Coord Image::centreCoord( const char *text, int size=1 ) const {
const Vector2 Image::centreCoord(const char *text, int size = 1) const {
int index = 0;
int line_no = 0;
int text_len = strlen(text);
@ -1957,7 +1957,7 @@ const Coord Image::centreCoord( const char *text, int size=1 ) const {
uint16_t char_height = font_variant.GetCharHeight();
int x = (width - (max_line_len * char_width )) / 2;
int y = (height - (line_no * char_height) ) / 2;
return Coord(x, y);
return {x, y};
}
/* RGB32 compatible: complete */
@ -2007,7 +2007,7 @@ https://lemire.me/blog/2018/02/21/iterating-over-set-bits-quickly/
*/
void Image::Annotate(
const std::string &text,
const Coord &coord,
const Vector2 &coord,
const uint8 size,
const Rgb fg_colour,
const Rgb bg_colour) {
@ -2031,8 +2031,8 @@ void Image::Annotate(
// Calculate initial coordinates of annotation so that everything is displayed even if the
// user set coordinates would prevent that.
uint32 x0 = ZM::clamp(static_cast<uint32>(coord.X()), 0u, x0_max);
uint32 y0 = ZM::clamp(static_cast<uint32>(coord.Y()), 0u, y0_max);
uint32 x0 = ZM::clamp(static_cast<uint32>(coord.x_), 0u, x0_max);
uint32 y0 = ZM::clamp(static_cast<uint32>(coord.y_), 0u, y0_max);
uint32 y = y0;
for (const std::string &line : lines) {
@ -2127,7 +2127,7 @@ void Image::Annotate(
}
}
void Image::Timestamp( const char *label, const time_t when, const Coord &coord, const int size ) {
void Image::Timestamp(const char *label, const time_t when, const Vector2 &coord, const int size) {
char time_text[64];
tm when_tm = {};
strftime(time_text, sizeof(time_text), "%y/%m/%d %H:%M:%S", localtime_r(&when, &when_tm));
@ -2294,10 +2294,10 @@ void Image::Fill( Rgb colour, const Box *limits ) {
/* Convert the colour's RGBA subpixel order into the image's subpixel order */
colour = rgb_convert(colour,subpixelorder);
unsigned int lo_x = limits?limits->Lo().X():0;
unsigned int lo_y = limits?limits->Lo().Y():0;
unsigned int hi_x = limits?limits->Hi().X():width-1;
unsigned int hi_y = limits?limits->Hi().Y():height-1;
unsigned int lo_x = limits ? limits->Lo().x_ : 0;
unsigned int lo_y = limits ? limits->Lo().y_ : 0;
unsigned int hi_x = limits ? limits->Hi().x_ : width - 1;
unsigned int hi_y = limits ? limits->Hi().y_ : height - 1;
if ( colours == ZM_COLOUR_GRAY8 ) {
for ( unsigned int y = lo_y; y <= hi_y; y++ ) {
unsigned char *p = &buffer[(y*width)+lo_x];
@ -2339,10 +2339,10 @@ void Image::Fill( Rgb colour, int density, const Box *limits ) {
/* Convert the colour's RGBA subpixel order into the image's subpixel order */
colour = rgb_convert(colour, subpixelorder);
unsigned int lo_x = limits?limits->Lo().X():0;
unsigned int lo_y = limits?limits->Lo().Y():0;
unsigned int hi_x = limits?limits->Hi().X():width-1;
unsigned int hi_y = limits?limits->Hi().Y():height-1;
unsigned int lo_x = limits ? limits->Lo().x_ : 0;
unsigned int lo_y = limits ? limits->Lo().y_ : 0;
unsigned int hi_x = limits ? limits->Hi().x_ : width - 1;
unsigned int hi_y = limits ? limits->Hi().y_ : height - 1;
if ( colours == ZM_COLOUR_GRAY8 ) {
for ( unsigned int y = lo_y; y <= hi_y; y++ ) {
unsigned char *p = &buffer[(y*width)+lo_x];
@ -2384,15 +2384,16 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) {
/* Convert the colour's RGBA subpixel order into the image's subpixel order */
colour = rgb_convert(colour, subpixelorder);
int n_coords = polygon.getNumCoords();
for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) {
const Coord &p1 = polygon.getCoord( i );
const Coord &p2 = polygon.getCoord( j );
size_t n_coords = polygon.GetVertices().size();
for (size_t j = 0, i = n_coords - 1; j < n_coords; i = j++) {
const Vector2 &p1 = polygon.GetVertices()[i];
const Vector2 &p2 = polygon.GetVertices()[j];
int x1 = p1.X();
int x2 = p2.X();
int y1 = p1.Y();
int y2 = p2.Y();
// The last pixel we can draw is width/height - 1. Clamp to that value.
int x1 = ZM::clamp(p1.x_, 0, static_cast<int>(width - 1));
int x2 = ZM::clamp(p2.x_, 0, static_cast<int>(width - 1));
int y1 = ZM::clamp(p1.y_, 0, static_cast<int>(height - 1));
int y2 = ZM::clamp(p2.y_, 0, static_cast<int>(height - 1));
double dx = x2 - x1;
double dy = y2 - y1;
@ -2457,7 +2458,7 @@ void Image::Outline( Rgb colour, const Polygon &polygon ) {
} // end foreach coordinate in the polygon
}
/* RGB32 compatible: complete */
// Polygon filling is based on the Scan-line Polygon filling algorithm
void Image::Fill(Rgb colour, int density, const Polygon &polygon) {
if (!(colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB24 || colours == ZM_COLOUR_RGB32)) {
Panic("Attempt to fill image with unexpected colours %d", colours);
@ -2466,120 +2467,92 @@ void Image::Fill(Rgb colour, int density, const Polygon &polygon) {
/* Convert the colour's RGBA subpixel order into the image's subpixel order */
colour = rgb_convert(colour, subpixelorder);
int n_coords = polygon.getNumCoords();
int n_global_edges = 0;
Edge global_edges[n_coords];
for ( int j = 0, i = n_coords-1; j < n_coords; i = j++ ) {
const Coord &p1 = polygon.getCoord(i);
const Coord &p2 = polygon.getCoord(j);
size_t n_coords = polygon.GetVertices().size();
int x1 = p1.X();
int x2 = p2.X();
int y1 = p1.Y();
int y2 = p2.Y();
std::vector<PolygonFill::Edge> global_edges;
global_edges.reserve(n_coords);
for (size_t j = 0, i = n_coords - 1; j < n_coords; i = j++) {
const Vector2 &p1 = polygon.GetVertices()[i];
const Vector2 &p2 = polygon.GetVertices()[j];
//Debug( 9, "x1:%d,y1:%d x2:%d,y2:%d", x1, y1, x2, y2 );
if ( y1 == y2 )
// Do not add horizontal edges to the global edge table.
if (p1.y_ == p2.y_)
continue;
double dx = x2 - x1;
double dy = y2 - y1;
Vector2 d = p2 - p1;
global_edges[n_global_edges].min_y = y1<y2?y1:y2;
global_edges[n_global_edges].max_y = y1<y2?y2:y1;
global_edges[n_global_edges].min_x = y1<y2?x1:x2;
global_edges[n_global_edges]._1_m = dx/dy;
n_global_edges++;
}
std::sort(global_edges, global_edges + n_global_edges, Edge::CompareYX);
global_edges.emplace_back(std::min(p1.y_, p2.y_),
std::max(p1.y_, p2.y_),
p1.y_ < p2.y_ ? p1.x_ : p2.x_,
d.x_ / static_cast<double>(d.y_));
#ifndef ZM_DBG_OFF
if ( logLevel() >= Logger::DEBUG9 ) {
for ( int i = 0; i < n_global_edges; i++ ) {
Debug(9, "%d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f",
i, global_edges[i].min_y, global_edges[i].max_y, global_edges[i].min_x, global_edges[i]._1_m);
}
}
#endif
std::sort(global_edges.begin(), global_edges.end(), PolygonFill::Edge::CompareYX);
int n_active_edges = 0;
Edge active_edges[n_global_edges];
int y = global_edges[0].min_y;
do {
for ( int i = 0; i < n_global_edges; i++ ) {
if ( global_edges[i].min_y == y ) {
Debug(9, "Moving global edge");
active_edges[n_active_edges++] = global_edges[i];
if ( i < (n_global_edges-1) ) {
memmove(&global_edges[i], &global_edges[i + 1], sizeof(*global_edges) * (n_global_edges - i - 1));
i--;
}
n_global_edges--;
std::vector<PolygonFill::Edge> active_edges;
active_edges.reserve(global_edges.size());
int32 scan_line = global_edges[0].min_y;
while (!global_edges.empty() || !active_edges.empty()) {
// Deactivate edges with max_y < current scan line
for (auto it = active_edges.begin(); it != active_edges.end();) {
if (scan_line >= it->max_y) {
it = active_edges.erase(it);
} else {
break;
it->min_x += it->_1_m;
++it;
}
}
std::sort(active_edges, active_edges + n_active_edges, Edge::CompareX);
#ifndef ZM_DBG_OFF
if ( logLevel() >= Logger::DEBUG9 ) {
for ( int i = 0; i < n_active_edges; i++ ) {
Debug(9, "%d - %d: min_y: %d, max_y:%d, min_x:%.2f, 1/m:%.2f",
y, i, active_edges[i].min_y, active_edges[i].max_y, active_edges[i].min_x, active_edges[i]._1_m );
// Activate edges with min_y == current scan line
for (auto it = global_edges.begin(); it != global_edges.end();) {
if (it->min_y == scan_line) {
active_edges.emplace_back(*it);
it = global_edges.erase(it);
} else {
++it;
}
}
#endif
if ( !(y%density) ) {
//Debug( 9, "%d", y );
for ( int i = 0; i < n_active_edges; ) {
int lo_x = int(round(active_edges[i++].min_x));
int hi_x = int(round(active_edges[i++].min_x));
std::sort(active_edges.begin(), active_edges.end(), PolygonFill::Edge::CompareX);
if (!(scan_line % density)) {
for (auto it = active_edges.begin(); it != active_edges.end(); ++it) {
int32 lo_x = static_cast<int32>(it->min_x);
int32 hi_x = static_cast<int32>(std::next(it)->min_x);
if (colours == ZM_COLOUR_GRAY8) {
unsigned char *p = &buffer[(y*width)+lo_x];
for ( int x = lo_x; x <= hi_x; x++, p++) {
uint8 *p = &buffer[(scan_line * width) + lo_x];
for (int32 x = lo_x; x <= hi_x; x++, p++) {
if (!(x % density)) {
//Debug( 9, " %d", x );
*p = colour;
}
}
} else if (colours == ZM_COLOUR_RGB24) {
unsigned char *p = &buffer[colours*((y*width)+lo_x)];
for ( int x = lo_x; x <= hi_x; x++, p += 3) {
constexpr uint8 bytesPerPixel = 3;
uint8 *ptr = &buffer[((scan_line * width) + lo_x) * bytesPerPixel];
for (int32 x = lo_x; x <= hi_x; x++, ptr += bytesPerPixel) {
if (!(x % density)) {
RED_PTR_RGBA(p) = RED_VAL_RGBA(colour);
GREEN_PTR_RGBA(p) = GREEN_VAL_RGBA(colour);
BLUE_PTR_RGBA(p) = BLUE_VAL_RGBA(colour);
RED_PTR_RGBA(ptr) = RED_VAL_RGBA(colour);
GREEN_PTR_RGBA(ptr) = GREEN_VAL_RGBA(colour);
BLUE_PTR_RGBA(ptr) = BLUE_VAL_RGBA(colour);
}
}
} else if (colours == ZM_COLOUR_RGB32) {
Rgb *p = (Rgb*)&buffer[((y*width)+lo_x)<<2];
for ( int x = lo_x; x <= hi_x; x++, p++) {
constexpr uint8 bytesPerPixel = 4;
Rgb *ptr = reinterpret_cast<Rgb *>(&buffer[((scan_line * width) + lo_x) * bytesPerPixel]);
for (int32 x = lo_x; x <= hi_x; x++, ptr++) {
if (!(x % density)) {
/* Fast, copies the entire pixel in a single pass */
*p = colour;
*ptr = colour;
}
}
}
}
}
y++;
for ( int i = n_active_edges-1; i >= 0; i-- ) {
if ( y >= active_edges[i].max_y ) {
// Or >= as per sheets
Debug(9, "Deleting active_edge");
if ( i < (n_active_edges-1) ) {
//memcpy( &active_edges[i], &active_edges[i+1], sizeof(*active_edges)*(n_active_edges-i) );
memmove( &active_edges[i], &active_edges[i+1], sizeof(*active_edges)*(n_active_edges-i) );
}
n_active_edges--;
} else {
active_edges[i].min_x += active_edges[i]._1_m;
}
}
} while ( n_global_edges || n_active_edges );
}
void Image::Fill(Rgb colour, const Polygon &polygon) {
Fill(colour, 1, polygon);
scan_line++;
}
}
void Image::Rotate(int angle) {

View File

@ -20,19 +20,18 @@
#ifndef ZM_IMAGE_H
#define ZM_IMAGE_H
#include "zm_coord.h"
#include "zm_ffmpeg.h"
#include "zm_jpeg.h"
#include "zm_logger.h"
#include "zm_mem_utils.h"
#include "zm_rgb.h"
#include "zm_vector2.h"
#if HAVE_ZLIB_H
#include <zlib.h>
#endif // HAVE_ZLIB_H
class Box;
class Image;
class Polygon;
#define ZM_BUFTYPE_DONTFREE 0
@ -96,24 +95,6 @@ class Image {
void update_function_pointers();
protected:
struct Edge {
int min_y;
int max_y;
double min_x;
double _1_m;
static bool CompareYX(const Edge &e1, const Edge &e2) {
if ( e1.min_y == e2.min_y )
return e1.min_x < e2.min_x;
return e1.min_y < e2.min_y;
}
static bool CompareX(const Edge &e1, const Edge &e2) {
return e1.min_x < e2.min_x;
}
};
inline void AllocImgBuffer(size_t p_bufsize) {
if ( buffer )
DumpImgBuffer();
@ -280,16 +261,16 @@ class Image {
//Image *Delta( const Image &image ) const;
void Delta( const Image &image, Image* targetimage) const;
const Coord centreCoord(const char *text, const int size) const;
const Vector2 centreCoord(const char *text, const int size) const;
void MaskPrivacy( const unsigned char *p_bitmask, const Rgb pixel_colour=0x00222222 );
void Annotate(const std::string &text,
const Coord &coord,
const Vector2 &coord,
uint8 size = 1,
Rgb fg_colour = kRGBWhite,
Rgb bg_colour = kRGBBlack);
Image *HighlightEdges( Rgb colour, unsigned int p_colours, unsigned int p_subpixelorder, const Box *limits=0 );
//Image *HighlightEdges( Rgb colour, const Polygon &polygon );
void Timestamp( const char *label, const time_t when, const Coord &coord, const int size );
void Timestamp(const char *label, const time_t when, const Vector2 &coord, const int size);
void Colourise(const unsigned int p_reqcolours, const unsigned int p_reqsubpixelorder);
void DeColourise();
@ -297,7 +278,7 @@ class Image {
void Fill( Rgb colour, const Box *limits=0 );
void Fill( Rgb colour, int density, const Box *limits=0 );
void Outline( Rgb colour, const Polygon &polygon );
void Fill( Rgb colour, const Polygon &polygon );
void Fill(Rgb colour, const Polygon &polygon) { Fill(colour, 1, polygon); };
void Fill(Rgb colour, int density, const Polygon &polygon);
void Rotate( int angle );
@ -311,6 +292,31 @@ class Image {
void Deinterlace_4Field(const Image* next_image, unsigned int threshold);
};
// Scan-line polygon fill algorithm
namespace PolygonFill {
class Edge {
public:
Edge() = default;
Edge(int32 min_y, int32 max_y, double min_x, double _1_m) : min_y(min_y), max_y(max_y), min_x(min_x), _1_m(_1_m) {}
static bool CompareYX(const Edge &e1, const Edge &e2) {
if (e1.min_y == e2.min_y)
return e1.min_x < e2.min_x;
return e1.min_y < e2.min_y;
}
static bool CompareX(const Edge &e1, const Edge &e2) {
return e1.min_x < e2.min_x;
}
public:
int32 min_y;
int32 max_y;
double min_x;
double _1_m;
};
}
#endif // ZM_IMAGE_H
/* Blend functions */

64
src/zm_line.h Normal file
View File

@ -0,0 +1,64 @@
/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ZONEMINDER_SRC_ZM_LINE_H_
#define ZONEMINDER_SRC_ZM_LINE_H_
#include "zm_vector2.h"
// Represents a part of a line bounded by two end points
class LineSegment {
public:
LineSegment(Vector2 start, Vector2 end) : start_(start), end_(end) {}
public:
Vector2 start_;
Vector2 end_;
};
// Represents an infinite line
class Line {
public:
Line(Vector2 p1, Vector2 p2) : position_(p1), direction_(p2 - p1) {}
explicit Line(LineSegment segment) : Line(segment.start_, segment.end_) {};
bool IsPointLeftOfOrColinear(Vector2 p) const {
int32 det = direction_.Determinant(p - position_);
return det >= 0;
}
Vector2 Intersection(Line const &line) const {
int32 det = direction_.Determinant(line.direction_);
if (det == 0) {
// lines are parallel or overlap, no intersection
return Vector2::Inf();
}
Vector2 c = line.position_ - position_;
double t = c.Determinant(line.direction_) / static_cast<double>(det);
return position_ + direction_ * t;
}
private:
Vector2 position_;
Vector2 direction_;
};
#endif //ZONEMINDER_SRC_ZM_LINE_H_

View File

@ -529,15 +529,17 @@ void Logger::logPrint(bool hex, const char *filepath, int line, int level, const
if (level <= mDatabaseLevel) {
if (zmDbConnected) {
int syslogSize = syslogEnd-syslogStart;
char escapedString[(syslogSize*2)+1];
mysql_real_escape_string(&dbconn, escapedString, syslogStart, syslogSize);
std::string escapedString;
escapedString.reserve((syslogSize * 2) + 1);
mysql_real_escape_string(&dbconn, &escapedString[0], syslogStart, syslogSize);
escapedString.resize(std::strlen(escapedString.c_str()));
std::string sql_string = stringtf(
"INSERT INTO `Logs` "
"( `TimeKey`, `Component`, `ServerId`, `Pid`, `Level`, `Code`, `Message`, `File`, `Line` )"
" VALUES "
"( %ld.%06ld, '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString, file, line
timeVal.tv_sec, timeVal.tv_usec, mId.c_str(), staticConfig.SERVER_ID, tid, level, classString, escapedString.c_str(), file, line
);
dbQueue.push(std::move(sql_string));
} else {

View File

@ -327,7 +327,7 @@ Monitor::Monitor()
record_audio(0),
//event_prefix
//label_format
label_coord(Coord(0,0)),
label_coord(Vector2(0,0)),
label_size(0),
image_buffer_count(0),
max_image_buffer_count(0),
@ -561,7 +561,7 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
/* "EventPrefix, LabelFormat, LabelX, LabelY, LabelSize," */
event_prefix = dbrow[col] ? dbrow[col] : ""; col++;
label_format = dbrow[col] ? ReplaceAll(dbrow[col], "\\n", "\n") : ""; col++;
label_coord = Coord(atoi(dbrow[col]), atoi(dbrow[col+1])); col += 2;
label_coord = Vector2(atoi(dbrow[col]), atoi(dbrow[col + 1])); col += 2;
label_size = atoi(dbrow[col]); col++;
/* "ImageBufferCount, `MaxImageBufferCount`, WarmupCount, PreEventCount, PostEventCount, StreamReplayBuffer, AlarmFrameCount, " */
@ -1039,6 +1039,7 @@ bool Monitor::connect() {
// Uh, why nothing? Why not nullptr?
snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "nothing");
video_store_data->size = sizeof(VideoStoreData);
usedsubpixorder = camera->SubpixelOrder(); // Used in CheckSignal
shared_data->valid = true;
} else if ( !shared_data->valid ) {
Error("Shared data not initialised by capture daemon for monitor %s", name.c_str());
@ -1481,12 +1482,18 @@ void Monitor::DumpZoneImage(const char *zone_string) {
zone_image->Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB);
}
extra_zone.Clip(Box(
{0, 0},
{static_cast<int32>(zone_image->Width()), static_cast<int32>(zone_image->Height())}
));
for (const Zone &zone : zones) {
if ( exclude_id && (!extra_colour || extra_zone.getNumCoords()) && zone.Id() == exclude_id )
if (exclude_id && (!extra_colour || !extra_zone.GetVertices().empty()) && zone.Id() == exclude_id) {
continue;
}
Rgb colour;
if ( exclude_id && !extra_zone.getNumCoords() && zone.Id() == exclude_id ) {
if (exclude_id && extra_zone.GetVertices().empty() && zone.Id() == exclude_id) {
colour = extra_colour;
} else {
if (zone.IsActive()) {
@ -1505,7 +1512,7 @@ void Monitor::DumpZoneImage(const char *zone_string) {
zone_image->Outline(colour, zone.GetPolygon());
}
if ( extra_zone.getNumCoords() ) {
if (!extra_zone.GetVertices().empty()) {
zone_image->Fill(extra_colour, 2, extra_zone);
zone_image->Outline(extra_colour, extra_zone);
}
@ -1544,9 +1551,14 @@ bool Monitor::CheckSignal(const Image *image) {
if (!config.timestamp_on_capture || !label_format[0])
break;
// Avoid sampling the rows with timestamp in
if ( index < (label_coord.Y()*width) || index >= (label_coord.Y()+Image::LINE_HEIGHT)*width )
if (
index < (label_coord.y_ * width)
||
index >= (label_coord.y_ + Image::LINE_HEIGHT) * width
) {
break;
}
}
if (colours == ZM_COLOUR_GRAY8) {
if (*(buffer+index) != grayscale_val)
@ -1843,7 +1855,7 @@ bool Monitor::Analyse() {
/* try to stay behind the decoder. */
if (decoding_enabled) {
while (!snap->image and !snap->decoded and !zm_terminate and !analysis_thread->Stopped()) {
while ((!snap->image or deinterlacing_value) and !snap->decoded and !zm_terminate and !analysis_thread->Stopped()) {
// Need to wait for the decoder thread.
Debug(1, "Waiting for decode");
packet_lock->wait();
@ -2832,7 +2844,7 @@ unsigned int Monitor::DetectMotion(const Image &comp_image, Event::StringSet &zo
} // end if CheckAlarms
} // end foreach zone
Coord alarm_centre;
Vector2 alarm_centre;
int top_score = -1;
if (alarm) {
@ -2898,8 +2910,8 @@ unsigned int Monitor::DetectMotion(const Image &comp_image, Event::StringSet &zo
} // end if alarm
if (top_score > 0) {
shared_data->alarm_x = alarm_centre.X();
shared_data->alarm_y = alarm_centre.Y();
shared_data->alarm_x = alarm_centre.x_;
shared_data->alarm_y = alarm_centre.y_;
Info("Got alarm centre at %d,%d, at count %d",
shared_data->alarm_x, shared_data->alarm_y, analysis_image_count);
@ -2954,7 +2966,7 @@ bool Monitor::DumpSettings(char *output, bool verbose) {
sprintf(output+strlen(output), "Subpixel Order : %u\n", camera->SubpixelOrder() );
sprintf(output+strlen(output), "Event Prefix : %s\n", event_prefix.c_str() );
sprintf(output+strlen(output), "Label Format : %s\n", label_format.c_str() );
sprintf(output+strlen(output), "Label Coord : %d,%d\n", label_coord.X(), label_coord.Y() );
sprintf(output+strlen(output), "Label Coord : %d,%d\n", label_coord.x_, label_coord.y_ );
sprintf(output+strlen(output), "Label Size : %d\n", label_size );
sprintf(output+strlen(output), "Image Buffer Count : %d\n", image_buffer_count );
sprintf(output+strlen(output), "Warmup Count : %d\n", warmup_count );

View File

@ -305,7 +305,7 @@ protected:
std::string event_prefix; // The prefix applied to event names as they are created
std::string label_format; // The format of the timestamp on the images
Coord label_coord; // The coordinates of the timestamp on the images
Vector2 label_coord; // The coordinates of the timestamp on the images
int label_size; // Size of the timestamp on the images
int32_t image_buffer_count; // Size of circular image buffer, kept in /dev/shm
int32_t max_image_buffer_count; // Max # of video packets to keep in packet queue

View File

@ -258,9 +258,11 @@ AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
}
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
int alignment = 32;
if (width%alignment) alignment = 1;
codec_imgsize = av_image_get_buffer_size(
format, width, height, 32);
format, width, height, alignment);
Debug(1, "buffer size %u from %s %dx%d", codec_imgsize, av_get_pix_fmt_name(format), width, height);
buffer = (uint8_t *)av_malloc(codec_imgsize);
int ret;
@ -271,7 +273,7 @@ AVFrame *ZMPacket::get_out_frame(int width, int height, AVPixelFormat format) {
format,
width,
height,
32))<0) {
alignment))<0) {
Error("Failed to fill_arrays %s", av_make_error_string(ret).c_str());
av_frame_free(&out_frame);
return nullptr;

View File

@ -19,91 +19,103 @@
#include "zm_poly.h"
#include "zm_line.h"
#include <cmath>
void Polygon::calcArea() {
double float_area = 0.0L;
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
double trap_area = ((coords[i].X()-coords[j].X())*((coords[i].Y()+coords[j].Y())))/2.0L;
float_area += trap_area;
//printf( "%.2f (%.2f)\n", float_area, trap_area );
}
area = (int)round(fabs(float_area));
Polygon::Polygon(std::vector<Vector2> vertices) : vertices_(std::move(vertices)), area(0) {
UpdateExtent();
UpdateArea();
UpdateCentre();
}
void Polygon::calcCentre() {
if ( !area && n_coords )
calcArea();
double float_x = 0.0L, float_y = 0.0L;
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
float_x += ((coords[i].Y()-coords[j].Y())*((coords[i].X()*2)+(coords[i].X()*coords[j].X())+(coords[j].X()*2)));
float_y += ((coords[j].X()-coords[i].X())*((coords[i].Y()*2)+(coords[i].Y()*coords[j].Y())+(coords[j].Y()*2)));
void Polygon::UpdateExtent() {
if (vertices_.empty())
return;
int min_x = vertices_[0].x_;
int max_x = 0;
int min_y = vertices_[0].y_;
int max_y = 0;
for (const Vector2 &vertex : vertices_) {
min_x = std::min(min_x, vertex.x_);
max_x = std::max(max_x, vertex.x_);
min_y = std::min(min_y, vertex.y_);
max_y = std::max(max_y, vertex.y_);
}
extent = Box({min_x, min_y}, {max_x, max_y});
}
void Polygon::UpdateArea() {
double float_area = 0.0;
for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
double trap_area = ((vertices_[i].x_ - vertices_[j].x_) * ((vertices_[i].y_ + vertices_[j].y_))) / 2.0;
float_area += trap_area;
}
area = static_cast<int32>(std::lround(std::fabs(float_area)));
}
void Polygon::UpdateCentre() {
if (!area && !vertices_.empty())
UpdateArea();
double float_x = 0.0;
double float_y = 0.0;
for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
float_x += ((vertices_[i].y_ - vertices_[j].y_)
* ((vertices_[i].x_ * 2) + (vertices_[i].x_ * vertices_[j].x_) + (vertices_[j].x_ * 2)));
float_y += ((vertices_[j].x_ - vertices_[i].x_)
* ((vertices_[i].y_ * 2) + (vertices_[i].y_ * vertices_[j].y_) + (vertices_[j].y_ * 2)));
}
float_x /= (6 * area);
float_y /= (6 * area);
centre = Coord( (int)round(float_x), (int)round(float_y) );
centre = Vector2(static_cast<int32>(std::lround(float_x)), static_cast<int32>(std::lround(float_y)));
}
Polygon::Polygon(int p_n_coords, const Coord *p_coords) : n_coords(p_n_coords) {
coords = new Coord[n_coords];
int min_x = -1;
int max_x = -1;
int min_y = -1;
int max_y = -1;
for ( int i = 0; i < n_coords; i++ ) {
coords[i] = p_coords[i];
if ( min_x == -1 || coords[i].X() < min_x )
min_x = coords[i].X();
if ( max_x == -1 || coords[i].X() > max_x )
max_x = coords[i].X();
if ( min_y == -1 || coords[i].Y() < min_y )
min_y = coords[i].Y();
if ( max_y == -1 || coords[i].Y() > max_y )
max_y = coords[i].Y();
}
extent = Box( min_x, min_y, max_x, max_y );
calcArea();
calcCentre();
}
Polygon::Polygon(const Polygon &p_polygon) :
n_coords(p_polygon.n_coords),
extent(p_polygon.extent),
area(p_polygon.area),
centre(p_polygon.centre)
{
coords = new Coord[n_coords];
for( int i = 0; i < n_coords; i++ ) {
coords[i] = p_polygon.coords[i];
}
}
Polygon &Polygon::operator=(const Polygon &p_polygon) {
n_coords = p_polygon.n_coords;
Coord *new_coords = new Coord[n_coords];
for (int i = 0; i < n_coords; i++) {
new_coords[i] = p_polygon.coords[i];
}
delete[] coords;
coords = new_coords;
extent = p_polygon.extent;
area = p_polygon.area;
centre = p_polygon.centre;
return *this;
}
bool Polygon::isInside( const Coord &coord ) const {
bool Polygon::Contains(const Vector2 &coord) const {
bool inside = false;
for ( int i = 0, j = n_coords-1; i < n_coords; j = i++ ) {
if ( (((coords[i].Y() <= coord.Y()) && (coord.Y() < coords[j].Y()) )
|| ((coords[j].Y() <= coord.Y()) && (coord.Y() < coords[i].Y())))
&& (coord.X() < (coords[j].X() - coords[i].X()) * (coord.Y() - coords[i].Y()) / (coords[j].Y() - coords[i].Y()) + coords[i].X()))
{
for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
if ((((vertices_[i].y_ <= coord.y_) && (coord.y_ < vertices_[j].y_)) || ((vertices_[j].y_ <= coord.y_) && (coord.y_ < vertices_[i].y_)))
&& (coord.x_ < (vertices_[j].x_ - vertices_[i].x_) * (coord.y_ - vertices_[i].y_) / (vertices_[j].y_ - vertices_[i].y_) + vertices_[i].x_)) {
inside = !inside;
}
}
return inside;
}
// Clip the polygon to a rectangular boundary box using the Sutherland-Hodgman algorithm
void Polygon::Clip(const Box &boundary) {
std::vector<Vector2> clipped_vertices = vertices_;
for (LineSegment const &clip_edge : boundary.Edges()) {
// convert our line segment to an infinite line
Line clip_line = Line(clip_edge);
std::vector<Vector2> to_clip = clipped_vertices;
clipped_vertices.clear();
for (size_t i = 0; i < to_clip.size(); ++i) {
Vector2 vert1 = to_clip[i];
Vector2 vert2 = to_clip[(i + 1) % to_clip.size()];
bool vert1_left = clip_line.IsPointLeftOfOrColinear(vert1);
bool vert2_left = clip_line.IsPointLeftOfOrColinear(vert2);
if (vert2_left) {
if (!vert1_left) {
clipped_vertices.push_back(Line(vert1, vert2).Intersection(clip_line));
}
clipped_vertices.push_back(vert2);
} else if (vert1_left) {
clipped_vertices.push_back(Line(vert1, vert2).Intersection(clip_line));
}
}
}
vertices_ = clipped_vertices;
UpdateExtent();
UpdateArea();
UpdateCentre();
}

View File

@ -21,96 +21,36 @@
#define ZM_POLY_H
#include "zm_box.h"
#include <vector>
class Coord;
//
// Class used for storing a box, which is defined as a region
// defined by two coordinates
//
// This class represents convex or concave non-self-intersecting polygons.
class Polygon {
protected:
struct Edge {
int min_y;
int max_y;
double min_x;
double _1_m;
static int CompareYX( const void *p1, const void *p2 ) {
const Edge *e1 = reinterpret_cast<const Edge *>(p1), *e2 = reinterpret_cast<const Edge *>(p2);
if ( e1->min_y == e2->min_y )
return int(e1->min_x - e2->min_x);
else
return int(e1->min_y - e2->min_y);
}
static int CompareX( const void *p1, const void *p2 ) {
const Edge *e1 = reinterpret_cast<const Edge *>(p1), *e2 = reinterpret_cast<const Edge *>(p2);
return int(e1->min_x - e2->min_x);
}
};
struct Slice {
int min_x;
int max_x;
int n_edges;
int *edges;
Slice() {
min_x = 0;
max_x = 0;
n_edges = 0;
edges = nullptr;
}
~Slice() {
delete edges;
}
};
protected:
int n_coords;
Coord *coords;
Box extent;
int area;
Coord centre;
protected:
void initialiseEdges();
void calcArea();
void calcCentre();
public:
inline Polygon() : n_coords(0), coords(nullptr), area(0) {
}
Polygon(int p_n_coords, const Coord *p_coords);
Polygon(const Polygon &p_polygon);
~Polygon() {
delete[] coords;
Polygon() : area(0) {}
explicit Polygon(std::vector<Vector2> vertices);
const std::vector<Vector2> &GetVertices() const {
return vertices_;
}
Polygon &operator=( const Polygon &p_polygon );
const Box &Extent() const { return extent; }
int32 Area() const { return area; }
const Vector2 &Centre() const { return centre; }
inline int getNumCoords() const { return n_coords; }
inline const Coord &getCoord( int index ) const {
return coords[index];
}
bool Contains(const Vector2 &coord) const;
inline const Box &Extent() const { return extent; }
inline int LoX() const { return extent.LoX(); }
inline int LoX(int p_lo_x) { return extent.LoX(p_lo_x); }
inline int HiX() const { return extent.HiX(); }
inline int HiX(int p_hi_x) { return extent.HiX(p_hi_x); }
inline int LoY() const { return extent.LoY(); }
inline int LoY(int p_lo_y) { return extent.LoY(p_lo_y); }
inline int HiY() const { return extent.HiY(); }
inline int HiY(int p_hi_y) { return extent.HiY(p_hi_y); }
inline int Width() const { return extent.Width(); }
inline int Height() const { return extent.Height(); }
void Clip(const Box &boundary);
inline int Area() const { return area; }
inline const Coord &Centre() const {
return centre;
}
bool isInside( const Coord &coord ) const;
private:
void UpdateExtent();
void UpdateArea();
void UpdateCentre();
private:
std::vector<Vector2> vertices_;
Box extent;
int32 area;
Vector2 centre;
};
#endif // ZM_POLY_H

View File

@ -20,6 +20,7 @@
#include "zm_logger.h"
#include "zm_utils.h"
#include <cassert>
#include <cstring>
namespace zm {
@ -131,8 +132,8 @@ std::string Authenticator::computeDigestResponse(const std::string &method, cons
#if HAVE_DECL_MD5 || HAVE_DECL_GNUTLS_FINGERPRINT
// The "response" field is computed as:
// md5(md5(<username>:<realm>:<password>):<nonce>:md5(<cmd>:<url>))
size_t md5len = 16;
unsigned char md5buf[md5len];
constexpr size_t md5len = 16;
uint8 md5buf[md5len];
char md5HexBuf[md5len * 2 + 1];
// Step 1: md5(<username>:<realm>:<password>)
@ -142,7 +143,9 @@ std::string Authenticator::computeDigestResponse(const std::string &method, cons
MD5((unsigned char*)ha1Data.c_str(), ha1Data.length(), md5buf);
#elif HAVE_DECL_GNUTLS_FINGERPRINT
gnutls_datum_t md5dataha1 = {(unsigned char *) ha1Data.c_str(), (unsigned int) ha1Data.length()};
gnutls_fingerprint( GNUTLS_DIG_MD5, &md5dataha1, md5buf, &md5len );
size_t md5_len_tmp = md5len;
gnutls_fingerprint(GNUTLS_DIG_MD5, &md5dataha1, md5buf, &md5_len_tmp);
assert(md5_len_tmp == md5len);
#endif
for ( unsigned int j = 0; j < md5len; j++ ) {
sprintf(&md5HexBuf[2*j], "%02x", md5buf[j] );
@ -157,7 +160,9 @@ std::string Authenticator::computeDigestResponse(const std::string &method, cons
MD5((unsigned char*)ha2Data.c_str(), ha2Data.length(), md5buf );
#elif HAVE_DECL_GNUTLS_FINGERPRINT
gnutls_datum_t md5dataha2 = {(unsigned char *) ha2Data.c_str(), (unsigned int) ha2Data.length()};
gnutls_fingerprint( GNUTLS_DIG_MD5, &md5dataha2, md5buf, &md5len );
md5_len_tmp = md5len;
gnutls_fingerprint(GNUTLS_DIG_MD5, &md5dataha2, md5buf, &md5_len_tmp);
assert(md5_len_tmp == md5len);
#endif
for ( unsigned int j = 0; j < md5len; j++ ) {
sprintf( &md5HexBuf[2*j], "%02x", md5buf[j] );
@ -178,7 +183,9 @@ std::string Authenticator::computeDigestResponse(const std::string &method, cons
MD5((unsigned char*)digestData.c_str(), digestData.length(), md5buf);
#elif HAVE_DECL_GNUTLS_FINGERPRINT
gnutls_datum_t md5datadigest = {(unsigned char *) digestData.c_str(), (unsigned int) digestData.length()};
gnutls_fingerprint( GNUTLS_DIG_MD5, &md5datadigest, md5buf, &md5len );
md5_len_tmp = md5len;
gnutls_fingerprint(GNUTLS_DIG_MD5, &md5datadigest, md5buf, &md5_len_tmp);
assert(md5_len_tmp == md5len);
#endif
for ( unsigned int j = 0; j < md5len; j++ ) {
sprintf( &md5HexBuf[2*j], "%02x", md5buf[j] );

View File

@ -204,9 +204,9 @@ Image *StreamBase::prepareImage(Image *image) {
last_crop = Box();
// Recalculate crop parameters, as %ges
int click_x = (last_crop.LoX() * 100 ) / last_act_image_width; // Initial crop offset from last image
int click_x = (last_crop.Lo().x_ * 100) / last_act_image_width; // Initial crop offset from last image
click_x += (x * 100) / last_virt_image_width;
int click_y = (last_crop.LoY() * 100 ) / last_act_image_height; // Initial crop offset from last image
int click_y = (last_crop.Lo().y_ * 100) / last_act_image_height; // Initial crop offset from last image
click_y += (y * 100) / last_virt_image_height;
Debug(3, "Got adjusted click at %d%%,%d%%", click_x, click_y);
@ -231,10 +231,10 @@ Image *StreamBase::prepareImage(Image *image) {
hi_y = act_image_height - 1;
lo_y = hi_y - (send_image_height - 1);
}
last_crop = Box( lo_x, lo_y, hi_x, hi_y );
last_crop = Box({lo_x, lo_y}, {hi_x, hi_y});
} // end if ( mag != last_mag || x != last_x || y != last_y )
Debug(3, "Cropping to %d,%d -> %d,%d", last_crop.LoX(), last_crop.LoY(), last_crop.HiX(), last_crop.HiY());
Debug(3, "Cropping to %d,%d -> %d,%d", last_crop.Lo().x_, last_crop.Lo().y_, last_crop.Hi().x_, last_crop.Hi().y_);
if ( !image_copied ) {
static Image copy_image;
copy_image.Assign(*image);

View File

@ -159,11 +159,11 @@ int SWScale::Convert(
}
#endif
int alignment = 1;
int alignment = width % 32 ? 1 : 32;
/* Check the buffer sizes */
size_t needed_insize = GetBufferSize(in_pf, width, height);
if (needed_insize > in_buffer_size) {
Debug(1,
Warning(
"The input buffer size does not match the expected size for the input format. Required: %zu for %dx%d %d Available: %zu",
needed_insize,
width,
@ -189,6 +189,14 @@ int SWScale::Convert(
return -6;
}
/*
input_avframe->format = in_pf;
input_avframe->width = width;
input_avframe->height = height;
output_avframe->format = out_pf;
output_avframe->width = new_width;
output_avframe->height = new_height;
*/
/* Fill in the buffers */
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
if (av_image_fill_arrays(input_avframe->data, input_avframe->linesize,

View File

@ -22,6 +22,7 @@
#include "zm_crypt.h"
#include "zm_logger.h"
#include "zm_utils.h"
#include <cassert>
#include <cstring>
#if HAVE_GNUTLS_GNUTLS_H
@ -236,8 +237,8 @@ User *zmLoadAuthUser(const char *auth, bool use_remote_addr) {
}
char auth_key[512] = "";
char auth_md5[32+1] = "";
size_t md5len = 16;
unsigned char md5sum[md5len];
constexpr size_t md5len = 16;
uint8 md5sum[md5len];
const char * hex = "0123456789abcdef";
while ( MYSQL_ROW dbrow = mysql_fetch_row(result) ) {
@ -263,7 +264,9 @@ User *zmLoadAuthUser(const char *auth, bool use_remote_addr) {
MD5((unsigned char *)auth_key, strlen(auth_key), md5sum);
#elif HAVE_DECL_GNUTLS_FINGERPRINT
gnutls_datum_t md5data = {(unsigned char *) auth_key, (unsigned int) strlen(auth_key)};
gnutls_fingerprint(GNUTLS_DIG_MD5, &md5data, md5sum, &md5len);
size_t md5_len_tmp = md5len;
gnutls_fingerprint(GNUTLS_DIG_MD5, &md5data, md5sum, &md5_len_tmp);
assert(md5_len_tmp == md5len);
#endif
unsigned char *md5sum_ptr = md5sum;
char *auth_md5_ptr = auth_md5;

80
src/zm_vector2.h Normal file
View File

@ -0,0 +1,80 @@
//
// ZoneMinder Coordinate Class Interface, $Date$, $Revision$
// Copyright (C) 2001-2008 Philip Coombes
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#ifndef ZM_VECTOR2_H
#define ZM_VECTOR2_H
#include "zm_define.h"
#include <cmath>
#include <limits>
//
// Class used for storing an x,y pair, i.e. a coordinate/vector
//
class Vector2 {
public:
Vector2() : x_(0), y_(0) {}
Vector2(int32 x, int32 y) : x_(x), y_(y) {}
static Vector2 Inf() {
static const Vector2 inf = {std::numeric_limits<int32>::max(), std::numeric_limits<int32>::max()};
return inf;
}
bool operator==(const Vector2 &rhs) const { return (x_ == rhs.x_ && y_ == rhs.y_); }
bool operator!=(const Vector2 &rhs) const { return (x_ != rhs.x_ || y_ != rhs.y_); }
// These operators are not idiomatic. If lexicographic comparison is needed, it should be implemented separately.
bool operator>(const Vector2 &rhs) const = delete;
bool operator>=(const Vector2 &rhs) const = delete;
bool operator<(const Vector2 &rhs) const = delete;
bool operator<=(const Vector2 &rhs) const = delete;
Vector2 operator+(const Vector2 &rhs) const {
return {x_ + rhs.x_, y_ + rhs.y_};
}
Vector2 operator-(const Vector2 &rhs) const {
return {x_ - rhs.x_, y_ - rhs.y_};
}
Vector2 operator*(double rhs) const {
return {static_cast<int32>(std::lround(x_ * rhs)), static_cast<int32>(std::lround(y_ * rhs))};
}
Vector2 &operator+=(const Vector2 &rhs) {
x_ += rhs.x_;
y_ += rhs.y_;
return *this;
}
Vector2 &operator-=(const Vector2 &rhs) {
x_ -= rhs.x_;
y_ -= rhs.y_;
return *this;
}
// Calculated the determinant of the 2x2 matrix as given by [[x_, y_], [v.x_y, v.y_]]
int32 Determinant(Vector2 const &v) const {
return (x_ * v.y_) - (y_ * v.x_);
}
public:
int32 x_;
int32 y_;
};
#endif // ZM_VECTOR2_H

View File

@ -281,7 +281,8 @@ bool VideoStore::open() {
}
}
av_buffer_unref(&hw_frames_ref);
}
av_buffer_unref(&hw_device_ctx);
} // end if hwdevice_type != NONE
#endif
AVDictionary *opts = 0;
@ -289,7 +290,7 @@ bool VideoStore::open() {
Debug(2, "Options? %s", Options.c_str());
ret = av_dict_parse_string(&opts, Options.c_str(), "=", ",#\n", 0);
if (ret < 0) {
Warning("Could not parse ffmpeg encoder options list '%s'\n", Options.c_str());
Warning("Could not parse ffmpeg encoder options list '%s'", Options.c_str());
} else {
AVDictionaryEntry *e = nullptr;
while ((e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr) {
@ -312,22 +313,20 @@ bool VideoStore::open() {
video_out_codec = nullptr;
}
Debug(1, "Success");
AVDictionaryEntry *e = nullptr;
while ((e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != nullptr) {
Warning("Encoder Option %s not recognized by ffmpeg codec", e->key);
}
if (video_out_codec) break;
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// We allocate and copy in newer ffmpeg, so need to free it
avcodec_free_context(&video_out_ctx);
if (hw_device_ctx) av_buffer_unref(&hw_device_ctx);
#endif
} // end foreach codec
if (!video_out_codec) {
Error("Can't open video codec!");
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// We allocate and copy in newer ffmpeg, so need to free it
avcodec_free_context(&video_out_ctx);
#endif
return false;
} // end if can't open codec
Debug(2, "Success opening codec");
@ -350,6 +349,8 @@ bool VideoStore::open() {
#else
avcodec_copy_context(video_out_stream->codec, video_out_ctx);
#endif
video_out_stream->time_base = video_in_stream ? video_in_stream->time_base : AV_TIME_BASE_Q;
if (monitor->GetOptVideoWriter() == Monitor::PASSTHROUGH) {
// Only set orientation if doing passthrough, otherwise the frame image will be rotated
Monitor::Orientation orientation = monitor->getOrientation();
if (orientation) {
@ -368,20 +369,12 @@ bool VideoStore::open() {
Warning("Unsupported Orientation(%d)", orientation);
}
} // end if orientation
video_out_stream->time_base = video_in_stream ? video_in_stream->time_base : AV_TIME_BASE_Q;
} // end if passthrough
if (audio_in_stream and audio_in_ctx) {
Debug(2, "Have audio_in_stream %p", audio_in_stream);
if (
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
audio_in_stream->codecpar->codec_id
#else
audio_in_stream->codec->codec_id
#endif
!= AV_CODEC_ID_AAC
) {
if (CODEC(audio_in_stream)->codec_id != AV_CODEC_ID_AAC) {
audio_out_codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
if (!audio_out_codec) {
Error("Could not find codec for AAC");
@ -501,7 +494,7 @@ bool VideoStore::open() {
AVDictionary *opts = nullptr;
std::string option_string = monitor->GetEncoderOptions();
ret = av_dict_parse_string(&opts, option_string.c_str(), "=", ",\n", 0);
ret = av_dict_parse_string(&opts, option_string.c_str(), "=", "#,\n", 0);
if (ret < 0) {
Warning("Could not parse ffmpeg output options '%s'", option_string.c_str());
}
@ -591,7 +584,6 @@ void VideoStore::flush_codecs() {
}
} // end if data returned from fifo
}
} // end while have buffered samples in the resampler
Debug(2, "av_audio_fifo_size = %d", av_audio_fifo_size(fifo));
@ -641,7 +633,7 @@ VideoStore::~VideoStore() {
flush_codecs();
// Flush Queues
Debug(1, "Flushing interleaved queues");
Debug(4, "Flushing interleaved queues");
av_interleaved_write_frame(oc, nullptr);
Debug(1, "Writing trailer");
@ -655,7 +647,7 @@ VideoStore::~VideoStore() {
// When will we not be using a file ?
if (!(out_format->flags & AVFMT_NOFILE)) {
/* Close the out file. */
Debug(2, "Closing");
Debug(4, "Closing");
if (int rc = avio_close(oc->pb)) {
Error("Error closing avio %s", av_err2str(rc));
}
@ -674,8 +666,13 @@ VideoStore::~VideoStore() {
if (video_out_stream) {
video_in_ctx = nullptr;
Debug(4, "Freeing video_out_ctx");
avcodec_close(video_out_ctx);
Debug(3, "Freeing video_out_ctx");
avcodec_free_context(&video_out_ctx);
if (hw_device_ctx) {
Debug(3, "Freeing hw_device_ctx");
av_buffer_unref(&hw_device_ctx);
}
} // end if video_out_stream
if (audio_out_stream) {
@ -688,6 +685,7 @@ VideoStore::~VideoStore() {
if (audio_out_ctx) {
Debug(4, "Success closing audio_out_ctx");
avcodec_close(audio_out_ctx);
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
avcodec_free_context(&audio_out_ctx);
#endif
@ -732,7 +730,7 @@ VideoStore::~VideoStore() {
bool VideoStore::setup_resampler() {
#if !defined(HAVE_LIBSWRESAMPLE) && !defined(HAVE_LIBAVRESAMPLE)
Error("%s", "Not built with resample library. Cannot do audio conversion to AAC");
Error("Not built with resample library. Cannot do audio conversion to AAC");
return false;
#else
int ret;
@ -740,17 +738,14 @@ bool VideoStore::setup_resampler() {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// Newer ffmpeg wants to keep everything separate... so have to lookup our own
// decoder, can't reuse the one from the camera.
audio_in_codec =
avcodec_find_decoder(audio_in_stream->codecpar->codec_id);
audio_in_codec = avcodec_find_decoder(audio_in_stream->codecpar->codec_id);
audio_in_ctx = avcodec_alloc_context3(audio_in_codec);
// Copy params from instream to ctx
ret = avcodec_parameters_to_context(
audio_in_ctx, audio_in_stream->codecpar);
ret = avcodec_parameters_to_context(audio_in_ctx, audio_in_stream->codecpar);
if (ret < 0) {
Error("Unable to copy audio params to ctx %s",
av_make_error_string(ret).c_str());
}
#else
// codec is already open in ffmpeg_camera
audio_in_ctx = audio_in_stream->codec;
@ -806,8 +801,7 @@ bool VideoStore::setup_resampler() {
if (found) {
Debug(3, "Sample rate is good %d", audio_out_ctx->sample_rate);
} else {
audio_out_ctx->sample_rate =
audio_out_codec->supported_samplerates[0];
audio_out_ctx->sample_rate = audio_out_codec->supported_samplerates[0];
Debug(1, "Sample rate is no good, setting to (%d)",
audio_out_codec->supported_samplerates[0]);
}
@ -1023,10 +1017,11 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
Debug(3, "Have encoding video frame count (%d)", frame_count);
if (!zm_packet->out_frame) {
Debug(3, "Have no out frame. codec is %s sw_pf %d %s hw_pf %d %s",
Debug(3, "Have no out frame. codec is %s sw_pf %d %s hw_pf %d %s %dx%d",
chosen_codec_data->codec_name,
chosen_codec_data->sw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->sw_pix_fmt),
chosen_codec_data->hw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->hw_pix_fmt)
chosen_codec_data->hw_pix_fmt, av_get_pix_fmt_name(chosen_codec_data->hw_pix_fmt),
video_out_ctx->width, video_out_ctx->height
);
AVFrame *out_frame = zm_packet->get_out_frame(video_out_ctx->width, video_out_ctx->height, chosen_codec_data->sw_pix_fmt);
if (!out_frame) {
@ -1056,7 +1051,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
}
// Go straight to out frame
swscale.Convert(zm_packet->in_frame, out_frame);
} else {
Error("Have neither in_frame or image in packet %d!",
zm_packet->image_index);
@ -1154,7 +1148,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
video_out_stream->time_base.num,
video_out_stream->time_base.den);
int64_t duration = 0;
if (zm_packet->in_frame) {
if (zm_packet->in_frame->pkt_duration) {
@ -1172,8 +1165,7 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
video_out_stream->time_base.den
);
} else if (video_last_pts != AV_NOPTS_VALUE) {
duration =
av_rescale_q(
duration = av_rescale_q(
zm_packet->in_frame->pts - video_last_pts,
video_in_stream->time_base,
video_out_stream->time_base);
@ -1184,7 +1176,9 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
duration
);
if (duration <= 0) {
duration = zm_packet->in_frame->pkt_duration ? zm_packet->in_frame->pkt_duration : av_rescale_q(1, video_in_stream->time_base, video_out_stream->time_base);
duration = zm_packet->in_frame->pkt_duration ?
zm_packet->in_frame->pkt_duration :
av_rescale_q(1, video_in_stream->time_base, video_out_stream->time_base);
}
} // end if in_frmae->pkt_duration
video_last_pts = zm_packet->in_frame->pts;
@ -1192,7 +1186,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
//duration = av_rescale_q(zm_packet->out_frame->pts - video_last_pts, video_in_stream->time_base, video_out_stream->time_base);
} // end if in_frmae
opkt.duration = duration;
} else { // Passthrough
AVPacket *ipkt = &zm_packet->packet;
ZM_DUMP_STREAM_PACKET(video_in_stream, (*ipkt), "Doing passthrough, just copy packet");
@ -1220,7 +1213,6 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
}
av_packet_rescale_ts(&opkt, video_in_stream->time_base, video_out_stream->time_base);
ZM_DUMP_STREAM_PACKET(video_out_stream, opkt, "after pts adjustment");
} // end if codec matches
@ -1232,15 +1224,14 @@ int VideoStore::writeVideoFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
} // end int VideoStore::writeVideoFramePacket( AVPacket *ipkt )
int VideoStore::writeAudioFramePacket(const std::shared_ptr<ZMPacket> &zm_packet) {
AVPacket *ipkt = &zm_packet->packet;
int ret;
if (!audio_out_stream) {
Debug(1, "Called writeAudioFramePacket when no audio_out_stream");
return 0;
// FIXME -ve return codes do not free packet in ffmpeg_camera at the moment
}
AVPacket *ipkt = &zm_packet->packet;
int ret;
ZM_DUMP_STREAM_PACKET(audio_in_stream, (*ipkt), "input packet");
if (!audio_first_dts) {
@ -1295,7 +1286,6 @@ int VideoStore::writeAudioFramePacket(const std::shared_ptr<ZMPacket> &zm_packet
// This will send a null frame, emptying out the resample buffer
input_frame = nullptr;
} // end while there is data in the resampler
} else {
av_init_packet(&opkt);
opkt.data = ipkt->data;
@ -1344,8 +1334,7 @@ int VideoStore::write_packet(AVPacket *pkt, AVStream *stream) {
int ret = av_interleaved_write_frame(oc, pkt);
if (ret != 0) {
Error("Error writing packet: %s",
av_make_error_string(ret).c_str());
Error("Error writing packet: %s", av_make_error_string(ret).c_str());
} else {
Debug(4, "Success writing packet");
}

View File

@ -32,7 +32,7 @@ void Zone::Setup(
int p_max_pixel_threshold,
int p_min_alarm_pixels,
int p_max_alarm_pixels,
const Coord &p_filter_box,
const Vector2 &p_filter_box,
int p_min_filter_pixels,
int p_max_filter_pixels,
int p_min_blob_pixels,
@ -130,10 +130,10 @@ void Zone::RecordStats(const Event *event) {
stats.alarm_blobs_,
stats.min_blob_size_,
stats.max_blob_size_,
stats.alarm_box_.LoX(),
stats.alarm_box_.LoY(),
stats.alarm_box_.HiX(),
stats.alarm_box_.HiY(),
stats.alarm_box_.Lo().x_,
stats.alarm_box_.Lo().y_,
stats.alarm_box_.Hi().x_,
stats.alarm_box_.Hi().y_,
stats.score_
);
zmDbDo(sql);
@ -219,10 +219,10 @@ bool Zone::CheckAlarms(const Image *delta_image) {
int alarm_mid_x = -1;
int alarm_mid_y = -1;
unsigned int lo_y = polygon.LoY();
unsigned int lo_x = polygon.LoX();
unsigned int hi_x = polygon.HiX();
unsigned int hi_y = polygon.HiY();
unsigned int lo_x = polygon.Extent().Lo().x_;
unsigned int lo_y = polygon.Extent().Lo().y_;
unsigned int hi_x = polygon.Extent().Hi().x_;
unsigned int hi_y = polygon.Extent().Hi().y_;
Debug(4, "Checking alarms for zone %d/%s in lines %d -> %d", id, label.c_str(), lo_y, hi_y);
@ -267,8 +267,8 @@ bool Zone::CheckAlarms(const Image *delta_image) {
Debug(5, "Current score is %d", stats.score_);
if (check_method >= FILTERED_PIXELS) {
int bx = filter_box.X();
int by = filter_box.Y();
int bx = filter_box.x_;
int by = filter_box.y_;
int bx1 = bx-1;
int by1 = by-1;
@ -630,10 +630,10 @@ bool Zone::CheckAlarms(const Image *delta_image) {
stats.score_ = 1; /* Fix for score of 0 when frame meets thresholds but alarmed area is not big enough */
Debug(5, "Current score is %d", stats.score_);
alarm_lo_x = polygon.HiX()+1;
alarm_hi_x = polygon.LoX()-1;
alarm_lo_y = polygon.HiY()+1;
alarm_hi_y = polygon.LoY()-1;
alarm_lo_x = polygon.Extent().Hi().x_ + 1;
alarm_hi_x = polygon.Extent().Lo().x_ - 1;
alarm_lo_y = polygon.Extent().Hi().y_ + 1;
alarm_hi_y = polygon.Extent().Lo().y_ - 1;
for (uint32 i = 1; i < kWhite; i++) {
BlobStats *bs = &blob_stats[i];
@ -684,11 +684,11 @@ bool Zone::CheckAlarms(const Image *delta_image) {
// Now outline the changed region
if (stats.score_) {
stats.alarm_box_ = Box(Coord(alarm_lo_x, alarm_lo_y), Coord(alarm_hi_x, alarm_hi_y));
stats.alarm_box_ = Box(Vector2(alarm_lo_x, alarm_lo_y), Vector2(alarm_hi_x, alarm_hi_y));
//if ( monitor->followMotion() )
if ( true ) {
stats.alarm_centre_ = Coord(alarm_mid_x, alarm_mid_y);
stats.alarm_centre_ = Vector2(alarm_mid_x, alarm_mid_y);
} else {
stats.alarm_centre_ = stats.alarm_box_.Centre();
}
@ -748,37 +748,39 @@ bool Zone::CheckAlarms(const Image *delta_image) {
bool Zone::ParsePolygonString(const char *poly_string, Polygon &polygon) {
char *str = (char *)poly_string;
int n_coords = 0;
int max_n_coords = strlen(str)/4;
Coord *coords = new Coord[max_n_coords];
std::vector<Vector2> vertices;
vertices.reserve(max_n_coords);
while (*str != '\0') {
char *cp = strchr(str, ',');
if (!cp) {
Error("Bogus coordinate %s found in polygon string", str);
break;
}
int x = atoi(str);
int y = atoi(cp + 1);
Debug(3, "Got coordinate %d,%d from polygon string", x, y);
coords[n_coords++] = Coord(x, y);
vertices.emplace_back(x, y);
char *ws = strchr(cp + 2, ' ');
if (ws)
if (ws) {
str = ws + 1;
else
break;
} // end while ! end of string
if (n_coords > 2) {
Debug(3, "Successfully parsed polygon string %s", str);
polygon = Polygon(n_coords, coords);
} else {
Error("Not enough coordinates to form a polygon!");
n_coords = 0;
break;
}
}
delete[] coords;
return n_coords ? true : false;
if (vertices.size() > 2) {
Debug(3, "Successfully parsed polygon string %s", str);
polygon = Polygon(vertices);
} else {
Error("Not enough coordinates to form a polygon!");
}
return !vertices.empty();
} // end bool Zone::ParsePolygonString(const char *poly_string, Polygon &polygon)
bool Zone::ParseZoneString(const char *zone_string, int &zone_id, int &colour, Polygon &polygon) {
@ -872,14 +874,21 @@ std::vector<Zone> Zone::Load(Monitor *monitor) {
continue;
}
if ( polygon.LoX() < 0 || polygon.HiX() >= (int)monitor->Width()
|| polygon.LoY() < 0 || polygon.HiY() >= (int)monitor->Height() ) {
if (polygon.Extent().Lo().x_ < 0 || polygon.Extent().Hi().x_ > static_cast<int32>(monitor->Width())
|| polygon.Extent().Lo().y_ < 0 || polygon.Extent().Hi().y_ > static_cast<int32>(monitor->Height())) {
Error("Zone %d/%s for monitor %s extends outside of image dimensions, (%d,%d), (%d,%d), fixing",
Id, Name, monitor->Name(), polygon.LoX(), polygon.LoY(), polygon.HiX(), polygon.HiY());
if ( polygon.LoX() < 0 ) polygon.LoX(0);
if ( polygon.HiX() >= (int)monitor->Width()) polygon.HiX((int)monitor->Width());
if ( polygon.LoY() < 0 ) polygon.LoY(0);
if ( polygon.HiY() >= (int)monitor->Height() ) polygon.HiY((int)monitor->Height());
Id,
Name,
monitor->Name(),
polygon.Extent().Lo().x_,
polygon.Extent().Lo().y_,
polygon.Extent().Hi().x_,
polygon.Extent().Hi().y_);
polygon.Clip(Box(
{0, 0},
{static_cast<int32>(monitor->Width()), static_cast<int32>(monitor->Height())}
));
}
if ( false && !strcmp( Units, "Percent" ) ) {
@ -899,7 +908,7 @@ std::vector<Zone> Zone::Load(Monitor *monitor) {
zones.emplace_back(
monitor, Id, Name, Type, polygon, AlarmRGB,
CheckMethod, MinPixelThreshold, MaxPixelThreshold,
MinAlarmPixels, MaxAlarmPixels, Coord(FilterX, FilterY),
MinAlarmPixels, MaxAlarmPixels, Vector2(FilterX, FilterY),
MinFilterPixels, MaxFilterPixels,
MinBlobPixels, MaxBlobPixels, MinBlobs, MaxBlobs,
OverloadFrames, ExtendAlarmFrames);
@ -922,9 +931,9 @@ bool Zone::DumpSettings(char *output, bool /*verbose*/) const {
type==INACTIVE?"Inactive":(
type==PRIVACY?"Privacy":"Unknown"
))))));
sprintf( output+strlen(output), " Shape : %d points\n", polygon.getNumCoords() );
for ( int i = 0; i < polygon.getNumCoords(); i++ ) {
sprintf( output+strlen(output), " %i: %d,%d\n", i, polygon.getCoord( i ).X(), polygon.getCoord( i ).Y() );
sprintf( output+strlen(output), " Shape : %zu points\n", polygon.GetVertices().size() );
for (size_t i = 0; i < polygon.GetVertices().size(); i++) {
sprintf(output + strlen(output), " %zu: %d,%d\n", i, polygon.GetVertices()[i].x_, polygon.GetVertices()[i].y_);
}
sprintf( output+strlen(output), " Alarm RGB : %06x\n", alarm_rgb );
sprintf( output+strlen(output), " Check Method: %d - %s\n", check_method,
@ -936,7 +945,7 @@ bool Zone::DumpSettings(char *output, bool /*verbose*/) const {
sprintf( output+strlen(output), " Max Pixel Threshold : %d\n", max_pixel_threshold );
sprintf( output+strlen(output), " Min Alarm Pixels : %d\n", min_alarm_pixels );
sprintf( output+strlen(output), " Max Alarm Pixels : %d\n", max_alarm_pixels );
sprintf( output+strlen(output), " Filter Box : %d,%d\n", filter_box.X(), filter_box.Y() );
sprintf(output+strlen(output), " Filter Box : %d,%d\n", filter_box.x_, filter_box.y_ );
sprintf( output+strlen(output), " Min Filter Pixels : %d\n", min_filter_pixels );
sprintf( output+strlen(output), " Max Filter Pixels : %d\n", max_filter_pixels );
sprintf( output+strlen(output), " Min Blob Pixels : %d\n", min_blob_pixels );
@ -960,8 +969,8 @@ void Zone::std_alarmedpixels(
if ( max_pixel_threshold )
calc_max_pixel_threshold = max_pixel_threshold;
lo_y = polygon.LoY();
hi_y = polygon.HiY();
lo_y = polygon.Extent().Lo().y_;
hi_y = polygon.Extent().Hi().y_;
for ( unsigned int y = lo_y; y <= hi_y; y++ ) {
unsigned int lo_x = ranges[y].lo_x;
unsigned int hi_x = ranges[y].hi_x;

View File

@ -21,12 +21,12 @@
#define ZM_ZONE_H
#include "zm_box.h"
#include "zm_coord.h"
#include "zm_define.h"
#include "zm_config.h"
#include "zm_poly.h"
#include "zm_rgb.h"
#include "zm_zone_stats.h"
#include "zm_vector2.h"
#include <algorithm>
#include <string>
@ -77,7 +77,7 @@ class Zone {
int min_alarm_pixels;
int max_alarm_pixels;
Coord filter_box;
Vector2 filter_box;
int min_filter_pixels;
int max_filter_pixels;
@ -112,7 +112,7 @@ class Zone {
int p_max_pixel_threshold,
int p_min_alarm_pixels,
int p_max_alarm_pixels,
const Coord &p_filter_box,
const Vector2 &p_filter_box,
int p_min_filter_pixels,
int p_max_filter_pixels,
int p_min_blob_pixels,
@ -137,7 +137,7 @@ class Zone {
int p_max_pixel_threshold=0,
int p_min_alarm_pixels=50,
int p_max_alarm_pixels=75000,
const Coord &p_filter_box=Coord( 3, 3 ),
const Vector2 &p_filter_box = Vector2(3, 3),
int p_min_filter_pixels=50,
int p_max_filter_pixels=50000,
int p_min_blob_pixels=10,
@ -164,7 +164,7 @@ class Zone {
blob_stats{},
stats(p_id)
{
Setup(Zone::INACTIVE, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Coord(0, 0), 0, 0, 0, 0, 0, 0, 0, 0);
Setup(Zone::INACTIVE, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Vector2(0, 0), 0, 0, 0, 0, 0, 0, 0, 0);
}
Zone(Monitor *p_monitor, int p_id, const char *p_label, ZoneType p_type, const Polygon &p_polygon)
:
@ -174,7 +174,7 @@ class Zone {
blob_stats{},
stats(p_id)
{
Setup(p_type, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Coord( 0, 0 ), 0, 0, 0, 0, 0, 0, 0, 0 );
Setup(p_type, p_polygon, kRGBBlack, (Zone::CheckMethod)0, 0, 0, 0, 0, Vector2(0, 0), 0, 0, 0, 0, 0, 0, 0, 0 );
}
Zone(const Zone &z);
@ -195,7 +195,7 @@ class Zone {
inline bool WasAlarmed() const { return was_alarmed; }
inline void SetAlarm() { was_alarmed = alarmed; alarmed = true; }
inline void ClearAlarm() { was_alarmed = alarmed; alarmed = false; }
inline Coord GetAlarmCentre() const { return stats.alarm_centre_; }
inline Vector2 GetAlarmCentre() const { return stats.alarm_centre_; }
inline unsigned int Score() const { return stats.score_; }
inline void ResetStats() {

View File

@ -21,8 +21,8 @@
#define ZM_ZONE_STATS_H
#include "zm_box.h"
#include "zm_coord.h"
#include "zm_logger.h"
#include "zm_vector2.h"
class ZoneStats {
public:
@ -35,8 +35,6 @@ class ZoneStats {
alarm_blobs_(0),
min_blob_size_(0),
max_blob_size_(0),
alarm_box_({}),
alarm_centre_({}),
score_(0) {};
void Reset() {
@ -47,10 +45,7 @@ class ZoneStats {
alarm_blobs_ = 0;
min_blob_size_ = 0;
max_blob_size_ = 0;
alarm_box_.LoX(0);
alarm_box_.LoY(0);
alarm_box_.HiX(0);
alarm_box_.HiY(0);
alarm_box_ = {};
alarm_centre_ = {};
score_ = 0;
}
@ -67,12 +62,12 @@ class ZoneStats {
alarm_blobs_,
min_blob_size_,
max_blob_size_,
alarm_box_.LoX(),
alarm_box_.LoY(),
alarm_box_.HiX(),
alarm_box_.HiY(),
alarm_centre_.X(),
alarm_centre_.Y(),
alarm_box_.Lo().x_,
alarm_box_.Lo().y_,
alarm_box_.Hi().x_,
alarm_box_.Hi().y_,
alarm_centre_.x_,
alarm_centre_.y_,
score_
);
}
@ -87,7 +82,7 @@ class ZoneStats {
int min_blob_size_;
int max_blob_size_;
Box alarm_box_;
Coord alarm_centre_;
Vector2 alarm_centre_;
unsigned int score_;
};

View File

@ -12,10 +12,13 @@
include(Catch)
set(TEST_SOURCES
zm_box.cpp
zm_comms.cpp
zm_crypt.cpp
zm_font.cpp
zm_utils.cpp)
zm_poly.cpp
zm_utils.cpp
zm_vector2.cpp)
add_executable(tests main.cpp ${TEST_SOURCES})

52
tests/zm_box.cpp Normal file
View File

@ -0,0 +1,52 @@
/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zm_catch2.h"
#include "zm_box.h"
TEST_CASE("Box: default constructor") {
Box b;
REQUIRE(b.Lo() == Vector2(0, 0));
REQUIRE(b.Hi() == Vector2(0, 0));
REQUIRE(b.Size() == Vector2(0, 0));
REQUIRE(b.Area() == 0);
}
TEST_CASE("Box: construct from lo and hi") {
Box b({1, 1}, {5, 5});
SECTION("basic properties") {
REQUIRE(b.Lo() == Vector2(1, 1));
REQUIRE(b.Hi() == Vector2(5, 5));
REQUIRE(b.Size() == Vector2(4 ,4));
REQUIRE(b.Area() == 16);
REQUIRE(b.Centre() == Vector2(3, 3));
REQUIRE(b.Vertices() == std::vector<Vector2>{{1, 1}, {5, 1}, {5, 5}, {1, 5}});
}
SECTION("contains") {
REQUIRE(b.Contains({0, 0}) == false);
REQUIRE(b.Contains({1, 1}) == true);
REQUIRE(b.Contains({3, 3}) == true);
REQUIRE(b.Contains({5, 5}) == true);
REQUIRE(b.Contains({6, 6}) == false);
}
}

30
tests/zm_catch2.h Normal file
View File

@ -0,0 +1,30 @@
/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ZONEMINDER_TESTS_ZM_CATCH2_H_
#define ZONEMINDER_TESTS_ZM_CATCH2_H_
#include "catch2/catch.hpp"
#include "zm_vector2.h"
inline std::ostream &operator<<(std::ostream &os, Vector2 const &value) {
os << "{ X: " << value.x_ << ", Y: " << value.y_ << " }";
return os;
}
#endif //ZONEMINDER_TESTS_ZM_CATCH2_H_

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_comms.h"
#include <array>
@ -224,15 +224,16 @@ TEST_CASE("ZM::UdpUnixSocket send/recv") {
ZM::UdpUnixSocket srv_socket;
ZM::UdpUnixSocket client_socket;
SECTION("send/recv byte buffer") {
std::array<char, 3> msg = {'a', 'b', 'c'};
std::array<char, msg.size()> rcv{};
SECTION("send/recv on unbound socket") {
SECTION("on unbound socket") {
REQUIRE(client_socket.send(msg.data(), msg.size()) == -1);
REQUIRE(srv_socket.recv(rcv.data(), rcv.size()) == -1);
}
SECTION("send/recv") {
SECTION("on bound socket") {
REQUIRE(srv_socket.bind(sock_path.c_str()) == true);
REQUIRE(srv_socket.isOpen() == true);
@ -246,6 +247,24 @@ TEST_CASE("ZM::UdpUnixSocket send/recv") {
}
}
SECTION("send/recv string") {
std::string msg = "abc";
std::string rcv;
rcv.reserve(msg.length());
REQUIRE(srv_socket.bind(sock_path.c_str()) == true);
REQUIRE(srv_socket.isOpen() == true);
REQUIRE(client_socket.connect(sock_path.c_str()) == true);
REQUIRE(client_socket.isConnected() == true);
REQUIRE(client_socket.send(msg) == static_cast<ssize_t>(msg.size()));
REQUIRE(srv_socket.recv(rcv) == static_cast<ssize_t>(msg.size()));
REQUIRE(rcv == msg);
}
}
TEST_CASE("ZM::TcpInetClient basics") {
ZM::TcpInetClient client;
REQUIRE(client.isClosed() == true);

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_crypt.h"

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_font.h"

71
tests/zm_poly.cpp Normal file
View File

@ -0,0 +1,71 @@
/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zm_catch2.h"
#include "zm_poly.h"
TEST_CASE("Polygon: default constructor") {
Polygon p;
REQUIRE(p.Area() == 0);
REQUIRE(p.Centre() == Vector2(0, 0));
}
TEST_CASE("Polygon: construct from vertices") {
std::vector<Vector2> vertices{{{0, 0}, {6, 0}, {0, 6}}};
Polygon p(vertices);
REQUIRE(p.Area() == 18);
REQUIRE(p.Extent().Size() == Vector2(6, 6));
}
TEST_CASE("Polygon: clipping") {
// This a concave polygon in a shape resembling a "W"
std::vector<Vector2> v = {
{3, 1},
{5, 1},
{6, 3},
{7, 1},
{9, 1},
{10, 8},
{8, 8},
{7, 5},
{5, 5},
{4, 8},
{2, 8}
};
Polygon p(v);
REQUIRE(p.GetVertices().size() == 11);
REQUIRE(p.Extent().Size() == Vector2(8, 7));
SECTION("boundary box larger than polygon") {
p.Clip(Box({1, 0}, {11, 9}));
REQUIRE(p.GetVertices().size() == 11);
REQUIRE(p.Extent().Size() == Vector2(8, 7));
}
SECTION("boundary box smaller than polygon") {
p.Clip(Box({2, 4}, {10, 7}));
REQUIRE(p.GetVertices().size() == 8);
REQUIRE(p.Extent().Size() == Vector2(8, 3));
}
}

View File

@ -15,7 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch2/catch.hpp"
#include "zm_catch2.h"
#include "zm_utils.h"
#include <sstream>

94
tests/zm_vector2.cpp Normal file
View File

@ -0,0 +1,94 @@
/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zm_catch2.h"
#include "zm_vector2.h"
TEST_CASE("Vector2: default constructor") {
Vector2 c;
REQUIRE(c.x_ == 0);
REQUIRE(c.y_ == 0);
}
TEST_CASE("Vector2: x/y constructor") {
Vector2 c(1, 2);
REQUIRE(c.x_ == 1);
REQUIRE(c.y_ == 2);
}
TEST_CASE("Vector2: assignment/copy") {
Vector2 c;
Vector2 c2(1, 2);
REQUIRE(c.x_ == 0);
REQUIRE(c.y_ == 0);
SECTION("assignment operator") {
c = c2;
REQUIRE(c.x_ == 1);
REQUIRE(c.y_ == 2);
}
SECTION("copy constructor") {
Vector2 c3(c2); // NOLINT(performance-unnecessary-copy-initialization)
REQUIRE(c3.x_ == 1);
REQUIRE(c3.y_ == 2);
}
}
TEST_CASE("Vector2: comparison operators") {
Vector2 c1(1, 2);
Vector2 c2(1, 2);
Vector2 c3(1, 3);
REQUIRE((c1 == c2) == true);
REQUIRE((c1 != c3) == true);
}
TEST_CASE("Vector2: arithmetic operators") {
Vector2 c(1, 1);
SECTION("addition") {
Vector2 c1 = c + Vector2(1, 1);
REQUIRE(c1 == Vector2(2, 2));
c += {1, 2};
REQUIRE(c == Vector2(2, 3));
}
SECTION("subtraction") {
Vector2 c1 = c - Vector2(1, 1);
REQUIRE(c1 == Vector2(0, 0));
c -= {1, 2};
REQUIRE(c == Vector2(0, -1));
}
SECTION("scalar multiplication") {
c = c * 2;
REQUIRE(c == Vector2(2, 2));
}
}
TEST_CASE("Vector2: determinate") {
Vector2 v(1, 1);
REQUIRE(v.Determinant({0, 0}) == 0);
REQUIRE(v.Determinant({1, 1}) == 0);
REQUIRE(v.Determinant({1, 2}) == 1);
}

View File

@ -1 +1 @@
1.36.0
1.37.0