source: libpipi/trunk/pipi/pipi.c @ 2902

Last change on this file since 2902 was 2902, checked in by Sam Hocevar, 12 years ago

Support C99 types on Win32 through the same hacks as in libcaca.

File size: 2.0 KB
Line 
1/*
2 *  libpipi       Pathetic image processing interface library
3 *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * pipi.c: core library routines
17 */
18
19#include "config.h"
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "pipi.h"
26#include "pipi_internals.h"
27
28/** \brief Return the \e libpipi version.
29 *
30 *  Return a read-only string with the \e libpipi version information.
31 *
32 *  This function never fails.
33 *
34 *  \return The \e libpipi version information.
35 */
36char const * pipi_get_version(void)
37{
38    return PACKAGE_VERSION;
39}
40
41/*
42static int init = 0;
43
44void _pipi_init(void)
45{
46    if(init)
47        return;
48
49    _pipi_init_pixels();
50}
51*/
52
53pipi_image_t *pipi_new(int w, int h)
54{
55    pipi_image_t *img;
56
57    img = malloc(sizeof(pipi_image_t));
58    memset(img, 0, sizeof(pipi_image_t));
59
60    img->w = w;
61    img->h = h;
62    img->last_modified = PIPI_PIXELS_UNINITIALISED;
63    img->codec_format = PIPI_PIXELS_UNINITIALISED;
64
65    img->wrap = 0;
66    img->u8 = 1;
67
68    return img;
69}
70
71pipi_image_t *pipi_copy(pipi_image_t *src)
72{
73    pipi_image_t *dst = pipi_new(src->w, src->h);
74
75    /* Copy properties */
76    dst->wrap = src->wrap;
77    dst->u8 = src->u8;
78
79    /* Copy pixels, if any */
80    if(src->last_modified != PIPI_PIXELS_UNINITIALISED)
81    {
82        pipi_pixels_t *srcp, *dstp;
83
84        srcp = &src->p[src->last_modified];
85        dstp = &dst->p[src->last_modified];
86
87        memcpy(dstp, srcp, sizeof(pipi_pixels_t));
88        dstp->pixels = malloc(dstp->bytes);
89        memcpy(dstp->pixels, srcp->pixels, dstp->bytes);
90
91        dst->last_modified = src->last_modified;
92    }
93
94    return dst;
95}
96
Note: See TracBrowser for help on using the repository browser.