libtthimage/Lib/patterns.c

160 lines
3.5 KiB
C
Raw Normal View History

2022-06-27 00:48:18 +02:00
/*
patterns.c
------------------
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "../tthimage.h"
/*::------------------------------------------------------------------::*/
2023-09-22 14:20:26 +02:00
int Image_pattern_000(Image_Desc *img, int foo)
2022-06-27 00:48:18 +02:00
{
int x, y, xx, yy, r, g, b;
#if DEBUG_LEVEL
fprintf(stderr, "%s : foo = %d\n", __func__, foo);
#endif
2023-09-22 14:20:26 +02:00
for (x=0; x<img->width; x++) {
2022-06-27 00:48:18 +02:00
xx = (x * 256) / img->width;
2023-09-22 14:20:26 +02:00
for (y=0; y<img->height; y++) {
2022-06-27 00:48:18 +02:00
yy = (y * 256) / img->height;
r = xx & yy & foo;
g = ((xx * yy) & 0xf8 );
b = xx ^ yy;
Image_plotRGB(img, x, y, r, g, b);
}
}
/*
sometime, a newbie ask me: "why use intermediate vars: r, g, and b ?"
my answer was: "clarity of code, small scarab<61>e".
*/
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
2023-09-22 14:20:26 +02:00
int Image_pattern_001(Image_Desc *img, int foo)
2022-06-27 00:48:18 +02:00
{
int x, y;
#if DEBUG_LEVEL
fprintf(stderr, "%s : foo is %d\n", __func__, foo);
#endif
for (x=0; x<img->width; x++)
for (y=0; y<img->height; y++)
Image_plotRGB(img, x, y, x^y^foo, (x*y)>>4, x&y);
2023-09-22 14:20:26 +02:00
return FUNC_IS_BETA;
2022-06-27 00:48:18 +02:00
}
/*::------------------------------------------------------------------::*/
2023-09-22 14:20:26 +02:00
int Image_pattern_002(Image_Desc *img, int foo)
2022-06-27 00:48:18 +02:00
{
int x, y, x2, y2;
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 002: %d\n", foo);
#endif
2023-09-22 14:20:26 +02:00
for (x=0; x<img->width; x++) {
2022-06-27 00:48:18 +02:00
x2 = (x * 256) / img->width;
2023-09-22 14:20:26 +02:00
for (y=0; y<img->height; y++) {
2022-06-27 00:48:18 +02:00
y2 = (y * 256) / img->height;
Image_plotRGB(img, x, y, (x2/2)&(y2/2)&foo, (x2*y2)>>3, x2^y2);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
2023-09-22 14:20:26 +02:00
int Image_pattern_003(Image_Desc *img, int foo)
2022-06-27 00:48:18 +02:00
{
int x, x2, y, y2;
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 003: foo is %d\n", foo);
#endif
/* added some ugly code the 28 february 2008 */
2023-09-22 14:20:26 +02:00
for (x=0; x<img->width; x++) {
2022-06-27 00:48:18 +02:00
x2 = (x * 256) / img->width;
2023-09-22 14:20:26 +02:00
for (y=0; y<img->height; y++) {
2022-06-27 00:48:18 +02:00
y2 = (y * 256) / img->height;
Image_plotRGB(img, x, y, (x2/4)&(y2/4)&foo, (x2*y2)>>5, x2^y2);
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
2023-09-22 14:20:26 +02:00
int Image_pattern_004(Image_Desc *img, int a, int b, int c, int d)
2022-06-27 00:48:18 +02:00
{
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 004: %d, %d, %d, %d\n", a, b, c, d);
#endif
fprintf(stderr, "NO CODE HERE\n");
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
int Image_pattern_005(Image_Desc *img, RGB_map *map)
{
int x, y;
double fx, fy;
int idx;
if (NULL == map) {
fprintf(stderr, "in %s:%s, map is NULL\n",
__FILE__, __func__);
return NULL_POINTER;
}
2023-09-22 14:20:26 +02:00
for (y=0; y<img->height; y++) {
2022-06-27 00:48:18 +02:00
fy = (double)y;
2023-09-22 14:20:26 +02:00
for (x=0; x<img->width; x++) {
2022-06-27 00:48:18 +02:00
fx = (double)x;
idx = (int)(127.0+(sin(fx)*cos(fy)*254.99));
idx &= 0xff;
(img->Gpix[y])[x] = map->green[idx];
(img->Bpix[y])[x] = map->blue[idx];
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
2023-09-22 14:20:26 +02:00
int Image_pattern_042(Image_Desc *img, int foo)
2022-06-27 00:48:18 +02:00
{
int x, y, r, g, b;
#if DEBUG_LEVEL
fprintf(stderr, "Pattern 042: threshold level is %d\n", foo);
#endif
r = g = b = 42;
2023-09-22 14:20:26 +02:00
for (x=0; x<img->width; x++) {
for (y=0; y<img->height; y++) {
2022-06-27 00:48:18 +02:00
r += rand() % 4;
if (r > foo) r = 0;
g += rand() % 4;
if (g > foo) g = 0;
b += rand() % 4;
if (b > foo) b = 0;
/* Image_plotRGB(img, x, y, r, g, b); */
(img->Rpix[y])[x] = r;
(img->Gpix[y])[x] = g;
(img->Bpix[y])[x] = b;
}
}
return OLL_KORRECT;
}
/*::------------------------------------------------------------------::*/