Skip to content

Commit

Permalink
source/source.cpp: fix rounding (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
WolframRhodium committed Jun 12, 2023
1 parent 492db6d commit b23ea3a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions source/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
struct BoxBlurVData {
VSNodeRef *node;
std::array<int, 3> radius;
bool rounding;

std::shared_mutex buffer_lock;
std::unordered_map<std::thread::id, void *> buffers;
Expand Down Expand Up @@ -108,12 +109,12 @@ static void blurV(
const int height,
const int stride,
const int radius,
void * buffer // [((width + 7) / 8 * 8) * 4]
void * buffer, // [((width + 7) / 8 * 8) * 4]
unsigned round
) {

// utilities
Divisor_ui div = radius * 2 + 1;
unsigned round = radius * 2;

uint32_t * buf = reinterpret_cast<uint32_t *>(buffer);
auto for_each_vec = [buf, width](auto func) -> void {
Expand Down Expand Up @@ -283,12 +284,14 @@ static const VSFrameRef *VS_CC BoxBlurVGetFrame(
const auto * srcp = vsapi->getReadPtr(src_frame, plane);
auto * dstp = vsapi->getWritePtr(dst_frame, plane);

auto round = (unsigned int) (d->rounding ? d->radius[plane] * 2 : 0);

if (bytes == 4) {
blurVF((float *) dstp, (const float *) srcp, width, height, stride, d->radius[plane], buffer);
} else if (bytes == 2) {
blurV((uint16_t *) dstp, (const uint16_t *) srcp, width, height, stride, d->radius[plane], buffer);
blurV((uint16_t *) dstp, (const uint16_t *) srcp, width, height, stride, d->radius[plane], buffer, round);
} else if (bytes == 1) {
blurV((uint8_t *) dstp, (const uint8_t *) srcp, width, height, stride, d->radius[plane], buffer);
blurV((uint8_t *) dstp, (const uint8_t *) srcp, width, height, stride, d->radius[plane], buffer, round);
}
}
}
Expand Down Expand Up @@ -467,7 +470,7 @@ static void VS_CC BoxBlurCreate(
vsapi->propSetNode(in_map, "clip", node, paReplace);
vsapi->createFilter(
in_map, out_map, "BlurV", BoxBlurVInit, BoxBlurVGetFrame, BoxBlurVFree,
fmParallel, 0, new BoxBlurVData{ node, radius }, core);
fmParallel, 0, new BoxBlurVData{ node, radius, (pass % 2) == 0 }, core);

node = vsapi->propGetNode(out_map, "clip", 0, nullptr);
vsapi->clearMap(out_map);
Expand Down Expand Up @@ -501,7 +504,7 @@ static void VS_CC BoxBlurCreate(
vsapi->propSetNode(vtmp1, "clip", node, paReplace);
vsapi->createFilter(
vtmp1, vtmp2, "BlurV", BoxBlurVInit, BoxBlurVGetFrame, BoxBlurVFree,
fmParallel, 0, new BoxBlurVData{ node, radius }, core);
fmParallel, 0, new BoxBlurVData{ node, radius, (pass % 2) == 0 }, core);

node = vsapi->propGetNode(vtmp2, "clip", 0, &err);
vsapi->clearMap(vtmp2);
Expand Down

0 comments on commit b23ea3a

Please sign in to comment.