LB Booster
« Load Bitmap from RGB triplet data... »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:49am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Load Bitmap from RGB triplet data...  (Read 724 times)
James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Load Bitmap from RGB triplet data...
« Thread started on: Feb 4th, 2012, 10:15am »

What would be interesting is if you could load a bitmap from RGB triplet data like this:

Code:
open "pictures.res" for input as #datafile

Loadbmp "smiley", 320, 240, #datafile, 3

#screen.box, "drawbmp smiley 0 0" 


In this case you would basically be loading 320 X 240 X 3 byte slots, slot number 3

or

Code:
Loadbmp "face", 640, 480, #differentfile, 100 


Load bitmap face, size 640 by 480, from #differentfile, slot number 100

Total bytes loaded this time: 921600

It would be interesting to be able to do loadbmp from raw data. 8-)

----------

John 3:3 Jesus answered and said unto him, Verily, verily, I say unto thee, Except a man be born again, he cannot see the kingdom of God.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Load Bitmap from RGB triplet data...
« Reply #1 on: Feb 4th, 2012, 12:45pm »

on Feb 4th, 2012, 10:15am, James wrote:
What would be interesting is if you could load a bitmap from RGB triplet data

Right, this time I really have been able to write code which does it:

Code:
  nomainwin
  WindowWidth = 320
  WindowHeight = 240
  open "Load raw RGB data" for graphics_nsb as #screen
  #screen "trapclose [quit]"
  call loadrgb "smiley", 320, 240, "C:\smiley.rgb", 0
  #screen "drawbmp smiley 0 0" 
  wait

[quit]
  close #screen
  end

sub loadrgb bmp$, width, height, file$, slot
  struct bmi, size as ulong, width as long, height as long, _
   planes as short, bitcount as short, compression as ulong, _
   sizeimage as ulong, xpermeter as long, ypermeter as long, _
   clrused as ulong, clrimportant as ulong

  struct dib, bits as long

  bmi.size.struct = len(bmi.struct) 
  bmi.width.struct = width
  bmi.height.struct = height
  bmi.planes.struct = 1
  bmi.bitcount.struct = 24

  calldll #gdi32, "CreateDIBSection", 0 as long, bmi as struct, _
   0 as long, dib as struct, 0 as long, 0 as long, hdib as long

  open file$ for binary as #rgbfile
  seek #rgbfile, slot * width * height * 3
  hfile = hwnd(#rgbfile)
  buffer = dib.bits.struct
  size = width * height * 3
  calldll #kernel32, "ReadFile", hfile as long, buffer as long, _
   size as long, dib as struct, 0 as long, ret as long 
  close #rgbfile 
  loadbmp bmp$, hdib  
  calldll #gdi32, "DeleteObject", hdib as long, ret as long
end sub 

This nearly works in LB4, except that it relies on the LBB extension of HWND() working with file handles as well as window handles.

Richard.
User IP Logged

James
New Member
Image


member is offline

Avatar




PM


Posts: 42
xx Re: Load Bitmap from RGB triplet data...
« Reply #2 on: Feb 4th, 2012, 2:01pm »

Thanks, Richard, that's nice! I tried it out!

What is the code's license? I hope it's public domain... smiley

--------

Romans 6:23 For the wages of sin is death; but the gift of God is eternal life through Jesus Christ our Lord.

« Last Edit: Feb 4th, 2012, 2:05pm by James » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls