How to load a .jpg file [SOLVED]

New to FreeBASIC? Post your questions here.
BasicCoder2
Posts: 3308
Joined: Jan 01, 2009 7:03

How to load a .jpg file [SOLVED]

Postby BasicCoder2 » Nov 01, 2018 4:46

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: 300
Joined: Sep 30, 2017 3:22

Re: How to load a .jpg file

Postby sancho3 » Nov 01, 2018 5:17

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

Re: How to load a .jpg file

Postby fxm » Nov 01, 2018 6:11

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: 3308
Joined: Jan 01, 2009 7:03

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

Postby BasicCoder2 » Nov 01, 2018 6:25

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: 7456
Joined: May 28, 2005 3:28

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

Postby D.J.Peters » Nov 01, 2018 11:38

May be FBImage is the key :-)

viewtopic.php?f=14&t=24105

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

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

Postby counting_pine » Nov 01, 2018 11:55

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: 1008
Joined: May 24, 2007 22:10
Location: The Netherlands

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

Postby badidea » Nov 01, 2018 18:59

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

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

Postby UEZ » Nov 01, 2018 19:19

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

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest