Exemplo n.º 1
0
bool CCommonParm::CheckParameters() {
    if (m_strDocDir.empty() && GetSourceType().empty()) {
        m_strError += "No sources";
        return false;
    }

    if ("yarchive" == GetSourceType() && GetSourceFormat() != "html" && GetSourceFormat() != "text")
        ythrow yexception() << "Error: /treat-as must be either \"html\" or \"text\".";

    if ("yarchive" == GetSourceType()) {
        if (GetLastUnloadDocNum() != -1)
            if (GetFirstUnloadDocNum() > GetLastUnloadDocNum() && GetLastUnloadDocNum() != -1) {
                m_strError += "Bad FirstUnloadDocNum is greater than LastUnloadDocNum.";
                return false;
            }
    }

    return true;
}
Exemplo n.º 2
0
/*
==================
Add principal (All other Add use this)
Add main (All public Add use this)
==================
*/
bool IND_SurfaceManager::AddMain	(IND_Surface	*pNewSurface,
                                     IND_Image		*pImage,
                                     int				pBlockSizeX,
                                     int				pBlockSizeY,
                                     IND_Type		pType,
                                     IND_Quality		pQuality)
{
    Debug->Header ("Creating surface", 5);

    if (!mOk || !pNewSurface || !pImage)
    {
        WriteMessage ();
        return 0;
    }

    Debug->Header ("From image:", 3);
    Debug->DataChar (pImage->GetName (), 1);

    Debug->Header ("File name:", 3);
    Debug->DataInt ((int) &pNewSurface->mSurface, 1);

    // Fill attributes
    pNewSurface->mSurface.mAttributes.mType		= pType;
    pNewSurface->mSurface.mAttributes.mQuality  = pQuality;

    // ----- Check IND_Type and IND_Quality of the image and choose a D3D source and destination format -----

    // ----- Source format (Image)------

    int mSrcBpp = pImage->GetBpp () / 8;									// Source bpp
    D3DFORMAT mSrcFormat = GetSourceFormat (pImage);						// D3D Format

    // ----- Destination format (Texture) ------

    D3DFORMAT mDstFormat = GetDestFormat (pNewSurface, pType, pQuality);	// D3D Format

    // ----- Cutting blocks -----

    // ----- Obtaining info in order to store the image -----

    INFO_SURFACE mI;
    mCutter->FillInfoSurface   (pImage, &mI, pBlockSizeX, pBlockSizeY);

    // Fill attributes
    pNewSurface->mSurface.mAttributes.mBlocksX			= mI.mBlocksX;
    pNewSurface->mSurface.mAttributes.mBlocksY			= mI.mBlocksY;
    pNewSurface->mSurface.mAttributes.mSpareX			= mI.mSpareX;
    pNewSurface->mSurface.mAttributes.mSpareY			= mI.mSpareY;
    pNewSurface->mSurface.mAttributes.mNumBlocks		= mI.mBlocksX * mI.mBlocksY;
    pNewSurface->mSurface.mAttributes.mNumTextures		= mI.mBlocksX * mI.mBlocksY;
    pNewSurface->mSurface.mAttributes.mIsHaveGrid		= 0;
    pNewSurface->mSurface.mAttributes.mWidthBlock		= mI.mWidthBlock;
    pNewSurface->mSurface.mAttributes.mHeightBlock		= mI.mHeightBlock;
    pNewSurface->mSurface.mAttributes.mWidth			= mI.mWidthImage;
    pNewSurface->mSurface.mAttributes.mHeight			= mI.mHeightImage;
    pNewSurface->mSurface.mAttributes.mIsHaveSurface	= 1;

    // Allocate space for the vertex buffer
    // This buffer will be used for drawing the IND_Surface using DrawPrimitiveUp
    pNewSurface->mSurface.mVertexArray = new CUSTOMVERTEX2D [mI.mNumVertices];

    // Each block, needs a texture. We use an array of textures in order to store them.
    pNewSurface->mSurface.mTexturesArray = new IND_Surface::TEXTURES [mI.mBlocksX * mI.mBlocksY];

    // Current position of the vertex
    int mPosX = 0;
    int mPosY = mI.mHeightImage;
    int mPosZ = 0;

    // Position in wich we are storing a vertex
    int mPosVer = 0;

    // Position in wich we are storing a texture
    int mCont = 0;

    // Image pointer
    byte *mPtrBlock = pImage->GetPointer ();

    // Vars
    int mActualWidthBlockX;
    int mActualHeightBlockY;
    float mActualU;
    float mActualV;
    int mActualSpareX;
    int mActualSpareY;

    // ----- Cutting blocks -----

    // We iterate the blocks starting from the lower row
    // We MUST draw the blocks in this order, because the image starts drawing from the lower-left corner
    for (int i = mI.mBlocksY; i > 0; i--)
    {
        for (int j = 1; j < mI.mBlocksX + 1; j++)
        {
            // ----- Vertices position of the block -----

            // There are 4 types of blocks: the ones of the right column, the ones of the upper row,
            // the one of the upper-right corner and the rest of blocks.
            // Depending on the block, we store the vertices one way or another.

            // Normal block
            if (i != 1 && j !=  mI.mBlocksX)
            {
                mActualWidthBlockX	= mI.mWidthBlock;
                mActualHeightBlockY	= mI.mHeightBlock;
                mActualU			= 1.0f;
                mActualV			= 1.0f;
                mActualSpareX		= 0;
                mActualSpareY		= 0;
            }

            // The ones of the right column
            if (i != 1 && j ==  mI.mBlocksX)
            {
                mActualWidthBlockX	= mI.mWidthSpareImage;
                mActualHeightBlockY	= mI.mHeightBlock;
                mActualU			= (float) mI.mWidthSpareImage / mI.mWidthBlock;
                mActualV			= 1.0f;
                mActualSpareX		= mI.mSpareX;
                mActualSpareY		= 0;
            }

            // The ones of the upper row
            if (i == 1 && j !=  mI.mBlocksX)
            {
                mActualWidthBlockX	= mI.mWidthBlock;
                mActualHeightBlockY	= mI.mHeightSpareImage;
                mActualU			= 1.0f;
                mActualV			= (float) mI.mHeightSpareImage / mI.mHeightBlock;
                mActualSpareX		= 0;
                mActualSpareY		= mI.mSpareY;
            }

            // The one of the upper-right corner
            if (i == 1 && j ==  mI.mBlocksX)
            {
                mActualWidthBlockX	= mI.mWidthSpareImage;
                mActualHeightBlockY	= mI.mHeightSpareImage;
                mActualU			= (float) mI.mWidthSpareImage / mI.mWidthBlock;
                mActualV			= (float) mI.mHeightSpareImage / mI.mHeightBlock;
                mActualSpareX		= mI.mSpareX;
                mActualSpareY		= mI.mSpareY;
            }

            // ----- Block creation (using the position, uv coordiantes and texture) -----

            // We push into the buffer the 4 vertices of the block
            Push4Vertices  (pNewSurface->mSurface.mVertexArray,			// Pointer to the buffer
                            mPosVer,									// Position in wich we are storing a vertex
                            mPosX,										// x
                            mPosY,										// y
                            mPosZ,										// z
                            mActualWidthBlockX,							// Block width
                            mActualHeightBlockY,						// Block height
                            mActualU,									// U mapping coordinate
                            mActualV);									// V mapping coordinate

            // Cuts a block from the image (bitmap)
            byte *mTempBlock = 0;
            mCutter->CutBlock  (mPtrBlock,
                                mI.mWidthImage,
                                mI.mWidthBlock,
                                mI.mHeightBlock,
                                mActualSpareX,
                                mActualSpareY,
                                mSrcBpp,
                                &mTempBlock);

            // We create a texture using the cutted bitmap block
            pNewSurface->mSurface.mTexturesArray [mCont].mTexture = CreateTexture (	mTempBlock,
                    mI.mWidthBlock,
                    mI.mHeightBlock,
                    mSrcBpp,
                    mSrcFormat,
                    mDstFormat);

            // Free the bitmap cutted block
            DisposeArray (mTempBlock);

            // ----- Advance -----

            // Increase in 4 vertices the position (we have already stored a quad)
            mPosVer += 4;

            // Increase the texture counter (we have alread stored one texture)
            mCont++;

            // ----- Column change -----

            // We point to the next block (memory and screen)
            mPosX += mI.mWidthBlock;
            mPtrBlock += mI.mWidthBlock * mSrcBpp;
        }

        // ----- Row change -----

        // We point to the next block  (memory and screen)
        mPosX = 0;
        mPtrBlock -= mI.mSpareX * mSrcBpp;

        // If this block is in the last row, we take in count the spare areas.
        if (i == 1)
        {
            mPosY -= mI.mSpareY;
            mPtrBlock += (mI.mWidthImage * mSrcBpp) * (mI.mSpareY - 1);
        }
        else
        {
            mPosY -= mI.mHeightBlock;
            mPtrBlock += (mI.mWidthImage * mSrcBpp) * (mI.mHeightBlock - 1);
        }
    }

    // ----- Puts the objet into the manager  -----

    AddToList (pNewSurface);

    // ----- Debug -----


    Debug->Header ("Type:", 3);
    Debug->DataChar (pNewSurface->GetTypeChar (), 1);

    Debug->Header ("Quality:", 3);
    Debug->DataChar (pNewSurface->GetQualityChar (), 1);

    Debug->Header ("Image size:", 3);
    Debug->DataInt (mI.mWidthImage, 0);
    Debug->DataChar ("x", 0);
    Debug->DataInt (mI.mHeightImage, 1);

    Debug->Header ("Block size:", 3);
    Debug->DataInt (mI.mWidthBlock, 0);
    Debug->DataChar ("x", 0);
    Debug->DataInt (mI.mHeightBlock, 1);

    Debug->Header ("Number of blocks:", 3);
    Debug->DataInt (mI.mBlocksX, 0);
    Debug->DataChar ("x", 0);
    Debug->DataInt (mI.mBlocksY, 1);

    Debug->Header ("Spare (Right | Down):", 3);
    Debug->DataInt (mI.mSpareX, 0);
    Debug->DataChar ("x", 0);
    Debug->DataInt (mI.mSpareY, 1);

    Debug->Header ("Not used percentage:", 3);
    Debug->DataFloat (mI.mNotUsedProportion, 0);
    Debug->DataChar ("%", 1);

    Debug->Header("Surface created", 6);

    return 1;
}