Hello Jay,
On Thursday 03 January 2002 17:28, Jay Link wrote:
> Guess this answers my question:
> #define MAXCOLORS       256
>
> I wonder if it would still work if you increased that to 16777216? Maybe
> some variables would have to be re-defined, but perhaps it could be done
> (easily).
Maybe it is possible, but I dont think this would be a good idea, because 
BMPs are bitmaps with a palette with indexed colors, and a big array would be 
needed to hold a palette with thousands or millions of colors ?.
Sometime ago (1993) I copied some samples of 24bit-color-BMPs , 
and I remember they were very big, after trying to put them as wallpapers in
Windows 3.1 the machine started to swap to disk heavily, so I have to remove
them as wallpapers, on a 8MB machine at that time  :-)

More recently I converted some routines for handling 8-bit-color BMPs,
unfortunately I lost the Original C code, but I keep the Yabasic source code
which I am attaching to this message, It is just plain Basic so it is easy to 
understand.
(If you want to test the code download the Yabasic
binary for JAPI from: www.japi.de ) 
the routines are in the file bmplib.yab
the file j.yab is a wrapper for making simple calls to JAPI
There are 2 methods for showing the bitmap:
one is pixel by pixel with the routine: DisplayImage() which is slow
the other method is with a specific built-in routine in JAPI that 
displays a block of pixels from arrays r() g() b() which is faster
hope this helps
bye
-Hermang
P.D. After several hours of porting this routines from C, I read from the JAPI
documentation that JAPI had a built-in simple command for displaying BMPs :-(
The original routines were oriented to DOS programming and depended on
writing directly to the frame buffer using BIOS routines so I removed and
rewrote large portions of the routines, maybe I left some variables which are
not used, check carefully when porting to C. 
The file bmplib.yab is a library, but if you use it as the main program then 
it tries to load a sample bitmap as a Demo. (bathsuit.bmp)





#!/usr/local/bin/japiyabasic
docu this library handles graphic files in 256 color BMP format
docu using JAPI functions, last review: March 28, 2001
docu programmed by Hermang Mansilla, [EMAIL PROTECTED]
FileSize=0
HeaderSize=0
ImageOffset=0
ImageWidth=0
ImageHeight=0
BitsPerPixel=8
debug=0
BufferSize=4
If ( peek$("library")="main" ) then
import j
 dim myerror$(1)
 sample$="bathsuit.bmp"
 myfp= OpenBMP(sample$,myerror$())
 ? myerror$(1)
 LoadFileHeader(myfp)
 LoadBitmapHeader(myfp)
 Report()
big=ImageWidth*ImageHeight
dim CBlue(256),CGreen(256),CRed(256)
dim r(big), g(big), b(big)
NumColors = 2 ^ BitsPerPixel
dim Palette(NumColors)
PixelsPerByte = int(8 / BitsPerPixel)
BytesPerRow = int(( ImageWidth - 1 ) / PixelsPerByte) + 1
LongwordsPerRow = int( ( BytesPerRow - 1 ) / 4) + 1
PixelsPerBuffer = PixelsPerByte * BufferSize
MaxWidth = PixelsPerByte * 320
  DisplayWidth = ImageWidth
  DisplayHeight = ImageHeight
dim image(DisplayHeight,DisplayWidth+7)
LoadColorMap(myfp)
? " Loading file : ",sample$,"  ..."
JWindow(ImageWidth+20,ImageHeight+40,"Testing BMP")
LoadImageData(myfp )
? time$
rem SetPalette(NumColors)
mycan=ezCanvas(10,30,ImageWidth,ImageHeight)
rem DisplayImage( image(), ImageWidth, ImageHeight )
j_drawimagesource(mycan,0,0,ImageWidth,ImageHeight,r(),g(),b())
? time$
input "ok" dumb$
j_quit()
EndIf

Sub QGetLong(fp,pos)
local tmp, low_byte, highbyte, retval
tmp=pos-1
seek #fp,tmp
low_byte=peek(fp)
highbyte=peek(fp)
retval=256*highbyte+low_byte
return retval
End Sub


Export Sub OpenBMP(f$,error$())
local ID$, fp, er$
er$="ok"
fp=open(f$,"rb")
ID$=chr$( peek(fp) ) + chr$( peek(fp) )
HeaderSize=QGetLong(fp,15)

if ( ID$<>"BM" or HeaderSize<>40 ) then
er$="Bad Bmp File"
close fp
fi
error$(1)=er$
return fp
End Sub

Export Sub LoadFileHeader(fp)
FileSize=QGetLong(fp,3)
ImageOffset=QGetLong(fp,11)
End Sub

Export Sub LoadBitmapHeader(fp)
ImageWidth =QGetLong(fp,19)
ImageHeight=QGetLong(fp,23)
seek #fp,28
BitsPerPixel=peek(fp)
End Sub

Export Sub LoadColorMap(fp)
rem  loads color values from Windows 3 bitmap header
rem  values start at byte 55 in the file. Four bytes are stored
rem  for each color, three for the blue, green and red values
rem  and one which is not used.

local byte,k
for k=0 to NumColors-1
  seek #fp, 55+4*k-1
  byte=peek(fp)
  CBlue(k)=byte
   seek #fp, 56+4*k-1
   byte=peek(fp)
   CGreen(k)=byte
  seek #fp, 57+4*k-1
  byte=peek(fp)
rem   CRed(k)=int(byte/4)
  CRed(k)=byte
next k
End Sub

Export Sub LoadImageData(FP)
local BasePosition, BytesPerRow, Buffer4$, byte,idx
local PixelBase, LongwordsPerRow,LongwordsToLoad, jxw
dim buffer(4)
  RowsToLoad=DisplayHeight
  NumPixels=PixelsPerBuffer
  BytesPerRow = int( (ImageWidth - 1) / PixelsPerByte + 1)
  LongwordsPerRow =int( (BytesPerRow - 1) / 4 + 1)

rem   Compute LongwordsToLoad since there is no point in
rem   loading more pixels for a row than we can display

  LongwordsToLoad = LongwordsPerRow

if debug=1  ? "row = ";
  FOR j = 0 TO RowsToLoad - 1
jxw=ImageWidth*(RowsToLoad-1-j)
    BasePosition = ImageOffset + 1 + j * LongwordsPerRow * 4
    FOR i = 0 TO LongwordsToLoad - 1
      seek #FP, BasePosition + i * 4-1
	for idx=1 to 4
	  buffer(idx)=peek(FP)
	next idx
      PixelBase = i * NumPixels
      FOR K = 0 TO NumPixels - 1
image(j,PixelBase+K)=buffer(K+1)
r(jxw+PixelBase+K)=CRed(buffer(K+1))
g(jxw+PixelBase+K)=CGreen(buffer(K+1))
b(jxw+PixelBase+K)=CBlue(buffer(K+1))

rem      GetPixel( buffer(), K, image(),j, PixelBase + K )
      NEXT K
    NEXT i
if debug=1  ? j," ";
  NEXT j
  CLOSE FP
?
End Sub : rem sub LoadImageData

Sub GetPixel(Buffer(), PixelNum, i(), idx1,idx2)
local PixelValue
local xBYTE, ByteNum
rem ByteNum=int(PixelNum/PixelsPerByte)+1
rem xBYTE=ASC( mid$(Buffer$, ByteNum,1) )
xBYTE=Buffer(PixelNum+1)
rem if PixelsPerByte=1
rem  PixelValue=xBYTE : REM 256 COLOR BMP
rem IF PixelsPerByte=2 THEN 
REM 16 COLOR BMP
rem  if mod(PixelNum,2)=0 then
rem	PixelValue=int(xBYTE/16)
rem  else
rem	PixelValue=mod(xBYTE,16)
rem  fi
rem ENDIF
i(idx1,idx2)=xBYTE
rem PixelValue
End Sub

Sub SetPalette(NumColors)
local ix, NewColor
for ix=0 to Numcolors-1
NewColor=65536*CBlue(ix)+256*CGreen(ix)+CRed(ix)
Palette(ix)=NewColor
next ix
End Sub

Sub DisplayImage( i(), PixelsPerRow, NumRows )
local y,x, p, r,g,b
for y=0 to NumRows-1
	for x=0 to PixelsPerRow-1
	p=i(NumRows-y-1,x)
	r=CRed(p)
	g=CGreen(p)
	b=CBlue(p)
		j_setcolor(mycan,r,g,b)
		j_drawpixel(mycan,x,y)
	next x
next y
End Sub

Sub Report()
? "FileSize   = " , FileSize
? "HeaderSize = " , HeaderSize
? "ImageOffset= " , ImageOffset
? "ImageWidth = " , ImageWidth
? "ImageHeight= " , ImageHeight
? "BitsPerPixel=" , BitsPerPixel
End Sub

docu abstract interface to Japi , by [EMAIL PROTECTED] , March 20, 2001 

dim ColorNames$(9) , JColor(9)
dim mb$(5), tmp$(8),tmp2$(8), mo$(5,8), l$(8)
dim menus(5), menuitems(5,8), menuobj$(20)
WW=0 : WH=0
debug=0
FlagInit=0
for i=1 to 8
read ColorNames$(i),JColor(i)
rem , JcolorVal(i)
next i


Export Sub InitJapi()
 if( j_start() = J_FALSE ) then
      print "can't connect to JAPI server"
      wait 3
      exit
 endif
FlagInit=1
End Sub

Export Sub JWindow(hwidth,vheigh,title$)
WW=hwidth
WH=vheigh
InitJapi()
frm = j_frame(title$)
j_setsize(frm,hwidth,vheigh)
j_show(frm)
End Sub

Export Sub ezLabel(xpos,ypos,text$)
local jlabel
jlabel=j_label(frm,text$)
j_setpos(jlabel,xpos,ypos)
rem ? jlabel
rem return jlabel
End Sub

Export Sub ezInput(x,y,size)
local tempobj
tempobj=j_textfield(frm,size)
j_setpos(tempobj,x,y)
return tempobj
End Sub

Export Sub ezButton(x,y,xsize,ysize,text$)
local tempobj
tempobj=j_button(frm,text$)
j_setpos(tempobj,x,y)
j_setsize(tempobj,xsize,ysize)
return tempobj
End Sub


Export Sub ezCanvas(posx,posy,width,height)
local canvas
canvas=j_canvas(frm,width,height)
j_setpos(canvas,posx,posy)
return canvas
End Sub


Export Sub ezMenu(s$)
local i,j, t,no
nm=split(s$,tmp$(),"|")
  if debug=1 ? nm, " Menus "
for i=1 to nm
 t=split(tmp$(i),tmp2$(),":")
 mb$(i)=tmp2$(1)
 no=split(tmp2$(2),l$(),",")
  if debug=1 ? "Header ",i," = ",mb$(i)
  for j=1 to no
  mo$(i,j)=l$(j)
  menuitems(i,0)=no
  if debug=1 ? "Opts ",j, " = ", mo$(i,j)
  next j
next i

menubar=j_menubar(frm)
for i=1 to nm
menus(i)=j_menu(menubar,mb$(i))
  for j=1 to menuitems(i,0)
    t=j_menuitem(menus(i),mo$(i,j))
    menuitems(i,j)=t
    menuobj$(t)=mo$(i,j)
  next j
next i
End Sub : rem ezmenu

Export Sub Item(i$)
local foundit
foundit=0
for i=1 to nm
for j=1 to menuitems(i,0)
if i$=mo$(i,j) foundit=menuitems(i,j)
next j
next i
return foundit
End Sub

Export sub ezAlert(title$,m$)
local alert
alert=j_alertbox(frm,title$,m$," OK ")
End Sub

Export sub ezDialog$(title$,path$)
local select$
select$=j_filedialog(frm,title$,path$)
return select$
End Sub


data "Red",2
data "Green",3
data "Blue"  ,4
data "Yellow" ,7
data "White",1
data "Black" ,0
data "Magenta" ,6
data "Orange",8


Reply via email to