How to load a .jpg file [SOLVED]

New to FreeBASIC? Post your questions here.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

How to load a .jpg file [SOLVED]

Post by BasicCoder2 »

Been looking for FreeBASIC code to load .jpg images which I seem to remember exists somewhere but haven't been able to locate it?

Tried this but failed to compile.

viewtopic.php?t=15284&highlight=jpeg+function


Command executed:
"C:\FreeBasic\fbc.exe" "C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas"

Compiler output:
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(490) error 57: Type mismatch, at parameter 2 (aData) of DECODE_BLOCK() in 'if decode_block(z, aData(0), _'
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(498) error 57: Type mismatch, at parameter 3 (aData) of IDCT_BLOCK() in 'aData(0), _'
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(526) error 57: Type mismatch, at parameter 2 (aData) of DECODE_BLOCK() in 'if decode_block(z, aData(0), _'
C:\FreeBasic\AGAMES\makeImages\loadJPG2.bas(535) error 57: Type mismatch, at parameter 3 (aData) of IDCT_BLOCK() in 'z->img_comp(n).w2, aData(0), @z->dequant(z->img_comp(n).tq))'

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for win32 (32bit)
OS: Windows NT 6.2 (build 9200)
Last edited by BasicCoder2 on Nov 01, 2018 6:24, edited 1 time in total.
sancho3
Posts: 358
Joined: Sep 30, 2017 3:22

Re: How to load a .jpg file

Post by sancho3 »

You need to change aData(0) to aData() in 4 places (each of the errors) and it will work.
I just tried it.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: How to load a .jpg file

Post by fxm »

Yes:
changelog.txt wrote: Version 1.00.0 (former 0.91.0):
[fixed]
- #576: Array elements could be passed to array parameters in place of the array itself: <myfunction( myarray(index) )>. However, the array index was simply ignored. The array must be passed without index now: <myfunction( myarray() )>
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: How to load a .jpg file [SOLVED]

Post by BasicCoder2 »

Thanks it works now. I wanted to automatically convert a stack of .jpg images taken from a video to .bmp images.
Also am using Joshy's imageScale(image,ratio) function.
Now I don't have to do it all manually with PAINT as I had done up to now !!
The images were extracted using this software because I suspect there is no FreeBASIC function to do that?
https://www.dvdvideosoft.com/guides/fre ... verter.htm

Code: Select all

....
'===========================================================================
' simple test
dim as integer   w,h,BytesPerPixel
dim as ubyte ptr pImageBuffer

pImageBuffer=LoadJPG("testImage.jpg",w,h,BytesPerPixel)

screenres 640,480,32
dim shared as any ptr myImage
myImage = imagecreate(1280,720)

if pImageBuffer then
  'screenres w,h,BytesPerPixel*8
  dim as ubyte ptr pRGB=pImageBuffer
  'screenlock
  for y as integer=0 to h-1
    for x as integer=0 to w-1
      pset myImage,(x,y),rgb(pRGB[0],pRGB[1],pRGB[2])
      pRGB+=BytesPerPixel
    next
  next
  screenlock
  put (0,0),ImageScale(myImage,.20),trans
  'put (0,0),myImage,trans
  screenunlock
  if pImageBuffer then deallocate(pImageBuffer)
end if

sleep
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: How to load a .jpg file [SOLVED]

Post by D.J.Peters »

May be FBImage is the key :-)

viewtopic.php?f=14&t=24105

Joshy
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: How to load a .jpg file [SOLVED]

Post by counting_pine »

For what it's worth, you can extract the frames directly to bmp using ffmpeg (or avconv):

Code: Select all

ffmpeg -i input.mp4 -vf "select=not(mod(n\,10))" -vsync vfr output_%03d.bmp
Credit: https://superuser.com/questions/391257/ ... -or-ffmpeg
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: How to load a .jpg file [SOLVED]

Post by badidea »

On linux, via CLI, I use ImageMagick for batch image conversion.
UEZ
Posts: 972
Joined: May 05, 2017 19:59
Location: Germany

Re: How to load a .jpg file [SOLVED]

Post by UEZ »

If you don't care about Linux compatibility you can use the Windows built-in library GDIPlus to load / save images in several formats, such as JPG, PNG, BMP, GIF, TIFF.

Check this out: LoadImage / SaveImage
Post Reply