]> git.plutz.net Git - stereofy/blobdiff - anaglyph.c
cleaned up fprintf function, fixing last compiler warning, enabled hard optimization...
[stereofy] / anaglyph.c
index 4aa84ff4de74cc00dfc62169171ede864f41c7a0..b0be61c53b1bc66bcda7ea27a3a18dc9a134383a 100644 (file)
@@ -1,3 +1,19 @@
+// Copyright 2011 Paul Hänsch
+// This file is part of Stereofy
+//
+// Stereofy is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Stereofy 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Stereofy.  If not, see <http://www.gnu.org/licenses/>.
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -35,13 +51,13 @@ int main(int argc, char *argv[]){
 int error(int code){
   char *msg = "Unknown Error\n";
   switch (code) {
-    case 1: msg = "Usage: anaglyph [ -[fhd]gm | -[fhd]rc | -fmc | -dab ] left.rgb right.rgb output.rgb\n";
-    case 2: msg = "Could not open input file for reading\n";
-    case 3: msg = "Could not open output file for writing\n";
-    case 4: msg = "Unexpected end of file\n";
-    case 5: msg = "Cannot write to output file\n";
+    case 1: msg = "Usage: anaglyph [ -[fhd]gm | -[fhd]rc | -fmc | -dab ] left.rgb right.rgb output.rgb\n"; break;
+    case 2: msg = "Could not open input file for reading\n"; break;
+    case 3: msg = "Could not open output file for writing\n"; break;
+    case 4: msg = "Unexpected end of file\n"; break;
+    case 5: msg = "Cannot write to output file\n"; break;
   }
-  fprintf(stderr, msg); return code;
+  fprintf(stderr, "%s", msg); return code;
 }
 
 // min-max to prevent overflowing in Dubois calculations
@@ -100,11 +116,11 @@ unsigned char* half_rc(unsigned char *out, const unsigned char *l, const unsigne
 
 //red-cyan Dubois
 unsigned char* dubois_rc(unsigned char *out, const unsigned char *l, const unsigned char *r){
-  out[0] = (unsigned char)mm((456*(int)l[0] +  500*(int)l[1] + 176*(int)l[2] +
+  out[0] = (unsigned char) mm((456*(int)l[0] +  500*(int)l[1] + 176*(int)l[2] +
         -43*(int)r[0] + -88*(int)r[1] +   -2*(int)r[2]) / 1000, 0, 255);
-  out[1] = (unsigned char)mm((-40*(int)l[0] +  -38*(int)l[1] + -16*(int)l[2] +
+  out[1] = (unsigned char) mm((-40*(int)l[0] +  -38*(int)l[1] + -16*(int)l[2] +
         378*(int)r[0] + 734*(int)r[1] +  -18*(int)r[2]) / 1000, 0, 255);
-  out[2] = (unsigned char)mm((-15*(int)l[0] +  -21*(int)l[1] +  -5*(int)l[2] +
+  out[2] = (unsigned char) mm((-15*(int)l[0] +  -21*(int)l[1] +  -5*(int)l[2] +
        -72*(int)r[0] +-113*(int)r[1] + 1226*(int)r[2]) / 1000, 0, 255);
   return out;
 }
@@ -117,19 +133,14 @@ unsigned char* full_mc(unsigned char *out, const unsigned char *l, const unsigne
   return out;
 }
 
-//magenta-cyan "Dubois"
-unsigned char* dubois_mc(unsigned char *out, const unsigned char *l, const unsigned char *r){
-  out[0] = (unsigned char)mm((529*(int)l[0] + 705*(int)l[1] + 24*(int)l[2] +
-        -62*(int)r[0] +-158*(int)r[1] +  -39*(int)r[2]) / 1000, 0, 255);
-  out[1] = (unsigned char)mm((-40*(int)l[0] +  -38*(int)l[1] + -16*(int)l[2] +
-        378*(int)r[0] + 734*(int)r[1] +  -18*(int)r[2]) / 1000, 0, 255);
-  out[2] = (unsigned char)mm((-15*(int)l[0] +  -24*(int)l[1] +   8*(int)l[2] +
-       -32*(int)r[0] + -19*(int)r[1] + 1081*(int)r[2]) / 1000, 0, 255);
-
-//  out[2] = (unsigned char)mm((-15*(int)l[0] +  -27*(int)l[1] +  21*(int)l[2] + gm
-//       9*(int)r[0] +  75*(int)r[1] +  937*(int)r[2]) / 1000, 0, 255);
-//  out[2] = (unsigned char)mm((-15*(int)l[0] +  -21*(int)l[1] +  -5*(int)l[2] + rc
-//     -72*(int)r[0] +-113*(int)r[1] + 1226*(int)r[2]) / 1000, 0, 255);
+//magenta-cyan experimental
+unsigned char* experimental_mc(unsigned char *out, const unsigned char *l, const unsigned char *r){
+  out[0] = (unsigned char) mm((556*(int)l[0] +  400*(int)l[1] + 176*(int)l[2] +
+        -43*(int)r[0] + -88*(int)r[1] +   -2*(int)r[2]) / 950, 0, 255);
+  out[1] = (unsigned char) mm((-40*(int)l[0] +  -38*(int)l[1] + -16*(int)l[2] +
+        278*(int)r[0] + 734*(int)r[1] +  -18*(int)r[2]) / 1100, 0, 255);
+  out[2] = (unsigned char) mm((-15*(int)l[0] +  -21*(int)l[1] + 600*(int)l[2] +
+       -72*(int)r[0] +-113*(int)r[1] + 621*(int)r[2]) / 950, 0, 255);
   return out;
 }
 
@@ -154,8 +165,8 @@ unsigned char* (*parse_func(const char *arg))(unsigned char*, const unsigned cha
   if (!strcmp(arg, "-drc")) return &dubois_rc;
 
   if (!strcmp(arg, "-fmc")) return &full_mc;
-  if (!strcmp(arg, "-dmc")) return &dubois_mc;
   if (!strcmp(arg, "-dab")) return &dubois_ab;
+  if (!strcmp(arg, "-emc")) return &experimental_mc;
   exit(error(1)); return &dubois_rc;
 }