+Copyright (C) 2015, 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 "nf.h"
+
+int nofading (
+ char *inpix, char *outpix,
+ uint_fast32_t border,
+ uint_fast8_t individual_channels,
+ uint_fast8_t enhance_alpha,
+ uint_fast8_t remove_alpha
+);
+
+int main (int argc, char *argv[])
+{
+ s_cgi *cgi;
+ char in_tmp[256];
+ char out_tmp[256];
+ char *in_path;
+ char *t;
+ uint_fast32_t border;
+ uint_fast8_t individual_channels, enhance_alpha, remove_alpha;
+
+ 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,"inpix", in_tmp, &in_path);
+ if (r)
+ break;
+
+ individual_channels = (cgiGetValue(cgi, "c")!=NULL) ? 0 : 1;
+ enhance_alpha = (cgiGetValue(cgi, "a")!=NULL) ? 1 : 0;
+ remove_alpha = (cgiGetValue(cgi, "n")!=NULL) ? 1 : 0;
+
+ t = cgiGetValue(cgi, "f");
+ if (t != NULL)
+ sscanf(t,"%"SCNuFAST32, &border);
+ else
+ border = 0;
+
+ r = nofading(
+ in_path, out_tmp,
+ border,
+ individual_channels, enhance_alpha, remove_alpha
+ );
+ if (r)
+ break;
+ r1 = send_file(out_tmp, "image/png", 0);
+ } while (0);
+ if (r)
+ {
+ r1 = send_data(nf, nf_size, "image/png", 500);
+ }
+ r2 = rm(in_tmp);
+ r3 = rm(out_tmp);
+ if (r)
+ return r;
+ if (r1)
+ return r1;
+ if (r2)
+ return r2;
+ if (r3)
+ return r3;
+ return 0;
+}
+
+int nofading (
+ char *inpix, char *outpix,
+ uint_fast32_t border,
+ uint_fast8_t individual_channels,
+ uint_fast8_t enhance_alpha,
+ uint_fast8_t remove_alpha
+)
+{
+ char s_border[11];
+ pid_t sub;
+ int r;
+
+ snprintf(s_border, 11, "%"PRIuFAST32, border);
+
+ sub = fork();
+ if (sub == 0)
+ {
+ r = execl(
+ NOFADING_PATH, NOFADING_PATH,
+ individual_channels ? "-c" : "-0",
+ enhance_alpha ? "-a" : "-0",
+ remove_alpha ? "-n" : "-0",
+ inpix, outpix,
+ s_border,
+ (char *)0
+ );
+ exit(r);
+ }
+ waitpid(sub, &r, 0);
+ return r;
+}
+
+/*