Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
test_interpolation_resample_window.c File Reference
#include "pixel/interpolation.h"
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <cmocka.h>
#include "win/main_wrapper.h"
Include dependency graph for test_interpolation_resample_window.c:

Go to the source code of this file.

Functions

static void _fill_identifiable (float *const pixels, const int width, const int height)
 A pixel whose channels encode its coordinates, so a misplaced copy is identifiable.
static void _expected_pixel (const int x, const int y, const int dx, const int dy, const int in_width, const int in_height, float *const out)
 What BORDER_REPLICATE says the output pixel at (x, y) must be.
static void _check_window (const int in_width, const int in_height, const int out_x, const int out_y, const int out_width, const int out_height)
 Resample one window and check every output pixel against the replicate rule.
static void test_window_contained (void **state)
static void test_window_taller_than_source (void **state)
static void test_window_wider_than_source (void **state)
static void test_window_transposed_source (void **state)
static void test_window_negative_offset (void **state)
static void test_window_entirely_outside (void **state)
static void test_window_single_pixel_source (void **state)
int main (int argc, char *argv[])

Function Documentation

◆ _check_window()

void _check_window ( const int in_width,
const int in_height,
const int out_x,
const int out_y,
const int out_width,
const int out_height )
static

◆ _expected_pixel()

void _expected_pixel ( const int x,
const int y,
const int dx,
const int dy,
const int in_width,
const int in_height,
float *const out )
static

What BORDER_REPLICATE says the output pixel at (x, y) must be.

Definition at line 69 of file test_interpolation_resample_window.c.

References out, and x.

Referenced by _check_window().

◆ _fill_identifiable()

void _fill_identifiable ( float *const pixels,
const int width,
const int height )
static

A pixel whose channels encode its coordinates, so a misplaced copy is identifiable.

dt_interpolation_resample() must stay inside its input, at every scale.

It has two implementations and they used to disagree about one case. At a resampling ratio of 1 – which is every export – it takes a memcpy path that walked roi_out->height rows at the INPUT's stride with no bounds check, so an output window larger than the source, or at a negative offset, read whatever followed the input buffer. The generic path cannot do that: _prepare_resampling_plan() clips every tap into the source, RESAMPLING_BORDER_MODE being BORDER_REPLICATE. Which path runs is decided by roi_out->scale alone, so the same request was safe at 0.5 and undefined at 1.0.

That is not hypothetical: drawlayer resolved a transposed canvas (7380x4928 for an image that was 4928x7380) and the export read unallocated heap from row 4928 down. doc/drawlayer.md section 8b has the measurement.

These tests pin the contract rather than either implementation: whatever the window, the resampler reads only its input and clamps to the edge. The source buffers are allocated with exactly their stated size so that a read past the end is a real overflow – run under ASAN (build-asan) and an escape is a hard failure, not a silent one.

Definition at line 55 of file test_interpolation_resample_window.c.

References height, width, and x.

Referenced by _check_window().

◆ main()

int main ( int argc,
char * argv[] )
Todo
: test if file with replaced ext exists
Todo
: add a callback to set the bpp without going through the config
Todo
: have a parameter in command line to get the export presets

Definition at line 167 of file test_interpolation_resample_window.c.

References test_window_contained(), test_window_entirely_outside(), test_window_negative_offset(), test_window_single_pixel_source(), test_window_taller_than_source(), test_window_transposed_source(), and test_window_wider_than_source().

◆ test_window_contained()

void test_window_contained ( void ** state)
static

The case that always worked: the window sits inside the source.

Definition at line 116 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().

◆ test_window_entirely_outside()

void test_window_entirely_outside ( void ** state)
static

Entirely outside, on both sides: every pixel is a corner of the source.

Definition at line 153 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().

◆ test_window_negative_offset()

void test_window_negative_offset ( void ** state)
static

Negative offsets, which indexed before the buffer. drawlayer's own KNOWN LIMIT.

Definition at line 145 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().

◆ test_window_single_pixel_source()

void test_window_single_pixel_source ( void ** state)
static

A one-pixel source has an edge to replicate and nothing else.

Definition at line 161 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().

◆ test_window_taller_than_source()

void test_window_taller_than_source ( void ** state)
static

Taller than the source. This is the drawlayer shape: rows past the end used to be heap.

Definition at line 124 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().

◆ test_window_transposed_source()

void test_window_transposed_source ( void ** state)
static

The transpose itself: a 64x48 source read as though it were 48x64.

Definition at line 138 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().

◆ test_window_wider_than_source()

void test_window_wider_than_source ( void ** state)
static

Wider than the source, which runs off the right of every row rather than off the end.

Definition at line 131 of file test_interpolation_resample_window.c.

References _check_window(), state, and void().

Referenced by main().