cosmetic
This commit is contained in:
parent
24b3d4de11
commit
5418e01820
110
Lib/image.c
110
Lib/image.c
@ -93,8 +93,7 @@ return 0;
|
||||
* on the structure who describe the image.
|
||||
* - - - > don't "free" this pointer, please.
|
||||
*/
|
||||
Image_Desc *
|
||||
Image_alloc(int width, int height, int type)
|
||||
Image_Desc * Image_alloc(int width, int height, int type)
|
||||
{
|
||||
Image_Desc *header;
|
||||
int foo;
|
||||
@ -192,19 +191,18 @@ return header;
|
||||
/*
|
||||
This fonction build another image from a model.
|
||||
*/
|
||||
Image_Desc *
|
||||
Image_clone (Image_Desc *src, int copy)
|
||||
Image_Desc * Image_clone (Image_Desc *src, int copy)
|
||||
{
|
||||
Image_Desc *image;
|
||||
|
||||
if ( src==NULL )
|
||||
if ( NULL == src )
|
||||
{
|
||||
fprintf(stderr, "Image_clone: source descriptor is NULL\n");
|
||||
exit(5);
|
||||
}
|
||||
|
||||
image = Image_alloc(src->width, src->height, src->type);
|
||||
if ( image==NULL )
|
||||
if ( NULL == image )
|
||||
{
|
||||
fprintf(stderr, "Image_clone: cloned descriptor is NULL\n");
|
||||
exit(5);
|
||||
@ -246,20 +244,16 @@ return FUNC_IS_ALPHA;
|
||||
* Helas, cette fonction ne marche que sur les images RGB
|
||||
* et comment la rendre compatible tout-types sans tout casser ?
|
||||
*/
|
||||
int
|
||||
Image_clear( Image_Desc *image, int r, int g, int b )
|
||||
int Image_clear( Image_Desc *image, int r, int g, int b )
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if (image->type == IMAGE_RGB)
|
||||
{
|
||||
for (y=0; y<image->height; y++)
|
||||
{
|
||||
if (image->type == IMAGE_RGB) {
|
||||
for (y=0; y<image->height; y++) {
|
||||
/*
|
||||
* XXX here we can go faster with a few memset
|
||||
*/
|
||||
for (x=0; x<image->width; x++)
|
||||
{
|
||||
for (x=0; x<image->width; x++) {
|
||||
(image->Rpix[y])[x] = r;
|
||||
(image->Gpix[y])[x] = g;
|
||||
(image->Bpix[y])[x] = b;
|
||||
@ -269,12 +263,9 @@ if (image->type == IMAGE_RGB)
|
||||
return 0; /* ok, this 'return' here is a "spleyterie" :) */
|
||||
}
|
||||
|
||||
if (image->type == IMAGE_RGBA)
|
||||
{
|
||||
for (y=0; y<image->height; y++)
|
||||
{
|
||||
for (x=0; x<image->width; x++)
|
||||
{
|
||||
if (image->type == IMAGE_RGBA) {
|
||||
for (y=0; y<image->height; y++) {
|
||||
for (x=0; x<image->width; x++) {
|
||||
(image->Rpix[y])[x] = r;
|
||||
(image->Gpix[y])[x] = g;
|
||||
(image->Bpix[y])[x] = b;
|
||||
@ -309,6 +300,7 @@ if (IMAGE_RGB != img->type) {
|
||||
|
||||
for (y=0; y<img->height; y++) {
|
||||
for (x=0; x<img->width; x++) {
|
||||
/* please, use memset here */
|
||||
(img->Rpix[y])[x] = rgba->r;
|
||||
(img->Gpix[y])[x] = rgba->g;
|
||||
(img->Bpix[y])[x] = rgba->b;
|
||||
@ -321,8 +313,7 @@ return FUNC_IS_BETA;
|
||||
* every image in memory have a comment field, who is writen
|
||||
* in TGA and PNM file when image is saved.
|
||||
*/
|
||||
int
|
||||
Image_set_comment(Image_Desc *image, char *text)
|
||||
int Image_set_comment(Image_Desc *image, char *text)
|
||||
{
|
||||
if (strlen(text) > IMG_OBJCOMMENT_LEN)
|
||||
return STRING_TOO_LONG;
|
||||
@ -331,8 +322,7 @@ return OLL_KORRECT;
|
||||
}
|
||||
/* 10 nov 2001: no #define for this not-so-magic 254 value ? */
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_plot_gray(Image_Desc *img, int x, int y, int v)
|
||||
int Image_plot_gray(Image_Desc *img, int x, int y, int v)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
{
|
||||
@ -352,8 +342,7 @@ int Image_plotRGB(Image_Desc *img, int x, int y, int r, int g, int b)
|
||||
fprintf(stderr, "PLOTRGB %d %d\n", x, y);
|
||||
#endif
|
||||
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
fprintf(stderr, "Errplot RGB X=%d, Y=%d %d, %d, %d\n", x, y, r, g, b);
|
||||
#if FORCE_ABORT
|
||||
abort();
|
||||
@ -368,8 +357,7 @@ return OLL_KORRECT;
|
||||
|
||||
int Image_plotRGBA(Image_Desc *img, int x, int y, int r, int g, int b, int a)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
/* may be an #if DEBUG_LEVEL here ? */
|
||||
fprintf(stderr, "Errplot RGBA X %4d Y %4d %d, %d, %d, %d\n",
|
||||
x, y, r, g, b, a);
|
||||
@ -387,11 +375,9 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_getRGB(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
int Image_getRGB(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
/* may be an #if DEBUG_LEVEL here ? */
|
||||
fprintf(stderr, "ERR GETRGB X %4d Y %4d\n", x, y);
|
||||
#if FORCE_ABORT
|
||||
@ -407,11 +393,9 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
return OLL_KORRECT;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
int
|
||||
Image_getRGBA(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb, int *pa)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
int Image_getRGBA(Image_Desc *img, int x, int y, int *pr, int *pg, int *pb, int *pa)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
fprintf(stderr, "ERR GETRGBA X %4d Y %4d\n", x, y);
|
||||
#if FORCE_ABORT
|
||||
abort();
|
||||
@ -419,10 +403,9 @@ if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
return OUT_OF_IMAGE;
|
||||
}
|
||||
|
||||
if (img->type != IMAGE_RGBA)
|
||||
{
|
||||
fprintf(stderr, "Image get RGBA: bad image type: %d, %s\n",
|
||||
img->type, Image_type2str(img->type));
|
||||
if (img->type != IMAGE_RGBA) {
|
||||
fprintf(stderr, "%s: bad image type: %d, %s\n",
|
||||
__func__, img->type, Image_type2str(img->type));
|
||||
#if FORCE_ABORT
|
||||
abort();
|
||||
#endif
|
||||
@ -443,16 +426,14 @@ return OLL_KORRECT;
|
||||
*/
|
||||
int Image_plot_channel(Image_Desc *img, char channel, int x, int y, int value)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "ERR PLOTCHANNEL X %4d Y %4d\n", x, y);
|
||||
#endif
|
||||
return OUT_OF_IMAGE;
|
||||
}
|
||||
|
||||
switch (channel)
|
||||
{
|
||||
switch (channel) {
|
||||
case 'r': case 'R': (img->Rpix[y])[x] = (uint8_t)(value&0xff); break;
|
||||
case 'g': case 'G': (img->Gpix[y])[x] = (uint8_t)(value&0xff); break;
|
||||
case 'b': case 'B': (img->Bpix[y])[x] = (uint8_t)(value&0xff); break;
|
||||
@ -466,44 +447,36 @@ return OLL_KORRECT;
|
||||
/*
|
||||
lecture d'une des composantes de l'image.
|
||||
*/
|
||||
int
|
||||
Image_R_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
int Image_R_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
fprintf(stderr, "ERR READ R PIX X%d Y%d\n", x, y);
|
||||
return OUT_OF_IMAGE;
|
||||
}
|
||||
return (int)((img->Rpix[y])[x]);
|
||||
}
|
||||
|
||||
int
|
||||
Image_G_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
int Image_G_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
fprintf(stderr, "ERR READ G PIX X%d Y%d\n", x, y);
|
||||
return OUT_OF_IMAGE;
|
||||
}
|
||||
return (int)((img->Gpix[y])[x]);
|
||||
}
|
||||
|
||||
int
|
||||
Image_B_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
int Image_B_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
fprintf(stderr, "ERR READ B PIX X%d Y%d\n", x, y);
|
||||
return OUT_OF_IMAGE;
|
||||
}
|
||||
return (int)((img->Bpix[y])[x]);
|
||||
}
|
||||
|
||||
int
|
||||
Image_A_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height )
|
||||
int Image_A_pixel(Image_Desc *img, int x, int y)
|
||||
{
|
||||
if ( x<0 || y<0 || x>=img->width || y>=img->height ) {
|
||||
fprintf(stderr, "ERR A PIX X%d Y%d\n", x, y);
|
||||
return OUT_OF_IMAGE;
|
||||
}
|
||||
@ -545,7 +518,7 @@ return 0;
|
||||
}
|
||||
/*::------------------------------------------------------------------::*/
|
||||
/*
|
||||
* no boundary control ?
|
||||
* no boundary control ? XXX
|
||||
*/
|
||||
int Image_pixel_copy(Image_Desc *s, int x, int y, Image_Desc *d, int i, int j)
|
||||
{
|
||||
@ -563,18 +536,16 @@ return OLL_KORRECT;
|
||||
*/
|
||||
int Image_compare_desc(Image_Desc *a, Image_Desc *b)
|
||||
{
|
||||
char *fmt = "Image at %p have no 'Dead Beef' in it\n";
|
||||
char *fmt = "%s: Image at %p have no 'Dead Beef' in it\n";
|
||||
|
||||
if ( (a==NULL) || (b==NULL) ) return NULL_DESCRIPTOR;
|
||||
|
||||
if ( a->magic != MAGIC_OF_IMAGE )
|
||||
{
|
||||
fprintf(stderr, fmt, a);
|
||||
if ( a->magic != MAGIC_OF_IMAGE ) {
|
||||
fprintf(stderr, fmt, __func__, a);
|
||||
return NOT_AN_IMAGE_DESC;
|
||||
}
|
||||
if ( b->magic != MAGIC_OF_IMAGE )
|
||||
{
|
||||
fprintf(stderr, fmt, a);
|
||||
if ( b->magic != MAGIC_OF_IMAGE ) {
|
||||
fprintf(stderr, fmt, __func__, a);
|
||||
return NOT_AN_IMAGE_DESC;
|
||||
}
|
||||
|
||||
@ -592,8 +563,7 @@ return OLL_KORRECT;
|
||||
c'est qu'il reste un pointeur fou chez
|
||||
l'appelant ...
|
||||
*/
|
||||
int
|
||||
Image_DeAllocate(Image_Desc *im)
|
||||
int Image_DeAllocate(Image_Desc *im)
|
||||
{
|
||||
int line;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user