FloatImg/Fonderie/crapulator.c

620 lines
13 KiB
C
Raw Normal View History

2020-11-02 11:25:00 +11:00
/*
* crapulator.c
*/
#include <stdio.h>
#include <stdlib.h>
2021-05-20 18:31:28 +11:00
#include <stdint.h>
2020-12-31 00:42:44 +11:00
#include <string.h>
#include <unistd.h>
2020-11-02 11:25:00 +11:00
2021-01-26 03:18:44 +11:00
#include "../floatimg.h"
2020-11-02 11:25:00 +11:00
2021-04-03 04:25:20 +11:00
#include "fifo.h"
2020-11-02 11:25:00 +11:00
#include "crapulator.h"
2020-11-16 21:12:29 +11:00
#include "glitches.h"
2020-12-03 05:55:06 +11:00
#include "sfx.h"
2020-11-02 11:25:00 +11:00
2021-02-23 13:49:24 +11:00
extern int verbosity;
2021-01-12 08:22:03 +11:00
/* -------------------------------------------------------------- */
static int trier_les_pixels(FloatImg *pimg)
{
FloatImg copy;
int foo;
fimg_clone(pimg, &copy, 1);
2021-01-14 02:09:27 +11:00
foo = fimg_qsort_rgb_a(pimg, &copy, 0);
2021-01-12 08:22:03 +11:00
if (foo) {
fprintf(stderr, "%s: err qsort rgb = %d\n", __func__, foo);
return foo;
}
2021-03-29 20:59:24 +11:00
incrustation_vignette(pimg, &copy, 0);
2021-01-12 08:22:03 +11:00
fimg_copy_data(&copy, pimg);
fimg_destroy(&copy);
return 0;
}
2020-11-04 20:41:21 +11:00
/* -------------------------------------------------------------- */
static int effect_3(FloatImg *image)
{
float value;
int foo;
value = fimg_get_maxvalue(image);
fimg_mul_cste(image, -1.0);
fimg_add_cste(image, value);
foo = fimg_count_negativ(image);
if (foo) {
fimg_dump_to_file(image, "err.fimg", 0);
fprintf(stderr, "%s negativ %d\n",
__func__, foo);
return -78;
}
return 0;
}
/* -------------------------------------------------------------- */
static int insitu_ctr2x2(FloatImg *pimg)
{
FloatImg img;
int retval;
fimg_clone(pimg, &img, 0);
retval = fimg_contour_2x2(pimg, &img, 0);
if (retval) {
fprintf(stderr, "%s : err contour %d\n",
__func__, retval);
exit(1);
}
fimg_copy_data(&img, pimg);
fimg_destroy(&img);
return 0;
}
2020-11-02 11:25:00 +11:00
/* -------------------------------------------------------------- */
2020-12-19 20:19:18 +11:00
static int insitu_filtre3x3(FloatImg *pimg, int typef)
2020-12-03 21:47:44 +11:00
{
FloatImg img;
2021-02-23 13:49:24 +11:00
int foo, retval;
2020-12-19 20:19:18 +11:00
FimgFilter3x3 *pfiltre;
2020-12-03 21:47:44 +11:00
2023-07-06 18:02:32 +11:00
static FimgFilter3x3 lowpass = {
2020-12-03 21:47:44 +11:00
{
1.0, 2.0, 1.0,
2.0, 4.0, 2.0,
1.0, 2.0, 1.0,
},
16.0, 0.0
};
2023-07-06 18:02:32 +11:00
static FimgFilter3x3 hipass = {
2021-10-18 03:32:53 +11:00
/* there was a bug with this filter */
2020-12-19 20:19:18 +11:00
{
-1.0, -1.0, -1.0,
-1.0, 9.0, -1.0,
-1.0, -1.0, -1.0,
},
1.0, 0.0
};
2023-07-06 18:02:32 +11:00
static FimgFilter3x3 diagonal = {
2021-10-18 03:32:53 +11:00
/* there was a bug with this filter */
2021-02-23 13:22:14 +11:00
{
2021-10-16 08:21:02 +11:00
4.0, 1.0, 0.0,
2021-02-23 13:22:14 +11:00
1.0, 0.0, -1.0,
2021-10-16 08:21:02 +11:00
0.0, -1.0, -4.0,
2021-02-23 13:22:14 +11:00
},
2021-02-25 21:39:36 +11:00
1.0, 0.0
2021-02-23 13:22:14 +11:00
};
2020-12-19 20:19:18 +11:00
switch (typef) {
case 0: pfiltre = &lowpass; break;
case 1: pfiltre = &hipass; break;
2021-02-23 13:22:14 +11:00
case 2: pfiltre = &diagonal; break;
2020-12-19 20:19:18 +11:00
default:
fprintf(stderr, "%s: bad filter number %d\n",
__func__, typef);
return -6;
break;
}
2020-12-03 21:47:44 +11:00
fimg_clone(pimg, &img, 0);
2020-12-19 20:19:18 +11:00
retval = fimg_filter_3x3(pimg, &img, pfiltre);
2020-12-03 21:47:44 +11:00
if (retval) {
fprintf(stderr, "%s error %d on filter\n", __func__, retval);
exit(1);
}
2021-02-25 21:39:36 +11:00
(void)fimg_killborders(&img); /* nice try ? */
2021-02-24 22:35:31 +11:00
foo = fimg_auto_shift_to_zero(&img, &img);
if (foo) {
fprintf(stderr, "%s: err %d zero shift\n", __func__, foo);
exit(1);
}
2021-02-23 13:49:24 +11:00
/** may be, we can check for negative values ? */
2021-02-24 22:35:31 +11:00
/** or is this useless because whe have shifted to zero ? */
2021-02-23 21:23:59 +11:00
if (verbosity > 1) {
2021-02-23 13:49:24 +11:00
foo = fimg_count_negativ(&img);
2021-02-24 22:35:31 +11:00
if (foo) {
fprintf(stderr, "%s -> %d / %d negative pixels\n", __func__,
foo, img.width*img.height);
}
2021-02-23 13:49:24 +11:00
}
2021-02-23 13:22:14 +11:00
fimg_killborders(&img);
2020-12-03 21:47:44 +11:00
fimg_copy_data(&img, pimg);
fimg_destroy(&img);
return retval;
}
/* -------------------------------------------------------------- */
2021-10-10 18:46:27 +11:00
int run_killrgb_0(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
// fprintf(stderr, "----> %s\n", __func__);
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_killrgb_v(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
// fprintf(stderr, "%s ---->\n", __func__);
2021-10-16 08:21:02 +11:00
return ret;
}
/* -------------------------------------------------------------- */
static int run_pixelize_0(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_pixelize_h_0(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
return ret;
}
/* -------------------------------------------------------------- */
static int run_pixelize_random(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_pixelize_h_rnd(img, &tmp, k);
2023-02-14 03:43:08 +11:00
if (verbosity > 1) fprintf(stderr, "in %s, pixelize H rnd -> %d\n",
__func__, ret);
2021-10-16 08:21:02 +11:00
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
2024-04-02 03:04:40 +11:00
return ret;
}
/* -------------------------------------------------------------- */
/* added Mon Apr 1 15:56:54 UTC 2024 */
static int run_triptyq(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_make_triptyq(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
2021-10-16 08:21:02 +11:00
return ret;
}
/* -------------------------------------------------------------- */
static int run_decomprgbz_color(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_decomp_rgbz_color(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
2022-05-15 05:49:59 +11:00
return ret;
}
/* -------------------------------------------------------------- */
/* nouveau 14 mai 2022 */
static int run_gr2popcol(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
2023-02-12 21:41:26 +11:00
ret = graylevel2popcolors(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
return ret;
}
/* -------------------------------------------------------------- */
/* new Sun Feb 12 11:30:02 CET 2023 */
static int run_rndfluffy(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_make_rndfluffy_lines(img, &tmp, k);
2022-05-15 05:49:59 +11:00
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
2021-10-16 08:21:02 +11:00
return ret;
}
/* -------------------------------------------------------------- */
static int run_decomprgbz_gray(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
2023-07-16 23:14:29 +11:00
/* ugly code here */
2021-10-16 08:21:02 +11:00
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = fimg_decomp_rgbz_gray(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
2021-10-10 18:46:27 +11:00
return ret;
}
/* -------------------------------------------------------------- */
2023-07-16 23:14:29 +11:00
/* new Sun Jul 16 11:27:43 UTC 2023 */
int run_suprbg(FloatImg *img, int notused)
{
FloatImg tmp;
int ret;
if (notused) {
fprintf(stderr, "FATAL: invalid notused in %s\n", __func__);
abort();
}
/* ugly code here */
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = poke_sup_rb_g(img, &tmp);
2024-04-02 03:04:40 +11:00
if (ret) {
fprintf(stderr, "%s: ret = %d\n", __func__, ret);
}
2023-07-16 23:14:29 +11:00
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
2024-04-02 03:04:40 +11:00
return ret;
2023-07-16 23:14:29 +11:00
}
/* -------------------------------------------------------------- */
2020-11-03 10:00:09 +11:00
/*
2020-12-07 22:52:17 +11:00
* This is the main filter engine used both for input and
* output processing. It can be called by the filterstack
* processor.
2020-11-03 10:00:09 +11:00
*/
2020-11-21 08:25:30 +11:00
2021-05-11 19:36:55 +11:00
#define DEBUG_THIS_CRAP 0
2020-11-21 08:25:30 +11:00
2020-11-03 00:51:48 +11:00
int crapulator(FloatImg *image, int idFx, float fval)
2020-11-02 11:25:00 +11:00
{
2020-11-06 07:07:38 +11:00
int retval;
// FloatImg imgtmp;
2020-11-02 11:25:00 +11:00
#if DEBUG_LEVEL
2020-11-03 00:51:48 +11:00
fprintf(stderr, ">>> %s ( %p %d %f )\n", __func__,
image, idFx, fval);
2020-11-02 11:25:00 +11:00
#endif
2020-11-21 08:25:30 +11:00
#if DEBUG_THIS_CRAP
2020-12-03 21:47:44 +11:00
static int count = 0;
int flag_debug = 0;
2021-04-02 13:16:26 +11:00
if (DEBUG_THIS_CRAP==count) {
2020-11-03 00:51:48 +11:00
flag_debug = 1;
2020-11-03 08:20:54 +11:00
fprintf(stderr, "DEBUG PT 1 in %s:%d\n", __func__, __LINE__);
2020-11-03 10:00:09 +11:00
fimg_save_as_png(image, "crap_before.png", 0);
2020-11-03 00:51:48 +11:00
}
2020-11-21 08:25:30 +11:00
#endif
2020-11-03 00:51:48 +11:00
2021-01-09 08:57:45 +11:00
retval = 0;
2020-11-03 00:51:48 +11:00
switch (idFx) {
2020-12-31 00:42:44 +11:00
case CR_none: /* DO NOTHING */
2021-04-02 13:16:26 +11:00
retval = 0;
break;
2020-12-31 00:42:44 +11:00
case CR_cos01:
2020-11-03 00:51:48 +11:00
fimg_cos_01(image, image,
fimg_get_maxvalue(image));
break;
2020-12-31 00:42:44 +11:00
case CR_cos010:
2020-11-03 00:51:48 +11:00
fimg_cos_010(image, image,
fimg_get_maxvalue(image));
break;
2020-12-31 00:42:44 +11:00
case CR_fx3:
2020-11-04 20:41:21 +11:00
retval = effect_3(image);
2020-11-03 00:51:48 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_rnd48a:
2020-11-03 00:51:48 +11:00
brotche_rand48_a(image, 0.20,
fimg_get_maxvalue(image));
break;
2020-12-31 00:42:44 +11:00
case CR_rnd48b:
2020-11-03 00:51:48 +11:00
brotche_rand48_b(image, 0.10,
fimg_get_maxvalue(image)*0.8);
break;
2020-12-31 00:42:44 +11:00
case CR_killcola:
2020-12-07 22:52:17 +11:00
retval = fimg_killcolors_a(image, 0.0);
2020-11-03 00:51:48 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_colmixa:
2020-11-03 00:51:48 +11:00
retval = fimg_colors_mixer_a(image, 2.0);
break;
2020-12-31 00:42:44 +11:00
case CR_ctr2x2:
2020-11-04 20:41:21 +11:00
retval = insitu_ctr2x2(image);
2020-11-03 00:51:48 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_classtrial:
2020-11-03 08:20:54 +11:00
retval = fimg_classif_trial(image, image, 0.37, 0);
2020-11-03 00:51:48 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_binarize:
2021-03-21 15:08:35 +11:00
retval = fimg_binarize(image, 0);
2020-11-06 07:07:38 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_trinarize:
2021-03-26 15:40:45 +11:00
retval = fimg_trinarize(image, 0);
2020-11-10 10:50:25 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_liss2x2:
2020-12-03 05:55:06 +11:00
retval = fimg_lissage_2x2(image);
2021-02-23 13:49:24 +11:00
// (void)fimg_killborders(image);
2020-12-03 05:55:06 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_liss3x3:
2020-12-24 20:28:56 +11:00
/* smooth filter */
2020-12-19 20:19:18 +11:00
retval = insitu_filtre3x3(image, 0);
2020-12-03 21:47:44 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_desaturate:
2020-12-20 23:19:35 +11:00
retval = fimg_desaturate(image, image, 0);
2020-12-07 22:52:17 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_killlines:
2020-12-09 01:51:07 +11:00
retval = kill_a_few_lines(image, fval,
2021-05-05 19:21:47 +11:00
image->height/19);
2020-12-09 01:51:07 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_water:
2021-01-14 02:09:27 +11:00
retval = bouger_les_pixels(image, 12);
2020-12-11 05:19:35 +11:00
break;
2020-12-31 00:42:44 +11:00
case CR_mirsplit:
2020-12-11 05:19:35 +11:00
retval = mirror_split(image, 0);
break;
2020-12-31 00:42:44 +11:00
case CR_updown:
2020-12-18 20:18:09 +11:00
retval = upside_down(image);
break;
2020-12-31 00:42:44 +11:00
case CR_hipass:
2020-12-24 20:28:56 +11:00
/* hipass filter */
2020-12-19 20:19:18 +11:00
retval = insitu_filtre3x3(image, 1);
break;
2021-02-23 13:22:14 +11:00
case CR_diagonal:
retval = insitu_filtre3x3(image, 2);
break;
2020-12-31 00:42:44 +11:00
case CR_octotree:
2020-12-29 22:56:26 +11:00
retval = octotree_classif(image, 0.500, 0);
2020-12-29 10:54:15 +11:00
break;
2021-01-04 01:21:38 +11:00
case CR_trinitron:
retval = trinitron(image, 0);
break;
2020-12-07 22:52:17 +11:00
2021-05-09 06:57:10 +11:00
case CR_sqrt:
retval = fimg_square_root(image, image, 1000.0);
break;
case CR_pow2:
retval = fimg_power_2(image, image, 1000.0);
break;
2021-05-30 08:29:13 +11:00
case CR_triplemul:
retval = fimg_sfx_triplemul(image, image, 0);
break;
2020-12-07 22:52:17 +11:00
/* here are the glitches */
2020-12-31 00:42:44 +11:00
case CR_bsombra: /* experiment ! */
2020-11-25 20:32:02 +11:00
retval = des_bords_sombres_a(image, 160);
2020-11-21 08:25:30 +11:00
break;
2021-05-11 19:36:55 +11:00
case CR_bsombrb: /* experiment ! */
2021-11-27 09:10:29 +11:00
retval = des_bords_sombres_b(image, 120);
2021-05-11 19:36:55 +11:00
break;
2021-10-18 03:32:53 +11:00
2020-12-31 00:42:44 +11:00
case CR_vsglitch:
2020-11-18 21:47:26 +11:00
/* please make this function more tweakable */
2020-12-03 05:55:06 +11:00
retval = vertical_singlitch(image, 290+rand()%45,
2020-12-31 00:42:44 +11:00
fval, 0.19, 0);
2020-11-15 21:47:37 +11:00
break;
2020-12-20 21:12:43 +11:00
2021-06-01 19:26:39 +11:00
case CR_crumphard: /* new june 1st 2021, in the bibcave */
retval = fimg_crump_hard(image, image, fval, 0);
break;
2020-12-31 00:42:44 +11:00
case CR_rndblks:
2020-12-24 02:40:45 +11:00
retval = random_blocks(image, 70);
2020-12-20 21:12:43 +11:00
break;
2020-12-31 10:46:12 +11:00
case CR_shiftln0:
retval = multilines_shift_0(image, 11, 120);
break;
2021-01-11 02:40:49 +11:00
case CR_qsortrgb:
2021-01-12 08:22:03 +11:00
retval = trier_les_pixels(image);
2021-01-11 02:40:49 +11:00
break;
2021-01-16 21:29:40 +11:00
case CR_multidots:
retval = plot_multidots(image, 42);
break;
2021-01-04 01:21:38 +11:00
case CR_nothing:
retval = do_something(image, 3);
break;
2021-10-10 18:46:27 +11:00
case CR_killrgb0:
retval = run_killrgb_0(image, 0);
break;
2021-10-16 08:21:02 +11:00
case CR_pixelizh:
retval = run_pixelize_0(image, 8);
break;
2023-02-14 03:43:08 +11:00
case CR_pixelizv:
retval = run_pixelize_0(image, 32);
break;
2021-10-16 08:21:02 +11:00
case CR_pixelrand:
2023-02-14 03:43:08 +11:00
retval = run_pixelize_random(image, 16);
2021-10-16 08:21:02 +11:00
break;
case CR_splitlevel:
retval = fimg_split_level(image, image, 0);
break;
case CR_decrgbzc:
2023-02-14 03:43:08 +11:00
retval = run_decomprgbz_color(image, 0);
2021-10-16 08:21:02 +11:00
break;
case CR_decrgbzg:
2023-02-14 03:43:08 +11:00
retval = run_decomprgbz_gray(image, 0);
2021-10-16 08:21:02 +11:00
break;
2021-03-21 06:32:25 +11:00
case CR_hilightr:
retval = fimg_highlight_color(image, image, 'R', 1.717);
break;
2022-05-15 05:49:59 +11:00
case CR_gr2popcol:
retval = run_gr2popcol(image, -1);
break;
2023-02-12 21:41:26 +11:00
case CR_fluffy:
retval = run_rndfluffy(image, 75);
break;
2023-07-16 23:14:29 +11:00
case CR_suprbg:
retval = run_suprbg(image, 0);
break;
2024-03-25 01:07:29 +11:00
case CR_thermocol:
/* new Wed Mar 20 19:42:42 UTC 2024 */
retval = fimg_auto_thermique(image, image, 0);
break;
2024-04-02 03:04:40 +11:00
case CR_triptyq:
/* added Mon Apr 1 15:52:32 UTC 2024*/
retval = run_triptyq(image, 0);
break;
2024-04-07 05:25:51 +11:00
case CR_togray:
retval = fimg_to_gray(image);
break;
2024-09-30 04:04:10 +11:00
case CR_shift0:
/* added Sun Sep 29 16:55:54 UTC 2024 */
retval = fimg_auto_shift_to_zero(image, image);
// fprintf(stderr, "******** Shift Zero -> %d\n", retval);
break;
2024-04-07 05:25:51 +11:00
2020-11-03 00:51:48 +11:00
default :
fprintf(stderr, "%s : effect #%d invalid\n",
__func__, idFx);
return -77;
}
2020-11-02 11:25:00 +11:00
2020-11-21 08:25:30 +11:00
#if DEBUG_THIS_CRAP
2020-11-03 00:51:48 +11:00
if (flag_debug) {
2020-11-03 08:20:54 +11:00
fprintf(stderr, "DEBUG PT 2 in %s:%d\n", __func__, __LINE__);
2020-11-03 10:00:09 +11:00
fimg_save_as_png(image, "crap_after.png", 0);
2020-11-21 08:25:30 +11:00
flag_debug = 0;
2020-11-02 11:25:00 +11:00
}
2020-11-21 08:25:30 +11:00
count++;
2020-12-03 21:47:44 +11:00
#endif
2020-11-02 11:25:00 +11:00
2020-11-03 00:51:48 +11:00
return retval;
2020-11-02 11:25:00 +11:00
}
2020-12-19 20:19:18 +11:00
/* -------------------------------------------------------------- */
typedef struct {
int id;
char *name;
int ipar;
float fpar;
int flags;
} Crapulor;
2021-04-02 13:16:26 +11:00
/* Warning: overengeniring inside */
#include "crapstr.h" /* generated file ! */
2020-12-30 02:40:26 +11:00
#define NBCRAP (sizeof(CrapL)/sizeof(Crapulor))
void list_crapulors(char *texte)
{
int idx;
2020-12-31 00:42:44 +11:00
#define OUT stdout
2023-02-12 02:08:25 +11:00
2023-07-16 23:14:29 +11:00
if (verbosity) {
fprintf(stderr, "We have around %ld filters now !\n", NBCRAP);
}
2023-07-17 17:56:23 +11:00
if (NULL!=texte && verbosity)
fprintf(OUT, " _________ %s _________\n", texte);
2020-12-31 00:42:44 +11:00
for (idx=0; CrapL[idx].id!=-1; idx++) {
2023-02-12 02:08:25 +11:00
if (verbosity) {
fprintf(OUT, " %-12s | %4d | %5d | %8.3f\n",
2020-12-30 02:40:26 +11:00
CrapL[idx].name,
2020-12-31 00:42:44 +11:00
CrapL[idx].id,
2020-12-30 02:40:26 +11:00
CrapL[idx].ipar,
CrapL[idx].fpar);
2023-02-12 02:08:25 +11:00
}
else {
fprintf(OUT, "%s\n", CrapL[idx].name);
}
2020-12-30 02:40:26 +11:00
}
2020-12-31 00:42:44 +11:00
#undef OUT
2020-12-30 02:40:26 +11:00
}
2020-11-11 05:30:49 +11:00
/* -------------------------------------------------------------- */
char * crap_name_from_number(int num)
{
2020-12-31 00:42:44 +11:00
int idx;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %d )\n", __func__, num);
#endif
for (idx=0; CrapL[idx].id!=-1; idx++) {
if (num == CrapL[idx].id) {
return CrapL[idx].name;
}
2020-12-16 03:49:12 +11:00
}
2020-11-02 11:25:00 +11:00
2020-11-11 05:30:49 +11:00
return "???";
}
/* -------------------------------------------------------------- */
int crap_number_from_name(char *name)
{
2020-12-31 10:46:12 +11:00
int idx, retval;
2020-12-31 00:42:44 +11:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
#endif
retval = -1; /* not found */
for (idx=0; CrapL[idx].id!=-1; idx++) {
2020-12-31 10:46:12 +11:00
if (0 == strcmp(CrapL[idx].name, name)) {
2020-12-31 00:42:44 +11:00
// fprintf(stderr, "found '%s' -> %d\n", name,
// CrapL[idx].id);
retval = CrapL[idx].id;
break;
}
}
2020-11-11 05:30:49 +11:00
2020-12-31 00:42:44 +11:00
return retval; /* not found */
2020-11-11 05:30:49 +11:00
}
2020-11-02 11:25:00 +11:00
/* -------------------------------------------------------------- */