libtthimage/Lib/anamorphose.c

140 lines
2.5 KiB
C
Raw Normal View History

2022-06-26 11:06:35 +02:00
/*
* ANAMORPHOSES
*
* new 18 octobre 2003
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
2022-07-07 12:52:00 +02:00
#include "../tthimage.h"
2022-06-26 11:06:35 +02:00
/*::------------------------------------------------------------------::*/
int
Image_anmo_X(Image_Desc *src, Image_Desc *dst)
{
int x, y;
double dnormx, dnormy;
2022-07-07 12:52:00 +02:00
fprintf(stderr, ">>> %s: %p -> %p\n", __func__, src, dst);
2022-06-26 11:06:35 +02:00
/*
* we scan the destination picture
*/
2022-07-07 12:52:00 +02:00
for (y=0; y<dst->height; y++) {
2022-06-26 11:06:35 +02:00
dnormy = (double)y/(double)dst->height;
2022-07-07 12:52:00 +02:00
for (x=0; x<dst->width; x++) {
2022-06-26 11:06:35 +02:00
dnormx = (double)x/(double)dst->width;
}
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* warning: this is a test function. prototype may change
* in a near futur.
*/
int
Image_anmo_grille(Image_Desc *dst)
{
if (dst->magic != MAGIC_OF_IMAGE)
{
fprintf(stderr, "Grille Anamorphose: need Dead Beef!\n");
return NOT_AN_IMAGE_DESC;
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/
/*
* warning: this is a test function. prototype may change
* in a not so near futur.
*/
#define STAT 1
int
Image_anmo_essai_0(char *nomtga, int w, int h, int flgtxt)
{
Image_Desc *image;
int x, y, x2, y2;
double dx, dy;
double angle;
int xorg, yorg;
double xamp, yamp;
#if STAT
long nb_in, nb_out;
#endif
2022-07-07 12:52:00 +02:00
if (NULL==(image = Image_alloc(w, h, 3))) {
fprintf(stderr, "%s %s : Abend: no mem\n", __FILE__, __func__);
2022-06-26 11:06:35 +02:00
exit(5);
}
fprintf(stderr, "--> %s %s %s\n", __FILE__, __DATE__, __TIME__);
/* d<>terminer les parametres de la deformation */
xorg = w / 2; yorg = h - 10;
xamp = 1.0; yamp = 1.0;
#if STAT
nb_in = nb_out = 0L;
#endif
/*
* we scan all the destination picture...
*/
for (x=0; x<w; x++)
{
dx = (double)x;
angle = (dx/(double)w * (M_PI/1)) + M_PI;
for (y=0; y<h; y++)
{
dy = (double)y;
x2 = (int)(cos(angle) * (dy*xamp)) + xorg;
y2 = (int)(sin(angle) * (dy*yamp)) + yorg;
if (x2>=0 && y2>=0 && x2<w-1 && y2<h-1)
{
/* Image_plotRGB(image, x2, y2, x*2, 200, y*2); */
(image->Rpix[y])[x] = x2*2;
(image->Gpix[y])[x] = 200;
(image->Bpix[y])[x] = y2*2;
#if STAT
nb_in++;
#endif
}
#if STAT
else
{
nb_out++;
}
#endif
}
}
#if STAT
fprintf(stderr, " %ld in, %ld out\n", nb_in, nb_out);
#endif
Image_cadre_A(image);
if (flgtxt)
{
Image_marque_timestamp(image, "essai anamorphose", NULL, 1);
}
Image_TGA_save(nomtga, image, 0);
Image_DeAllocate(image); free(image);
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/