added a new function : fimg_rotate_90, need more tests

This commit is contained in:
tonton Th
2020-03-24 09:31:52 +01:00
parent 394b24bc92
commit e9a61bb96a
6 changed files with 125 additions and 11 deletions

View File

@@ -3,7 +3,7 @@
COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0
DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
fimg-libpnm.o rampes.o sfx0.o geometry.o
fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o
#---------------------------------------------------------------
@@ -33,6 +33,9 @@ filtrage.o: filtrage.c $(DEPS)
geometry.o: geometry.c $(DEPS)
gcc $(COPT) -c $<
rotate.o: rotate.c $(DEPS)
gcc $(COPT) -DDEBUG_LEVEL=1 -c $<
sfx0.o: sfx0.c $(DEPS)
gcc $(COPT) -c $<

65
funcs/rotate.c Normal file
View File

@@ -0,0 +1,65 @@
/*
* FLOATIMG
* rotation matricielle des images
* #coronamaison Mon 23 Mar 2020 11:45:59 AM CET
*/
#include <stdio.h>
#include <string.h>
#include "../floatimg.h"
extern int verbosity;
/* --------------------------------------------------------------------- */
int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused)
{
int foo;
int x, y;
float rgb[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__,
src, dst, notused);
#endif
if (src->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: src type %d not valid\n", __func__,
src->type);
return -6;
}
/* check if dst pic is not allocated */
if ( 0 == (dst->type | dst->width | dst->height) ) {
fprintf(stderr, "in %s, %p is empty\n", __func__, dst);
/* OK allocate a new fpic */
foo = fimg_create(dst, src->height, src->width, src->type);
if (foo) {
fprintf(stderr, "%s: err %d create new pic\n", __func__, foo);
return -887;
}
if (verbosity) fimg_describe(dst, "new pic");
}
/* check if dst and src are conpatibles */
if ( (src->type != dst->type) ||
(src->width != dst->height) || (src->height != dst->width) ) {
fprintf(stderr, "%s: src & dst not compatibles\n", __func__);
return -888;
}
/*
* THIS IS A CRUDE IMPLEMENTATION
*/
for (y=0; y<src->height; y++) {
for (x=0; x<src->width; x++) {
fimg_get_rgb(src, x, y, rgb);
fimg_plot_rgb(dst, y, x, rgb[0], rgb[1], rgb[2]);
}
}
/* we don't have any cleanup to make */
return 0;
}
/* --------------------------------------------------------------------- */

View File

@@ -4,6 +4,7 @@
*/
#include <stdio.h>
#include <string.h>
#include "../floatimg.h"

View File

@@ -12,12 +12,43 @@ int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
int essai_rotate(char *infile)
{
FloatImg src, dst;
int foo;
if (NULL != infile) {
fprintf(stderr, "%s: loading %s\n", __func__, infile);
foo = fimg_create_from_dump(infile, &src);
if (foo) {
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
return foo;
}
}
else {
fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__);
abort();
}
fimg_save_as_png(&src, "test.png", 0);
foo = fimg_rotate_90(&src, &dst, 0);
fprintf(stderr, "rotate 90 -> %d\n", foo);
foo = fimg_save_as_png(&dst, "rotated90.png", 0);
foo = fimg_save_as_pnm(&dst, "rotated90.pnm", 0);
fimg_destroy(&src);
return -1;
}
/* --------------------------------------------------------------------- */
int essai_filtrage_3x3(char *infile)
{
FloatImg src, dst;
int foo, idx;
char buffer[100];
int foo; /// , idx;
// char buffer[100];
FimgFilter3x3 filter_a = {
@@ -54,7 +85,10 @@ else {
fimg_save_as_png(&src, "test.png", 0);
foo = fimg_clone(&src, &dst, 0);
if (foo) {
fprintf(stderr, "%s: err clone %p\n", __func__, &src);
return -44;
}
fimg_filter_3x3(&src, &dst, &filter_a);
foo = fimg_clamp_negativ(&dst);
if (foo) {
@@ -310,9 +344,9 @@ if (foo) {
}
*/
foo = essai_filtrage_3x3(filename);
foo = essai_rotate(filename);
if (foo) {
fprintf(stderr, "Filtre 3x3 ====> %d\n", foo);
fprintf(stderr, "Essai ====> %d\n", foo);
}
fprintf(stderr, "++++++++++++++ end of pid %d\n", getpid());