diff --git a/src/zm_eventstream.cpp b/src/zm_eventstream.cpp index 4bad2d61a..621970130 100644 --- a/src/zm_eventstream.cpp +++ b/src/zm_eventstream.cpp @@ -810,7 +810,7 @@ bool EventStream::sendFrame(Microseconds delta_us) { fputs("Content-Type: image/x-rgbz\r\n", stdout); break; case STREAM_RAW : - img_buffer = (uint8_t*)(send_image->Buffer()); + img_buffer = send_image->Buffer(); img_buffer_size = send_image->Size(); fputs("Content-Type: image/x-rgb\r\n", stdout); break; diff --git a/src/zm_image.h b/src/zm_image.h index 24626d789..74e5931eb 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -179,9 +179,11 @@ class Image { } } - /* Internal buffer should not be modified from functions outside of this class */ + inline uint8_t* Buffer() { return buffer; } inline const uint8_t* Buffer() const { return buffer; } + inline uint8_t* Buffer(unsigned int x, unsigned int y=0) { return &buffer[(y*linesize) + x*colours]; } inline const uint8_t* Buffer(unsigned int x, unsigned int y=0) const { return &buffer[(y*linesize) + x*colours]; } + /* Request writeable buffer */ uint8_t* WriteBuffer(const unsigned int p_width, const unsigned int p_height, const unsigned int p_colours, const unsigned int p_subpixelorder); // Is only acceptable on a pre-allocated buffer diff --git a/src/zm_monitorstream.cpp b/src/zm_monitorstream.cpp index 067946eb7..5c32b8e05 100644 --- a/src/zm_monitorstream.cpp +++ b/src/zm_monitorstream.cpp @@ -422,7 +422,7 @@ bool MonitorStream::sendFrame(Image *image, SystemTimePoint timestamp) { break; case STREAM_RAW : fputs("Content-Type: image/x-rgb\r\n", stdout); - img_buffer = (uint8_t*)send_image->Buffer(); + img_buffer = send_image->Buffer(); img_buffer_size = send_image->Size(); break; case STREAM_ZIP : diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp index bc7086614..f0c09ec78 100644 --- a/src/zm_zone.cpp +++ b/src/zm_zone.cpp @@ -206,7 +206,7 @@ bool Zone::CheckAlarms(const Image *delta_image) { // Get the difference image Image *diff_image = image = new Image(*delta_image); int diff_width = diff_image->Width(); - uint8_t* diff_buff = (uint8_t*)diff_image->Buffer(); + uint8_t* diff_buff = diff_image->Buffer(); uint8_t* pdiff; unsigned int pixel_diff_count = 0; @@ -283,7 +283,7 @@ bool Zone::CheckAlarms(const Image *delta_image) { int lo_x = ranges[y].lo_x; int hi_x = ranges[y].hi_x; - pdiff = (uint8_t*)diff_image->Buffer(lo_x, y); + pdiff = diff_image->Buffer(lo_x, y); for (int x = lo_x; x <= hi_x; x++, pdiff++) { if (*pdiff == kWhite) { @@ -366,7 +366,7 @@ bool Zone::CheckAlarms(const Image *delta_image) { int lo_x = ranges[y].lo_x; int hi_x = ranges[y].hi_x; - pdiff = (uint8_t*)diff_image->Buffer(lo_x, y); + pdiff = diff_image->Buffer(lo_x, y); for (int x = lo_x; x <= hi_x; x++, pdiff++) { if (*pdiff == kWhite) { Debug(9, "Got white pixel at %d,%d (%p)", x, y, pdiff); @@ -980,7 +980,7 @@ void Zone::std_alarmedpixels( unsigned int hi_x = ranges[y].hi_x; Debug(7, "Checking line %d from %d -> %d", y, lo_x, hi_x); - uint8_t *pdiff = (uint8_t*)pdiff_image->Buffer(lo_x, y); + uint8_t *pdiff = pdiff_image->Buffer(lo_x, y); const uint8_t *ppoly = ppoly_image->Buffer(lo_x, y); for ( unsigned int x = lo_x; x <= hi_x; x++, pdiff++, ppoly++ ) { diff --git a/src/zmbenchmark.cpp b/src/zmbenchmark.cpp index 244094a54..5e6b93e42 100644 --- a/src/zmbenchmark.cpp +++ b/src/zmbenchmark.cpp @@ -140,7 +140,7 @@ std::shared_ptr GenerateRandomImage( Image *image = new Image(width, height, ZM_COLOUR_GRAY8, ZM_SUBPIX_ORDER_NONE); // Set it to black initially. - memset((void *) image->Buffer(0, 0), 0, (size_t) image->LineSize() * (size_t) image->Height()); + memset(image->Buffer(0, 0), 0, (size_t) image->LineSize() * (size_t) image->Height()); // Now randomize the pixels inside a box. const int box_width = (width * change_box_percent) / 100; @@ -149,7 +149,7 @@ std::shared_ptr GenerateRandomImage( const int box_y = (int) ((uint64_t) mt_rand() * (height - box_height) / RAND_MAX); for (int y = 0 ; y < box_height ; y++) { - uint8_t *row = (uint8_t *) image->Buffer(box_x, box_y + y); + uint8_t *row = image->Buffer(box_x, box_y + y); for (int x = 0 ; x < box_width ; x++) { row[x] = (uint8_t) mt_rand(); }