delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/24/03:06:59

From: ludvig <ludvig AT club-internet DOT fr>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: 16bpp PutPixel
Date: Sun, 24 Aug 1997 04:43:54 +0200
Organization: Grolier Interactive Europe
Lines: 72
Message-ID: <33FF9FEA.260C@club-internet.fr>
References: <19970816190400 DOT PAA15010 AT ladder02 DOT news DOT aol DOT com>
Reply-To: ludvig AT club-internet DOT fr
NNTP-Posting-Host: ppp-104-48.villette.club-internet.fr
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Gingko 69 wrote:
> 
> Hi,
> 
> I'm having trouble getting a putpixel function to work in VESA2 16bpp
> modes. My program uses 24bpp internal rendering, and so I would appreciate
> if someone could post a 24->16bpp converter. Thanks in advance.
> 
> Gingko
Hi Ginko.

I had the problem that I wanted to draw 16bits images but all my drawing
programs could only produce 8 or 24 bits so I wrote a small function
that loads a 24bit BMP and converts it to 16. BTW the code is rather
old(and written for borland C++ v4.52)) so it might be some stupidities
in it, but it works korrectly.

Here it is:

unsigned char far* Sprite::Load24BmpTo16(char *name)
{
const block=999;
int i,j,han,n,xs,ys;
unsigned long size;
unsigned bytes;
unsigned char bus[1024];
unsigned char far *info;
unsigned int r,g,b,ih,il;
if(_dos_open(name,O_RDONLY,&han)!=0)
 return(NULL); // File Not Found
else
 {
  _dos_read(han,bus,54,&bytes);  // Header
  xs=bus[18]+bus[19]*256;
  ys=bus[22]+bus[23]*256;
  size=4+xs*ys*2;
  if((info=(unsigned char far*)farmalloc(size))==NULL) // Dynamic Mem.
Alloc.
	exit(1);  // Not enough memory
  info[0]=bus[18];   // Width & Height for the Bitmap
  info[1]=bus[19];
  info[2]=bus[22];
  info[3]=bus[23];
  _dos_read(han,bus,block,&bytes);
  n=0;
  for(j=0;j<ys;j++)
	for (i=0;i<xs;i++)
	 {
	  b=bus[n]/8;
	  g=bus[n+1]/4;
	  r=bus[n+2]/8;
	  il=r*8+((g/8));
	  ih=(g&7)*32+b;


	  info[5+(xs*2*ys+i*2-1)-((j+1)*xs*2)]=ih;
	  info[5+(xs*2*ys+i*2)-((j+1)*xs*2)]=il;
	  n=n+3;
	  if (n==(block))
		{
		 n=0;
		 if (_dos_read(han,bus,block,&bytes)!=0)
		  {
			_dos_close(han);
			return(NULL);
		  }
		}
	 }
	 _dos_close(han);
	 return(info);
	}
}

- Raw text -


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