aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-05-22 01:00:24 +0200
committerMattias Andrée <maandree@operamail.com>2014-05-22 01:00:24 +0200
commitffc354a0fd1c497b50176b63a6da6cbf6be90534 (patch)
treec9e55138a17d7fc01535131960cadda091befaef
parentdoc (diff)
downloadlibgamma-ffc354a0fd1c497b50176b63a6da6cbf6be90534.tar.gz
libgamma-ffc354a0fd1c497b50176b63a6da6cbf6be90534.tar.bz2
libgamma-ffc354a0fd1c497b50176b63a6da6cbf6be90534.tar.xz
add initialise, destroy and free for gamma ramps
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile2
-rw-r--r--src/libgamma-method.c269
-rw-r--r--src/libgamma-method.h162
3 files changed, 432 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 56d22bf..ae8db5f 100644
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,7 @@ C_FLAGS = $(OPTIMISE) $(WARN) -std=$(STD) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
# Object files for the library.
-LIBOBJ = libgamma-facade gamma-helper
+LIBOBJ = libgamma-facade libgamma-method gamma-helper
# Include configurations from `./configure`.
diff --git a/src/libgamma-method.c b/src/libgamma-method.c
new file mode 100644
index 0000000..164d0b4
--- /dev/null
+++ b/src/libgamma-method.c
@@ -0,0 +1,269 @@
+/**
+ * libgamma — Display server abstraction layer for gamma ramp adjustments
+ * Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "libgamma-method.h"
+
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_ramps_initialise(libgamma_gamma_ramps_t* restrict this)
+{
+ size_t n = this->red_size + this->green_size + this->blue_size;
+ this->red = malloc(n * sizeof(uint16_t));
+ this->green = this-> red + this-> red_size;
+ this->blue = this->green + this->green_size;
+ return this->red ? 0 : -1;
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps_destroy(libgamma_gamma_ramps_t* restrict this)
+{
+ free(this->red);
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps_free(libgamma_gamma_ramps_t* restrict this)
+{
+ free(this->red);
+ free(this);
+}
+
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t* restrict this)
+{
+ size_t n = this->red_size + this->green_size + this->blue_size;
+ this->red = malloc(n * sizeof(uint32_t));
+ this->green = this-> red + this-> red_size;
+ this->blue = this->green + this->green_size;
+ return this->red ? 0 : -1;
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps32_destroy(libgamma_gamma_ramps32_t* restrict this)
+{
+ free(this->red);
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t* restrict this)
+{
+ free(this->red);
+ free(this);
+}
+
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t* restrict this)
+{
+ size_t n = this->red_size + this->green_size + this->blue_size;
+ this->red = malloc(n * sizeof(uint64_t));
+ this->green = this-> red + this-> red_size;
+ this->blue = this->green + this->green_size;
+ return this->red ? 0 : -1;
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps64_destroy(libgamma_gamma_ramps64_t* restrict this)
+{
+ free(this->red);
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t* restrict this)
+{
+ free(this->red);
+ free(this);
+}
+
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t* restrict this)
+{
+ size_t n = this->red_size + this->green_size + this->blue_size;
+ this->red = malloc(n * sizeof(float));
+ this->green = this-> red + this-> red_size;
+ this->blue = this->green + this->green_size;
+ return this->red ? 0 : -1;
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsf_destroy(libgamma_gamma_rampsf_t* restrict this)
+{
+ free(this->red);
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t* restrict this)
+{
+ free(this->red);
+ free(this);
+}
+
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t* restrict this)
+{
+ size_t n = this->red_size + this->green_size + this->blue_size;
+ this->red = malloc(n * sizeof(double));
+ this->green = this-> red + this-> red_size;
+ this->blue = this->green + this->green_size;
+ return this->red ? 0 : -1;
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsd_destroy(libgamma_gamma_rampsd_t* restrict this)
+{
+ free(this->red);
+}
+
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t* restrict this)
+{
+ free(this->red);
+ free(this);
+}
+
diff --git a/src/libgamma-method.h b/src/libgamma-method.h
index ec15f86..c3fb36a 100644
--- a/src/libgamma-method.h
+++ b/src/libgamma-method.h
@@ -840,5 +840,167 @@ typedef struct libgamma_gamma_rampsd
} libgamma_gamma_rampsd_t;
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_ramps_initialise(libgamma_gamma_ramps_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps_destroy(libgamma_gamma_ramps_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps_free(libgamma_gamma_ramps_t* restrict this);
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_ramps32_initialise(libgamma_gamma_ramps32_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps32_destroy(libgamma_gamma_ramps32_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps32_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps32_free(libgamma_gamma_ramps32_t* restrict this);
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_ramps64_initialise(libgamma_gamma_ramps64_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps64_destroy(libgamma_gamma_ramps64_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_ramps64_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_ramps64_free(libgamma_gamma_ramps64_t* restrict this);
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_rampsf_initialise(libgamma_gamma_rampsf_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsf_destroy(libgamma_gamma_rampsf_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsf_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsf_free(libgamma_gamma_rampsf_t* restrict this);
+
+
+/**
+ * Initialise a gamma ramp in the proper way that allows all adjustment
+ * methods to read from and write to it without causing segmentation violation
+ *
+ * The input must have `red_size`, `green_size` and `blue_size` set to the
+ * sizes of the gamma ramps that should be allocated
+ *
+ * @param this The gamma ramps
+ * @return Zero on success, -1 on allocation error, `errno` will be set accordingly
+ */
+int libgamma_gamma_rampsd_initialise(libgamma_gamma_rampsd_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise
+ * initialises in the proper manner
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsd_destroy(libgamma_gamma_rampsd_t* restrict this);
+
+/**
+ * Release resources that are held by a gamma ramp strcuture that
+ * has been allocated by `libgamma_gamma_rampsd_initialise` or otherwise
+ * initialises in the proper manner, as well as release the pointer
+ * to the structure
+ *
+ * @param this The gamma ramps
+ */
+void libgamma_gamma_rampsd_free(libgamma_gamma_rampsd_t* restrict this);
+
+
+
#endif