Direct Image Buffer Access Macros

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Direct Image Buffer Access Macros

Post by vdecampo »

Browsing the forums, I've never seen a simple example of accessing the properties of an image buffer. Hope someone finds these macros useful.

Code: Select all

#Define imgSizeX(imgBuffer) Peek(Integer,imgBuffer+8)
#Define imgSizeY(imgBuffer) Peek(Integer,imgBuffer+12)
#Define imgPitch(imgBuffer) Peek(Integer,imgBuffer+16)
#Define imgBytes(imgBuffer) Cast(UByte Ptr,imgBuffer+32)

ScreenRes 640,480,32,1

Dim P As Any Ptr

P = ImageCreate(320,240,RGBA(255,255,255,0),32)

Print "Image Size X=" & imgSizeX(P)
Print "Image Size Y=" & imgSizeY(P)
Print "One Line has " & imgPitch(P) & " Bytes"
Print "The pixels start at " & imgBytes(P)


DeAllocate(P)

Sleep
Works with FBC 0.18.

Cheers!
-Vince
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

you can found it often here in forum but not with the out of date PEEK() syntax
i think it's not so good the image descriptor can be changed from time to time

#include "fbgfx.bi"
dim as FB.Image ptr picture=ImageCreate(width,height,initcolor)
? picture->width
? picture->height
? picture->pitch
...
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

I am avoiding FBGFX until the licensing issue is resolved.

See thread...
http://www.freebasic.net/forum/viewtopi ... highlight=

Until then, this method is valid for FBC 0.18 release and can easily be modified if the header changes.

Here is a version without PEEK for those who think PEEK is "out-of-date"

Code: Select all

#Define imgBytes(imgBuffer) Cast(UByte Ptr,imgBuffer+32)

Type imgInfo_STRUCT
	Unknown1 As Integer
	Unknown2 As Integer
	imgSizeX As Integer
	imgSizeY As Integer
	imgPitch As Integer
End Type

ScreenRes 640,480,32,1

Dim imgINFO As imgInfo_STRUCT Ptr

imgINFO = Cast(imgInfo_STRUCT Ptr, ImageCreate(320,240,RGBA(255,255,255,0),32))

Print "Image Size X=" & imgINFO[0].imgSizeX
Print "Image Size Y=" & imgINFO[0].imgSizeY
Print "One Line has " & imgINFO[0].imgPitch & " Bytes"
Print "The pixels start at " & imgBytes(imgINFO)

DeAllocate(imgINFO)

Sleep
Peek, for me, is simply a low level memory access tool. It saves me time from having to do this...

ASM
mov eax, [pointer]
mov eax, [eax]
END ASM


Actually, if would be a nice idea if the header data was accessible as an intrisic type or if these macros were part of the FBC command set.

-Vince
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Post by DrV »

The header is not the licensing problem - it's the actual library. Whether or not you use the fbgfx.bi header, when you call Screen, etc. you are causing the fbgfx library to be linked.

The FB.Image structure defined in fbgfx.bi is the best way to access the image header now, since it will be updated in case any changes occur in the future.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

@Emphasis on what DrV Said.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

The ambiguity of the FBGFX license is causing me to reconsider if FreeBASIC is a language I should bother using in the first place.

It is disingenuous, in my opinion, to have reference to FBGFX commands in the FreeBASIC help as if they are part of the standard runtime library.

I don't see documentation for FBSound or Allegro or other 3rd party libraries in there.

What is the license status for FBGFX?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

vdecampo wrote:I don't see documentation for FBSound...
this older doc (click) are in the fbsound.x.yz/doc folder ?!?
Last edited by D.J.Peters on Sep 25, 2017 16:59, edited 1 time in total.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

What I am referring to is the .CHM file..

FB-manual-chm-02.jul.2007.chm
How can I link/use Gfxlib?

Gfxlib is "built in" into the language, it is not necessary to include any .bi file or to link any library explicitely. FB detects you want to use Gfxlib when it finds a Screen or ScreenRes instruction. So to use Gfxlib, just start a graphics screen mode and use the graphics commands.
This line from the help file suggest FBGFX is bundled with FreeBASIC and so becomes part of the standard runtime regardless of the fact it is a separately linked library. This would negate FBGFX as having a separately license.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

vdecampo, FBgfx is only included when you use screen or screenres, which are necessary for FBgfx functions. That isn't related to FBgfx.bi, which I think it just a part of the normal FB Package (check the text uptop in the .bi and see what it says).

There's really no ambiguity here. :-/
FB detects you want to use Gfxlib when it finds a Screen or ScreenRes instruction. So to use Gfxlib, just start a graphics screen mode and use the graphics commands.
I don't see documentation for FBSound or Allegro or other 3rd party libraries in there.
Look at their websites :-)
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

That isn't related to FBgfx.bi, which I think it just a part of the normal FB Package (check the text uptop in the .bi and see what it says).
Please don't take information out of context. The quote from the help file clearly states..
Gfxlib is "built in" into the language, it is not necessary to include any .bi file or to link any library explicitely
It is saying FBGFX is "Built-In" and will link implicitly.

I'm not sure how you are related to FBGFX, but unless you can clarify the license, I believe you are just splitting hairs.
Quote:
I don't see documentation for FBSound or Allegro or other 3rd party libraries in there.
Look at their websites :-)
I know where to find documentation for these libraries. My point (which you missed) was that these libraries are not "Built-In" to the language or implicitly link.

I appreciate your opinion, but that is all it is, your opinion. I am looking for definitive answers from developers authorized to speak on this issue, or someone who can point me in the proper direction to find the information myself.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

vdecampo, that was probably one of the most insulting posts I've ever read on the forum. Honestly.

You obviously didn't read the rest of my post, or care to understand it. But no, I don't have a big #%$@ developer text under my name, do I? Hah, hahahah.
I appreciate your opinion, but that is all it is, your opinion.
No. I'm right, and you're Π$/- me off.
link any library explicitely
In fact, you've never linked to FBgfx in any of your code, have you? Course, FBgfx.bi includes libfbgfx, but I already told you to look in fbgfx.bi to see if it did that.

Here's an idea. Compile a program with a screen/screenres call. Okay? Asshole. (Just putting emphasis on what a prick you are). Look at the size of the exe. Then compile the same program without a screen/screenres call. Oh wow. Lot smaller, no? Must've not included something bulky this time...

The implicitness is due to you not ever having to include FBgfx yourself. By using the functionality of the graphics library, FreeBASIC knows to include it.
I am looking for definitive answers from developers authorized to speak on this issue, or someone who can point me in the proper direction to find the information myself.
Developers authorized to speak on the issue? You're not asking anything only a developer would know, bud. I'm as authorized to speak on this as they are. Want to be pointed in the right direction? Okay: 1) Get some common sense. 2) You can always look at the source. 3) Stop being an bright.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

You should have read the post before I edited it! (I try to stay professional)

I only answer posts when I think I have a positive contribution, not to pick apart the syntax or semantics of the poster.

This is what you did (and actively do from what I read of your many postings).

I am sorry you were insulted. I am used to dealing matter-of-fact and not in the realm of "I think I'm right". When I express my opinion, I always say it is my opinion. You answer is YOUR opinion. I merely made you aware of that.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

Look, that isn't opinion. Get that through your head. I'm starting to think you're a troll...
When I express my opinion, I always say it is my opinion. You answer is YOUR opinion. I merely made you aware of that.
No. My answer was factual. When I sport my opinion, you're right, it's just my opinion. When I state some facts, you might want to read 'em.

2+2=4? No no no, that's just my OPINION. Take the pi (very complex number which someone like you couldn't understand) out of the word opinion, and I now declare all of your text, your ONION.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

I don't know who you THINK you are, but I've been writing software longer than you've probably been born. And if that's not the case, your attitude is deplorable for an adult.

We are done.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

I think I'm someone who stated facts, and I don't care how long you've been programming software for.

You can't have been using English all that long. You still don't know what an opinion is. Maybe you've never touched Open Source Software, where sometimes people other than active developers know what they're talking about.

We're done only if you continue to ignore my posts, till a developer comes along and states the same stuff I've been saying. Then you can go to your little elite land of "developers only please".
Post Reply