From 165e8cbf59faf7cbc1b7c83eaa9b165a05a4b90e Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 3 Sep 2010 17:34:09 +0300 Subject: [PATCH] Add nearest neighbor resizer This resizer might be useful as example and for some special encoding modes... --- Changelog.utf8 | 1 + streamtools/Makefile | 2 +- streamtools/resizer-nearest.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 streamtools/resizer-nearest.cpp diff --git a/Changelog.utf8 b/Changelog.utf8 index 836be0a..51791e3 100644 --- a/Changelog.utf8 +++ b/Changelog.utf8 @@ -71,6 +71,7 @@ Changes since JPC-RR Release 10.5: - Add new dumping system. - Allow direct output to I420. - oggenc and x264 output drivers. +- Add nearest neighbor resizer. Changes since JPC-RR Release 10.16: =================================== diff --git a/streamtools/Makefile b/streamtools/Makefile index 495116f..e14382d 100644 --- a/streamtools/Makefile +++ b/streamtools/Makefile @@ -2,7 +2,7 @@ all: screenshot.exe dumppackets.exe picturestodump.exe audiotodump.exe demuxdum CXXFLAGS2=-g -O2 -Wall -fopenmp CXXFLAGS=$(CXXFLAGS2) -RESIZE_DRIVERS=resize.o resizer-lanczos.o +RESIZE_DRIVERS=resize.o resizer-lanczos.o resizer-nearest.o I420_DRIVER_FILES=output-drv-rawi420.o rgbtorgb.o X264_DRIVER_FILES=output-drv-x264.o rgbtorgb.o OUTPUT_DRIVERS=$(RESIZE_DRIVERS) dedup.o output-drv.o output-drv-rawrgbx.o output-drv-timecodev2.o output-drv-rawaudio.o output-drv-wav.o $(I420_DRIVER_FILES) $(X264_DRIVER_FILES) output-drv-oggenc.o diff --git a/streamtools/resizer-nearest.cpp b/streamtools/resizer-nearest.cpp new file mode 100644 index 0000000..64c5804 --- /dev/null +++ b/streamtools/resizer-nearest.cpp @@ -0,0 +1,46 @@ +#include "resize.hpp" +#include +#include +#include + +namespace +{ + inline uint32_t nnscale(uint32_t value, uint32_t trange, uint32_t srange) + { + //x / trange is as good approximation for value / srange as possible. + //=> x is as good approximation for value * trange / srange as possible. + return (uint32_t)(((uint64_t)value * trange + srange / 2) / srange); + } + + class resizer_local : public resizer + { + public: + void operator()(uint8_t* target, uint32_t twidth, uint32_t theight, + const uint8_t* source, uint32_t swidth, uint32_t sheight) + { + uint32_t* __restrict__ src = (uint32_t*)source; + uint32_t* __restrict__ dest = (uint32_t*)target; + + for(uint32_t y = 0; y < theight; y++) + for(uint32_t x = 0; x < twidth; x++) { + uint32_t _x = nnscale(x, swidth, twidth); + uint32_t _y = nnscale(y, sheight, theight); + dest[y * twidth + x] = src[_y * swidth + _x]; + } + } + }; + + class resizer_local_factory : public resizer_factory + { + public: + resizer_local_factory() + : resizer_factory("nearest") + { + } + + resizer& make(const std::string& type) + { + return *new resizer_local(); + } + } factory; +} -- 2.11.4.GIT