Index: palcat.c
===================================================================
--- palcat.c	(revision 238)
+++ palcat.c	(working copy)
@@ -42,15 +42,17 @@
 
 
 static char* outname = NULL;
+static char* inname = NULL;
 
 
 static scc_param_t scc_parse_params[] = {
   { "o", SCC_PARAM_STR, 0, 0, &outname },
+  { "i", SCC_PARAM_STR, 0, 0, &inname },
   { NULL, 0, 0, 0, NULL }
 };
 
 static void usage(char* prog) {
-  printf("Usage: %s -o merged.bmp inputA.bmp inputB.bmp\n",prog);
+  printf("Usage: %s -o merged.bmp [-i in.bmp] inputA.bmp in.bmp inputB.bmp\n",prog);
   exit(-1);
 }
 
@@ -64,25 +66,67 @@
 
   if(!files || !outname) usage(argv[0]);
 
+  if (inname)
+  {
+    out = scc_img_open(inname);
+    if (!out)
+      inname = NULL;
+  }
 
   for(f = files ; f ; f = f->next) {
-    in = scc_img_open(f->val);
+    if (!inname || strcmp(f->val, inname)) {
+      in = scc_img_open(f->val);
+    } else {
+      // Found input filename, now switch to append mode
+      inname = NULL;
+      continue;
+    }
+
     if(!in) {
-      printf("Failed to open %s.\n",f->val);
+      printf("Failed to open image '%s'.\n",f->val);
+      if (out)
+        scc_img_free(out);
       return 1;
     }
 
     if(!out) {
+      // Assign output to first file specified
       out = in;
       continue;
+    } else if (inname) {
+      uint8_t *ptr, *end;
+
+      // Pre-append bitmap
+      ptr = out->pal;
+      out->pal = malloc((out->ncol+in->ncol)*3);
+      memcpy(out->pal,  in->pal,  in->ncol*3);       // stick new palette at the start
+      memcpy(out->pal+3*in->ncol, ptr, out->ncol*3); // move old palette to the end
+      free(ptr);
+
+      out->ncol += in->ncol;
+
+      // Offset bitmap data in image by input colors (assuming data is 8bit)
+      end = out->data+(out->w*out->h);
+      for (ptr = out->data; ptr != end; ptr++)
+      {
+        *ptr += in->ncol;
+      }
+      
+    } else {
+      // Append bitmap
+      out->pal = realloc(out->pal,(out->ncol+in->ncol)*3);
+      memcpy(out->pal+3*out->ncol,in->pal,in->ncol*3);
+      out->ncol += in->ncol;
     }
-    out->pal = realloc(out->pal,(out->ncol+in->ncol)*3);
-    memcpy(out->pal+3*out->ncol,in->pal,in->ncol*3);
-    out->ncol += in->ncol;
     
     scc_img_free(in);
   }
-  if(!scc_img_save_bmp(out,outname)) return 1;
+
+  if(!scc_img_save_bmp(out,outname)) {
+    scc_img_free(out);
+    return 1;
+  }
   
+  scc_img_free(out);
   return 0;
 }
Index: scc_param.c
===================================================================
--- scc_param.c	(revision 238)
+++ scc_param.c	(working copy)
@@ -163,7 +163,7 @@
   if(!params[i].name) return SCC_PARAM_UNKNOWN;
 
   parser = scc_param_get_parser(params[i].type);
-  if(!params[i].name) return SCC_PARAM_UNKNOWN;
+  if(!parser) return SCC_PARAM_UNKNOWN;
 
   if(!((parser->flags & SCC_PARAM_TYPE_NO_ARG) || v))
     return SCC_PARAM_NEED_ARG;
