Bug with BSAVE?

General FreeBASIC programming questions.
badidea
Posts: 2179
Joined: May 24, 2007 22:10
Location: The Netherlands

Bug with BSAVE?

Postby badidea » Feb 19, 2019 22:49

My chm help file (for version 1.0.5) says on BSAVE:

Syntax
Declare Function BSave ( ByRef filename As Const String, ByVal source As Any Ptr, ByVal size As Ulong = 0, ByVal pal As Any Ptr = 0, ByVal bitsperpixel As Long = 0 ) As Long
Usage
result = BSave( filename, source [,[ size ][,[ pal ][, bitsperpixel ]]] )

So if that if want to save a BMP file, 'size' and 'pal' can be left empty while choosing a value for 'bitsperpixel':
bsave ("bla.bmp", img.pFbImg, , , 32)

But this results in:
No matching overloaded function, BSAVE() in 'bsave ("bla.bmp", img.pFbImg, , , 32)'

The following is allowed:
bsave ("bla.bmp", img.pFbImg, , 0, 32)

But shouldn't the first form be ok as well?
badidea
Posts: 2179
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Bug with BSAVE?

Postby badidea » Feb 19, 2019 22:58

Oh, and another one. With 32 for 'bitsperpixel', I would expect that it saves the alpha-channel, but it does not.
I'll makes some test code...

This input image:
https://nr100.home.xs4all.nl/badidea/Berlin_sans32.bmp
This code:

Code: Select all

const as integer SCREEN_W = 800
const as integer SCREEN_H = 600

#include once "fbgfx.bi"
#include once "file.bi"

'===============================================================================

type int2d
   dim as integer x, y
end type

type bitmap_header field = 1
   bfType          as ushort
   bfsize          as ulong
   bfReserved1     as ushort
   bfReserved2     as ushort
   bfOffBits       as ulong
   biSize          as ulong
   biWidth         as ulong
   biHeight        as ulong
   biPlanes        as ushort
   biBitCount      as ushort
   biCompression   as ulong
   biSizeImage     as ulong
   biXPelsPerMeter as ulong
   biYPelsPerMeter as ulong
   biClrUsed       as ulong
   biClrImportant  as ulong
end type

type image_type
   dim as any ptr pFbImg
   dim as int2d size
   declare sub create(sizeInit as int2d, colorInit as ulong)
   declare function createFromBmp(fileName as string) as integer
   declare sub destroy()
   declare destructor()
end type

sub image_type.create(sizeInit as int2d, colorInit as ulong)
   pFbImg = imagecreate(sizeInit.x, sizeInit.y, colorInit)
   size = sizeInit
end sub

function image_type.createFromBmp(fileName as string) as integer
   dim as bitmap_header bmp_header
   dim as int2d bmpSize
   if fileExists(filename) then
      open fileName for binary as #1
         get #1, , bmp_header
      close #1
      bmpSize.x = bmp_header.biWidth
      bmpSize.y = bmp_header.biHeight
      create(bmpSize, &hff000000)
      bload fileName, pFbImg
      'print "Bitmap loaded: " & filename
      return 0
   end if
   'print "File not found: " & filename
   return -1
end function

sub image_type.destroy()
   if (pFbImg <> 0) then
      imagedestroy(pFbImg)
      pFbImg = 0
   end if
end sub

destructor image_type()
   destroy()
end destructor

'===============================================================================

screenres SCREEN_W, SCREEN_H, 32
width SCREEN_W \ 8, SCREEN_H \ 16

dim as image_type img

img.createFromBmp("Berlin_sans32.bmp")
'fix color where alpha is zero (error in this bmp)
for y as integer = 0 to img.size.y-1
   for x as integer = 0 to img.size.x-1
      if (point (x, y, img.pFbImg) and &hff000000) = 0 then
         pset img.pFbImg, (x, y), 0
      end if
   next
next

line(0, 0) - (SCREEN_W-1, SCREEN_H-1), &h004080a0, bf
put(0, 0), img.pFbImg, alpha
bsave ("bla123out.bmp", img.pFbImg, , 0, 32)
sleep

Creates "bla123out.bmp" with alpha-channel lost?


EDIT: Sorry, I does seems to save the alpha-channel, but other programs display the newly created image different. E.g. 'Gimp' does not recognise the alpha channel.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: Bug with BSAVE?

Postby sancho3 » Feb 20, 2019 3:25

It might be a bug or a documentation issue.
If you include the bit depth you have to include at least a null(0) for palette or you get that error.
There is no matching bug report as yet.

Code: Select all

Dim As Any ptr t
'Bsave("bla.bmp", t,,,32)       ' error
Bsave("bla.bmp", t,,,)         ' no error
Bsave("bla.bmp", t,,0,32)      ' no error
Sleep

fxm
Posts: 10037
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Bug with BSAVE?

Postby fxm » Feb 20, 2019 7:08

Yes, it seems that currently, the syntax allowed for BSave use (due to existing overload procedures) is rather:
result = BSave( filename, source [,[ size ][, pal | , pal, bitsperpixel ]] )

or:
result = BSave( filename, source [,[ size ][,[ pal | pal, bitsperpixel ]]] )
(maybe more clear)

Return to “General”

Who is online

Users browsing this forum: No registered users and 15 guests