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

Last change on this file since 2756 was 2756, checked in by Sam Hocevar, 12 years ago
  • Add a new image flag, u8, which indicates whether the image samples come from an 8-bpp source.
File size: 1.7 KB
Line 
1/*
2 *  libpipi       Proper image processing implementation 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#include "common.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "pipi.h"
27#include "pipi_internals.h"
28
29/*
30static int init = 0;
31
32void _pipi_init(void)
33{
34    if(init)
35        return;
36
37    _pipi_init_pixels();
38}
39*/
40
41pipi_image_t *pipi_new(int w, int h)
42{
43    pipi_image_t *img;
44
45    img = malloc(sizeof(pipi_image_t));
46    memset(img, 0, sizeof(pipi_image_t));
47
48    img->w = w;
49    img->h = h;
50    img->last_modified = PIPI_PIXELS_UNINITIALISED;
51    img->codec_format = PIPI_PIXELS_UNINITIALISED;
52
53    img->wrap = 0;
54    img->u8 = 1;
55
56    return img;
57}
58
59pipi_image_t *pipi_copy(pipi_image_t *src)
60{
61    pipi_image_t *dst = pipi_new(src->w, src->h);
62
63    /* Copy properties */
64    dst->wrap = src->wrap;
65    dst->u8 = src->u8;
66
67    /* Copy pixels, if any */
68    if(src->last_modified != PIPI_PIXELS_UNINITIALISED)
69    {
70        pipi_pixels_t *srcp, *dstp;
71
72        srcp = &src->p[src->last_modified];
73        dstp = &dst->p[src->last_modified];
74
75        memcpy(dstp, srcp, sizeof(pipi_pixels_t));
76        dstp->pixels = malloc(dstp->bytes);
77        memcpy(dstp->pixels, srcp->pixels, dstp->bytes);
78
79        dst->last_modified = src->last_modified;
80    }
81
82    return dst;
83}
84
Note: See TracBrowser for help on using the repository browser.