IMAGECREATE() and GET problem

DOS specific questions.
Post Reply
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

IMAGECREATE() and GET problem

Post by Cpcdos »

Hello

i have a problem with IMAGECREATE() and GET commands

Code: Select all

BIT = 16
ScreenRes 1024, 768, BIT, 2

Dim As Any Ptr imageCur = ImageCreate(50, 50, 0, BIT)
Get (100, 100)-(200, 200), imageCur
Put (1, 1), ImageCur
When i put content of ImageCur, i have a 8bit image inftead 16Bit.. Why ?

Best Regards
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: IMAGECREATE() and GET problem

Post by TJF »

How can you compile that code? BIT is a pre-defined macro!

When I rename BIT, it's working fine under Ubuntu / fbc-0.24. What output do you get by this code

Code: Select all

VAR BIT_ = 16
SCREENRES 1024, 768, BIT_, 2

VAR imageCur = IMAGECREATE(50, 50, 0, BIT_)
IF imageCur THEN
  GET (100, 100)-(200, 200), imageCur
  PUT (1, 1), ImageCur

  VAR w = 0, h = 0, bpp = 0, pitch = 0, pixdata = CAST(ANY PTR, 0), size = 0
  VAR i = IMAGEINFO(imagecur, w, h, bpp, pitch, pixdata, size)
  IMAGEDESTROY(imagecur)
  SCREEN 0
  ?"ImageInfo: "; i
  ?"    width: "; w
  ?"   heigth: "; h
  ?"      bpp: "; bpp
  ?"    pitch: "; pitch
  ?"  pixdata: "; pixdata
  ?"     size: "; size
  SLEEP
ELSE
  ?"ImageCreate failed"
END IF
bpp should be = 2 (bytes per pixel).
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: IMAGECREATE() and GET problem

Post by Cpcdos »

With your code, i have this :


Image
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: IMAGECREATE() and GET problem

Post by fxm »

I don't understand the aim of this test.
My PC crashes because of image buffer overflow.

That works with a consistent GET compared to IMAGECREATE:

Code: Select all

VAR BIT_ = 16
SCREENRES 1024, 768, BIT_, 2
VAR imageCur = IMAGECREATE(50, 50, 0, BIT_)
IF imageCur THEN
  GET (100, 100)-(149, 149), imageCur
  PUT (1, 1), ImageCur

  VAR w = 0, h = 0, bpp = 0, pitch = 0, pixdata = CAST(ANY PTR, 0), size = 0
  VAR i = IMAGEINFO(imagecur, w, h, bpp, pitch, pixdata, size)
  IMAGEDESTROY(imagecur)
  SCREEN 0
  ?"ImageInfo: "; i
  ?"    width: "; w
  ?"   heigth: "; h
  ?"      bpp: "; bpp
  ?"    pitch: "; pitch
  ?"  pixdata: "; pixdata
  ?"     size: "; size
  SLEEP
ELSE
  ?"ImageCreate failed"
END IF

Code: Select all

ImageInfo:  0
    width:  50
   heigth:  50
      bpp:  2
    pitch:  112
  pixdata: 17072256
     size:  5632
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: IMAGECREATE() and GET problem

Post by Cpcdos »

No solutions ?
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: IMAGECREATE() and GET problem

Post by dkl »

The image is only 50x50 - that's too small to hold an area of 101x101 pixels. As a result there will be a buffer overflow during the GET statement.

I'm wondering though why FB doesn't do the bound check... maybe it's because it just writes into the given buffer, without caring what it is or contains. "Get" also supports writing into arrays and it does have a bounds check for that. So, I wonder whether it could be changed to assume being given a properly initialized fb.Image buffer if it's not an array. It should be ok, because ImageCreate() is the only sane way to create the buffer for Get to write into, but who knows - old code may still be passing manually allocated uninitialized buffers.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: IMAGECREATE() and GET problem

Post by Cpcdos »

Oups..

For be sure
i have dimensioned imagecur at 300x300 and captured 200x200 pixels.. i have the same problem :/
i have test this code

Code: Select all

imageCur = IMAGECREATE(300, 300, 0, 8)
Get (1, 1)-(200, 200), imageCur
PUT (500, 500), ImageCur

      w = 0 : h = 0 : bpp = 0 : pitch = 0 : pixdata = CAST(ANY PTR, 0) :  size = 0
      i = IMAGEINFO(imagecur, w, h, bpp, pitch, pixdata, size)
      IMAGEDESTROY(imagecur)
	  locate 5, 
      ?"ImageInfo: "; i
      ?"    width: "; w
      ?"   heigth: "; h
      ?"      bpp: "; bpp
      ?"    pitch: "; pitch
      ?"  pixdata: "; pixdata
      ?"     size: "; size
and i have this :
Image
dkl
Site Admin
Posts: 3235
Joined: Jul 28, 2005 14:45
Location: Germany

Re: IMAGECREATE() and GET problem

Post by dkl »

Perhaps it will work with Put's Pset mode, instead of the default Xor:

Code: Select all

PUT (500, 500), ImageCur, pset
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: IMAGECREATE() and GET problem

Post by fxm »

How is defined your graphic screen?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: IMAGECREATE() and GET problem

Post by TJF »

This looks like different color bit settings between your dosbox frame buffer and the fbgfx. FB uses R:5-G:6-B:5 format. Try to adjust that in DosBox.
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: IMAGECREATE() and GET problem

Post by Cpcdos »

Thank you dkl

this problem provient of PUT (500, 500), ImageCur, pset

my program work !

Thank's you all !
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: IMAGECREATE() and GET problem

Post by fxm »

Inconsistency between:
IMAGECREATE(300, 300, 0, 8)
and
bpp : 2

=> risk of image buffer overflow?
Cpcdos
Posts: 207
Joined: Mar 06, 2013 13:52
Location: France - LYON 69003
Contact:

Re: IMAGECREATE() and GET problem

Post by Cpcdos »

Ho yes !, i have replaced by 16 or 32
8 is ugly ;-)
Post Reply