Compare commits

..

No commits in common. "bcf57f8764e18d6ab7e7a3dcf31cfdd8125fd2f8" and "b8d86da9a0169d6542d8b6f02cb95b5d49277404" have entirely different histories.

7 changed files with 41 additions and 136 deletions

View File

@ -2,7 +2,7 @@
* floatimg.h
*/
#define FIMG_VERSION 62
#define FIMG_VERSION 61
/*
* in memory descriptor
@ -23,9 +23,9 @@ typedef struct {
* fimg file header
*/
typedef struct {
char magic[8];
// char magic[8];
int w, h, t;
} FimgFileHead;
} FimgFhead;
/*
* core module

View File

@ -7,7 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "string.h"
#include "../floatimg.h"
@ -16,8 +16,7 @@ extern int verbosity; /* must be declared around main() */
/* ---------------------------------------------------------------- */
int fimg_fileinfos(char *fname, int *datas)
{
FILE *fp;
FimgFileHead filehead;
FILE *fp;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, datas);
@ -28,43 +27,29 @@ if (NULL==fp) {
perror(fname);
return -1;
}
if (1 != fread(&filehead, sizeof(FimgFileHead), 1, fp)) {
fprintf(stderr, "%s: %s bad read\n", __func__, fname);
if (3 != fread(datas, sizeof(int), 3, fp)) {
fprintf(stderr, "%s: %s short read\n", __func__, fname);
fclose(fp);
return -2;
}
fclose(fp);
#if DEBUG_LEVEL
fprintf(stderr, " magic [%s]\n", filehead.magic);
#endif
if (strncmp(filehead.magic, "FIMG", 4)) {
fprintf(stderr, "'%s' is not a fimg file.\n", fname);
return -3;
}
datas[0] = filehead.w;
datas[1] = filehead.h;
datas[2] = filehead.t;
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_dump_to_file(FloatImg *fimg, char *fname, int notused)
int fimg_dump_to_file(FloatImg *head, char *fname, int notused)
{
FILE *fp;
int foo, nbre;
FimgFileHead filehead;
FILE *fp;
int foo, nbre, dims[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, fimg,
fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, head,
fname, notused);
#endif
if (3 != fimg->type) {
fprintf(stderr, "%s : bat type %d\n", __func__, fimg->type);
if (3 != head->type) {
fprintf(stderr, "%s : bat type %d\n", __func__, head->type);
return -8;
}
@ -74,23 +59,22 @@ if (NULL==fp) {
return -1;
}
strcpy(filehead.magic, "FIMG");
filehead.w = fimg->width; filehead.h = fimg->height;
filehead.t = fimg->type;
dims[0] = head->width; dims[1] = head->height;
dims[2] = head->type;
foo = fwrite(&filehead, sizeof(FimgFileHead), 1, fp);
if (1 != foo) {
foo = fwrite(dims, sizeof(int), 3, fp);
if (3 != foo) {
perror(fname);
fclose(fp);
return -2;
}
nbre = fimg->width*fimg->height*3;
nbre = head->width*head->height*3;
#if DEBUG_LEVEL
fprintf(stderr, " %s : data at %p\n", __func__, fimg->R);
fprintf(stderr, " %s : data at %p\n", __func__, head->R);
#endif
foo = fwrite(fimg->R, sizeof(float), nbre, fp);
if (nbre != foo) {
foo = fwrite(head->R, sizeof(float), nbre, fp);
if (nbre!=foo) {
perror(fname);
fclose(fp);
return -3;
@ -101,12 +85,10 @@ fclose(fp);
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_create_from_dump(char *fname, FloatImg *head)
{
FILE *fp;
int foo;
FimgFileHead filehead;
FILE *fp;
int foo, dims[3];
#if DEBUG_LEVEL
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
@ -118,24 +100,24 @@ if (NULL==fp) {
exit(1);
}
foo = fread(&filehead, sizeof(FimgFileHead), 1, fp);
if (1 != foo) {
foo = fread(dims, sizeof(int), 3, fp);
if (3 != foo) {
fprintf(stderr, "%s : short read\n", fname);
fclose(fp);
return -1;
}
#if DEBUG_LEVEL
fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__,
filehead.w, filehead.h, filehead.t, fname);
dims[0], dims[1], dims[2], fname);
#endif
foo = fimg_create(head, filehead.w, filehead.h, filehead.t);
foo = fimg_create(head, dims[0], dims[1], dims[2]);
if (foo) {
fprintf(stderr, "%s : create -> %d\n", __func__, foo);
return foo;
}
foo = fread(head->R, sizeof(float), filehead.w*filehead.h*3, fp);
foo = fread(head->R, sizeof(float), dims[0]*dims[1]*3, fp);
fclose(fp);

10
lib/t.c
View File

@ -12,20 +12,16 @@ int main(int argc, char *argv[])
{
int foo;
FloatImg fimg;
int datas[3];
verbosity = 1;
foo = fimg_create(&fimg, 640, 480, 3);
foo = fimg_load_from_pnm("/tmp/00000.ppm", &fimg, 0);
printf("retour du truc ---> %d\n", foo);
printf("retour du truc %d\n", foo);
fimg_printhead(&fimg);
// fimg_save_as_pnm(&fimg, "foo.pnm", 0);
foo = fimg_dump_to_file(&fimg, "foo.fimg", 0);
foo = fimg_fileinfos("foo.fimg", datas);
fimg_save_as_pnm(&fimg, "foo.pnm", 0);
return 0;
}

View File

@ -29,7 +29,7 @@ fimg_describe(&dst, "created fimg from dump");
foo = fimg_load_from_pnm(srcname, &src, 0);
if (foo) fprintf(stderr, "create src fimg from '%s' -> %d\n", dstname, foo);
#if DEBUG_LEVEL
fimg_describe(&src, "created fimg from PNM");
fimg_describe(&qrc, "created fimg from PNM");
#endif
// fprintf(stderr, "src is %dx%d\n", src.width, src.height);

View File

@ -5,85 +5,30 @@
#include "../floatimg.h"
int verbosity;
int g_width, g_height;
/* --------------------------------------------------------------------- */
int testfile(char *path)
{
int foo, numbers[3];
foo = fimg_fileinfos(path, numbers);
if (foo) {
#if DEBUG_LEVEL
fprintf(stderr, "%s -> err %d\n", path, foo);
#endif
return foo;
}
fprintf(stderr, "\t\t%d x %d\n",numbers[0], numbers[1]);
if (3 != numbers[2]) {
fprintf(stderr, "file %s, %d : bad type\n", path, numbers[2]);
return -7;
}
return foo;
}
/* --------------------------------------------------------------------- */
void help(int v)
{
puts("options :");
puts("\t-v\tincrease verbosity");
puts("\t-o\tname of output file");
puts("\t-s\tname of source file");
if (verbosity) { puts(""); fimg_print_version(1); }
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, idx;
int foo;
int opt;
char *output_file = "noname.fimg";
char *source_file = "noname.fimg";
g_width = g_height = 0;
while ((opt = getopt(argc, argv, "ho:s:v")) != -1) {
while ((opt = getopt(argc, argv, "ho:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'o': output_file = optarg; break;
case 's': source_file = optarg; break;
case 'v': verbosity++; break;
}
}
#if DEBUG_LEVEL
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
#endif
foo = testfile(source_file);
fprintf(stderr, "Source %s -> %d\n", source_file, foo);
foo = testfile(output_file);
fprintf(stderr, "Output %s -> %d\n", output_file, foo);
for (idx=optind; idx<argc; idx++) {
fprintf(stderr, "%5d %s\n", idx, argv[idx]);
foo = testfile(argv[idx]);
fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo);
}
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -85,9 +85,7 @@ if (argc == 1) {
}
foo = various_numbers_from_file(argv[optind], 0);
if (foo) {
fprintf(stderr, "got a %d ?\n", foo);
}
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -4,38 +4,22 @@
#include "../floatimg.h"
int verbosity;
/* --------------------------------------------------------------------- */
void help(int lj)
{
fimg_print_version(1);
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
int foo;
int width, height;
char *fname;
FloatImg fimg;
while ((opt = getopt(argc, argv, "ho:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'v': verbosity++; break;
}
}
if (4 != argc) {
fimg_print_version(1);
fprintf(stderr, "Usage:\n\t%s quux.fimg width height\n", argv[0]);
exit(1);
}
fname = argv[optind];
width = atoi(argv[optind+1]); height = atoi(argv[optind+2]);
fname = argv[1];
width = atoi(argv[2]); height = atoi(argv[3]);
fprintf(stderr, "making '%s' %d x %d\n", fname, width, height);
foo = fimg_create(&fimg, width, height, 3);
@ -47,7 +31,7 @@ fimg_clear(&fimg);
foo = fimg_dump_to_file(&fimg, fname, 0);
if (foo) {
fprintf(stderr, "dump fimg -> %d\n", foo);
fprintf(stderr, "dump floatimg -> %d\n", foo);
exit(1);
}