www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/11/15:51:15

From: Antonio Carlos Moreirao de Queiroz <acmq AT coe DOT ufrj DOT br>
Message-Id: <199604111943.QAA03228@alpha.coe.ufrj.br>
Subject: Palette problems in V2
To: djgpp AT delorie DOT com
Date: Thu, 11 Apr 1996 16:43:30 -0300 (EST)

/*
This example demonstrates a possible problem with setrgbpalette()
or setpalette() in bcc2grx, or in the equivalent functions in GRX.
Compile with:
gcc tstpal.c -o tstpal -lbcc2 -lgrx20
Put a small windows 16 colors bitmap file (as arches.bmp) in the current
directory (or set the envirnment variable BMP) and run the program.
Compiled with Borland C, or djgpp V1 (modify the header), it works correctly.
With djgpp V2 (files downloaded from SimTel), the colors are wrong, and
setpalette() appears to not have any effect.

Can someone give me some hint on what is wrong?

Antonio Carlos M. de Queiroz
*/

#ifdef __GNUC__
#include <libbcc.h>
#include <grx20.h>
#include <pc.h>
#else
#include <graphics.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int board,mode,i;
char c;

void drawbitmap(int x,int y, const char *filename)
/* Reads and plots a Windows 16 colors bitmap */
{
  int i,j,k,b,dw,dh;
  FILE *arquivo;
  char path[256];
  char *env;
  short int buf[166];

  typedef struct {unsigned short int w,h;} dimensions;

  env=getenv("BMP"); /* BMP is where the BMP files are */
  if (env) sprintf(path,"%s/%s",env,filename);
  else strcpy(path,filename);
  arquivo=fopen(path,"rb");
  if (arquivo) {
    fread(&buf,2,59,arquivo);
    dw=buf[9]-1;
    dh=buf[11]-1;
    for (i=0; i<=15; i++) {
      k=27+2*i;
      setrgbpalette(i,buf[k+1]>>2,buf[k]>>10,buf[k]>>2);
      setpalette(i,i);
    }
    k=dw+1;
    while ((k % 8)!=0) k++;
    k=k/4;
    for (j=y+dh; j>=y; j--) {
      fread(&buf,2,k,arquivo);
      swab((char*)buf,(char*)buf,k<<1);
      b=12;
      for (i=0; i<=dw; i++) {
	putpixel(x+i,j,(buf[i>>2]>>b)&(unsigned short int)15);
	if (b>0) b-=4; else b=12;
      }
    }
    fclose(arquivo);
  }
}

void main(void)
{
  board=DETECT;
  /* TCBGI is where the .CHR and .BGI files are */
  initgraph(&board,&mode,getenv("TCBGI"));
  /* Shows the first 16 colors */
  for (i=0; i<16; i++) {
    setfillstyle(SOLID_FILL,i);
    bar(250,i*10,319,i*10+9);
  }
  c=getchar();
  /* Plots the bitmap file arches.bmp (from Windows 3.1) */
  drawbitmap(0,0,"arches.bmp");
  c=getchar();
  restorecrtmode();
}

- Raw text -


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