_bin_pal_mixdiff_path = @_PATH($bin_path, pal_mixdiff)
_bin_pal_unmix_path = @_PATH($bin_path, pal_unmix)
_bin_pal_cgi_path = @_PATH($bin_path, pal-cgi)
+_bin_remap_t_1_path = @_PATH($bin_path, remap_t_1)
_bin_reveal_path = @_PATH($bin_path, reveal)
_bin_reveal_cgi_path = @_PATH($bin_path, reveal-cgi)
+_bin_t-1_cgi_path = @_PATH($bin_path, t-1-cgi)
_conf_path = @_PATH($conf_path, $name\.conf)
CONF_npb = $_bin_npb_cgi_path
CONF_pal = $_bin_pal_cgi_path
CONF_reveal = $_bin_reveal_cgi_path
+CONF_t-1 = $_bin_t-1_cgi_path
MAKE_CONFIGURE = CONFIGURE = $configure
C_PAL_MIX_PATH = @_C_DEFINE_STR(PAL_MIX_PATH, $_bin_pal_mix_path)
C_PAL_MIXDIFF_PATH = @_C_DEFINE_STR(PAL_MIXDIFF_PATH, $_bin_pal_mixdiff_path)
C_PAL_UNMIX_PATH = @_C_DEFINE_STR(PAL_UNMIX_PATH, $_bin_pal_unmix_path)
+C_REMAP_T_1_PATH = @_C_DEFINE_STR(REMAP_T_1_PATH, $_bin_remap_t_1_path)
C_REVEAL_PATH = @_C_DEFINE_STR(REVEAL_PATH, $_bin_reveal_path)
--- /dev/null
+/*
+t-1-cgi.c
+The online interface for remapping t-1
+05.12.2022
+
+Copyright (C) 2022 Balthasar Szczepański
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Requires cgilib (http://www.infodrom.org/projects/cgilib/)
+*/
+
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#include <cgi.h>
+
+#include "online-core.h"
+#include "t1.h"
+
+#define N0 3
+#define N1 85
+
+int remap (
+ char *inpix, char *outpix,
+ char *palette,
+ uint_fast8_t p0, uint_fast8_t p1
+);
+int main (int argc, char *argv[])
+{
+ s_cgi *cgi;
+ char in_tmp[256];
+ char out_tmp[256];
+ char *in_path;
+ char *t;
+ char *palette;
+ char noname[]=" ";
+ uint8_t p0, p1;
+
+ int r=0;
+ int r1=0;
+ int r2=0;
+ int r3=0;
+
+ do {
+ make_tmp_path(in_tmp, 256, 0, "");
+ make_tmp_path(out_tmp, 256, 1, ".png");
+
+ cgi=cgiInit();
+
+ r = get_file(cgi,"inpix2", in_tmp, &in_path);
+ if (r)
+ r = get_file(cgi,"inpix", in_tmp, &in_path);
+ if (r)
+ break;
+
+ t = cgiGetValue(cgi, "p0");
+ if (t != NULL)
+ sscanf(t,"%"SCNuFAST8, &p0);
+ else
+ p0 = N0;
+
+ t = cgiGetValue(cgi, "p1");
+ if (t != NULL)
+ sscanf(t,"%"SCNuFAST8, &p1);
+ else
+ p1 = N1;
+
+ palette = cgiGetValue(cgi, "b64");
+ if (palette==NULL)
+ palette = noname;
+
+ r = remap(
+ in_path, out_tmp,
+ palette,
+ p0, p1
+ );
+ if (r)
+ break;
+
+ r1 = send_file(out_tmp, "image/png", 0);
+ } while (0);
+ if (r)
+ {
+ r1 = send_data(t1, t1_size, "image/png", 500);
+ }
+ r2 = rm(in_tmp);
+ r3 = rm(out_tmp);
+ if (r1)
+ return r1;
+ if (r2)
+ return r2;
+ if (r3)
+ return r3;
+ return 0;
+}
+
+int remap (
+ char *inpix, char *outpix,
+ char *palette,
+ uint_fast8_t p0, uint_fast8_t p1
+)
+{
+ char s_p0[4];
+ char s_p1[4];
+
+ pid_t sub;
+ int r;
+
+ snprintf(s_p0, 4, "%"PRIuFAST8, p0);
+ snprintf(s_p1, 4, "%"PRIuFAST8, p1);
+
+ sub = fork();
+ if (sub == 0)
+ {
+ r = execl(
+ REMAP_T_1_PATH, REMAP_T_1_PATH,
+ inpix, outpix,
+ palette,
+ s_p0, s_p1,
+ (char *) 0
+ );
+ exit(r);
+ }
+ waitpid(sub, &r, 0);
+ return r;
+}