diff --git a/imagebuffer.cpp b/imagebuffer.cpp index da01b3f..2af6bfb 100644 --- a/imagebuffer.cpp +++ b/imagebuffer.cpp @@ -46,7 +46,7 @@ void ImageBuffer::push(const MyImage &img) { if (load < static_cast(buffer.capacity())) load += 1; mutex.unlock(); - std::cerr << "load: " << bufferLoad() << "\t pressure: " << bufferPreassure() << std::endl; + //std::cerr << "load: " << bufferLoad() << "\t pressure: " << bufferPreassure() << std::endl; } bool ImageBuffer::bufferNotEmpty() { @@ -69,3 +69,19 @@ bool ImageBuffer::pop(MyImage &img) { return ret; } +bool ImageBuffer::readLast(MyImage &img) { + bool ret = false; + mutex.lock(); + if (load > 0) { + size_t idx; + if (current_write_index != 0) { + idx = static_cast(current_write_index) - 1; + } else { + idx = buffer.capacity() -1; + } + img = buffer[idx]; + ret = true; + } + mutex.unlock(); + return ret; +} diff --git a/imagebuffer.h b/imagebuffer.h index 1d5e708..8b272a3 100644 --- a/imagebuffer.h +++ b/imagebuffer.h @@ -17,6 +17,7 @@ public: void resize(size_t new_size); void push(const MyImage &img); bool pop(MyImage &img); + bool readLast(MyImage &img); size_t capacity(); double bufferPreassure(); int64_t bufferLoad();