diff options
author | Mattias Andrée <maandree@kth.se> | 2023-01-22 11:32:39 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-01-22 11:32:50 +0100 |
commit | bd0da30a3d8a92baff536ecc1c7c2e36ea1b419d (patch) | |
tree | cd064cac67ae8f4759457765275e6714f583ed22 | |
parent | m + add CIE XYZ support + add libglitter_per_channel_desaturate_{double,float} (diff) | |
download | libglitter-bd0da30a3d8a92baff536ecc1c7c2e36ea1b419d.tar.gz libglitter-bd0da30a3d8a92baff536ecc1c7c2e36ea1b419d.tar.bz2 libglitter-bd0da30a3d8a92baff536ecc1c7c2e36ea1b419d.tar.xz |
m + add libglitter_colour_space_convert_rasters_{double,float}
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | libglitter.h | 47 | ||||
-rw-r--r-- | libglitter_colour_space_convert_rasters_double.c | 75 | ||||
-rw-r--r-- | libglitter_colour_space_convert_rasters_float.c | 6 | ||||
-rw-r--r-- | libglitter_per_channel_desaturate_double.c | 6 |
6 files changed, 130 insertions, 7 deletions
@@ -17,6 +17,8 @@ LIB_NAME = glitter OBJ =\ + libglitter_colour_space_convert_rasters_double.o\ + libglitter_colour_space_convert_rasters_float.o\ libglitter_compose_double.o\ libglitter_compose_float.o\ libglitter_compose_uint16.o\ @@ -1,4 +1,3 @@ -Add colour space conversion Add support for GPU-acceleration Add man pages Add tests diff --git a/libglitter.h b/libglitter.h index 50d451d..649d522 100644 --- a/libglitter.h +++ b/libglitter.h @@ -83,7 +83,7 @@ void libglitter_free_render_context(LIBGLITTER_RENDER_CONTEXT *); * as such, the given pointer shall not be used anywhere * else during the execution of the function and the * inner pointers shall be considered undefined after - * the execution of the function + * the execution of the function. * @param input Input raster; cells are adjacent * @param output_rowsize The number of cells in a row in each output raster * @param output_cellsize The number of values stored in each output raster, @@ -118,7 +118,7 @@ void libglitter_compose_float(float **, const float *restrict, size_t, size_t, * as such, the given pointer shall not be used anywhere * else during the execution of the function and the * inner pointers shall be considered undefined after - * the execution of the function + * the execution of the function. * @param input Input raster; cells are adjacent * @param output_rowsize The number of cells in a row in each output raster * @param output_cellsize The number of values stored in each output raster, @@ -235,7 +235,7 @@ void libglitter_desaturate_float(float **, size_t, size_t, size_t, size_t, size_ * as such, the given pointer shall not be used anywhere * else during the execution of the function and the * inner pointers shall be considered undefined after - * the execution of the function + * the execution of the function. * @param nrasters The number of rasters * @param rowsize The number of cells in a row in each raster * @param cellsize The number of values stored in each raster, @@ -302,4 +302,45 @@ void libglitter_get_colour_space_conversion_matrix_float(float[3][3], float, flo float, float, float, float, float, int); +/** + * Convert set of rasters from one colour space to another + * + * @param n The number of input rasters + * @param m The number of output rasters + * @param outputs Array of output rasters. The function may change + * the offset for each raster, as such, the given + * pointer shall not be used anywhere else during + * the execution of the function and the inner + * pointers shall be considered undefined after the + * execution of the function. + * @param inputs Array of input rasters. The function may change + * the offset for each raster, as such, the given + * pointer shall not be used anywhere else during + * the execution of the function and the inner + * pointers shall be considered undefined after the + * execution of the function. + * @param output_rowsize The number of cells in a row in each output raster + * @param output_cellsize The number of values stored in each output raster, + * between each cell, plus 1 (that is, the number of + * values per cell) + * @param input_rowsize The number of cells in a row in each input raster + * @param input_cellsize The number of values stored in each input raster, + * between each cell, plus 1 (that is, the number of + * values per cell) + * @param width The horizontal number of pixels in the rasters + * @param height The vertical number of pixels in the rasters + * @param matrix Colour space conversion matrix + */ +void libglitter_colour_space_convert_rasters_double(size_t n, size_t m, double **, const double **, + size_t, size_t, size_t, size_t, size_t, size_t, const double[n][m]); + +/** + * This value is identical to `libglitter_colour_space_convert_rasters_double`, + * apart from it parameter types, see `libglitter_colour_space_convert_rasters_double` + * for details about this function + */ +void libglitter_colour_space_convert_rasters_float(size_t n, size_t m, float **, const float **, + size_t, size_t, size_t, size_t, size_t, size_t, const float[n][m]); + + #endif diff --git a/libglitter_colour_space_convert_rasters_double.c b/libglitter_colour_space_convert_rasters_double.c new file mode 100644 index 0000000..7128998 --- /dev/null +++ b/libglitter_colour_space_convert_rasters_double.c @@ -0,0 +1,75 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +static void +multiply_33(double **outputs, size_t opos, const double **inputs, size_t ipos, const double matrix[3][3]) +{ + double i0 = inputs[0][ipos], i1 = inputs[1][ipos], i2 = inputs[2][ipos]; + outputs[0][opos] = i0 * matrix[0][0] + i1 * matrix[1][0] + i2 * matrix[2][0]; + outputs[1][opos] = i0 * matrix[0][1] + i1 * matrix[1][1] + i2 * matrix[2][1]; + outputs[2][opos] = i0 * matrix[0][2] + i1 * matrix[1][2] + i2 * matrix[2][2]; +} + + +static void +multiply_nn(size_t n, double **outputs, size_t opos, const double **inputs, size_t ipos, + const double matrix[n][n], double buffer[n]) +{ + size_t i, j; + for (j = 0; j < n; j++) + buffer[j] = inputs[j][ipos]; + for (i = 0; i < n; i++) { + outputs[i][opos] = buffer[0] * matrix[0][i]; + for (j = 1; j < n; j++) + outputs[i][opos] += buffer[j] * matrix[j][i]; + } +} + + +static void +multiply_nm(size_t n, size_t m, double **outputs /* m */, size_t opos, const double **inputs /* n */, + size_t ipos, const double matrix[n][m], double buffer[n]) +{ + size_t i, j; + for (j = 0; j < n; j++) + buffer[j] = inputs[j][ipos]; + for (i = 0; i < m; i++) { + outputs[i][opos] = buffer[0] * matrix[0][i]; + for (j = 1; j < n; j++) + outputs[i][opos] += buffer[j] * matrix[j][i]; + } +} + + +void +libglitter_colour_space_convert_rasters_double(size_t n, size_t m, double **outputs /* m */, const double **inputs /* n */, + size_t output_rowsize, size_t output_cellsize, size_t input_rowsize, + size_t input_cellsize, size_t width, size_t height, const double matrix[n][m]) +{ + size_t y, x, output_i, input_i, output_blanking, input_blanking; + double *buffer; + + output_blanking = (output_rowsize - width) * output_cellsize; + input_blanking = (input_rowsize - width) * input_cellsize; + output_i = 0; + input_i = 0; + + if (n == 3 && m == 3) { + for (y = 0; y < height; y++, output_i += output_blanking, input_i += input_blanking) + for (x = 0; x < width; x++, output_i += output_cellsize, input_i += input_cellsize) + multiply_33(outputs, output_i, inputs, input_i, matrix); + + } else if (n == m) { + buffer = alloca(n * sizeof(*buffer)); + for (y = 0; y < height; y++, output_i += output_blanking, input_i += input_blanking) + for (x = 0; x < width; x++, output_i += output_cellsize, input_i += input_cellsize) + multiply_nn(n, outputs, output_i, inputs, input_i, matrix, buffer); + + } else { + buffer = alloca(n * sizeof(*buffer)); + for (y = 0; y < height; y++, output_i += output_blanking, input_i += input_blanking) + for (x = 0; x < width; x++, output_i += output_cellsize, input_i += input_cellsize) + multiply_nm(n, m, outputs, output_i, inputs, input_i, matrix, buffer); + } +} diff --git a/libglitter_colour_space_convert_rasters_float.c b/libglitter_colour_space_convert_rasters_float.c new file mode 100644 index 0000000..c77835a --- /dev/null +++ b/libglitter_colour_space_convert_rasters_float.c @@ -0,0 +1,6 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#define libglitter_colour_space_convert_rasters_double libglitter_colour_space_convert_rasters_float +#define double float +#define fma fmaf +#include "libglitter_colour_space_convert_rasters_double.c" diff --git a/libglitter_per_channel_desaturate_double.c b/libglitter_per_channel_desaturate_double.c index 8561708..04edbf3 100644 --- a/libglitter_per_channel_desaturate_double.c +++ b/libglitter_per_channel_desaturate_double.c @@ -8,9 +8,9 @@ void -libglitter_per_channel_desaturate_double(double **rasters, size_t nrasters, size_t rowsize, - size_t cellsize, size_t width, size_t height, - const double *saturations, const double *primary_ys) +libglitter_per_channel_desaturate_double(double **rasters, size_t nrasters, size_t rowsize, size_t cellsize, + size_t width, size_t height, const double *restrict saturations, + const double *restrict primary_ys) { size_t y, x, ch, raster_y, raster_i; double intensity; |