Browse Source

clean the code

master
tth 3 years ago
parent
commit
38eae482ba
  1. 7
      floatimg.h
  2. 37
      lib/fimg-core.c
  3. 6
      lib/t.c

7
floatimg.h

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 62
#define FIMG_VERSION 64
/*
* in memory descriptor
@ -27,6 +27,11 @@ typedef struct { @@ -27,6 +27,11 @@ typedef struct {
int w, h, t;
} FimgFileHead;
#define FIMG_TYPE_GRAY 1
#define FIMG_TYPE_RGB 3
#define FIMG_TYPE_RGBA 4
/*
* core module
*/

37
lib/fimg-core.c

@ -14,14 +14,26 @@ @@ -14,14 +14,26 @@
extern int verbosity; /* must be declared around main() */
/* ---------------------------------------------------------------- */
static int fimg_type_is_valid(int t)
static int fimg_type_is_valid(int type)
{
switch (t) {
case 1: case 3: case 4: return 1;
switch (type) {
case FIMG_TYPE_GRAY:
case FIMG_TYPE_RGB:
case FIMG_TYPE_RGBA: return 1;
}
return 0;
}
/* --------------------------------------------------------------------- */
static char *fimg_str_type(int type)
{
switch (type) {
case FIMG_TYPE_GRAY: return "gray";
case FIMG_TYPE_RGB: return "rgb";
case FIMG_TYPE_RGBA: return "rgba";
}
return "???";
}
/* --------------------------------------------------------------------- */
int fimg_print_version(int k)
{
fprintf(stderr, "*** FloatImg library, alpha v%d (%s, %s)\n",
@ -52,9 +64,11 @@ if( ! fimg_type_is_valid(head->type) ) { @@ -52,9 +64,11 @@ if( ! fimg_type_is_valid(head->type) ) {
return -1;
}
printf(" size %d x %d x %d\n",
head->width, head->height, head->type);
printf(" type %d\n", head->type);
printf(" dims %d x %d\n",
head->width, head->height);
printf(" fval/count %f %d\n", head->fval, head->count);
printf(" pixels@ %p %p %p %p\n",
head->R, head->G, head->B, head->A);
@ -78,7 +92,7 @@ if ( ! fimg_type_is_valid(t) ) { @@ -78,7 +92,7 @@ if ( ! fimg_type_is_valid(t) ) {
memset(fimg, 0, sizeof(FloatImg));
surface = w * h;
size = surface * t * sizeof(float);
size = surface * t * sizeof(float);
#if DEBUG_LEVEL > 1
fprintf(stderr, "surface is %d pixels, need %d bytes\n", surface, size);
#endif
@ -97,11 +111,12 @@ fimg->width = w; fimg->height = h; @@ -97,11 +111,12 @@ fimg->width = w; fimg->height = h;
fimg->type = t;
fimg->R = fptr;
if ( (t==3) || (t==4) ) {
if ( (t==FIMG_TYPE_RGB) || (t==FIMG_TYPE_RGBA) ) {
fimg->G = fptr + surface;
fimg->B = fptr + surface + surface;
}
if ( t==4 ) fimg->A = fptr + (3 * surface);
if ( t==FIMG_TYPE_RGBA ) fimg->A = fptr + (3 * surface);
/* ok this a really WTF fragment of code */
return 0;
}
@ -120,10 +135,12 @@ if (NULL == fimg) { @@ -120,10 +135,12 @@ if (NULL == fimg) {
}
if ( ! fimg_type_is_valid(fimg->type) ) {
fprintf(stderr, "%s : type %d invalid\n", __func__,
fimg->type);
return -2;
}
if (NULL == fimg->R) {
fprintf(stderr, "%s : %p already freeed\n", __func__, fimg);
fprintf(stderr, "%s : %p already freed\n", __func__, fimg);
return -3;
}
free(fimg->R);
@ -147,7 +164,7 @@ if ( ! fimg_type_is_valid(fimg->type) ) { @@ -147,7 +164,7 @@ if ( ! fimg_type_is_valid(fimg->type) ) {
size = fimg->width * fimg->height * fimg->type * sizeof(float);
memset(fimg->R, 0, size);
return -1;
return 0;
}
/* --------------------------------------------------------------------- */

6
lib/t.c

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "string.h"
#include <string.h>
#include "../floatimg.h"
@ -16,9 +16,11 @@ int datas[3]; @@ -16,9 +16,11 @@ int datas[3];
verbosity = 1;
fimg_print_version(0);
foo = fimg_create(&fimg, 640, 480, 3);
printf("retour du truc ---> %d\n", foo);
printf("retour fimg_create ---> %d\n", foo);
fimg_printhead(&fimg);

Loading…
Cancel
Save