From: <mr...@mr...> - 2005-04-12 11:04:18
|
# This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2005/04/12 13:03:30+02:00 mr...@fo... = # image: new() function to create blank image # = # src/image/image.c # 2005/04/12 13:03:30+02:00 mr...@fo... +83 -2 # implement image:new # = # src/image/TC2Module # 2005/04/12 13:03:30+02:00 mr...@fo... +1 -0 # implement image:new # = # interfaces/image.tc2 # 2005/04/12 13:03:30+02:00 mr...@fo... +1 -0 # add new() function # = diff -Nru a/interfaces/image.tc2 b/interfaces/image.tc2 --- a/interfaces/image.tc2 2005-04-12 13:03:48 +02:00 +++ b/interfaces/image.tc2 2005-04-12 13:03:48 +02:00 @@ -1,4 +1,5 @@ symbol "read" image_t *(*%s)(url_t *u, image_params_t *) +symbol "new" image_t *(*%s)(image_params_t *, uint64_t *bg) require "URL" include #include <tctypes.h> diff -Nru a/src/image/TC2Module b/src/image/TC2Module --- a/src/image/TC2Module 2005-04-12 13:03:48 +02:00 +++ b/src/image/TC2Module 2005-04-12 13:03:48 +02:00 @@ -5,5 +5,6 @@ description "Image" sources image.c implement "image" "read" read_img +implement "image" "new" img_new postinit img_init shutdown img_shdn diff -Nru a/src/image/image.c b/src/image/image.c --- a/src/image/image.c 2005-04-12 13:03:48 +02:00 +++ b/src/image/image.c 2005-04-12 13:03:48 +02:00 @@ -1,5 +1,5 @@ /** - Copyright (C) 2004 Michael Ahlberg, M=C3=A5ns Rullg=C3=A5rd + Copyright (C) 2004-2005 Michael Ahlberg, M=C3=A5ns Rullg=C3=A5rd = Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -24,7 +24,7 @@ = #include <stdio.h> #include <string.h> -#include <image.h> +#include <tcalloc.h> #include <image_tc2.h> = #ifdef HAVE_LIBMAGIC @@ -95,4 +95,85 @@ magic_close(file_magic); #endif return 0; +} + +static void +img_free(void *p) +{ + image_t *img =3D p; + free(img->data[0]); +} + +static void +img_fill(u_char *d, int s, uint64_t c, int bpp) +{ + int i, j; + + while(s--){ + for(i =3D 0; i < bpp; i++){ +#if TCENDIAN =3D=3D TCENDIAN_LITTLE + j =3D i; +#else + j =3D bpp - i - 1; +#endif + d[j] =3D (c >> 8 * i) & 0xff; + } + d +=3D bpp; + } +} + +extern image_t * +img_new(image_params_t *pm, uint64_t *bg) +{ + image_t *img; + int planes; + int size; + int bpp; + int i; + + switch(pm->pixel_type & IMAGE_COLOR_TYPEMASK){ + case IMAGE_COLOR_GRAY: + bpp =3D 1; + break; + case IMAGE_COLOR_RGB: + case IMAGE_COLOR_YUV: + bpp =3D 3; + break; + case IMAGE_COLOR_CMYK: + bpp =3D 4; + break; + default: + tc2_print("IMAGE", TC2_PRINT_ERROR, "unknown image format %i\n", + pm->pixel_type); + return NULL; + } + + if(pm->pixel_type & IMAGE_COLOR_ALPHA) + bpp++; + if(pm->pixel_type & IMAGE_COLOR_PLANAR){ + planes =3D bpp; + bpp =3D 1; + } else { + planes =3D 1; + } + + img =3D tcallocdz(sizeof(*img), NULL, img_free); + img->params =3D *pm; + + size =3D 0; + for(i =3D 0; i < planes; i++) + size +=3D pm->width[i] * pm->height[i] * bpp; + img->data[0] =3D malloc(size); + + size =3D 0; + for(i =3D 0; i < planes; i++){ + img->data[i] =3D img->data[0] + size; + size +=3D pm->width[i] * pm->height[i] * bpp; + img_fill(img->data[i], pm->width[i] * pm->height[i], bg[i], bpp); + img->linesize[i] =3D pm->width[i] * bpp; + } + + img->params.pixelsize =3D bpp; + + return img; } |