C# GM_Set RasterDisplayOptions problems

pmacepmace Global Mapper UserPosts: 30Trusted User
edited July 2011 in SDK
Mike,

Get seems to work fine but set does nothing.

Trying to either turn Color.Black transparent or blend black with black background to stitch overlapping tiles.

DLLWrapper declarations below
// Sets the options to use when displaying the given raster layer
        [DllImport(DLLFileName, EntryPoint = "GM_SetRasterDisplayOptions")]
        public static extern GM_Error_t32 GM_SetRasterDisplayOptions
        (
            ref GM_LayerHandle_t32           aLayer,     // in: layer to set options for
            ref GM_RasterDisplayOptions_t    aOptions    // in: display options for raster layer
        );

        // Retrieves the options to use when displaying the given raster layer
        [DllImport(DLLFileName, EntryPoint = "GM_GetRasterDisplayOptions")]
        public static extern GM_Error_t32 GM_GetRasterDisplayOptions
        (
            ref GM_LayerHandle_t32          aLayer,     // in: layer to get options for
            out GM_RasterDisplayOptions_t  aOptions    // out: display options for raster layer
        );

Comments

  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited July 2011
    How are you making the call? Make sure to set the mSize member of GM_RasterDisplayOptions_t structure so that the SDK knows what you think the size of the structure is (this is for forward binary compatibility).

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    Added Marshal.Sizeof. No change.

    Here's the C# declarations
    // This type represents the different contrast adjustment modes that are available
        public enum GM_ContrastMode_t8 : byte 
        {
            GM_Contrast_None = 0,
            GM_Contrast_PercentageStretch,  // Stretch within some std-dev of mean to 0-255 range
            GM_Contrast_RangeStretch,       // Stretch entire valid range to 0-255 range
    
            GM_Contrast_NumModes,
            GM_Contrast_DefaultAuto = GM_Contrast_PercentageStretch
        };
        // This type represents the different blend modes available
        public enum GM_BlendMode_t8 : byte
        {
            GM_BlendMode_None = 0,
            GM_BlendMode_Multiple,
            GM_BlendMode_Screen,
            GM_BlendMode_Overlay,
            GM_BlendMode_HardLight,
            GM_BlendMode_ColorBurn,
            GM_BlendMode_ColorDodge,
            GM_BlendMode_ApplyColor,
            GM_BlendMode_ApplyColorReverse,
            GM_BlendMode_Darken,
            GM_BlendMode_Lighten,
            GM_BlendMode_Difference,
            GM_BlendMode_Exclusion,
            GM_BlendMode_KeepRedChannel,
            GM_BlendMode_KeepGreenChannel,
            GM_BlendMode_KeepBlueChannel,
            GM_BlendMode_SpotNaturalColor,      // view SPOT images as natural color
            GM_BlendMode_PsuedoNaturalColor,    // simple weighted average
            GM_BlendMode_ColorToGrayscale,      // convert RGB color image to grayscale
    
            // IMPORTANT NOTE: When adding new blend modes also add to the GM_BlendMode_t8 enumeration
            // in GlobalMapperInterface.h, which should match this.
    
            GM_BlendMode_NumModes
        };
    
        // Enumeration of different raster/elevation sampling methods available
        public enum GM_SamplingMethod_t8 : byte
        {
            GM_SAMPLING_NEAREST_NEIGHBOR,       // Nearest neighbor sampling
            GM_SAMPLING_BILINEAR_INTERPOLATION, // Bilinear interpolation
            GM_SAMPLING_BICUBIC_INTERPOLATION,  // Bicubic interpolation
            GM_SAMPLING_BOX_AVG_3X3,            // Box averager 3x3 grid
            GM_SAMPLING_BOX_AVG_4X4,            // Box averager 4x4 grid
            GM_SAMPLING_BOX_AVG_5X5,            // Box averager 5x5 grid
            GM_SAMPLING_BOX_AVG_7X7,            // Box averager 7x7 grid
            GM_SAMPLING_BOX_MAX_3X3,            // Box maximizer 3x3 grid
            GM_SAMPLING_BOX_MAX_4X4,            // Box maximizer 4x4 grid
            GM_SAMPLING_BOX_MAX_5X5,            // Box maximizer 5x5 grid
            GM_SAMPLING_BOX_MAX_7X7,            // Box maximizer 7x7 grid
    
            GM_NUM_SAMPLING_METHODS
        };
    
        // This type represents the display options available for raster and elevation layers
        public struct  GM_RasterDisplayOptions_t
        {
            public UInt32                  mSize;              // Size of structure
            public GM_ContrastMode_t8 mContrastMode;      // Contrast adjustment mode
            public bool mAutoClipCollar;    // Automatically crop off a DRG, BSB, or other known collar boundary
            public byte mColorIntensity;    // Color intensity (0-20). Lower values are lighter, higher values are darker.
            public GM_SamplingMethod_t8 mSamplingMethod;    // Specify how resampling should be done for this layer for display and export
            public bool mTextureMap;        // Texture map this raster layer over any underlying elevation layers.
            public GM_BlendMode_t8 mBlendMode;         // Blend mode to use to blend this raster layer with underlying layers or to interpret the color values of the layer
    
            // Translucent/transparency support
            public UInt16 mTranslucency;          // Translucency level of layer (0 - completely see-through, 512 - completely opaque)
            public bool mTransparent;           // Is layer transparent?
            public UInt32 mTransparentColor;      // Color to make transparent
            public byte mTransparentColorDist;  // Fuzzy transparency support. Distance from transparent color to treat nearby colors transparent.
    
            // Color channel adjustment
            public SByte mRedAdjustPercent;      // Percentage to adjust red color channel by (-100 to 100)
            public SByte mGreenAdjustPercent;    // Percentage to adjust red color channel by (-100 to 100)
            public SByte mBlueAdjustPercent;     // Percentage to adjust red color channel by (-100 to 100)
    
            // Color band layout support
            public bool mBandLayoutValid;       // Are the band layout values valid?
            public byte mBandIdxRed;            // Index of color band (0-based) to use for red color channel
            public byte mBandIdxGreen;          // Index of color band (0-based) to use for green color channel
            public byte mBandIdxBlue;           // Index of color band (0-based) to use for blue color channel
    
            // Contrast adjustment parameters
            public double mContrastNumStdDev;     // Number of standard deviations from mean to stretch for contrast adjustment (if 0 is used the default of 2 will be used)
            public bool mContrastShared;        // Is the contrast adjustment shared with other loaded layers?
    
            // Color Grade options
            public bool mColorGradeValid;       // Are the color grade options valid?
            public byte mColorGradeRedInMin;    // Minimum red input color value
            public byte mColorGradeRedInMax;    // Maximum red input color value
            public byte mColorGradeRedOutMin;   // Minimum red output color value
            public byte mColorGradeRedOutMax;   // Maximum red output color value
            public byte mColorGradeBlueInMin;   // Minimum Blue input color value
            public byte mColorGradeBlueInMax;   // Maximum Blue input color value
            public byte mColorGradeBlueOutMin;  // Minimum Blue output color value
            public byte mColorGradeBlueOutMax;  // Maximum Blue output color value
            public byte mColorGradeGreenInMin;  // Minimum Green input color value
            byte        mColorGradeGreenInMax;  // Maximum Green input color value
            public byte mColorGradeGreenOutMin; // Minimum Green output color value
            public byte mColorGradeGreenOutMax; // Maximum Green output color value
            public float mColorGradeSaturation;  // Saturation (valid 0.0 - 1.0)
    
        };
    
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    Working rom the c# sample

    in DrawLayersToBitmap
                    // Fill our layer list
                    for (Int32 i = 0; i < LayerHandles.Count; i++)
                    {
                        // Extract the data from the buffer
                        theLayerHandle = (IntPtr)LayerHandles[i];
                        
                        GM_RasterDisplayOptions_t rdo = new GM_RasterDisplayOptions_t();
                        //GlobalMapperDLL.GM_GetRasterDisplayOptions(ref theLayerHandle, out rdo);
                        rdo.mSize = (uint)Marshal.SizeOf(rdo);
                        rdo.mTransparent = true;
                        rdo.mTransparentColor = (UInt32)0;
                        rdo.mTransparentColorDist = 32;
                        //rdo.mTranslucency = 255;
                        rdo.mBlendMode = GM_BlendMode_t8.GM_BlendMode_Lighten;
                        rdo.mSamplingMethod = GM_SamplingMethod_t8.GM_SAMPLING_BICUBIC_INTERPOLATION;
                        GlobalMapperDLL.GM_SetRasterDisplayOptions(ref theLayerHandle, ref rdo);
                        GlobalMapperDLL.GM_GetRasterDisplayOptions(ref theLayerHandle, out rdo);
                         
                        IntPtr theDestPtr = (IntPtr)((UInt32)theLayerListPtr + i * Marshal.SizeOf(theLayerHandle));
                        Marshal.StructureToPtr( theLayerHandle, theDestPtr, false );
                    }
    
                    // Do the draw
                    IntPtr Hdc = graphics.GetHdc();
    				LastGMError = GlobalMapperDLL.GM_DrawLayerList
                        (
                        Hdc, 
                        theLayerListPtr, 
                        LayerHandles.Count,
                        GlobalMapperDLL.GM_DrawFlags_t32.GM_DrawFlags_IncrementalRender | GlobalMapperDLL.GM_DrawFlags_t32.GM_DrawFlags_EraseBackground,
                        ref CurrentViewRect, 
                        0, 
                        0, 
                        BackGroundBitmap.Width, 
                        BackGroundBitmap.Height
                        );
    
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited July 2011
    The issue is likely in the GM_RasterDisplayOptions_t declaration. The C# 'bool' type is a 32-bit value, not an 8-bit value like the 'boolean' type in the SDK. Use 'Byte' instead of 'bool' in your C# declaration and that should fix things.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    OK,

    The option values are now preserved--get after set returns same values.

    But to no measurable effect: Background set to 0xFF000000 and trans color set to same.

    Neither blending nor transparency take effect.

    test.jpg
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited July 2011
    Are you calling GM_SetBackgroundColor to set the background color to black (0x00000000)? Also what version of the SDK are you using? I don't really see anything wrong with your code now.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    That pix was a blend. this is a tran failure
    test2.jpg
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    Black would be 0xFF000000 would it not?
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    Either way makes no difference.

    The black in the img is indeed 0,0,0 and neither setting Background to black and blending, nor black to transparent does anything.
  • global_mapperglobal_mapper Administrator Posts: 17,238
    edited July 2011
    I tested this myself and found the issue. Your GM_GetRasterDisplayOptions and GM_SetRasterDisplayOptions declarations have the aLayerHandle declared as 'ref' but they should not be. Each of your calls to these were returning GM_Error_InvalidLayer because a pointer to the layer handle was being passed in rather than the layer handle value. Once I fixed that everything worked fine.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • pmacepmace Global Mapper User Posts: 30Trusted User
    edited July 2011
    Thanks, Mike

    That (and the need to set the following values) cured it:
    rdo.mTranslucency = 512;
    rdo.mColorIntensity = 10;
    rdo.mContrastShared = 1;
    rdo.mColorGradeSaturation = 1.0f;
Sign In or Register to comment.