libtthimage/Lib/contrast.c

135 lines
3.2 KiB
C
Raw Normal View History

2022-06-26 20:06:35 +11:00
/*
* contrast.c - 31 dec 2013
*/
#include <stdio.h>
#include <math.h>
2022-06-28 21:25:31 +11:00
#include "../tthimage.h"
2022-06-26 20:06:35 +11:00
2023-09-18 07:36:08 +11:00
/*::------------------------------------------------------------------::*/
/*
* new: Fri Sep 15 20:18:35 UTC 2023
* inspired by the sam func in FloatImg
*/
int Image_egalise_cos01(Image_Desc *source, Image_Desc *but, int k)
{
2023-09-26 20:17:04 +11:00
int lut[256], uc;
int idx, foo;
/* int x, y, pix; */
2023-09-18 07:36:08 +11:00
float fidx;
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
source, but, k);
if ( (foo=Image_compare_desc(source, but)) ) {
fprintf(stderr, "%s: images not compatible, %d\n", __func__, foo);
return foo;
}
for (idx=0; idx<256; idx++) {
fidx = (float)idx / 255.0;
uc = (unsigned char)(255.0*(0.5 - 0.5 * cos(3.141592654*fidx)));
lut[idx] = uc;
/* printf("%7d %7d\n", idx, uc); */
}
2023-09-26 20:17:04 +11:00
/*
* old original code, replaced...
*
2023-09-18 07:36:08 +11:00
for (y=0; y<source->height; y++) {
for (x=0; x<source->width; x++) {
pix = source->Rpix[y][x];
but->Rpix[y][x] = lut[pix];
pix = source->Gpix[y][x];
but->Gpix[y][x] = lut[pix];
pix = source->Bpix[y][x];
but->Bpix[y][x] = lut[pix];
}
}
2023-09-26 20:17:04 +11:00
*
* ... by a func from 'calculs.c'
*/
Image_LUT_mono(source, but, lut);
2023-09-18 07:36:08 +11:00
2023-09-26 20:17:04 +11:00
return FUNC_IS_BETA;
2023-09-18 07:36:08 +11:00
}
2022-06-26 20:06:35 +11:00
/*::------------------------------------------------------------------::*/
/*
* cette fonction peut etre utilisee avec la meme image
* en source et en destination.
*/
int Image_pix_square(Image_Desc *source, Image_Desc *but, int k)
{
int x, y, r, g, b, foo;
float fr, fg, fb;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %p -> %p\n", __func__, source, but);
#endif
2023-09-18 07:36:08 +11:00
if (k) {
fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k);
}
2022-06-26 20:06:35 +11:00
if ( (foo=Image_compare_desc(source, but)) ) {
fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
return foo;
}
for (y=0; y<source->height; y++) {
for (x=0; x<source->width; x++) {
fr = ((float)(source->Rpix[y])[x]) / 255.0;
fg = ((float)(source->Gpix[y])[x]) / 255.0;
fb = ((float)(source->Bpix[y])[x]) / 255.0;
r = (int)(fr * fr * 255.0);
g = (int)(fg * fg * 255.0);
b = (int)(fb * fb * 255.0);
(but->Rpix[y])[x] = r;
(but->Gpix[y])[x] = g;
(but->Bpix[y])[x] = b;
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/*
* cette fonction peut etre utilisee avec la meme image
* en source et en destination.
*/
int Image_pix_sqroot(Image_Desc *source, Image_Desc *but, int k)
{
int x, y, foo;
float fr, fg, fb;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %p -> %p\n", __func__, source, but);
#endif
2023-09-18 07:36:08 +11:00
if (k) {
fprintf(stderr, "In %s, k must be 0, was %d\n", __func__, k);
}
2022-06-26 20:06:35 +11:00
if ( (foo=Image_compare_desc(source, but)) ) {
fprintf(stderr, "%s : images are differents %d\n", __func__, foo);
return foo;
}
for (y=0; y<source->height; y++) {
for (x=0; x<source->width; x++) {
fr = ((float)(source->Rpix[y])[x]) / 255.0;
fg = ((float)(source->Gpix[y])[x]) / 255.0;
fb = ((float)(source->Bpix[y])[x]) / 255.0;
(but->Rpix[y])[x] = (int)(sqrt(fr) * 255.0);
(but->Gpix[y])[x] = (int)(sqrt(fg) * 255.0);
(but->Bpix[y])[x] = (int)(sqrt(fb) * 255.0);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/