cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/16/05:31:38

From: acottrel AT magna DOT com DOT au (Andrew Cottrell)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A TIFF loader for Allegro?
Date: Thu, 16 Apr 1998 08:21:29 GMT
Organization: Magna Data - Internet Solutions Provider
Lines: 169
Message-ID: <3535baa3.1093347@news.magna.com.au>
References: <353573AB DOT 9807063E AT concentric DOT net>
Reply-To: acottrel AT spam DOT magna DOT com DOT au
NNTP-Posting-Host: saccess-08-113.magna.com.au
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I added LIBTIFF support to Allegro 2.2 about a year ago. The LIBTIFF
is available from ftp://ftp.sgi.com/graphics/tiff/. It is relatively
easy load TIFF files, a non working sample is shown below.  

The code was written for a specific TIFF color depth and converted to
another color depth.

Andrew

#include <allegro.h>
#include <tiffio.h>

#define MAX_COLOR 255

typedef struct {
	 BYTE redcap[MAX_COLOR+1];
	 BYTE greencap[MAX_COLOR+1];
	 BYTE bluecap[MAX_COLOR+1];
} PALHeader;

#define RTIF_DEBUG 1
extern PALHeader    PALInfo;
extern BITMAP *the_image;
extern PALLETE the_pallete;

int max_colors_found =0;

int AddColor(BYTE red, BYTE green, BYTE blue)
{
     int loop;
     for(loop=0;loop<MAX_COLOR;loop++)
     {
         if (loop>=max_colors_found)
         {
             PALInfo.redcap[loop]   = red;
             PALInfo.greencap[loop] = green;
             PALInfo.bluecap[loop]  = blue;
             max_colors_found++;
             return(loop);
         }
         else
         {
             if ((PALInfo.redcap[loop]   == red)   &&
                 (PALInfo.greencap[loop] == green) &&
                 (PALInfo.bluecap[loop]  == blue))
             {
                 return(loop);
             }
         }
     }
     return(0);
}

int ReadTIFF(char *File_Name)
{
	TIFF* tif;
	TIFFRGBAImage img;
    char err_msg[1024];
    int stoponerr, width, height, xloop, yloop;
    int red,blue,green, color, cap;
    static  unsigned long * raster = NULL;		/* displayable
image */
    char FileOpen[80];
    uint16 i, bitspersample;


    strcpy(FileOpen,File_Name);
    strupr(FileOpen);

    max_colors_found =1;
    PALInfo.redcap[0]   = 0;
    PALInfo.greencap[0] = 0;
    PALInfo.bluecap[0]  = 0;
    /* read in the bitmap file */
    stoponerr = 1;
    tif = TIFFOpen(FileOpen, "rC");
    if (!TIFFRGBAImageOK(tif, err_msg))
    {
	    TIFFError(FileOpen, err_msg);
        exit(0);
    }
	if (!TIFFRGBAImageBegin(&img, tif, stoponerr, err_msg))
	{
	    TIFFError(FileOpen, err_msg);
        exit(0);
    }
    width = img.width;
    height = img.height;

    if (raster != NULL)
    {
	    _TIFFfree(raster);
	    raster = NULL;
    }
    raster = (uint32*) _TIFFmalloc(width * height * sizeof (uint32));
	if (raster == NULL)
	{
		TIFFError(FileOpen, "No space for raster buffer");
        exit(0);
    }
	/*
	 * Fetch the image.
	 */
	if (!TIFFRGBAImageGet(&img, raster, width, height))
    {
		TIFFError(FileOpen, "Could not get
TIFFRGBAImageGet.");
        exit(0);
    }
	if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample))
    {
		TIFFError(FileOpen, "Could not get
TIFFTAG_BITSPERSAMPLE.");
        exit(0);
    }
	if (bitspersample != 4)
	{
		fprintf(stderr,
		    " %s: Sorry, only handle 4-bit samples.\n",
FileOpen);
        exit(0);
	}
    if (the_image)
    {
        destroy_bitmap(the_image);
        the_image = NULL;
    }
    the_image = create_bitmap(width, height);

/* x% weighting -> fraction of full color */
    for (yloop=0; yloop<height; yloop++)
	{
		unsigned long src = yloop * width;
		for (xloop=0; xloop<width; xloop++)
		{
			unsigned long rgb = raster[src + xloop];
			unsigned char r = TIFFGetR(rgb);
			unsigned char g = TIFFGetG(rgb);
			unsigned char b = TIFFGetB(rgb);

     		the_image->line[height-yloop-1][xloop] =
(BYTE)(AddColor(r, g, b) & 0xFF);
		}
    }

    for (color = 0; color <= maxcolors; color++)
    {
       the_pallete[color].r = PALInfo.redcap[color]   ;
       the_pallete[color].g = PALInfo.greencap[color] ;
       the_pallete[color].b = PALInfo.bluecap[color]  ;
    }

    TIFFRGBAImageEnd(&img);
	if (tif != NULL)
    {
	    TIFFClose(tif);
	    tif = NULL;
    }
	if (raster != NULL)
    {
        _TIFFfree(raster);
	    raster = NULL;
    }
    return TRUE;
}


>  Does anybody know if some one has written a .tif/.tiff loader  that can be used with Allegro's load_bitmap?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019