FloatImg/tools/fimgextract.c

149 lines
3.4 KiB
C
Raw Normal View History

2023-01-21 19:06:36 +11:00
/*
* This thing is just a mess !
* ***************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
2024-09-30 03:46:38 +11:00
#include <string.h>
2023-01-21 19:06:36 +11:00
#include "../floatimg.h"
int verbosity; // nasty global var.
2024-04-08 20:52:42 +11:00
/* --------------------------------------------------------------------- */
2024-09-30 03:46:38 +11:00
/* nouveau - Mon Apr 8 11:52:18 UTC 2024 */
2024-04-08 20:52:42 +11:00
int copy_metadata(FloatImg *src, FloatImg *dst)
{
FimgMetaData *mdsrc, *mddst;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, src, dst);
#endif
mdsrc = &(src->mdatas); mddst = &(dst->mdatas);
2024-09-30 03:46:38 +11:00
if (verbosity) fprintf(stderr, "%s: %p --> %p\n", __func__, mdsrc, mddst);
mdsrc->reserved[1] = 0x55555555;
memcpy(mddst, mdsrc, sizeof(FimgMetaData));
2024-04-08 20:52:42 +11:00
return 0;
}
2023-01-21 19:06:36 +11:00
/* --------------------------------------------------------------------- */
/* nouveau ~ 2 octobre 2022 */
int extractor(char *srcname, char *dstname, FimgArea51 *rect)
{
FloatImg src, dst;
int foo;
2023-07-10 11:26:57 +11:00
#if DEBUG_LEVEL
2023-01-21 19:06:36 +11:00
fprintf(stderr, ">>> %s ( %s %s %p )\n", __func__, srcname, dstname, rect);
2023-07-10 11:26:57 +11:00
#endif
2023-01-21 19:06:36 +11:00
if (verbosity) {
print_rectangle((char *)__func__, rect);
}
foo = fimg_create_from_dump(srcname, &src);
if (foo) {
fprintf(stderr, "%s: load %s from dump --> %d\n", __func__,
srcname, foo);
return foo;
}
foo = fimg_create(&dst, rect->w, rect->h, 3);
if (foo) {
fprintf(stderr, "%s: fimg create dst --> %d\n", __func__, foo);
return foo;
}
/* REAL operation was here ! */
foo = fimg_extractor(&src, &dst, rect);
if (foo) {
fprintf(stderr, "%s: fimg extractor --> %d\n", __func__, foo);
#ifdef MUST_ABORT
abort(); // kill me hardly !
#endif
return foo;
}
2024-09-30 03:46:38 +11:00
2024-04-08 20:52:42 +11:00
/* XXX
* may be we can also copy the metadate from src to dst ?
* with an option on the command line ?
*/
2024-09-30 03:46:38 +11:00
foo = copy_metadata(&src, &dst);
2023-01-21 19:06:36 +11:00
2024-04-08 20:52:42 +11:00
foo = fimg_dumpmd_to_file(&dst, dstname, NULL, 0);
2023-01-21 19:06:36 +11:00
if (foo) {
fprintf(stderr, "%s: dumping datas to '%s' give us a %d\n",
__func__, dstname, foo);
return foo;
}
return 0;
}
/* --------------------------------------------------------------------- */
void help(void)
{
printf("-- Fimg Extractor -- lib v%d -- %s %s\n", FIMG_VERSION,
__DATE__, __TIME__);
puts("usage:\n\tfimgextract [options] source.fimg width,height,xpos,ypos");
puts("options:");
2024-04-08 20:52:42 +11:00
puts("\t-m\t\tcopy metadata bloc");
2023-01-21 19:06:36 +11:00
puts("\t-o out.fimg\tname the output file");
2023-07-08 21:43:00 +11:00
puts("\t-v\t\tmake me a blabla box");
2023-01-21 19:06:36 +11:00
puts("\t-x\t\tenable crashy feature");
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, idx;
int opt;
int experiment = 0;
FimgArea51 area;
char *output_file = "out.fimg";
while ((opt = getopt(argc, argv, "ho:vx")) != -1) {
switch(opt) {
case 'h': help(); break;
2024-09-30 03:46:38 +11:00
case 'm': break;
2023-01-21 19:06:36 +11:00
case 'o': output_file = optarg; break;
case 'v': verbosity++; break;
case 'x': experiment++; break;
2023-05-29 18:06:57 +11:00
default: exit(1);
2023-01-21 19:06:36 +11:00
}
}
2023-07-08 21:43:00 +11:00
if (verbosity) {
fprintf(stderr, "argc = %d optind = %d\n", argc, optind);
for (idx=optind; idx<argc; idx++) {
fprintf(stderr, " %5d %s\n", idx, argv[idx]);
}
2023-01-21 19:06:36 +11:00
}
if (argc==optind) {
2023-10-29 09:47:25 +11:00
fprintf(stderr, "what the fsck ?\n");
2023-01-21 19:06:36 +11:00
exit(0);
}
2023-07-08 21:43:00 +11:00
foo = parse_rectangle(argv[optind+1], &area, 0);
2023-01-21 19:06:36 +11:00
if (4 != foo) {
fprintf(stderr, "%s: parse_rectangle --> %d\n", argv[0], foo);
exit(1);
}
2023-07-08 21:43:00 +11:00
foo = extractor(argv[optind], output_file, &area);
2023-01-21 19:06:36 +11:00
if (foo) {
fprintf(stderr, "%s: extractor --> %d\n", __func__, foo);
exit(1);
}
return 0;
}
/* --------------------------------------------------------------------- */