Index: /libpipi/trunk/pipi/pipi.h
===================================================================
--- /libpipi/trunk/pipi/pipi.h	(revision 2705)
+++ /libpipi/trunk/pipi/pipi.h	(revision 2706)
@@ -87,4 +87,6 @@
 
 extern pipi_image_t *pipi_mean(pipi_image_t *, pipi_image_t *);
+extern pipi_image_t *pipi_min(pipi_image_t *, pipi_image_t *);
+extern pipi_image_t *pipi_max(pipi_image_t *, pipi_image_t *);
 
 extern pipi_image_t *pipi_convolution(pipi_image_t *, int, int, double[]);
Index: /libpipi/trunk/pipi/context.c
===================================================================
--- /libpipi/trunk/pipi/context.c	(revision 2705)
+++ /libpipi/trunk/pipi/context.c	(revision 2706)
@@ -147,4 +147,34 @@
         ctx->nimages--;
     }
+    else if(!strcmp(cmd, "min"))
+    {
+        pipi_image_t *dst;
+
+        if(ctx->nimages < 2)
+            return -1;
+        dst = pipi_min(ctx->images[ctx->nimages - 2],
+                       ctx->images[ctx->nimages - 1]);
+        if(dst == NULL)
+            return -1;
+        pipi_free(ctx->images[ctx->nimages - 2]);
+        pipi_free(ctx->images[ctx->nimages - 1]);
+        ctx->images[ctx->nimages - 2] = dst;
+        ctx->nimages--;
+    }
+    else if(!strcmp(cmd, "max"))
+    {
+        pipi_image_t *dst;
+
+        if(ctx->nimages < 2)
+            return -1;
+        dst = pipi_max(ctx->images[ctx->nimages - 2],
+                       ctx->images[ctx->nimages - 1]);
+        if(dst == NULL)
+            return -1;
+        pipi_free(ctx->images[ctx->nimages - 2]);
+        pipi_free(ctx->images[ctx->nimages - 1]);
+        ctx->images[ctx->nimages - 2] = dst;
+        ctx->nimages--;
+    }
     else if(!strcmp(cmd, "wrap"))
     {
Index: /libpipi/trunk/pipi/Makefile.am
===================================================================
--- /libpipi/trunk/pipi/Makefile.am	(revision 2705)
+++ /libpipi/trunk/pipi/Makefile.am	(revision 2706)
@@ -41,5 +41,6 @@
 # Submodules
 combine_sources = \
-	combine/mean.c
+	combine/mean.c \
+	combine/minmax.c
 
 filter_sources = \
Index: /libpipi/trunk/pipi/combine/minmax.c
===================================================================
--- /libpipi/trunk/pipi/combine/minmax.c	(revision 2706)
+++ /libpipi/trunk/pipi/combine/minmax.c	(revision 2706)
@@ -0,0 +1,122 @@
+/*
+ *  libpipi       Proper image processing implementation library
+ *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
+ *                All Rights Reserved
+ *
+ *  $Id$
+ *
+ *  This library is free software. It comes without any warranty, to
+ *  the extent permitted by applicable law. You can redistribute it
+ *  and/or modify it under the terms of the Do What The Fuck You Want
+ *  To Public License, Version 2, as published by Sam Hocevar. See
+ *  http://sam.zoy.org/wtfpl/COPYING for more details.
+ */
+
+/*
+ * minmax.c: min and max computation functions
+ */
+
+#include "config.h"
+#include "common.h"
+
+#include "pipi.h"
+#include "pipi_internals.h"
+
+pipi_image_t *pipi_min(pipi_image_t *img1, pipi_image_t *img2)
+{
+    pipi_image_t *dst;
+    pipi_pixels_t *img1p, *img2p, *dstp;
+    float *img1data, *img2data, *dstdata;
+    int x, y, w, h;
+
+    if(img1->w != img2->w || img1->h != img2->h)
+        return NULL;
+
+    w = img1->w;
+    h = img1->h;
+
+    dst = pipi_new(w, h);
+    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
+    dstdata = (float *)dstp->pixels;
+
+    img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
+    img1data = (float *)img1p->pixels;
+    img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
+    img2data = (float *)img2p->pixels;
+
+    for(y = 0; y < h; y++)
+    {
+        for(x = 0; x < w; x++)
+        {
+            float p, q;
+
+            p = img1data[4 * (y * w + x)];
+            q = img2data[4 * (y * w + x)];
+            dstdata[4 * (y * w + x)] = p < q ? p : q;
+
+            p = img1data[4 * (y * w + x) + 1];
+            q = img2data[4 * (y * w + x) + 1];
+            dstdata[4 * (y * w + x) + 1] = p < q ? p : q;
+
+            p = img1data[4 * (y * w + x) + 2];
+            q = img2data[4 * (y * w + x) + 2];
+            dstdata[4 * (y * w + x) + 2] = p < q ? p : q;
+
+            p = img1data[4 * (y * w + x) + 3];
+            q = img2data[4 * (y * w + x) + 3];
+            dstdata[4 * (y * w + x) + 3] = p < q ? p : q;
+        }
+    }
+
+    return dst;
+}
+
+pipi_image_t *pipi_max(pipi_image_t *img1, pipi_image_t *img2)
+{
+    pipi_image_t *dst;
+    pipi_pixels_t *img1p, *img2p, *dstp;
+    float *img1data, *img2data, *dstdata;
+    int x, y, w, h;
+
+    if(img1->w != img2->w || img1->h != img2->h)
+        return NULL;
+
+    w = img1->w;
+    h = img1->h;
+
+    dst = pipi_new(w, h);
+    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
+    dstdata = (float *)dstp->pixels;
+
+    img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
+    img1data = (float *)img1p->pixels;
+    img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
+    img2data = (float *)img2p->pixels;
+
+    for(y = 0; y < h; y++)
+    {
+        for(x = 0; x < w; x++)
+        {
+            float p, q;
+
+            p = img1data[4 * (y * w + x)];
+            q = img2data[4 * (y * w + x)];
+            dstdata[4 * (y * w + x)] = p > q ? p : q;
+
+            p = img1data[4 * (y * w + x) + 1];
+            q = img2data[4 * (y * w + x) + 1];
+            dstdata[4 * (y * w + x) + 1] = p > q ? p : q;
+
+            p = img1data[4 * (y * w + x) + 2];
+            q = img2data[4 * (y * w + x) + 2];
+            dstdata[4 * (y * w + x) + 2] = p > q ? p : q;
+
+            p = img1data[4 * (y * w + x) + 3];
+            q = img2data[4 * (y * w + x) + 3];
+            dstdata[4 * (y * w + x) + 3] = p > q ? p : q;
+        }
+    }
+
+    return dst;
+}
+
Index: /libpipi/trunk/src/pipi.c
===================================================================
--- /libpipi/trunk/src/pipi.c	(revision 2705)
+++ /libpipi/trunk/src/pipi.c	(revision 2706)
@@ -57,4 +57,14 @@
                 return EXIT_FAILURE;
         }
+        else if(!strcmp(argv[0], "--min"))
+        {
+            if(pipi_command(ctx, "min") != 0)
+                return EXIT_FAILURE;
+        }
+        else if(!strcmp(argv[0], "--max"))
+        {
+            if(pipi_command(ctx, "max") != 0)
+                return EXIT_FAILURE;
+        }
         else if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o"))
         {
