This commit is contained in:
tTh 2024-08-16 13:30:19 +02:00
parent 24b3d4de11
commit 5418e01820

View File

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