Streamtools: Refactor rescaling code
[jpcrr.git] / streamtools / dedup.cpp
blob917e4fe23bec83747d84c96b99c42892798931e5
1 #include "dedup.hpp"
2 #include <cstring>
4 dedup::dedup(uint32_t max, uint32_t width, uint32_t height)
6 if(max)
7 framebuffer.resize(4 * width * height);
8 bound = max;
9 current = 0; //First can't be dup.
12 bool dedup::operator()(const uint8_t* buffer)
14 if(!bound)
15 return false; //Dup detection disabled.
17 //Update buffer if not identical.
18 bool is_dup = (current && !memcmp(&framebuffer[0], buffer, framebuffer.size()));
19 if(!is_dup)
20 memcpy(&framebuffer[0], buffer, framebuffer.size());
22 //Decrement current if match, otherwise reset to bound
23 current = is_dup ? (current - 1) : bound;
25 return is_dup;