ossimRefPtr<ossimImageData> ossimHistogramEqualization::runEqualizationAlgorithm(T, ossimRefPtr<ossimImageData> tile) { if(!theAccumulationHistogram || !getHistogram()) { return tile; } // for now we will always pull from res 0 information ossimRefPtr<ossimMultiBandHistogram> histo = getHistogram()->getMultiBandHistogram(0); if(histo.valid()) { ossim_uint32 maxBands = ( (histo->getNumberOfBands() > tile->getNumberOfBands())? tile->getNumberOfBands(): histo->getNumberOfBands()); long offsetUpperBound = tile->getHeight()*tile->getWidth(); for(ossim_uint32 band = 0; band < maxBands; ++band) { ossimRefPtr<ossimHistogram> bandHisto = histo->getHistogram(band); T* buf = static_cast<T*>(tile->getBuf(band)); double *histoLut = band<theForwardLut.size()?theForwardLut[band]:NULL; ossim_uint32 actualBand = theBandList[band]; if(bandHisto.valid()) { if(buf&&histoLut&&(actualBand < histo->getNumberOfBands())) { if(theInverseFlag) { histoLut = theInverseLut[actualBand]; } if(histoLut) { if(tile->getDataObjectStatus() == OSSIM_FULL) { T minPix = (T)tile->getMinPix(actualBand); T maxPix = (T)tile->getMaxPix(actualBand); for(long offset = 0; offset < offsetUpperBound; ++offset) { ossim_int32 idx = bandHisto->GetIndex(buf[offset]); if(idx>=0) { T value = (T)(histoLut[idx]); //--- // Assign clamping to min max. // // ESH 03/2009 -- Clamping to within min-max fixed //--- buf[offset] = value < minPix ? minPix : (value > maxPix ? maxPix : value); } } } else { T minPix = (T)tile->getMinPix(actualBand); T maxPix = (T)tile->getMaxPix(actualBand); T nullPix = (T)tile->getNullPix(actualBand); for(long offset = 0; offset < offsetUpperBound; ++offset) { ossim_int32 idx = bandHisto->GetIndex(buf[offset]); if((buf[offset]!=nullPix)&&(idx>=0)) { T value = (T)(histoLut[idx]); //--- // Assign clamping to min max. // // ESH 03/2009 -- Clamping to within min-max fixed //--- buf[offset] = value < minPix ? minPix : (value > maxPix ? maxPix : value); } else { buf[offset] = nullPix; } } } } } } } tile->validate(); } return tile; }
bool ossimCodecFactory::decodeJpeg( const std::vector<ossim_uint8>& in, ossimRefPtr<ossimImageData>& out ) const { bool result = false; // Note: This is public and can be called directly; hence, the signature check // Check for jpeg signature: if ( in.size() > 3 ) { if ( (in[0] == 0xff) && (in[1] == 0xd8) && (in[2] == 0xff) && (in[3] == 0xe0) ) { /* This struct contains the JPEG decompression parameters and pointers * to working space (which is allocated as needed by the JPEG library). */ jpeg_decompress_struct cinfo; /* We use our private extension JPEG error handler. * Note that this struct must live as long as the main JPEG parameter * struct, to avoid dangling-pointer problems. */ ossimJpegErrorMgr jerr; /* Step 1: allocate and initialize JPEG decompression object */ /* We set up the normal JPEG error routines, then override error_exit. */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = ossimJpegErrorExit; /* Establish the setjmp return context for my_error_exit to use. */ if (setjmp(jerr.setjmp_buffer) == 0) { result = true; /* Now we can initialize the JPEG decompression object. */ jpeg_CreateDecompress(&cinfo, JPEG_LIB_VERSION, sizeof(cinfo)); //--- // Step 2: specify data source. In this case we will uncompress from // memory so we will use "ossimJpegMemorySrc" in place of " jpeg_stdio_src". //--- ossimJpegMemorySrc ( &cinfo, &(in.front()), (size_t)(in.size()) ); /* Step 3: read file parameters with jpeg_read_header() */ jpeg_read_header(&cinfo, TRUE); /* Step 4: set parameters for decompression */ /* In this example, we don't need to change any of the defaults set by * jpeg_read_header(), so we do nothing here. */ /* Step 5: Start decompressor */ jpeg_start_decompress(&cinfo); #if 0 /* Please leave for debug. (drb) */ if ( traceDebug() ) { ossimNotify(ossimNotifyLevel_DEBUG) << "jpeg cinfo.output_width: " << cinfo.output_width << "\njpeg cinfo.output_height: " << cinfo.output_height << "\n"; } #endif const ossim_uint32 SAMPLES = cinfo.output_width; const ossim_uint32 LINES = cinfo.output_height; const ossim_uint32 BANDS = cinfo.output_components; if ( out.valid() ) { // This will resize tile if not correct. out->setImageRectangleAndBands( ossimIrect(0,0,(ossim_int32)SAMPLES-1,(ossim_int32)LINES-1), BANDS ); } else { out = new ossimU8ImageData( 0, BANDS, SAMPLES, LINES ); out->initialize(); } // Get pointers to the cache tile buffers. std::vector<ossim_uint8*> destinationBuffer(BANDS); for (ossim_uint32 band = 0; band < BANDS; ++band) { destinationBuffer[band] = out->getUcharBuf(band); } std::vector<ossim_uint8> lineBuffer(SAMPLES * cinfo.output_components); JSAMPROW jbuf[1]; jbuf[0] = (JSAMPROW) &(lineBuffer.front()); while (cinfo.output_scanline < LINES) { // Read a line from the jpeg file. jpeg_read_scanlines(&cinfo, jbuf, 1); //--- // Copy the line which if band interleaved by pixel the the band // separate buffers. //--- ossim_uint32 index = 0; for (ossim_uint32 sample = 0; sample < SAMPLES; ++sample) { for (ossim_uint32 band = 0; band < BANDS; ++band) { destinationBuffer[band][sample] = lineBuffer[index]; ++index; } } for (ossim_uint32 band = 0; band < BANDS; ++band) { destinationBuffer[band] += SAMPLES; } } // Set the tile status: out->validate(); // clean up... jpeg_finish_decompress(&cinfo); } // Matches: if (setjmp(jerr.setjmp_buffer) == 0) jpeg_destroy_decompress(&cinfo); } // Matches: if ( (in[0] == 0xff) ... ) } // Matches: if ( in.size() > 3 ) return result; }