[comp.lang.modula2] JPI M2 v2.0--Graph.ImageSize Bug?!

jordan@aerospace.aero.org (Larry M. Jordan) (05/30/90)

JPI Modula-2 v2.0 Library Bug--Graph.ImageSize

I have been tracking down an illusive bug for 2 weeks now regarding
image saving/restore and dynamic memory allocation/deallocation while in
VGA mode 12H (Graph._VRES16COLOR).  I, of course, assumed the problem was 
in my code, and have managed to rewrite or strip away anything which might be 
contributing to the problem.  Today, I have traced the problem to
Graph.ImageSize.  For VGA mode 12H (at least) the routine returns a
value which appears too small to hold the image to be gotten with 
Graph.GetImage!  Consider the following code fragment:

  VAR size: LONGCARD;
  ...
  size := Graph.ImageSize(0,0,100,100);

  (* size is 5155 bytes *)

I claim that size should be at least 5252 bytes, plus the few bytes needed to
maintain some state information required by Graph.PutImage.  Th
size for this 101x101 pixel region can be computed by the following
function:

  PROCEDURE Size(x1,y1,x2,y2: CARDINAL): CARDINAL;
  BEGIN
    RETURN (((x2 - x1) DIV 8) + 1) * (y2 - y1 + 1) * 4
  END Size;

where:
   ((x2 - x1) DIV 8) + 1   is the number of bytes per row
   (y2 - y1 + 1)           is the number of rows
   4                       is the number of bit planes

For the 101x101 region, the Size function returns 5252.  And, assuming
that 5 bytes are required for state info, a workable size appears
to be 5257 bytes to save the region.  It should be stated, that I am
assuming image save/restore routines which I've borrowed from Winton's
book.
 
When I substitute my Size function for the one supplied in the Graph
module, my application appears to run fine and not blow up with
a 'Far Heap OUT OF MEMORY' error. Also, what reinforces the idea
that Graph.ImageSize returns an incorrect value (and not that there
is anything wrong with Graph.GetImage/Graph.PutImage) is that
my application also runs fine if an arbitrarily large amount of
storage is statically allocated for saved regions.

Has anyone else experienced this problem?  I have the standard edition,
and thus cannot check the graph module library source to see if my
suspicions are correct.  So, if anyone out there has the extended
edition of JPI M2 v2.0, please check Graph.ImageSize and reply.

Thanks