]> bicyclesonthemoon.info Git - ott/enhance/blobdiff - nofading-cgi.c
nofading online
[ott/enhance] / nofading-cgi.c
index 2c20885b80599c0e8c4c7a9e245b528736b96111..5b4f065562aa98b2bb895db2527fa040e92d6305 100644 (file)
-// nofadingd.cpp
-// The online interface for the fading enhancement tool
-// 04.03.2015
-// 
-// Copyright (C) 2015  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/)
-// line 146 of cgi.h must be changed from:
-// extern }
-// to:
-// }
-
-by balthasar_s
-    Fri Jun 12, 2015 6:59 am UTC
-     
-    Forum: Individual XKCD Comic Threads
-    Topic: 1190: "Time"
-    Replies: 93408
-    Views: 10895653
+/*
+nofading-cgi.c
+The online interface for the fading enhancement tool
+04.12.2022
 
+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;
+}
+
+/*
 
 
 #include <cgi.h>
@@ -145,4 +249,6 @@ void mustard(int mustard)
                fclose(pix);
        }
        exit(mustard);
-}
\ No newline at end of file
+}
+
+*/
\ No newline at end of file