Page: FBgfx Image and Font Buffers

Forum for discussion about the documentation project.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Page: FBgfx Image and Font Buffers

Post by badidea »

First, there is a dead line on (A) TutFBgfxImgAndFontBuf. Remove the link?

Second, I was looking for the fb.image structure, which I could only find on the 'tutorial' wiki page above.
If it is part of freebasic since verion 0.17, it deserves a place on a 'real' reference page I think.

There are these related pages (that I could find):
(B) Internal graphics formats which explains old and new buffer format, but not the data type.
(C) GET/PUT image header example which is quite confusing and obsolete I think.
(D) IMAGEINFO which offers the same functionality in a different way, but does not really mention fb.image as an alternative. It does link to (B).

Documentation seems a bit messy with some history.
Remove (C), expand (B) with details on the fb.image structure?
Is it better to use "ImageInfo" than using the fb.image structure?
The structure is more convenient I think, but involves 'scary' pointers.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

At the ImageInfo documentation page, by presenting 'ImageInfo()' as an alternative to easily access the main characteristics of an image, rather than directly accessing the internal FB.IMAGE structure through a typed pointer to member data, we could therefore show this structure rather as information.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Page: FBgfx Image and Font Buffers

Post by dodicat »

An fb.image structure is in fbgfx.bi, or is it now an internal structure in the latest build?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

To my knowledge, a single fb.image structure is defined in fbgfx.bi, also used by the internal code.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Page: FBgfx Image and Font Buffers

Post by dodicat »

Is there not an error in fbgfx.bi with IMAGE?

Code: Select all



'' Image buffer header, old style
	''
	type _OLD_HEADER field = 1
		bpp : 3 as ushort
		width : 13 as ushort
		height as ushort
	end type


	'' Image buffer header, new style (incorporates old header)
	''
	type IMAGE field = 1
		union
			old as _OLD_HEADER
			_type as ulong ''<<----- type as ulong causes error
		end union
		bpp as long
		width as ulong
		height as ulong
		pitch as ulong
		_reserved(1 to 12) as ubyte
		
'		'' properties
		declare property pixels() as ubyte ptr
	end type
	
	'' This is a trick to obtain a pointer to the pixels data area
	''
	property IMAGE.pixels() as ubyte ptr
		return cast(ubyte ptr, @this) + sizeof(IMAGE)
	end property
screen 19
dim as image ptr i
i=imagecreate(900,300)
print i->_type
print i->pixels

dim as ubyte ptr p
imageinfo i,,,,,p
print p
sleep
	

	 
Because of type as ulong in the union, you can no longer use the optional property.
You have to change to
_type as ulong or something similar.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

Yes, if we un-comment the 'pixels()' property, 'type' can no longer be used as a member name.
But I'm not sure if the member name 'type' is used as is by the internal code, but think it is, otherwise I don't see the point in commenting out this property declaration/definition.

Otherwise, I would have simplify the definition of the 'pixels()' property as:

Code: Select all

	property IMAGE.pixels() as any ptr
		return @This + 1
	end property
in order to additionally be able to use it as an initializer/assignment of any user pointer.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

badidea wrote:(C) GET/PUT image header example which is quite confusing and obsolete I think.
Neither confused nor obsolete.
This simple example shows how access the image information directly in the image header structure ('PUT_HEADER', being an alias of the 'IMAGE' Type) and not through the 'ImageInfo()' keyword.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Page: FBgfx Image and Font Buffers

Post by dodicat »

You can bring the property out into an extension of fb.image (in fbgfx.bi).
But it is of no benefit, but it avoids a compile error.

Code: Select all

#include "fbgfx.bi"

type _image extends fb.image
      declare property pixels() as ubyte ptr
end type

	property _IMAGE.pixels() as ubyte ptr
		return cast(any ptr, @this) + sizeof(fb.IMAGE)
	end property
      
      
     screen 19 ,32
      dim as _image ptr i=imagecreate(401,342)
      print i->width,i->height,i->bpp
      print i->pixels
      print
      dim as any ptr p
      dim as integer w,h,bpp
      imageinfo i,w,h,bpp,,p
      print w,h,bpp
      print p
      
      sleep
      imagedestroy(i)
      
      
      
 
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Page: FBgfx Image and Font Buffers

Post by badidea »

fxm wrote:
badidea wrote:(C) GET/PUT image header example which is quite confusing and obsolete I think.
Neither confused nor obsolete.
This simple example shows how access the image information directly in the image header structure ('PUT_HEADER', being an alias of the 'IMAGE' Type) and not through the 'ImageInfo()' keyword.
Ok, maybe not obsolete. But why 2 names for the same thing?
For documentation I would chose the most clear name which is IMAGE for me.
Confusing, because there are (at least) 3 ways to access to same information (imageInfo, fb.image, fb.put_header).
At least a remark on fb.image should be on this page I think.
fxm wrote:At the ImageInfo documentation page, by presenting 'ImageInfo()' as an alternative to easily access the main characteristics of an image, rather than directly accessing the internal FB.IMAGE structure through a typed pointer to member data, we could therefore show this structure rather as information.
You suggest add this to the ImageInfo page?
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

badidea wrote:
fxm wrote:At the ImageInfo documentation page, by presenting 'ImageInfo()' as an alternative to easily access the main characteristics of an image, rather than directly accessing the internal FB.IMAGE structure through a typed pointer to member data, we could therefore show this structure rather as information.
You suggest add this to the ImageInfo page?
Yes.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Page: FBgfx Image and Font Buffers

Post by badidea »

dodicat wrote:You can bring the property out into an extension of fb.image (in fbgfx.bi).
But it is of no benefit, but it avoids a compile error.
...
Why of no benefit? I think it is quite convenient that you can access the pixel pointer without declaring a variable first and then passing as an argument to a function call.

Code: Select all

print i->pixels
instead of

Code: Select all

dim as any ptr p
imageinfo i,,,,,p
print p
BTW: What editor are you using? Indentation all over the place.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Page: FBgfx Image and Font Buffers

Post by badidea »

fxm wrote:
badidea wrote:
fxm wrote:At the ImageInfo documentation page, by presenting 'ImageInfo()' as an alternative to easily access the main characteristics of an image, rather than directly accessing the internal FB.IMAGE structure through a typed pointer to member data, we could therefore show this structure rather as information.
You suggest add this to the ImageInfo page?
Yes.
Done, but I left out 'we could therefore show this structure rather as information'. Not sure what you mean with that and it its adds anything. But if is does, I am quite sure you know how to edit the page.

I must say that like MediaWiki more than WikkaWiki. And WikkaWiki seems end of life, see 'So long, and thanks for all the fish' note on: http://wikkawiki.org/HomePage
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

badidea wrote:Done, but I left out 'we could therefore show this structure rather as information'.
Yes indeed, this is not like for the EVENT and FBARRAY structures for example, where it is mandatory to access the names of the member data to obtain the desired information.
In the case of the IMAGE structure, a specific user interface ('ImageInfo ()') exists.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Page: FBgfx Image and Font Buffers

Post by dodicat »

imageinfo still remains as one of the awkward points regarding 32bits vs 64 bits.
You can use long or integer in 32 bits, but only integer in 64 bits (including gas64) for retrieved information.
There have been a number of posts regarding the usage of long/integer in 32/64 bits.

badidea.
I use fbide, but didn't indent on that occasion.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Page: FBgfx Image and Font Buffers

Post by fxm »

fxm wrote:
badidea wrote:Done, but I left out 'we could therefore show this structure rather as information'.
Yes indeed, this is not like for the EVENT and FBARRAY structures for example, where it is mandatory to access the names of the member data to obtain the desired information.
In the case of the IMAGE structure, a specific user interface ('ImageInfo ()') exists.
But the two image chunk header structures (the old or the new), extracted from fbgfx.bi, can be added in the 'Internal graphics formats' documentation page, to highlighter the description text of each header structure and its size (4 or 32 bytes).

[edit]
Done.
Post Reply