Sfoglia il codice sorgente

* autocontrast.c: simple autocontrast filter; does not work very well.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2680 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 anni fa
parent
commit
b7c2d1f847
3 ha cambiato i file con 112 aggiunte e 0 eliminazioni
  1. +1
    -0
      pipi/Makefile.am
  2. +110
    -0
      pipi/filter/autocontrast.c
  3. +1
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Vedi File

@@ -37,6 +37,7 @@ codec_sources =

# Submodules
filter_sources = \
filter/autocontrast.c \
filter/blur.c \
filter/convolution.c



+ 110
- 0
pipi/filter/autocontrast.c Vedi File

@@ -0,0 +1,110 @@
/*
* 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.
*/

/*
* autocontrast.c: autocontrast functions
* TODO: the current approach is naive; we should use the histogram in order
* to decide how to change the contrast.
*/

#include "config.h"
#include "common.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include "pipi.h"
#include "pipi_internals.h"

pipi_image_t *pipi_autocontrast(pipi_image_t *src)
{
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
float *srcdata, *dstdata;
float min = 1.0, max = 0.0, t;
int x, y, w, h, gray;

w = src->w;
h = src->h;

gray = (src->last_modified == PIPI_PIXELS_Y_F);

srcp = gray ? pipi_getpixels(src, PIPI_PIXELS_Y_F)
: pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
srcdata = (float *)srcp->pixels;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
if(gray)
{
if(srcdata[y * w + x] < min)
min = srcdata[y * w + x];
if(srcdata[y * w + x] > max)
max = srcdata[y * w + x];
}
else
{
if(srcdata[4 * (y * w + x)] < min)
min = srcdata[4 * (y * w + x)];
if(srcdata[4 * (y * w + x)] > max)
max = srcdata[4 * (y * w + x)];
if(srcdata[4 * (y * w + x) + 1] < min)
min = srcdata[4 * (y * w + x) + 1];
if(srcdata[4 * (y * w + x) + 1] > max)
max = srcdata[4 * (y * w + x) + 1];
if(srcdata[4 * (y * w + x) + 2] < min)
min = srcdata[4 * (y * w + x) + 2];
if(srcdata[4 * (y * w + x) + 2] > max)
max = srcdata[4 * (y * w + x) + 2];
}
}
}

if(min >= max)
return pipi_copy(src);

t = 1. / (max - min);

dst = pipi_new(w, h);
dstp = gray ? pipi_getpixels(dst, PIPI_PIXELS_Y_F)
: pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstdata = (float *)dstp->pixels;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
if(gray)
{
dstdata[y * w + x] = (srcdata[y * w + x] - min) * t;
}
else
{
dstdata[4 * (y * w + x)]
= (srcdata[4 * (y * w + x)] - min) * t;
dstdata[4 * (y * w + x) + 1]
= (srcdata[4 * (y * w + x) + 1] - min) * t;
dstdata[4 * (y * w + x) + 2]
= (srcdata[4 * (y * w + x) + 2] - min) * t;
}
}
}

return dst;
}


+ 1
- 0
pipi/pipi.h Vedi File

@@ -81,6 +81,7 @@ extern pipi_image_t *pipi_convolution(pipi_image_t *, int, int, double[]);
extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);
extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *,
float, float, float, float);
extern pipi_image_t *pipi_autocontrast(pipi_image_t *);

extern int pipi_flood_fill(pipi_image_t *,
int, int, float, float, float, float);


Caricamento…
Annulla
Salva