Board index » delphi » GETIMAGE Not Working - Better Code Example

GETIMAGE Not Working - Better Code Example

Thank you for your responses to my question. Here is a better example of the
code I'm using, which causes the error.

uses
  Graph, crt, dos;

var Gd, Gm : integer;

var Window : array [1 .. 11] of record
              x : integer;
              y : integer;
              x2 : integer;
              y2 : integer;
              P : pointer;
             end;

procedure DrawWindow (handle : integer);
          var x1, y1, x2, y2 : integer;
          var Size : integer;

          begin
          x1 := Window[handle].x;
          y1 := Window[handle].y;
          x2 := Window[handle].x2;
          y2 := Window[handle].y2;

          Size := ImageSize(x1,y1,x2,y2);
          GetMem(Window[handle].P, Size);
          GetImage(x1,y1,x2,y2,Window[handle].P^);

          {Commands to draw window
                .
                .
                .
                                }
        end;

begin

Gd := Detect; InitGraph(Gd, Gm, 'c:\tp\bgi');

Window[1].x := 20;
Window[1].y := 20;
Window[1].x2 := 400;
Window[1].y2 := 400;

DrawWindow (1);

readln;

end.

Someone mentioned it could be exceeding 64k and would have to be split up.
This is entirely possible; the windows are large, and it is in 640x480 mode.
So how would I go about splitting it up?

 

Re:GETIMAGE Not Working - Better Code Example


Well, man, I think it all breaks down with the reason I told you: you
exceed the 64k-border, which makes your program crash in line
<getmem(...)>. The window you defined is 380x380 pixels large. I don't how
Borland arranged all the stuff in the graph unit.. default graphics mode is
usually VGA (4-bit color), so that normally 2 pixels should be stored in
ONE byte. If this is the case in the Borland graphics unit, your window
would have a size of 1 44 400 pixels and for the standard 4-bit VGA mode,
this would mean the half of the required amount of pixels; 72200 BYTES. In
realmode (your program is running in realmode), this is FORBIDDEN! The
maximum is, as I told you, 64k, that means something about 65534 bytes or
so. You see, this will be quite a hack for you...

...1.) When lazy, forbid windows allocating more than 64k bytes.., ;-)) not
recom...

...2.) When good at maths (well uhm.. I am not... at least not that good...
;-))
You have to add MORE POINTERS to the WINDOW RECORD. (1st)
You have to CREATE a PROCEDURE that DEVIDES the WINDOW in several 64K-PARTS
using those pointers...(2nd)
The procedure that devided the window in parts must also remember, where
each part starts and stops (these are subwindows, in a way).(3rd)

Try it and OPTIMIZE it!

Hope it helps.. ;-.))

CU

Re:GETIMAGE Not Working - Better Code Example


In article <7nqcup$q1...@news2.tor.accglobal.net>,

Quote
Transactoid <transact...@hotmail.com> wrote:
>Thank you for your responses to my question. Here is a better example of the
>code I'm using, which causes the error.

>uses
>  Graph, crt, dos;

>var Gd, Gm : integer;

>var Window : array [1 .. 11] of record
>              x : integer;
>              y : integer;
>              x2 : integer;
>              y2 : integer;
>              P : pointer;
>             end;

>procedure DrawWindow (handle : integer);
>          var x1, y1, x2, y2 : integer;
>          var Size : integer;

>          begin
>          x1 := Window[handle].x;
>          y1 := Window[handle].y;
>          x2 := Window[handle].x2;
>          y2 := Window[handle].y2;

>          Size := ImageSize(x1,y1,x2,y2);
>          GetMem(Window[handle].P, Size);
>          GetImage(x1,y1,x2,y2,Window[handle].P^);

>          {Commands to draw window
>                .
>                .
>                .
>                                }
>        end;

>begin

>Gd := Detect; InitGraph(Gd, Gm, 'c:\tp\bgi');

>Window[1].x := 20;
>Window[1].y := 20;
>Window[1].x2 := 400;
>Window[1].y2 := 400;

Come on, that is 144,000 pixles. At 16 colors it is 72,200 bytes (+a few
for book keeping). You need to do it in parts of no less than about 64K.

Quote

>DrawWindow (1);

>readln;

>end.

>Someone mentioned it could be exceeding 64k and would have to be split up.
>This is entirely possible; the windows are large, and it is in 640x480 mode.
>So how would I go about splitting it up?

Simply get window (20,20),(199,400) and (200,400),(200,400) separately.
In a more generic case use imagesize to to estimate how much you can get
at once. For example use imagesize() to check how much one pixel row in
your image takes, then divide 65500 by that and you get how many rows you
can safely take with one getimage(). On 16 color modes you could also
use the fact that one pixel takes 4 bits, i.e. 2 pixels take one byte,
in addition there is  some book keeping (IIRC about a 6-12 bytes)

Osmo

Other Threads