示例#1
0
  CompressWorker(string inputFile, string outputFile, int width, int height)
    : CNCSFile(), imageWidth(width), imageHeight(height)
  {
    // Fill out the band information structure
    NCSFileBandInfo bandInfo[IMAGE_BANDS];
    bandInfo[0].nBits = 8;
    bandInfo[0].bSigned = FALSE;
    bandInfo[0].szDesc = "Red";

    bandInfo[1].nBits = 8;
    bandInfo[1].bSigned = FALSE;
    bandInfo[1].szDesc = "Green";

    bandInfo[2].nBits = 8;
    bandInfo[2].bSigned = FALSE;
    bandInfo[2].szDesc = "Blue";

//     bandInfo[3].nBits = 8;
//     bandInfo[3].bSigned = FALSE;
//     bandInfo[3].szDesc = "Alpha";

    // Fill out the file information structure
    NCSFileViewFileInfoEx fileInfo;
    fileInfo.nSizeX = width;
    fileInfo.nSizeY = height;
    fileInfo.nBands = IMAGE_BANDS;
    fileInfo.nCompressionRate = 20;
    fileInfo.eCellSizeUnits = ECW_CELL_UNITS_METERS;
    fileInfo.fCellIncrementX = 1000;
    fileInfo.fCellIncrementY = 1000;
    fileInfo.fOriginX = 0;
    fileInfo.fOriginY = 0;
    fileInfo.szDatum = "RAW";
    fileInfo.szProjection = "RAW";

    fileInfo.fCWRotationDegrees = 0;
    fileInfo.eColorSpace = NCSCS_sRGB;
    fileInfo.eCellType = NCSCT_UINT8;
    fileInfo.pBands = bandInfo;

    CNCSError error = SetFileInfo(fileInfo);    
    string errorMessage = error.GetErrorMessage();

    // Open file for output
    char* fileNameC = new char[1000];
    strncpy(fileNameC, outputFile.c_str(), 1000);
    NCSError errorCode = Open(fileNameC, false, true);
    if(errorCode != NCS_SUCCESS) {
      string errorMessage = string(FormatErrorText(errorCode));
      cout << "NCS: " << errorMessage << endl;
    }
    delete[] fileNameC;

    // Open the input file
    input = CreateFile(inputFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    inputBuffer = new unsigned char[imageWidth * IMAGE_BANDS];
  }
示例#2
0
INT WINAPI WinMain( HINSTANCE , HINSTANCE, LPSTR , INT )
{
  int imageWidth = 43200;
  int imageHeight = 21600;
  string inputFile = "earth_diffuse_1km_shaded_RGB.raw";
  string outputFile = "earth_diffuse_1km_shaded.ecw";

  cout << "Input file: " << inputFile << " Output file: " << outputFile << endl;

  CNCSFile::SetKeySize();
 
  CompressWorker worker(inputFile, outputFile, imageWidth, imageHeight);
  CNCSError error = worker.Write();
  string errorMessage = error.GetErrorMessage();
}
示例#3
0
CNCSError ECWDEMCompressor::Compress(ImageFormatECWDEM *NewIFECW, RasterBounds *RBounds, char *pDstFile, UINT32 ImgWidth, UINT32 ImgHeight, char Depth, UINT16 nRate)
{
//NCSFileViewFileInfoEx has basic info about the file - dimensions, bands,
//georeferencing information etc.
    NCSFileViewFileInfoEx *pDstInfo = (NCSFileViewFileInfoEx *)NCSMalloc(sizeof(NCSFileViewFileInfoEx), true);
    NCSFileViewFileInfoEx DstInfo = *pDstInfo;
    CNCSError Error;

    IFECW = NewIFECW;
    DstInfo.nSizeX = ImgWidth;
    DstInfo.nSizeY = ImgHeight;
    switch (Depth)
    {
    case 8:
        DstInfo.eCellType = NCSCT_UINT8;
        break;
    case 16:
        DstInfo.eCellType = NCSCT_UINT16;
        break;
    //case 28: DstInfo.eCellType = NCSCT_IEEE4; break;
    case 28:
        DstInfo.eCellType = NCSCT_UINT32;
        break;
    } // switch

    DstInfo.nBands = 1;
    DstInfo.nCompressionRate = nRate;
    DstInfo.eColorSpace = NCSCS_GREYSCALE;

#ifdef WCS_BUILD_VNS
    if (RBounds && RBounds->FetchCoordSys())
    {
        IFECW->CreateECWGeoRefNewAPI(RBounds->FetchCoordSys(), &DstInfo, RBounds);
    } // if
#endif // WCS_BUILD_VNS

//DstInfo.szProjection = "RAW";
//DstInfo.szDatum = "RAW";
//DstInfo.eCellSizeUnits = ECW_CELL_UNITS_METERS;
//DstInfo.fCellIncrementX = 1.0;
//DstInfo.fCellIncrementY = 1.0;
//DstInfo.fOriginX = 0.0;
//DstInfo.fOriginY = 0.0;

    DstInfo.pBands = (NCSFileBandInfo *)(new NCSFileBandInfo[DstInfo.nBands]);
    DstInfo.pBands[0].nBits = Depth;
    DstInfo.pBands[0].bSigned = false;
    DstInfo.pBands[0].szDesc = "Elevation";

//Call SetFileInfo to establish the file information we are going to
//use for compression.  The parameters used are those from the NCSFileViewFileInfoEx
//struct we have populated using metadata derived from our input raster.
    Error = SetFileInfo(DstInfo);
    Error = Open(pDstFile, false, true);
    if (Error == NCS_SUCCESS)
    {
#ifdef WCS_BUILD_JP2BOX_SUPPORT
        JP2UUID3DNBox RangeEquivs(NewIFECW->HighElev, NewIFECW->LowElev, (unsigned long int)NewIFECW->MaxValue, 0);
        AddBox(&RangeEquivs);
#endif // WCS_BUILD_JP2BOX_SUPPORT

        Error = Write();
        if (Error == NCS_SUCCESS)
            fprintf(stdout,"Finished compression\n");
        else if (Error == NCS_USER_CANCELLED_COMPRESSION)
            fprintf(stdout,"Compression cancelled\n");
        else fprintf(stdout,"Error during compression: %s\n",Error.GetErrorMessage());

        Error = Close(true);
    } // if

    return(Error);

} // ECWDEMCompressor::Compress