aboutsummaryrefslogtreecommitdiffstats
path: root/src/output.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-16 19:28:39 +0200
committerMattias Andrée <maandree@kth.se>2016-07-16 19:28:39 +0200
commit0c0d0ca0da8060484ab5f41a6ee73087755a69e3 (patch)
treedd455f5a29edba440f2194a60fc06f0ceed8f397 /src/output.c
parentattributes (diff)
downloadcoopgammad-0c0d0ca0da8060484ab5f41a6ee73087755a69e3.tar.gz
coopgammad-0c0d0ca0da8060484ab5f41a6ee73087755a69e3.tar.bz2
coopgammad-0c0d0ca0da8060484ab5f41a6ee73087755a69e3.tar.xz
Restructure
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/types/output.c (renamed from src/output.c)220
1 files changed, 1 insertions, 219 deletions
diff --git a/src/output.c b/src/types/output.c
index e8913dd..8576baa 100644
--- a/src/output.c
+++ b/src/types/output.c
@@ -16,24 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "output.h"
-#include "util.h"
+#include "../util.h"
-#include <libclut.h>
-
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
- * The name of the process
- */
-extern char* restrict argv0;
-
-
-
-/**
* Free all resources allocated to an output.
* The allocation of `output` itself is not freed,
* nor is its the libgamma destroyed.
@@ -272,211 +262,3 @@ struct output* output_find_by_name(const char* restrict key, struct output* rest
return bsearch(&k, base, n, sizeof(*base), output_cmp_by_name);
}
-
-/**
- * Remove a filter from an output
- *
- * @param out The output
- * @param filter The filter
- * @return The index of the filter, `out->table_size` if not found
- */
-static ssize_t remove_filter(struct output* restrict out, struct filter* restrict filter)
-{
- size_t i, n = out->table_size;
-
- for (i = 0; i < n; i++)
- if (!strcmp(filter->class, out->table_filters[i].class))
- break;
-
- if (i == out->table_size)
- {
- fprintf(stderr, "%s: ignoring attempt to removing non-existing filter on CRTC %s: %s",
- argv0, out->name, filter->class);
- return (ssize_t)(out->table_size);
- }
-
- filter_destroy(out->table_filters + i);
- libgamma_gamma_ramps8_destroy(&(out->table_sums[i].u8));
-
- n = n - i - 1;
- memmove(out->table_filters + i, out->table_filters + i + 1, n * sizeof(*(out->table_filters)));
- memmove(out->table_sums + i, out->table_sums + i + 1, n * sizeof(*(out->table_sums)));
- out->table_size--;
-
- return (ssize_t)i;
-}
-
-
-/**
- * Add a filter to an output
- *
- * @param out The output
- * @param filter The filter
- * @return The index given to the filter, -1 on error
- */
-ssize_t add_filter(struct output* restrict out, struct filter* restrict filter)
-{
- size_t i, n = out->table_size;
- int r = -1;
-
- /* Remove? */
- if (filter->lifespan == LIFESPAN_REMOVE)
- return remove_filter(out, filter);
-
- /* Update? */
- for (i = 0; i < n; i++)
- if (!strcmp(filter->class, out->table_filters[i].class))
- break;
- if (i != n)
- {
- filter_destroy(out->table_filters + i);
- out->table_filters[i] = *filter;
- return (ssize_t)i;
- }
-
- /* Add! */
- for (i = 0; i < n; i++)
- if (filter->priority > out->table_filters[i].priority)
- break;
-
- if (n == out->table_alloc)
- {
- void* new;
-
- new = realloc(out->table_filters, (n + 10) * sizeof(*(out->table_filters)));
- if (new == NULL)
- return -1;
- out->table_filters = new;
-
- new = realloc(out->table_sums, (n + 10) * sizeof(*(out->table_sums)));
- if (new == NULL)
- return -1;
- out->table_sums = new;
-
- out->table_alloc += 10;
- }
-
- memmove(out->table_filters + i + 1, out->table_filters + i, (n - i) * sizeof(*(out->table_filters)));
- memmove(out->table_sums + i + 1, out->table_sums + i, (n - i) * sizeof(*(out->table_sums)));
- out->table_size++;
-
- COPY_RAMP_SIZES(&(out->table_sums[i].u8), out);
- switch (out->depth)
- {
- case 8: r = libgamma_gamma_ramps8_initialise(&(out->table_sums[i].u8)); break;
- case 16: r = libgamma_gamma_ramps16_initialise(&(out->table_sums[i].u16)); break;
- case 32: r = libgamma_gamma_ramps32_initialise(&(out->table_sums[i].u32)); break;
- case 64: r = libgamma_gamma_ramps64_initialise(&(out->table_sums[i].u64)); break;
- case -1: r = libgamma_gamma_rampsf_initialise(&(out->table_sums[i].f)); break;
- case -2: r = libgamma_gamma_rampsd_initialise(&(out->table_sums[i].d)); break;
- default:
- abort();
- }
- if (r < 0)
- return -1;
-
- out->table_filters[i] = *filter;
-
- return (ssize_t)i;
-}
-
-
-/**
- * Recalculate the resulting gamma and
- * update push the new gamma ramps to the CRTC
- *
- * @param output The output
- * @param first_updated The index of the first added or removed filter
- * @return Zero on success, -1 on error
- */
-int flush_filters(struct output* restrict output, size_t first_updated)
-{
- union gamma_ramps plain;
- union gamma_ramps* last;
- size_t i;
- int r = 0;
-
- if (first_updated == 0)
- {
- if (make_plain_ramps(&plain, output) < 0)
- return -1;
- last = &plain;
- }
- else
- last = output->table_sums + (first_updated - 1);
-
- for (i = first_updated; i < output->table_size; i++)
- {
- apply(output->table_sums + i, output->table_filters[i].ramps, output->depth, last);
- last = output->table_sums + i;
- }
-
- switch (output->depth)
- {
- case 8: r = libgamma_crtc_set_gamma_ramps8(output->crtc, last->u8); break;
- case 16: r = libgamma_crtc_set_gamma_ramps16(output->crtc, last->u16); break;
- case 32: r = libgamma_crtc_set_gamma_ramps32(output->crtc, last->u32); break;
- case 64: r = libgamma_crtc_set_gamma_ramps64(output->crtc, last->u64); break;
- case -1: r = libgamma_crtc_set_gamma_rampsf(output->crtc, last->f); break;
- case -2: r = libgamma_crtc_set_gamma_rampsd(output->crtc, last->d); break;
- default:
- abort();
- }
- if (r)
- libgamma_perror(argv0, r); /* Not fatal */
-
- if (first_updated == 0)
- libgamma_gamma_ramps8_destroy(&(plain.u8));
-
- return 0;
-}
-
-
-/**
- * Make identity mapping ramps
- *
- * @param ramps Output parameter for the ramps
- * @param output The output for which the ramps shall be configured
- * @return Zero on success, -1 on error
- */
-int make_plain_ramps(union gamma_ramps* restrict ramps, struct output* restrict output)
-{
- COPY_RAMP_SIZES(&(ramps->u8), output);
- switch (output->depth)
- {
- case 8:
- if (libgamma_gamma_ramps8_initialise(&(ramps->u8)))
- return -1;
- libclut_start_over(&(ramps->u8), UINT8_MAX, uint8_t, 1, 1, 1);
- break;
- case 16:
- if (libgamma_gamma_ramps16_initialise(&(ramps->u16)))
- return -1;
- libclut_start_over(&(ramps->u16), UINT16_MAX, uint16_t, 1, 1, 1);
- break;
- case 32:
- if (libgamma_gamma_ramps32_initialise(&(ramps->u32)))
- return -1;
- libclut_start_over(&(ramps->u32), UINT32_MAX, uint32_t, 1, 1, 1);
- break;
- case 64:
- if (libgamma_gamma_ramps64_initialise(&(ramps->u64)))
- return -1;
- libclut_start_over(&(ramps->u64), UINT64_MAX, uint64_t, 1, 1, 1);
- break;
- case -1:
- if (libgamma_gamma_rampsf_initialise(&(ramps->f)))
- return -1;
- libclut_start_over(&(ramps->f), 1.0f, float, 1, 1, 1);
- break;
- case -2:
- if (libgamma_gamma_rampsd_initialise(&(ramps->d)))
- return -1;
- libclut_start_over(&(ramps->d), (double)1, double, 1, 1, 1);
- break;
- default:
- abort();
- }
- return 0;
-}
-