Przeglądaj źródła

Implement pipi_rotate(). Currently nearest-neighbour only, supersample if

you need more precision.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3546 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 15 lat temu
rodzic
commit
859e659c5b
4 zmienionych plików z 105 dodań i 1 usunięć
  1. +1
    -0
      pipi/Makefile.am
  2. +3
    -1
      pipi/context.c
  3. +100
    -0
      pipi/filter/rotate.c
  4. +1
    -0
      pipi/pipi.h

+ 1
- 0
pipi/Makefile.am Wyświetl plik

@@ -70,6 +70,7 @@ filter_sources = \
filter/blur.c \
filter/convolution.c \
filter/color.c \
filter/rotate.c \
filter/transform.c \
filter/median.c \
filter/dilate.c \


+ 3
- 1
pipi/context.c Wyświetl plik

@@ -71,6 +71,7 @@ pipi_command_t const *pipi_get_command_list(void)
{ "rotate90", 0 },
{ "rotate180", 0 },
{ "rotate270", 0 },
{ "rotate", 1 },
{ "invert", 0 },
{ "threshold", 1 },
{ "dilate", 0 },
@@ -350,7 +351,7 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
pipi_free(tmp);
}
else if(!strcmp(cmd, "brightness") || !strcmp(cmd, "contrast")
|| !strcmp(cmd, "threshold"))
|| !strcmp(cmd, "threshold") || !strcmp(cmd, "rotate"))
{
pipi_image_t *src, *dst = NULL;
char const *arg;
@@ -368,6 +369,7 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
{
case 'b': dst = pipi_brightness(src, val); break;
case 'c': dst = pipi_contrast(src, val); break;
case 'r': dst = pipi_rotate(src, val); break;
case 't': dst = pipi_threshold(src, val); break;
}
if(dst == NULL)


+ 100
- 0
pipi/filter/rotate.c Wyświetl plik

@@ -0,0 +1,100 @@
/*
* libpipi Pathetic image processing interface 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.
*/

/*
* wave.c: wave and other warping effects
*/

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif

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

pipi_image_t *pipi_rotate(pipi_image_t *src, double a)
{
pipi_image_t *dst;
pipi_pixels_t *srcp, *dstp;
float *srcdata, *dstdata;
double sina, cosa, cx, cy;
int x, y, w, h, i, gray;

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

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

srcp = gray ? pipi_get_pixels(src, PIPI_PIXELS_Y_F32)
: pipi_get_pixels(src, PIPI_PIXELS_RGBA_F32);
srcdata = (float *)srcp->pixels;

dst = pipi_new(w, h);
dstp = gray ? pipi_get_pixels(dst, PIPI_PIXELS_Y_F32)
: pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32);
dstdata = (float *)dstp->pixels;

sina = sin(a * M_PI / 180.0);
cosa = cos(a * M_PI / 180.0);

cx = (double)w / 2.0;
cy = (double)h / 2.0;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
double dx, dy;
int x2, y2;

dx = ((double)x - cx) * cosa - ((double)y - cy) * sina;
dy = ((double)y - cy) * cosa + ((double)x - cx) * sina;

x2 = (int)(cx + dx + 0.5);
y2 = (int)(cy + dy + 0.5);

if(gray)
{
if(x2 < 0 || y2 < 0 || x2 >= w || y2 >= h)
;
else
dstdata[y * w + x] = srcdata[y2 * w + x2];
}
else
{
if(x2 < 0 || y2 < 0 || x2 >= w || y2 >= h)
{
dstdata[4 * (y * w + x) + 3] = 0.0f;
}
else
{
for(i = 0; i < 4; i++)
{
dstdata[4 * (y * w + x) + i]
= srcdata[4 * (y2 * w + x2) + i];
}
}
}
}
}

return dst;
}


+ 1
- 0
pipi/pipi.h Wyświetl plik

@@ -192,6 +192,7 @@ __extern pipi_image_t *pipi_invert(pipi_image_t *);
__extern pipi_image_t *pipi_threshold(pipi_image_t *, double);
__extern pipi_image_t *pipi_hflip(pipi_image_t *);
__extern pipi_image_t *pipi_vflip(pipi_image_t *);
__extern pipi_image_t *pipi_rotate(pipi_image_t *, double);
__extern pipi_image_t *pipi_rotate90(pipi_image_t *);
__extern pipi_image_t *pipi_rotate180(pipi_image_t *);
__extern pipi_image_t *pipi_rotate270(pipi_image_t *);


Ładowanie…
Anuluj
Zapisz