| 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 | /* |
|---|
| 30 | static int init = 0; |
|---|
| 31 | |
|---|
| 32 | void _pipi_init(void) |
|---|
| 33 | { |
|---|
| 34 | if(init) |
|---|
| 35 | return; |
|---|
| 36 | |
|---|
| 37 | _pipi_init_pixels(); |
|---|
| 38 | } |
|---|
| 39 | */ |
|---|
| 40 | |
|---|
| 41 | pipi_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 | return img; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | pipi_image_t *pipi_copy(pipi_image_t *src) |
|---|
| 57 | { |
|---|
| 58 | pipi_image_t *dst = pipi_new(src->w, src->h); |
|---|
| 59 | |
|---|
| 60 | /* Copy properties */ |
|---|
| 61 | dst->wrap = src->wrap; |
|---|
| 62 | |
|---|
| 63 | /* Copy pixels, if any */ |
|---|
| 64 | if(src->last_modified != PIPI_PIXELS_UNINITIALISED) |
|---|
| 65 | { |
|---|
| 66 | pipi_pixels_t *srcp, *dstp; |
|---|
| 67 | |
|---|
| 68 | srcp = &src->p[src->last_modified]; |
|---|
| 69 | dstp = &dst->p[src->last_modified]; |
|---|
| 70 | |
|---|
| 71 | memcpy(dstp, srcp, sizeof(pipi_pixels_t)); |
|---|
| 72 | dstp->pixels = malloc(dstp->bytes); |
|---|
| 73 | memcpy(dstp->pixels, srcp->pixels, dstp->bytes); |
|---|
| 74 | |
|---|
| 75 | dst->last_modified = src->last_modified; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | return dst; |
|---|
| 79 | } |
|---|
| 80 | |
|---|