00001 #include "inmemformat.h" 00002 #include <algorithm> 00003 00004 char* InMemFormat::getMemRect( int iband, 00005 int x, 00006 int y, 00007 int w, 00008 int h, 00009 int nw, 00010 int nh, 00011 ScaleType st ) const { 00012 int ow = mMemBandSet[iband].width; 00013 int oh = mMemBandSet[iband].height; 00014 char *orig = mMemBandSet[iband].data; 00015 00016 scaleData( &orig, x, y, w, h, ow, oh, nw ,nh, 00017 mMemBandSet[iband].dtype, st, false ); 00018 00019 return orig; 00020 } 00021 00022 void InMemFormat::stateToMem( ) { 00023 std::vector<BandInf> &binfset = mEmulateFormat->getBandInfSet(); 00024 std::vector<int> dellist; 00025 00026 for ( int imem=0; imem < (int)mMemBandSet.size(); imem++ ) { 00027 if ( mMemBandSet[imem].iband == mImgState->mRed ) 00028 continue; 00029 00030 if ( mMemBandSet[imem].iband == mImgState->mGreen ) 00031 continue; 00032 00033 if ( mMemBandSet[imem].iband == mImgState->mBlue ) 00034 continue; 00035 00036 dellist.push_back( imem ); 00037 } 00038 00039 int idel; 00040 for ( idel=0; idel < (int)dellist.size(); idel++ ) 00041 delete [] mMemBandSet[dellist[idel]].data; 00042 00043 for ( idel=0; idel < (int)dellist.size(); idel++ ) 00044 mMemBandSet.erase( mMemBandSet.begin() + dellist[idel] ); 00045 00046 if ( !inMemSet( mImgState->mRed ) ) { 00047 MemBandInf bmem; 00048 bmem.iband = mImgState->mRed; 00049 if ( bmem.iband >= 0 ) { 00050 bmem.dtype = binfset[ bmem.iband ].type; 00051 bmem.width = binfset[ bmem.iband ].width; 00052 bmem.height = binfset[ bmem.iband ].height; 00053 bmem.sz_dtype = ImageFormat::dtypeSize( binfset[ bmem.iband ].type ); 00054 bmem.data = (char*)mEmulateFormat->getBand( bmem.iband, 0, 0, bmem.width, 00055 bmem.height, bmem.width, bmem.height ); 00056 mMemBandSet.push_back( bmem ); 00057 } 00058 } 00059 00060 if ( !inMemSet( mImgState->mGreen ) ) { 00061 MemBandInf bmem; 00062 bmem.iband = mImgState->mGreen; 00063 if ( bmem.iband >= 0 ) { 00064 bmem.dtype = binfset[ bmem.iband ].type; 00065 bmem.width = binfset[ bmem.iband ].width; 00066 bmem.height = binfset[ bmem.iband ].height; 00067 bmem.sz_dtype = ImageFormat::dtypeSize( binfset[ bmem.iband ].type ); 00068 bmem.data = (char*)mEmulateFormat->getBand( bmem.iband, 0, 0, bmem.width, 00069 bmem.height, bmem.width, bmem.height ); 00070 mMemBandSet.push_back( bmem ); 00071 } 00072 } 00073 00074 if ( !inMemSet( mImgState->mBlue ) ) { 00075 MemBandInf bmem; 00076 bmem.iband = mImgState->mBlue; 00077 if ( bmem.iband >= 0 ) { 00078 bmem.dtype = binfset[ bmem.iband ].type; 00079 bmem.width = binfset[ bmem.iband ].width; 00080 bmem.height = binfset[ bmem.iband ].height; 00081 bmem.sz_dtype = ImageFormat::dtypeSize( binfset[ bmem.iband ].type ); 00082 bmem.data = (char*)mEmulateFormat->getBand( bmem.iband, 0, 0, bmem.width, 00083 bmem.height, bmem.width, bmem.height ); 00084 mMemBandSet.push_back( bmem ); 00085 } 00086 } 00087 } 00088 00089 void* InMemFormat::getBand( int iband, 00090 int x1, 00091 int y1, 00092 int w1, 00093 int h1, 00094 int w2, 00095 int h2, 00096 ScaleType st ) const { 00097 char *data = NULL; 00098 unsigned int imem; 00099 00100 for ( imem=0; imem < mMemBandSet.size(); imem++ ) { 00101 if ( iband == mMemBandSet[imem].iband ) { 00102 data = getMemRect( imem, x1, y1, w1, h1, w2, h2, st ); 00103 break; 00104 } 00105 } 00106 00107 if ( data == NULL ) 00108 data = (char*)mEmulateFormat->getBand( iband, x1, y1, w1, h1, w2, h2, st ); 00109 00110 return(void*)data; 00111 } 00112 00113 00114 00115 00116
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |