Exemple #1
0
void PlayerHistory::SetNextCallback(boost::function<Media ()> callback)
{
  bool init = get_next_.empty();
  get_next_ = callback;
  ResetCache();
  if (init)
  {
    //Force filling out of the current item
    queue_end_++;
    Lookup(current_);
  }
}
HRESULT CImage::GetGray(int nRows, int nCols, int nBand, BYTE* gray)
{
	if(m_pGdalImage==NULL&&m_fpRaws==NULL)
	{
		return S_FALSE;
	}

	if(m_bFlip)
	{
		nRows=m_nRows-nRows-1;
	}

	if(nRows<0||nRows>=m_nRows||nCols<0||nCols>=m_nCols)
	{
		memset(gray,0,m_nBPB);
		return S_OK;
	}
	
	if(nRows<m_nCacheRow0||nRows>=m_nCacheRow1)
	{
		ResetCache(nRows,nCols);
	}

	UINT datatype=ConvertGDALDataType2DataType(m_datatype);
	int nBPB;
	GetBPB(&nBPB);

	if(m_pHistogram==NULL)
	{
		memcpy(gray,
				m_pCache+nBand*m_nCacheBandSize+(nRows-m_nCacheRow0)*m_nCacheScanSize+nCols*m_nBPB,
				m_nBPB);
	}
	else
	{
		*gray=m_pHistogram[nBand].LUT(m_pCache+nBand*m_nCacheBandSize+(nRows-m_nCacheRow0)*m_nCacheScanSize+nCols*m_nBPB,datatype);
	}

	return S_OK;
}
HRESULT CImage::GetPixel(int nRows, int nCols, BYTE* pPixel)
{
	if(m_pGdalImage==NULL&&m_fpRaws==NULL)
	{
		return S_FALSE;
	}

	if(m_bFlip)
	{
		nRows=m_nRows-nRows-1;
	}

	if(nRows<0||nRows>=m_nRows||nCols<0||nCols>=m_nCols)
	{
		memset(pPixel,0,m_nBPB*m_nBandNum);
		return S_OK;
	}

	/*if(m_fpRaws!=NULL)
	{
		if(m_nBandNum==m_nImgNum)
		{
			unsigned int nOffset=(nRows*m_nCols+nCols)*m_nBPB;
			for(int i=0;i<m_nBandNum;i++)
			{
				fseek(m_fpRaws[i],nOffset,SEEK_SET);
				fread(pPixel+i*m_nBPB,m_nBPB,1,m_fpRaws[i]);
			}
		}
		else
		{
			for(int i=0;i<m_nBandNum;i++)
			{
				unsigned int nOffset=(nRows*m_nCols+nCols)*m_nBPB+i*m_nRows*m_nCols*m_nBPB;
				fseek(m_fpRaws[0],nOffset,SEEK_SET);
				fread(pPixel+i*m_nBPB,m_nBPB,1,m_fpRaws[0]);
			}
		}

		return S_OK;
	}
	else if(m_pGdalImage!=NULL)*/
	{
		if(nRows<m_nCacheRow0||nRows>=m_nCacheRow1)
		{
			ResetCache(nRows,nCols);
		}

		UINT datatype=ConvertGDALDataType2DataType(m_datatype);
		int nBPB;
		GetBPB(&nBPB);

		if(m_pHistogram==NULL)
		{
			for(int i=0;i<m_nBandNum;i++)
			{
				memcpy(pPixel+i*m_nBPB,
						m_pCache+i*m_nCacheBandSize+(nRows-m_nCacheRow0)*m_nCacheScanSize+nCols*m_nBPB,
						m_nBPB);
			}
		}
		else
		{
			for(int i=0;i<m_nBandNum;i++)
			{
				pPixel[i]=m_pHistogram[i].LUT(m_pCache+i*m_nCacheBandSize+(nRows-m_nCacheRow0)*m_nCacheScanSize+nCols*m_nBPB,datatype);
			}
		}
		
	}
	
	return S_OK;
}
HRESULT CImage::ReadImgBand(float fSrcLeft, float fSrcTop, float fSrcRight, float fSrcBottom, 
							   BYTE* pBuf, int nBufWidth, int nBufHeight, int nBandNum, 
							   int nDestLeft, int nDestTop, int nDestRight, int nDestBottom, 
							   int nSrcSkip, int nDestSkip)
{
	if(m_bFlip)
	{
		float tempTop=m_nRows-fSrcBottom;
		float tempBottom=m_nRows-fSrcTop;
		fSrcTop=tempTop;
		fSrcBottom=tempBottom;
	}

	if(fSrcBottom-fSrcTop<m_nCacheRow)
	{
		float xScale=(fSrcRight-fSrcLeft)/(nDestRight-nDestLeft);
		float yScale=(fSrcBottom-fSrcTop)/(nDestBottom-nDestTop);
		
		for(int i=nDestTop;i<nDestBottom;i++)
		{
			int nImageRow=(int)((i-nDestTop)*yScale+fSrcTop+0.5);
			if(nImageRow<0||nImageRow>=m_nRows)
			{
				continue;
			}
			if(nImageRow<m_nCacheRow0||nImageRow>=m_nCacheRow1)
			{
				
				ResetCache(nImageRow,0);
			}

			int nRowIndex=i;
			if(m_bFlip)
			{
				nRowIndex=nBufHeight-nRowIndex-1;
			}
			BYTE* pBufIndex=pBuf+nRowIndex*nBufWidth*m_nBPB*nBandNum+nDestSkip*m_nBPB;
			BYTE* pCacheIndex=m_pCache+nSrcSkip*m_nCacheBandSize+(nImageRow-m_nCacheRow0)*m_nCacheScanSize;
			for(int j=nDestLeft;j<nDestRight;j++)
			{
				int nImageCol=(int)((j-nDestLeft)*xScale+fSrcLeft+0.5);
				if(nImageCol<0||nImageCol>=m_nCols)
				{
					continue;
				}
				memcpy(pBufIndex+j*nBandNum*m_nBPB,pCacheIndex+nImageCol*m_nBPB,m_nBPB);
			}
		}
	}
	else
	{
		int band=nSrcSkip+1;
		GDALDataType datatype=m_datatype;
		int nBPB=m_nBPB;

		int offset=nDestSkip*nBPB;
		
		int nLeft=(int)(fSrcLeft+0.5);
		int nTop=(int)(fSrcTop+0.5);
		int nRight=(int)(fSrcRight+0.5);
		int nBottom=(int)(fSrcBottom+0.5);

		int nXOffset=0;
		if(nLeft<0)
		{
			nXOffset=0-nLeft;
			nLeft=0;
		}
		else if(nLeft>=m_nCols)
		{
			return S_OK;
		}
		if(nRight>m_nCols)
		{
			nRight=m_nCols;
		}
		else if(nRight<0)
		{
			return S_OK;
		}
		int nYOffset=0;
		if(nTop<0)
		{
			nYOffset=0-nTop;
			nTop=0;
		}
		else if(nTop>=m_nRows)
		{
			return S_OK;
		}
		if(nBottom>m_nRows)
		{
			nBottom=m_nRows;
		}
		else if(nBottom<0)
		{
			return S_OK;
		}

		int nWidth=nRight-nLeft;
		int nHeight=nBottom-nTop;
		float xscale=(float)nBufWidth/(fSrcRight-fSrcLeft);
		float yscale=(float)nBufHeight/(fSrcBottom-fSrcTop);
		int nTempBufWidth=(int)(nWidth*xscale+0.5);
		int nTempBufHeight=(int)(nHeight*yscale+0.5);
		nXOffset=(int)(nXOffset*xscale+0.5);
		nYOffset=(int)(nYOffset*yscale+0.5);

		BYTE* pTempBuf=new BYTE[nTempBufWidth*nTempBufHeight*nBPB];
		memset(pTempBuf,255,nTempBufWidth*nTempBufHeight*nBPB);

		if(m_pGdalImage!=NULL)
		{
			CPLErr error=((GDALRasterBand*)GDALGetRasterBand(m_pGdalImage,band))->
			RasterIO(GF_Read,
					 nLeft,nTop,
					 nWidth,nHeight,
					 pTempBuf,
					 nTempBufWidth,nTempBufHeight,
					 datatype,
					 0,0);
		}
		else if(m_fpRaws!=NULL)
		{	
			BYTE* pTmp=new BYTE[nWidth*m_nBPB];
			for(int i=0;i<nTempBufHeight;i++)
			{
				unsigned long nOffset=((int)(i/yscale+0.5)+nTop)*m_nCols*m_nBPB;
				BYTE* pTempBufIndex=pTempBuf+i*nTempBufWidth*m_nBPB;

				if(m_nBandNum==m_nImgNum)//seprate
				{
					fseek(m_fpRaws[nSrcSkip],nOffset+((int)(nLeft/xscale+0.5))*m_nBPB,SEEK_SET);
					fread(pTmp,nWidth*m_nBPB,1,m_fpRaws[nSrcSkip]);
				}
				else//bsq
				{
					fseek(m_fpRaws[0],nOffset+((int)(nLeft/xscale+0.5))*m_nBPB+nSrcSkip*m_nRows*m_nCols*m_nBPB,SEEK_SET);
					fread(pTmp,nWidth*m_nBPB,1,m_fpRaws[0]);
				}

				int j=0;
				for(j=0;j<nTempBufWidth;j++)
				{
					//pTempBufIndex[j]=pTmp[(int)(j/xscale+0.5)];
					memcpy(pTempBufIndex+j*m_nBPB,pTmp+(int)(j/xscale+0.5)*m_nBPB,m_nBPB);
				}
			}
			delete [] pTmp;
			pTmp=NULL;
		}
		
		offset=offset+nXOffset*nBPB*nBandNum;
		for(int i=0;i<nTempBufHeight;i++)
		{
			int nRowIndex=i+nYOffset;
			if(m_bFlip)
			{
				nRowIndex=nBufHeight-nRowIndex-1;
			}
			if(nRowIndex>=nBufHeight||nRowIndex<0)
			{
				continue;
			}
			BYTE* pBufIndex=pBuf+nRowIndex*nBufWidth*nBPB*nBandNum;
			BYTE* pTempBufIndex=pTempBuf+i*nTempBufWidth*nBPB;
			for(int j=0;j<nTempBufWidth;j++)
			{
				if(j+nXOffset>=nBufWidth)
				{
					break;
				}
				memcpy(pBufIndex+offset,pTempBufIndex,nBPB);
				pBufIndex=pBufIndex+nBPB*nBandNum;
				pTempBufIndex=pTempBufIndex+nBPB;
			}
		}
		delete [] pTempBuf; pTempBuf=NULL;
	}
	
	return S_OK;
}
Exemple #5
0
/* Set screen bit depth for PalmOS3 */
void SetScreenModeOS3( void )
{
    Err     err;
    UInt16  activeFormID;
    Boolean resolutionChanged;
    Boolean depthChanged;

    if ( screenDepth == Prefs()->screenDepth &&
         screenHiRes == HiResType() )
        return;

    resolutionChanged = false;
    depthChanged      = false;

    /* Since HiResType() is set to unknownHiRes by default, the following two
       if statements will both return true to at least give HiResInitialize()
       the benifit of the doubt and the chance to initialize itself. If it
       cannot, then HiResType() is set to noHiRes, and no further attempts
       are made during the course of this session of the viewer */
    if ( ! IsHiResTypeNone( HiResType() ) ) {
        if ( IsHiResTypeNone( screenHiRes ) ) {
            err = HiResInitialize();
            if ( err == errNone )
                resolutionChanged = true;
            else if ( HiResStop != NULL )
                HiResStop();
        }
    }

    /* By default screenDepth is set to 0 when there aren't any preferences.
       Find the true default at this point instead of later on after falsly
       causing a display error */
    if ( Prefs()->screenDepth == 0 )
        SetDefaultScreenMode( true );

    /* Figure out the best resolution for this device */
    if ( ! forceDefaultScreen ) {
        HiRes hiResType;

        hiResType = HiResType();

        if ( IsHiResTypePalm( hiResType ) ) {
            err = WinScreenGetAttribute( winScreenHeight, &screenHeight );
            if ( err != errNone )
                screenHeight = PALM_SCREEN_HEIGHT;
            err = WinScreenGetAttribute( winScreenWidth, &screenWidth );
            if ( err != errNone )
                screenWidth  = PALM_SCREEN_WIDTH;
        }
        else if ( IsHiResTypeSony( hiResType ) ) {
            screenHeight = SONY_SCREEN_HEIGHT;
            screenWidth  = SONY_SCREEN_WIDTH;
        }
        else if ( IsHiResTypeHandera( hiResType ) ) {
            screenHeight = HANDERA_SCREEN_HEIGHT;
            screenWidth  = HANDERA_SCREEN_WIDTH;
        }
        else {
            screenHeight = NORMAL_SCREEN_HEIGHT;
            screenWidth  = NORMAL_SCREEN_WIDTH;
        }
    }

    /* If we no longer want hires... */
    if ( IsHiResTypeNone( HiResType() ) ) {
        /* ... and are currently in a hires mode, hires needs to be disabled */
        if ( ! IsHiResTypeNone( screenHiRes ) ) {
            if ( HiResStop != NULL )
                HiResStop();
            resolutionChanged = true;
        }
    }

    if ( screenDepth != Prefs()->screenDepth )
        depthChanged = true;

    screenDepth = Prefs()->screenDepth;
    screenHiRes = HiResType();

    MSG( _( "Setting screen to %ldx%ldx%ld\n", screenWidth, screenHeight,
        screenDepth ) );

    /* Handera dislikes being told what to set the values for
       screenWidth and screenHeight, so let it think what it wants */
    if ( IsHiResTypeHandera( HiResType() ) ) {
        err = WinScreenMode( winScreenModeSet, NULL, NULL,
            &screenDepth, NULL );
    }
    else {
        UInt16  prevCoordSys;

        prevCoordSys   = PalmSetCoordinateSystem( NATIVE );
        err = WinScreenMode( winScreenModeSet, &screenWidth, &screenHeight,
                  &screenDepth, NULL );
        if ( err != errNone ) {
            WinScreenMode( winScreenModeGetDefaults, &screenWidth, &screenHeight,
                NULL, NULL );
            err = WinScreenMode( winScreenModeSet, &screenWidth, &screenHeight,
                      &screenDepth, NULL );
        }
        PalmSetCoordinateSystem( prevCoordSys );
    }

    /* If we're having problems, set to hardware's default resolution */
    if ( err != errNone ) {
        MSG( _( "Unsuccessful. Trying 'safe' default values.\n" ) );
        if ( HiResStop != NULL )
            HiResStop();
        screenHiRes = noHiRes;

        SetDefaultScreenMode( true );
        resolutionChanged = true; /* assume it has */
        forceDefaultScreen = true;

        MSG( _( "Setting screen to %ldx%ldx%ld\n", screenWidth, screenHeight,
            screenDepth ) );
    }
    activeFormID = FrmGetActiveFormID();
    if ( IsVisibleToolbar( activeFormID ) ) {
        FrmEraseForm( FrmGetFormPtr( activeFormID ) );
        MainFormInit();
    }

    if ( resolutionChanged ) {
        SetHiResFunctions();
        InitializeViewportBoundaries();
    }

    if ( depthChanged ) {
        HanderaResetSilkScreen();
        ResetCache();
    }
    SetFontFunctions();
}
Exemple #6
0
std::string Authenticity::Assay
    (calendar_date const& candidate
    ,fs::path const&      data_path
    )
{
    // The cached date is valid unless it's the peremptorily-invalid
    // default value of JDN zero.
    if
        (  calendar_date(jdn_t(0)) != Instance().CachedDate_
        && candidate               == Instance().CachedDate_
        )
        {
        return "cached";
        }

    ResetCache();

    std::ostringstream oss;

    // Read the passkey and valid-date-range files each time
    // because they might change while the program is running.
    // They'll be validated against validated md5sums a fraction
    // of a second later, to guard against fraudulent manipulation.

    // Read saved passkey from file.
    std::string passkey;
    {
    fs::path passkey_path(data_path / "passkey");
    fs::ifstream is(passkey_path);
    if(!is)
        {
        oss
            << "Unable to read passkey file '"
            << passkey_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    is >> passkey;
    if(!is.eof())
        {
        oss
            << "Error reading passkey file '"
            << passkey_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    if(passkey.size() != chars_per_formatted_hex_byte * md5len)
        {
        oss
            << "Length of passkey '"
            << passkey
            << "' is "
            << passkey.size()
            << " but should be "
            << chars_per_formatted_hex_byte * md5len
            << ". Try reinstalling."
            ;
        return oss.str();
        }
    }

    // Read valid date range [begin, end) from file.
    calendar_date begin(last_yyyy_date ());
    calendar_date end  (gregorian_epoch());
    {
    fs::path expiry_path(data_path / "expiry");
    fs::ifstream is(expiry_path);
    if(!is)
        {
        oss
            << "Unable to read expiry file '"
            << expiry_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    is >> begin >> end;
    if(!is || !is.eof())
        {
        oss
            << "Error reading expiry file '"
            << expiry_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }
    }

    // Make sure candidate date is within valid range.
    if(candidate < begin)
        {
        oss
            << "Current date "
            << candidate.str()
            << " is invalid: this system cannot be used before "
            << begin.str()
            << ". Contact the home office."
            ;
        return oss.str();
        }
    if(end <= candidate)
        {
        oss
            << "Current date "
            << candidate.str()
            << " is invalid: this system cannot be used after "
            << (-1 + end).str()
            << ". Contact the home office."
            ;
        return oss.str();
        }

    // Validate all data files.
    fs::path original_path(fs::current_path());
    if(0 != chdir(data_path.string().c_str()))
        {
        oss
            << "Unable to change directory to '"
            << data_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }
    try
        {
        system_command("md5sum --check --status " + std::string(md5sum_file()));
        }
    catch(...)
        {
        report_exception();
        oss
            << "At least one required file is missing, altered, or invalid."
            << " Try reinstalling."
            ;
        return oss.str();
        }
    if(0 != chdir(original_path.string().c_str()))
        {
        oss
            << "Unable to restore directory to '"
            << original_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    // The passkey must match the md5 sum of the md5 sum of the file
    // of md5 sums of secured files.

    char c_passkey[md5len];
    unsigned char u_passkey[md5len];
    std::FILE* md5sums_file = std::fopen
        ((data_path / md5sum_file()).string().c_str()
        ,"rb"
        );
    md5_stream(md5sums_file, u_passkey);
    std::fclose(md5sums_file);
    std::memcpy(c_passkey, u_passkey, md5len);
    md5_buffer(c_passkey, md5len, u_passkey);
    std::memcpy(c_passkey, u_passkey, md5len);
    md5_buffer(c_passkey, md5len, u_passkey);
    std::string expected = md5_hex_string
        (std::vector<unsigned char>(u_passkey, u_passkey + md5len)
        );
    if(passkey != expected)
        {
        oss
            << "Passkey is incorrect for this version."
            << " Contact the home office."
            ;
        return oss.str();
        }
    // Cache the validated date.
    Instance().CachedDate_ = candidate;
    return "validated";
}