Pārlūkot izejas kodu

* Added bezier files, lolz.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2789 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
jylam pirms 16 gadiem
vecāks
revīzija
6d69dcc7ea
2 mainītis faili ar 106 papildinājumiem un 0 dzēšanām
  1. +47
    -0
      examples/bezier.c
  2. +59
    -0
      pipi/paint/bezier.c

+ 47
- 0
examples/bezier.c Parādīt failu

@@ -0,0 +1,47 @@
#include "config.h"
#include "common.h"

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

#include <pipi.h>

int main(int argc, char *argv[])
{
char *srcname = NULL, *dstname = NULL;
pipi_image_t *img, *newimg;
int ret = 0;
if(argc < 2)
{
fprintf(stderr, "%s: too few arguments\n", argv[0]);
fprintf(stderr, "Usage: %s <src> <dest>\n", argv[0]);
return EXIT_FAILURE;
}

srcname = argv[1];
dstname = argv[2];

img = pipi_load(srcname);

if(!img) {
fprintf(stderr, "Can't open %s for reading\n", srcname);
return -1;
}

newimg = pipi_copy(img);
pipi_free(img);

int w = pipi_get_image_width(newimg);
int h = pipi_get_image_height(newimg);


pipi_draw_bezier4(newimg , 1, 1, w-1, 1, w-1, h-1, 1, h-1 , 0x00FF0000, 20, 1);

pipi_save(newimg, dstname);

pipi_free(newimg);

return ret;
}


+ 59
- 0
pipi/paint/bezier.c Parādīt failu

@@ -0,0 +1,59 @@
/*
* libpipi Proper image processing implementation library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* 2008 Jean-Yves Lamoureux <jylam@lnxscene.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.
*/

/*
* bezier.c: bezier curves rendering functions
*/

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

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

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


int pipi_draw_bezier4(pipi_image_t *img ,
int x1, int y1,
int x2, int y2,
int x3, int y3,
int x4, int y4,
uint32_t c, int n, int aa)
{
if(img->last_modified == PIPI_PIXELS_RGBA_C)
{
float t;
float x= x1, y= y1;
float lx, ly;
for(t=0; t<1; t+=(1.0f/n))
{
float a = t;
float b = 1 - t;

lx = x; ly = y;

x = (x1*(b*b*b)) + 3*x2*(b*b)*a + 3*x4*b*(a*a) + x3*(a*a*a);
y = (y1*(b*b*b)) + 3*y2*(b*b)*a + 3*y4*b*(a*a) + y3*(a*a*a);

pipi_draw_line(img , lx, ly, x, y, c, aa);
}
pipi_draw_line(img , x, y, x3, y3, c, aa);
}

return 0;
}

Notiek ielāde…
Atcelt
Saglabāt