2022-06-26 11:06:35 +02:00
|
|
|
/*
|
|
|
|
calcluts.c
|
|
|
|
----------
|
|
|
|
|
2023-11-18 19:56:25 +01:00
|
|
|
voir aussi: luts15bits.c & palettes.c
|
2022-06-26 11:06:35 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef NEED_ALLOCA_H
|
|
|
|
#include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
2022-07-07 12:52:00 +02:00
|
|
|
#include "../tthimage.h"
|
2022-06-26 11:06:35 +02:00
|
|
|
|
|
|
|
/*::------------------------------------------------------------------::*/
|
2023-10-11 22:36:16 +02:00
|
|
|
int Image_calclut_lin(int *lut, int v0, int v255)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
|
|
|
int foo, quux, delta;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2023-10-11 22:36:16 +02:00
|
|
|
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, lut, v0, v255);
|
2022-06-26 11:06:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
delta = v255 - v0;
|
2023-10-11 22:36:16 +02:00
|
|
|
if (delta == 0) {
|
2022-06-26 11:06:35 +02:00
|
|
|
return DIVISOR_IS_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2023-10-11 22:36:16 +02:00
|
|
|
fprintf(stderr, " calclut lin: delta = %d\n", delta);
|
2022-06-26 11:06:35 +02:00
|
|
|
#endif
|
|
|
|
|
2023-10-11 22:36:16 +02:00
|
|
|
for (foo=0; foo<256; foo++) {
|
2022-06-26 11:06:35 +02:00
|
|
|
quux = (foo * delta / 255) + v0;
|
2023-10-11 22:36:16 +02:00
|
|
|
#if DEBUG_LEVEL > 1
|
2022-06-26 11:06:35 +02:00
|
|
|
printf("lut(%d) = %d\n", foo, quux);
|
|
|
|
#endif
|
|
|
|
lut[foo] = quux;
|
|
|
|
}
|
|
|
|
|
2023-11-18 19:56:25 +01:00
|
|
|
return FUNC_IS_ALPHA;
|
2022-06-26 11:06:35 +02:00
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
2023-10-11 22:36:16 +02:00
|
|
|
int Image_calclut_foo(int *lut, int v0, int v255)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
2023-10-11 22:36:16 +02:00
|
|
|
fprintf(stderr, ">>> %s ( %p %d %d )\n", __func__, lut, v0, v255);
|
2022-06-26 11:06:35 +02:00
|
|
|
|
|
|
|
return FUNC_IS_ALPHA;
|
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
2023-10-11 22:36:16 +02:00
|
|
|
int Image_print_lut(int *lut, char *fname, int flag)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int foo;
|
|
|
|
|
2023-10-11 22:36:16 +02:00
|
|
|
if (strcmp(fname, "-")) fp = fopen(fname, "w");
|
|
|
|
else fp = stdout;
|
2022-06-26 11:06:35 +02:00
|
|
|
|
2023-10-11 22:36:16 +02:00
|
|
|
for (foo=0; foo<256; foo++) {
|
|
|
|
if (flag) printf("%4d ", foo);
|
|
|
|
printf(" %4d\n", lut[foo]);
|
2022-06-26 11:06:35 +02:00
|
|
|
}
|
|
|
|
|
2023-10-11 22:36:16 +02:00
|
|
|
if (fp!=stdout) fclose(fp);
|
2022-06-26 11:06:35 +02:00
|
|
|
|
2023-11-18 19:56:25 +01:00
|
|
|
return FUNC_IS_ALPHA;
|
2022-06-26 11:06:35 +02:00
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|
2023-10-11 22:36:16 +02:00
|
|
|
int Image_load_lut(int *lut, char *fname, int flag)
|
2022-06-26 11:06:35 +02:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int value, foo, idx;
|
|
|
|
|
2023-10-11 22:36:16 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, fname, lut);
|
|
|
|
#endif
|
|
|
|
|
2022-06-26 11:06:35 +02:00
|
|
|
if (flag) {
|
|
|
|
fprintf(stderr, "in %s, flag must be O, was %d\n", __func__, flag);
|
|
|
|
return WRONG_FLAG;
|
|
|
|
}
|
|
|
|
|
2023-10-11 22:36:16 +02:00
|
|
|
if (NULL==(fp=fopen(fname, "r"))) {
|
2022-06-26 11:06:35 +02:00
|
|
|
fprintf(stderr, "%s can't fopen %s\n", __func__, fname);
|
|
|
|
return 666;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* WARNING : very crude code here (4 nov 1999) */
|
2023-10-11 22:36:16 +02:00
|
|
|
for (idx=0; idx<256; idx++) {
|
2022-06-26 11:06:35 +02:00
|
|
|
foo = fscanf(fp, "%d", &value);
|
|
|
|
if (1==foo) lut[idx] = value;
|
|
|
|
else lut[idx] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
2023-11-18 19:56:25 +01:00
|
|
|
return FUNC_IS_ALPHA;
|
2022-06-26 11:06:35 +02:00
|
|
|
}
|
|
|
|
/*::------------------------------------------------------------------::*/
|