On Sun, 6 Feb 2000, Andreas Beck wrote:

> Let's get something done (you all know that I hate the "no action talk only" 
> syndrome):
> 
> 1. Someone please propose an external API for an image loader/writer. At
> best one that already exists with working code attached to it.
> 
> 2. We will then discuss it and improve it until we are satisfied.
> 
> 3. We will the implement it or restructure existing code to work like LibGGI
> dynamically loading loaders/writers as required.
> 
> 4. We add libs for all known/documented file formats, starting from "use
> ppmtools" stubs to have a catchall system from scratch.
> 
> 5. We write a few glue components that take care of colorspace conversion
> and image representation/transfer.
> 
> O.K. - let's go ... task 1. is on schedule ...

attached. The code doesn't compile yet, but it could work...


Christoph Egger
E-Mail: [EMAIL PROTECTED]
/*
   ******************************************************************************

   bitmap overview

   Copyright (C) 1999-2000 Christoph Egger   [[EMAIL PROTECTED]]

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

   ******************************************************************************
 */


#include <stdlib.h>
#include <string.h>
#include <limits.h>


typedef struct bitmap_type_info_t
{
        char *ext;
        int (*load)(void **data, char *filename);
        int (*save)(void **data, char *filename);
} bitmap_type_info_t;


static struct bitmap_type_info_t bitmap_types[] =
{
   { "bmp", load_bmp, save_bmp },
   { "lbm", load_lbm, NULL     },
   { "pcx", load_pcx, save_pcx },
   { "tga", load_tga, save_tga },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     },
   { NULL,  NULL,     NULL     }
};

#define MAX_BITMAP_TYPES   (sizeof(bitmap_types) / sizeof(bitmap_type_info_t))



/* register_bitmap_file_type:
 *  Informs of a new image file type, telling it how to load and
 *  save files of this format (either function may be NULL).
 */
void register_bitmap_file_type(char *ext,
                int (*load)(void **data, char *filename), int (*save)(void **data, 
char *filename))
{
   int i;

   for (i=0; i<MAX_BITMAP_TYPES; i++) {
      if ((!bitmap_types[i].ext) || (strcmp(bitmap_types[i].ext, ext) == 0)) {
         bitmap_types[i].ext = ext;
         bitmap_types[i].load = load;
         bitmap_types[i].save = save;
         return;
      }
   }
}



/* load_bitmap:
 *  Loads a bitmap from disk.
 */
int load_bitmap(void **data, char *filename)
{
   int i;

   for (i=0; i<MAX_BITMAP_TYPES; i++) {
      if ((bitmap_types[i].ext) && 
          (strcmp(bitmap_types[i].ext, get_extension(filename)) == 0)) {
         if (bitmap_types[i].load)
            return bitmap_types[i].load(data, filename);
         else
            return -1;
      }
   }

   return -1;
}



/* save_bitmap:
 *  Writes a bitmap to disk.
 */
int save_bitmap(void **data, char *filename)
{
   int i;

   for (i=0; i<MAX_BITMAP_TYPES; i++) {
      if ((bitmap_types[i].ext) && 
          (strcmp(bitmap_types[i].ext, get_extension(filename)) == 0)) {
         if (bitmap_types[i].save)
            return bitmap_types[i].save(data, filename);
         else
            return -1;
      }
   }

   return -1;
}
/*
   ******************************************************************************

   bitmap overview

   Copyright (C) 1999-2000 Christoph Egger   [[EMAIL PROTECTED]]

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

   ******************************************************************************
 */


#ifndef READBMP_H
#define READBMP_H


__BEGIN_DECLS

/* register_bitmap_file_type:
 *  Informs of a new image file type, telling it how to load and
 *  save files of this format (either function may be NULL).
 */
void register_bitmap_file_type(char *ext, int (*load)(void **data, char *filename),
                int (*save)(void **data, char *filename));

/* load_bitmap:
 *  Loads a bitmap from disk, returns 0 if successful
 */
int load_bitmap(void **data, char *filename);

/* save_bitmap:
 *  Writes a bitmap to disk, returns 0 if successful
 */
int save_bitmap(void **data, char *filename);




/* load_bmp:
 *  Loads both a Windows BMP and a OS/2 BMP file.
 */
int load_bmp(void **data, char *filename);


/* save_bmp:
 *  Writes a bitmap into a BMP file.
 */
int save_bmp(void **data, char *filename);


/* load_tga:
 *  Loads a 256 color or 24 bit uncompressed TGA file.
 */
int load_tga(char **data, char *filename);


/* save_tga:
 *  Writes a bitmap into a TGA file
 */
int save_tga(char **data, char *filename);


/* load_pcx:
 *  Loads a 256 color PCX file.
 */
int load_pcx(char **data, char *filename);


/* save_pcx:
 *  Writes a bitmap into a PCX file.
 */
int save_pcx(void **data, char *filename);


/* load_lbm:
 *  Loads IFF ILBM/PBM files with up to 8 bits per pixel
 */
int load_lbm(void **data, char *filename);

__END_DECLS

#endif                          /* READBMP_H */

Reply via email to