Author Topic: Array of XYDoubles  (Read 503 times)

PaulSamuelson

  • Newbie
  • *
  • Posts: 20
Array of XYDoubles
« on: May 23, 2017, 04:31:24 pm »
I am using a DLL that requires an "Array of XYDoubles" as one of the parameters. It is a series of (3 or more) points describing a polygon. If I understand the "Array of XYDoubles" correctly (I could certainly be wrong here, since something doesn't work), it is basically a structure with pairs of X and Y values stuffed in as doubles.

First question: Am I correct that I can use a structure for this array?

Next question: Am I doing it correctly?

I am not sure if the coordinates should be in pixels or a percentage of width, so I have tried both.

The code does not error, but does not give draw on the image either. What am I missing?


Thank you,

Paul



My code:

lCoordinates = "0,0 | 1,1 | 0,1"

  polyPoints = ItemCount(lCoordinates,"|") ;number of points in polygon

  ;build descriptor for structure
  structdescriptor = "double:x1 double:y1"
  For PP = 2 To polyPoints
    structdescriptor = structdescriptor:" double:x":PP:" double:y":PP
  Next
  structPoints = DllStructAlloc(structdescriptor)

   ;poke values into structure
  For PP = 1 To polyPoints
    XY = ItemExtract(PP,lCoordinates,"|")
    xVal = StrTrim(ItemExtract(1,XY,",")) + 0.0
    yVal = StrTrim(ItemExtract(2,XY,",")) + 0.0
    DllStructPoke(structPoints,"x":PP,DataCast(xVal,0))
    DllStructPoke(structPoints,"y":PP,DataCast(yVal,0))
  Next

  DllCall(IS6,long:"_is6_PolygonFillImage",lpbinary:polyLayer,long:polyLayerW,long:polyLayerH,long:4,long:4 * polyLayerW,lpstruct:structPoints,long:polyPoints,lpnull,lpnull,lpnull,lpnull,long:lColor,double:1.0,lpnull,lpnull,long:0)



The DLL function parameters are:

   Param                Use
   ------------------------------------
   pImage               image
   uWidth               width in pixels
   uHeight              height
   uBytesPerPixel       bytes per pixel (1, 3 or 4)
   uInRowStride         number of bytes in a pImage pixel row

   pPoints              array of XYdouble values describing the polygon to fill   

   uNumPoints           points in the pPoints array

   pOverlayImage        image to be used as the fill pattern. NULL, if filling a solid color.
                        image tiling starts at the minimum X,Y value in pPoints.
                        if uBytesPerPixel = 4, the image is not alpha-blended.
                        it is simply copied onto the output image.

   uOverlayWidth        image width in pixels
   uOverlayHeight       image height
   uOverRowStride       number of bytes in an overlay image row

   uColorSpec           fill color, if not filling with an image.
                        if uBytesPerPixel = 1, the low byte of this value is used as the output.
                        if uBytesPerPixel = 3, this value is treated as a COLORREF value.
                        if uBytesPerPixel = 4, this value is treated as a COLORREF value with the high BYTE set to the output alpha value.

   fOpacity             0 to 1. 1 = solid, 0 = transparent. not supported when using an overlay image.

   pPal                 pallete for colormapped images (uBytesPerPixel=1). see Notes.

   uPalColors           entries in pPal

   uFlags               bit      purpose
                        ---      -------
                        0        use opacity value for filling. see Notes for palette info
                        1        set when image is in BGR (or BGRA) order
                        2        smooth the polygon edges
   Return
   ------
      FALSE on failure
---------------------------------------------------------*/
_ISDeclSpec BOOL        _ISCConv _ISFn( is6_PolygonFillImage )(BYTE *pImage, UINT32 uWidth, UINT32 uHeight, UINT32 uBytesPerPixel, UINT32 uInRowStride, XYdouble *pPoints, UINT32 uNumPoints, BYTE *pOverImage, UINT32 uOverW, UINT32 uOverH, UINT32 uOverRowStride, UINT32 uClrSpec, double fOpacity, RGBQUAD *pPal, UINT32 uPalColors, UINT32 uFlags);



The definition of the XYDOUBLE_STRUCT is:

// double-precision point structure, used in some ImgSource functions
#ifndef IS_XYDOUBLE_STRUCT_DEF
#define IS_XYDOUBLE_STRUCT_DEF
typedef struct XY_tag
{
   double x;
   double y;
} XYdouble;
#endif


stanl

  • Pundit
  • *****
  • Posts: 650
Re: Array of XYDoubles
« Reply #1 on: May 24, 2017, 04:40:12 am »
is DataCast() a udf? 

PaulSamuelson

  • Newbie
  • *
  • Posts: 20
Re: Array of XYDoubles
« Reply #2 on: May 24, 2017, 04:56:12 am »
No, it's a WinBatch function

DataCast
Converts or casts a value from one data type to another.

Syntax:
DataCast( value, mode )

Parameters:
(f) value: specifies the value to be converted or cast.

(i) mode: specifies the operation to perform:

Returns:
(f)  depends on mode specified. See below.

 

Mode
 Meaning
 
0
 Cast single-precision floating point to double-precision floating point.

"value" specifies a single-precision (32-bit) floating point value, represented as a WIL long value containing the same bit sequence as the float value.

Returns a WIL floating point value (64-bit).
 
1
 Cast double-precision floating point to single-precision floating point.

"value" specifies a WIL floating point value (64-bit).

Returns a single-precision (32-bit) floating point value, represented as a WIL long value containing the same bit sequence as the float value.
 

JTaylor

  • Pundit
  • *****
  • Posts: 786
    • Data & Stuff Inc.
Re: Array of XYDoubles
« Reply #3 on: May 24, 2017, 06:35:54 am »
Interesting that in over 20 years of using WinBatch there are still Functions I have never heard of before.

Jim

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: Array of XYDoubles
« Reply #4 on: May 24, 2017, 08:24:19 am »
I am using a DLL that requires an "Array of XYDoubles" as one of the parameters. It is a series of (3 or more) points describing a polygon. If I understand the "Array of XYDoubles" correctly (I could certainly be wrong here, since something doesn't work), it is basically a structure with pairs of X and Y values stuffed in as doubles.

First question: Am I correct that I can use a structure for this array?

Next question: Am I doing it correctly?

I am not sure if the coordinates should be in pixels or a percentage of width, so I have tried both.

The code does not error, but does not give draw on the image either. What am I missing?


First answer:  Technically you are creating a single structure with many members.  But since the memory layout is identical to the memory layout of an array of structures, what you are doing should work.  In fact,  it is a clever way to pass an array to a native function.

Second non-answer:   Don't see anything that looks untoward but the problem may lie with one of the other parameters in the call.  You may have to review the functions documentation to determine if you are missing or otherwise incorrectly using one of the other function parameters.

BTW, it is not necessary to use the DataCast function because the DllStructPoke function will perform the conversion for you.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


PaulSamuelson

  • Newbie
  • *
  • Posts: 20
Re: Array of XYDoubles
« Reply #5 on: May 24, 2017, 10:06:41 am »
I found the problem. It was related to another parameter, which is used a little differently than other calls I make with the same DLL. Thanks for confirming I was on track with the array of doubles. That helped reduce the variable count to identify the problem.

Thanks,

Paul