Pārlūkot izejas kodu

* codec.c: support for stock images in pipi_load().

* stock.c: start working on stock image generation; for instance:
      pipi pipi:bayer64 -o image.png
    will generate a 64x64 Bayer dithering pattern and save it to image.png.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2695 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam pirms 16 gadiem
vecāks
revīzija
3014994c61
4 mainītis faili ar 81 papildinājumiem un 5 dzēšanām
  1. +1
    -0
      pipi/Makefile.am
  2. +8
    -4
      pipi/codec.c
  3. +2
    -1
      pipi/pipi.h
  4. +70
    -0
      pipi/stock.c

+ 1
- 0
pipi/Makefile.am Parādīt failu

@@ -19,6 +19,7 @@ libpipi_la_SOURCES = \
context.c \
pixels.c \
codec.c \
stock.c \
resize.c \
dither.c \
measure.c \


+ 8
- 4
pipi/codec.c Parādīt failu

@@ -16,17 +16,21 @@
* codec.c: image I/O functions
*/

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

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

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

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

pipi_image_t *pipi_load(const char *name)
pipi_image_t *pipi_load(char const *name)
{
if(!strncmp(name, "pipi:", 5))
return pipi_load_stock(name + 5);

#if USE_IMLIB2
return pipi_load_imlib2(name);
#elif USE_OPENCV


+ 2
- 1
pipi/pipi.h Parādīt failu

@@ -71,7 +71,8 @@ extern pipi_context_t *pipi_create_context(void);
extern void pipi_destroy_context(pipi_context_t *);
extern int pipi_command(pipi_context_t *, char const *, ...);

extern pipi_image_t *pipi_load(const char *);
extern pipi_image_t *pipi_load(char const *);
extern pipi_image_t *pipi_load_stock(char const *);
extern pipi_image_t *pipi_new(int, int);
extern pipi_image_t *pipi_copy(pipi_image_t *);
extern void pipi_free(pipi_image_t *);


+ 70
- 0
pipi/stock.c Parādīt failu

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

/*
* stock.c: stock images
*/

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

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

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

pipi_image_t *pipi_load_stock(char const *name)
{
pipi_image_t *ret;
pipi_pixels_t *pix;
float *data;

/* Generate a Bayer dithering pattern. */
if(!strncmp(name, "bayer", 5))
{
int i, j, n = atoi(name + 5);

if(n <= 0 || (n & (n - 1))) /* is n a power of two? */
return NULL;

ret = pipi_new(n, n);
pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F);
data = (float *)pix->pixels;

for(j = 0; j < n; j++)
for(i = 0; i < n; i++)
{
int k, l, x = 0;

for(k = 1, l = n * n / 4; k < n; k *= 2, l /= 4)
{
if((i & k) && (j & k))
x += l;
else if(i & k)
x += 3 * l;
else if(j & k)
x += 2 * l;
}

data[j * n + i] = (double)(x + 1) / (n * n + 1);
}

return ret;
}

return NULL;
}


Notiek ielāde…
Atcelt
Saglabāt