CPLErr IntergraphRasterBand::SetStatistics( double dfMin, double dfMax, double dfMean, double dfStdDev ) { hHeaderOne.Minimum = INGR_SetMinMax( eDataType, dfMin ); hHeaderOne.Maximum = INGR_SetMinMax( eDataType, dfMax ); return GDALRasterBand::SetStatistics( dfMin, dfMax, dfMean, dfStdDev ); }
GDALDataset *IntergraphDataset::Create( const char *pszFilename, int nXSize, int nYSize, int nBands, GDALDataType eType, char **papszOptions ) { int nDeviceResolution = 1; const char *pszValue; const char *pszCompression = NULL; pszValue = CSLFetchNameValue(papszOptions, "RESOLUTION"); if( pszValue != NULL ) nDeviceResolution = -atoi( pszValue ); char *pszExtension = CPLStrlwr(CPLStrdup(CPLGetExtension(pszFilename))); if ( EQUAL( pszExtension, "rle" ) ) pszCompression = INGR_GetFormatName(RunLengthEncoded); CPLFree(pszExtension); if( eType != GDT_Byte && eType != GDT_Int16 && eType != GDT_Int32 && eType != GDT_UInt16 && eType != GDT_UInt32 && eType != GDT_Float32&& eType != GDT_Float64 ) { CPLError( CE_Failure, CPLE_AppDefined, "Data type not supported (%s)", GDALGetDataTypeName( eType ) ); return NULL; } // -------------------------------------------------------------------- // Fill headers with minimun information // -------------------------------------------------------------------- INGR_HeaderOne hHdr1; INGR_HeaderTwoA hHdr2; INGR_ColorTable256 hCTab; int i; memset(&hHdr1, 0, SIZEOF_HDR1); memset(&hHdr2, 0, SIZEOF_HDR2_A); memset(&hCTab, 0, SIZEOF_CTAB); hHdr1.HeaderType.Version = INGR_HEADER_VERSION; hHdr1.HeaderType.Type = INGR_HEADER_TYPE; hHdr1.HeaderType.Is2Dor3D = INGR_HEADER_2D; hHdr1.DataTypeCode = (uint16) INGR_GetFormat( eType, (pszCompression!=NULL)?pszCompression:"None" ); hHdr1.WordsToFollow = ( ( SIZEOF_HDR1 * 3 ) / 2 ) - 2; hHdr1.ApplicationType = GenericRasterImageFile; hHdr1.XViewOrigin = 0.0; hHdr1.YViewOrigin = 0.0; hHdr1.ZViewOrigin = 0.0; hHdr1.XViewExtent = 0.0; hHdr1.YViewExtent = 0.0; hHdr1.ZViewExtent = 0.0; for( i = 0; i < 15; i++ ) hHdr1.TransformationMatrix[i] = 0.0; hHdr1.TransformationMatrix[15] = 1.0; hHdr1.PixelsPerLine = nXSize; hHdr1.NumberOfLines = nYSize; hHdr1.DeviceResolution = nDeviceResolution; hHdr1.ScanlineOrientation = UpperLeftHorizontal; hHdr1.ScannableFlag = NoLineHeader; hHdr1.RotationAngle = 0.0; hHdr1.SkewAngle = 0.0; hHdr1.DataTypeModifier = 0; hHdr1.DesignFileName[0] = '\0'; hHdr1.DataBaseFileName[0] = '\0'; hHdr1.ParentGridFileName[0] = '\0'; hHdr1.FileDescription[0] = '\0'; hHdr1.Minimum = INGR_SetMinMax( eType, 0.0 ); hHdr1.Maximum = INGR_SetMinMax( eType, 0.0 ); hHdr1.GridFileVersion = 3; hHdr1.Reserved[0] = 0; hHdr1.Reserved[1] = 0; hHdr1.Reserved[2] = 0; hHdr2.Gain = 0; hHdr2.OffsetThreshold = 0; hHdr2.View1 = 0; hHdr2.View2 = 0; hHdr2.ViewNumber = 0; hHdr2.Reserved2 = 0; hHdr2.Reserved3 = 0; hHdr2.AspectRatio = nXSize / nYSize; hHdr2.CatenatedFilePointer = 0; hHdr2.ColorTableType = NoColorTable; hHdr2.NumberOfCTEntries = 0; hHdr2.Reserved8 = 0; for( i = 0; i < 110; i++ ) hHdr2.Reserved[i] = 0; hHdr2.ApplicationPacketLength = 0; hHdr2.ApplicationPacketPointer = 0; // -------------------------------------------------------------------- // RGB Composite assumption // -------------------------------------------------------------------- if( eType == GDT_Byte && nBands == 3 ) { hHdr1.DataTypeCode = Uncompressed24bit; } // -------------------------------------------------------------------- // Create output file with minimum header info // -------------------------------------------------------------------- VSILFILE *fp = VSIFOpenL( pszFilename, "wb+" ); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Attempt to create file %s' failed.\n", pszFilename ); return NULL; } GByte abyBuf[MAX(SIZEOF_HDR1,SIZEOF_CTAB)]; INGR_HeaderOneMemToDisk( &hHdr1, abyBuf ); VSIFWriteL( abyBuf, 1, SIZEOF_HDR1, fp ); INGR_HeaderTwoAMemToDisk( &hHdr2, abyBuf ); VSIFWriteL( abyBuf, 1, SIZEOF_HDR2_A, fp ); unsigned int n = 0; for( i = 0; i < 256; i++ ) { STRC2BUF( abyBuf, n, hCTab.Entry[i].v_red ); STRC2BUF( abyBuf, n, hCTab.Entry[i].v_green ); STRC2BUF( abyBuf, n, hCTab.Entry[i].v_blue ); } VSIFWriteL( abyBuf, 1, SIZEOF_CTAB, fp ); VSIFCloseL( fp ); // -------------------------------------------------------------------- // Returns a new IntergraphDataset from the created file // -------------------------------------------------------------------- return ( IntergraphDataset * ) GDALOpen( pszFilename, GA_Update ); }