Esempio n. 1
0
PLCLine *PLCContext::getOutputLine(int line)

{
    CPLAssert( outputDS != NULL );
    
    int  i, width = outputDS->GetRasterXSize();
    PLCLine *lineObj = new PLCLine(width);

    for( i=0; i < outputDS->GetRasterCount(); i++ )
    {
        CPLErr eErr;
        GDALRasterBand *band = outputDS->GetRasterBand(i+1);
        
        if( band->GetColorInterpretation() == GCI_AlphaBand )
            eErr = band->RasterIO(GF_Read, 0, line, width, 1, 
                                  lineObj->getAlpha(), width, 1, GDT_Byte,
                                  0, 0);
        else
            eErr = band->RasterIO(GF_Read, 0, line, width, 1, 
                                  lineObj->getBand(i), width, 1, GDT_Int16, 
                                  0, 0);

        if( eErr != CE_None )
            exit(1);
    }

    return lineObj;
}
static void RebuildOutputLineFromSourceMap(PLCContext *plContext,
                                           int line)

{
    PLCLine *lineObj = plContext->getNextOutputLine();
    GByte *dst_alpha = lineObj->getAlpha();
    unsigned int i, iPixel, width=lineObj->getWidth();

    CPLAssert( plContext->line == line );

/* -------------------------------------------------------------------- */
/*      Read the source map for this line.                              */
/* -------------------------------------------------------------------- */
    unsigned short *source = lineObj->getSource();

    CPLErr eErr = plContext->sourceTraceDS->GetRasterBand(1)->RasterIO(
        GF_Read, 0, line, width, 1, 
        source, width, 1, GDT_UInt16, 0, 0);

    if( eErr != CE_None )
        exit( 1 );
    
/* -------------------------------------------------------------------- */
/*      Read inputs.                                                    */
/* -------------------------------------------------------------------- */
    std::vector<PLCLine *> inputLines;

    for(i = 0; i < plContext->inputFiles.size(); i++ )
        inputLines.push_back(plContext->inputFiles[i]->getLine(line));

/* -------------------------------------------------------------------- */
/*      Build output based on source map.                               */
/* -------------------------------------------------------------------- */
    for( iPixel = 0; iPixel < width; iPixel++ )
    {
        if( source[iPixel] == 0 )
            dst_alpha[iPixel] = 0;
        else
        {
            for(int iBand=0; iBand < lineObj->getBandCount(); iBand++)
            {
                float *dst_pixels = lineObj->getBand(iBand);

                dst_pixels[iPixel] = 
                        inputLines[source[iPixel]-1]->getBand(iBand)[iPixel];
            }
            dst_alpha[iPixel] = 255;
        }
    }

/* -------------------------------------------------------------------- */
/*      Write out the image pixels and alpha.                           */
/* -------------------------------------------------------------------- */
    plContext->writeOutputLine(true);
}