Exemplo n.º 1
0
BOOL CDIBitmap :: PadBits() {
	if( m_bIsPadded )
		return TRUE;

    // dwAdjust used when bits per pixel spreads over more than 1 byte
    DWORD dwAdjust = 1, dwOffset = 0, dwPadOffset=0;
	BOOL bIsOdd = FALSE;
    
	dwPadOffset = GetBytesPerLine(GetBitsPerPixel(), GetWidth());
	dwOffset = LastByte(GetBitsPerPixel(), GetWidth());

	if( dwPadOffset == dwOffset )
		return TRUE;

    BYTE * pTemp = new BYTE [GetWidth()*dwAdjust];
    if( !pTemp ) {
		TRACE1("CDIBitmap::PadBits(): could not allocate row of width %d.\n", GetWidth());
		return FALSE;
	}
    
    // enough space has already been allocated for the bit array to
    // include the padding, so we just need to shift rows around.
    // This will pad each "row" on a DWORD alignment.

    for( DWORD row = GetHeight()-1 ; row>0 ; --row ) {
	    CopyMemory((void *)pTemp, (const void *)(m_pPixels + (row*dwOffset)), dwOffset );
	    CopyMemory((void *)(m_pPixels + (row*dwPadOffset)), (const void *)pTemp, dwOffset);
	}
    delete [] pTemp;
    
    return TRUE;
}
Exemplo n.º 2
0
BOOL CDIBitmap::UnPadBits() {
	if( ! m_bIsPadded )
		return TRUE;

	DWORD dwAdjust = 1;
	BOOL bIsOdd = FALSE;

	DWORD dwPadOffset = GetBytesPerLine(GetBitsPerPixel(), GetWidth());
	DWORD dwOffset = LastByte(GetBitsPerPixel(), GetWidth());

    BYTE * pTemp = new BYTE [dwOffset];
    if( !pTemp ) {
		TRACE1("CDIBitmap::UnPadBits() could not allocate row of width %d.\n", GetWidth());
		return FALSE;
	}

    // enough space has already been allocated for the bit array to
    // include the padding, so we just need to shift rows around.
    for( DWORD row=1 ; row < DWORD(GetHeight()); ++row ) {
		CopyMemory((void *)pTemp, (const void *)(m_pPixels + row*(dwPadOffset)), dwOffset);
	    CopyMemory((void *)(m_pPixels + (row*dwOffset)), (const void *)pTemp, dwOffset);
	}

    delete [] pTemp;
    
    return TRUE;
}
Exemplo n.º 3
0
    void
    ImageLoader::updateLineArray() {
        unsigned myHeight     = GetHeight();
        unsigned myLineStride = GetBytesPerLine();

        const unsigned char * pBits = _myData->begin();
        for (unsigned i = 0; i < myHeight; ++i) {
            m_pLineArray[i] = (PLBYTE*)pBits; // caution: const leak
            pBits += myLineStride;
        }
    }
Exemplo n.º 4
0
    void
    ImageLoader::loadCubemap(std::vector<asl::Ptr<ReadableBlockHandle> > & theBlocks, unsigned theDepth) {

        for (unsigned i = 0; i < 6; ++i) {
            string myDescription = string("Face")+as_string(i)+"_"+_myFilename;
            ImageLoader myFaceBmp(theBlocks[i], myDescription, _myTextureManager.lock());
            myFaceBmp.ensurePowerOfTwo(IMAGE_RESIZE_SCALE, theDepth);

            if (i == 0) {
                // Setup current image to have 6 times the height of one face
                Create(myFaceBmp.GetWidth(), myFaceBmp.GetHeight() * 6 * theDepth, myFaceBmp.GetPixelFormat(),
                    0, 0, myFaceBmp.GetResolution());
            }

            // Check if new face is compatible with other faces
            if (myFaceBmp.GetBitsPerPixel() != GetBitsPerPixel()) {
                throw ImageLoaderException(string("The cubemap-face: ") + myDescription + " has " +
                    as_string(myFaceBmp.GetBitsPerPixel()) + " but should have " +
                    as_string(GetBitsPerPixel()), PLUS_FILE_LINE);
            }

            if (myFaceBmp.HasAlpha() != HasAlpha()) {
                throw ImageLoaderException(string("The cubemap-face: ") + myDescription + " alpha-flag: " +
                    as_string(myFaceBmp.HasAlpha()) + " but should be: " +
                    as_string(HasAlpha()), PLUS_FILE_LINE);
            }

            if (myFaceBmp.IsGreyscale() != IsGreyscale()) {
                throw ImageLoaderException(string("The cubemap-face: ") + myDescription + " greyscale-flag: " +
                    as_string(myFaceBmp.IsGreyscale()) + " but should be: " +
                    as_string(IsGreyscale()), PLUS_FILE_LINE);
            }

            int myTargetWidth  = GetWidth();
            int myTargetHeight = GetHeight() / 6 / theDepth;
            if (myFaceBmp.GetWidth() != myTargetWidth || myFaceBmp.GetHeight() != myTargetHeight) {
                AC_WARNING << "Resizing bitmap " << myDescription << " to " << myTargetWidth << "x" << myTargetHeight << ".";
                myFaceBmp.ApplyFilter(PLFilterResizeBilinear(myTargetWidth, myTargetHeight));
            }

            // Copy face into destination bitmap
            PLBYTE ** mySrcLines = myFaceBmp.GetLineArray();
            PLBYTE ** myDstLines = GetLineArray();

            unsigned int myFaceHeight = myFaceBmp.GetHeight();
            long myLineSize = GetBytesPerLine();
            for (unsigned int y = 0; y < myFaceHeight; ++y) {
                memcpy(myDstLines[y + myFaceHeight * i], mySrcLines[y], myLineSize);
            }
        }
    }
Exemplo n.º 5
0
void CDebugger::SaveBytesPerLine()
{
	auto memoryView = GetMemoryViewWindow()->GetMemoryView();
	auto bytesPerLine = memoryView->GetBytesPerLine();
	CAppConfig::GetInstance().SetPreferenceInteger(PREF_DEBUGGER_MEMORYVIEW_BYTEWIDTH, bytesPerLine);
}
Exemplo n.º 6
0
Arquivo: c.c Projeto: Aliandrana/cc65
void WriteCFile (const StrBuf* Data, const Collection* A, const Bitmap* B)
/* Write the contents of Data to a file in C format */
{
    FILE*       F;
    const char* D;
    unsigned    Size;


    /* Get the name of the image */
    const StrBuf* S = GetBitmapName (B);

    /* Get the file name */
    const char* Name = NeedAttrVal (A, "name", "write");

    /* Check the number of bytes per line */
    unsigned BytesPerLine = GetBytesPerLine (A);

    /* Get the number base */
    unsigned Base = GetBase (A);

    /* Get the identifier */
    const char* Ident = GetIdentifier (A);

    /* Open the output file */
    F = fopen (Name, "w");
    if (F == 0) {
        Error ("Cannot open output file `%s': %s", Name, strerror (errno));
    }

    /* Write a readable header */
    fprintf (F,
             "/*\n"
             "** This file was generated by %s %s from\n"
             "** %.*s (%ux%u, %u colors%s)\n"
             "*/\n"
             "\n",
             ProgName,
             GetVersionAsString (),
             SB_GetLen (S), SB_GetConstBuf (S),
             GetBitmapWidth (B), GetBitmapHeight (B),
             GetBitmapColors (B),
             BitmapIsIndexed (B)? ", indexed" : "");

    /* If an identifier was given, output #defines for width, height, the
    ** number of colors and declare a variable for the data.
    */
    if (Ident) {
        fprintf (F,
                 "#define %s_COLORS       %u\n"
                 "#define %s_WIDTH        %u\n"
                 "#define %s_HEIGHT       %u\n"
                 "const unsigned char %s[] = {\n",
                 Ident, GetBitmapColors (B),
                 Ident, GetBitmapWidth (B),
                 Ident, GetBitmapHeight (B),
                 Ident);
    }

    /* Write the data */
    D    = SB_GetConstBuf (Data);
    Size = SB_GetLen (Data);
    while (Size) {

        unsigned I;

        /* Output one line */
        unsigned Chunk = Size;
        if (Chunk > BytesPerLine) {
            Chunk = BytesPerLine;
        }
        fputs ("    ", F);
        for (I = 0; I < Chunk; ++I) {
            switch (Base) {
                case 10:
                    fprintf (F, "%u,", *D++ & 0xFF);
                    break;
                case 16:
                    fprintf (F, "0x%02X,", *D++ & 0xFF);
                    break;

            }
        }
        fputc ('\n', F);

        /* Bump the counters */
        Size -= Chunk;
    }

    /* Terminate the array if we had an identifier */
    if (Ident) {
        fputs ("};\n", F);
    }

    /* Close the file */
    if (fclose (F) != 0) {
        Error ("Error closing output file `%s': %s", Name, strerror (errno));
    }
}
Exemplo n.º 7
0
 long
 ImageLoader::GetMemUsed () {
     return GetBytesPerLine() * GetHeight();
 }