HRESULT CLR_GFX_Bitmap::CreateInstanceBmp( CLR_RT_HeapBlock& ref, const CLR_UINT8* data, const CLR_UINT32 size )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    TINYCLR_HEADER();

    CLR_GFX_Bitmap*           bitmap    = NULL;
    CLR_GFX_BitmapDescription bm;
    BmpDecoder                decoder;

    TINYCLR_CHECK_HRESULT(decoder.BmpInitOutput( data, size ));

    if(bm.BitmapDescription_Initialize( decoder.width, decoder.height, CLR_GFX_BitmapDescription::c_NativeBpp ) == false)
    {
        // Failed if width / height / size is not within spec.
        TINYCLR_SET_AND_LEAVE(CLR_E_FAIL);
    }

    // Allocate the memory that the decoded bitmap would need
    TINYCLR_CHECK_HRESULT(CLR_GFX_Bitmap::CreateInstance( ref, bm ));

    TINYCLR_CHECK_HRESULT(CLR_GFX_Bitmap::GetInstanceFromHeapBlock (ref, bitmap));

    TINYCLR_CHECK_HRESULT(decoder.BmpStartOutput( bitmap ));
    
    TINYCLR_NOCLEANUP();
}
Пример #2
0
CLR_UINT32 CLR_GFX_FontDescription::GetCharacterSize() const
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    // We need the sentinel character at the end to ensure proper width caclulation. 
    // (char width is determined by the difference of the subsequent offset and the current one)
    return sizeof(CLR_GFX_FontCharacter) * (m_characters + 1);
}
Пример #3
0
void CLR_GFX_Font::RelocationHandler( CLR_RT_HeapBlock_BinaryBlob* ptr )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    CLR_GFX_Font* pThis = (CLR_GFX_Font*)ptr->GetData();

    pThis->Relocate();
}
Пример #4
0
void JPEGErrorHandler( j_common_ptr cinfo )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    JPEGErrorManager* errorManager = (JPEGErrorManager*) cinfo->err;
#if 0
    longjmp((long long *)errorManager->setjmpBuffer, 1);
#else
    longjmp(errorManager->setjmpBuffer, 1);
#endif
}
Пример #5
0
void CLR_GFX_Font::Relocate()
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_ranges                  );
    CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_chars                   );
    CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_rangesEx                );
    CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_charsEx                 );
    CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_antiAliasingData        );
    CLR_RT_GarbageCollector::Heap_Relocate( (void**)&m_bitmap.m_palBitmap.data );
}
Пример #6
0
CLR_UINT32 CLR_GFX_FontDescription::GetCharacterExSize() const
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    CLR_UINT32 size = 0;

    if(m_flags & c_FontEx)
    {
        size = ROUNDTOMULTIPLE(sizeof(CLR_GFX_FontCharacterEx) * (m_characters), CLR_UINT32);
    }

    return size;
}
Пример #7
0
HRESULT CLR_GFX_Font::CreateInstance( CLR_RT_HeapBlock& ref, const CLR_UINT8* data, CLR_RT_Assembly* assm )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    TINYCLR_HEADER();

    CLR_RT_HeapBlock_BinaryBlob*     blob;
    CLR_GFX_Font*                    font;
    const CLR_GFX_FontDescription*   fd;
    const CLR_GFX_BitmapDescription* bm;

    fd         = (const CLR_GFX_FontDescription*  )data; data += sizeof(CLR_GFX_FontDescription  );
    bm         = (const CLR_GFX_BitmapDescription*)data; data += sizeof(CLR_GFX_BitmapDescription);

    TINYCLR_CHECK_HRESULT(CLR_RT_HeapBlock_BinaryBlob::CreateInstance( ref, sizeof(CLR_GFX_Font), NULL, CLR_GFX_Font::RelocationHandler, CLR_RT_HeapBlock::HB_CompactOnFailure ));

    blob = ref.DereferenceBinaryBlob();
    font = (CLR_GFX_Font*)blob->GetData();

    font->m_font                   = *fd;
    font->m_bitmap.m_bm            = *bm;
    font->m_fontEx.m_antiAliasSize = 0;

    font->Font_Initialize();

    font->m_ranges        = (CLR_GFX_FontCharacterRange*)data; data += fd->GetRangeSize();
    font->m_chars         = (     CLR_GFX_FontCharacter*)data; data += fd->GetCharacterSize();
    font->m_bitmap.m_palBitmap.data = (      CLR_UINT32*)data; data += bm->GetTotalSize();

    font->m_bitmap.m_bm.m_flags |= CLR_GFX_BitmapDescription::c_ReadOnly;

    if(fd->m_flags & CLR_GFX_FontDescription::c_FontEx)
    {       
        font->m_fontEx           = *(( const CLR_GFX_FontDescriptionEx*)data); data += sizeof(CLR_GFX_FontDescriptionEx);
        font->m_rangesEx         =  (     CLR_GFX_FontCharacterRangeEx*)data; data += fd->GetRangeExSize();
        font->m_charsEx          =  (          CLR_GFX_FontCharacterEx*)data; data += fd->GetCharacterExSize();
        font->m_antiAliasingData =  (                        CLR_UINT8*)data; data += font->m_fontEx.GetAntiAliasSize();
    }

    blob->m_assembly = assm;

    font->GetCharInfo( c_UnicodeReplacementCharacter, font->m_defaultChar );

    TINYCLR_NOCLEANUP();
}
Пример #8
0
void CLR_GFX_Font::Font_Initialize()
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    CLR_UINT8* buf = (CLR_UINT8*)&this[ 1 ];

    m_bitmap.Bitmap_Initialize();

    m_ranges        = (CLR_GFX_FontCharacterRange*)buf; buf += m_font.GetRangeSize    ();
    m_chars         = (CLR_GFX_FontCharacter*     )buf; buf += m_font.GetCharacterSize();
    
    if(m_font.m_flags & CLR_GFX_FontDescription::c_FontEx)
    {
        m_rangesEx = (CLR_GFX_FontCharacterRangeEx*)buf; buf += m_font.GetRangeExSize();
        m_charsEx  = (     CLR_GFX_FontCharacterEx*)buf; buf += m_font.GetCharacterExSize();    
        m_antiAliasingData =                        buf; buf += m_fontEx.GetAntiAliasSize();
    }
    
    m_bitmap.m_palBitmap.data = (CLR_UINT32*)buf; 
}
Пример #9
0
//--//
int CLR_GFX_Font::StringOut( LPCSTR str, int maxChars, CLR_INT32 kerning, CLR_GFX_Bitmap* bm, int xPos, int yPos, CLR_UINT32 color )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    CLR_RT_UnicodeHelper      uh; uh.SetInputUTF8( str );
    CLR_UINT16                buf[ 3 ];    
    CLR_UINT32                nTotWidth = 0;
    CLR_GFX_FontCharacterInfo chr;

    yPos += m_font.m_metrics.m_offset;

    while(maxChars-- != 0)
    {
        uh.m_outputUTF16      = buf;
        uh.m_outputUTF16_size = MAXSTRLEN(buf);

        if(uh.ConvertFromUTF8( 1, false ) == false) break;

        CLR_UINT16             c   = buf[ 0 ];
        
        GetCharInfo( c, chr );

        if(chr.isValid)
        {
            //It doesn't look like we support kerning??
            _ASSERTE(c_DefaultKerning == kerning);

            int nOffset = ((nTotWidth + (chr.width+1)/2) * kerning / c_DefaultKerning) - (chr.width+1)/2;

            nTotWidth = nOffset + chr.width;

            if(bm)
            {
                DrawChar( bm, chr, xPos + chr.marginLeft + nOffset, yPos, color );
            }                
        }
    }

    return xPos + nTotWidth;
}
Пример #10
0
HRESULT CLR_GFX_Bitmap::CreateInstanceGif( CLR_RT_HeapBlock& ref, const CLR_UINT8* data, const CLR_UINT32 size )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    TINYCLR_HEADER();

    GifDecoder*               decoder;
    CLR_GFX_Bitmap*           bitmap   = NULL;
    CLR_GFX_BitmapDescription bm;

    // Allocate the decoder
    decoder = (GifDecoder*)CLR_RT_Memory::Allocate( sizeof(GifDecoder) );  CHECK_ALLOCATION(decoder);

    // Initialize the decompression engine
    TINYCLR_CHECK_HRESULT( decoder->GifInitDecompress( data, size ) );

    // At this point decoder would have all the correct output dimension info, so we initialized the CLR_GFX_BitmapDescription
    // with that information, note that we currently only support decompression into the native bpp
    if(bm.BitmapDescription_Initialize( decoder->header.LogicScreenWidth, decoder->header.LogicScreenHeight, CLR_GFX_BitmapDescription::c_NativeBpp ) == false)
    {
        // if the resulting bitmap doesn't match our constraints, stop the decompression
        TINYCLR_SET_AND_LEAVE(CLR_E_INVALID_PARAMETER);
    }

    // Allocate the memory that the decompressed bitmap would need
    TINYCLR_CHECK_HRESULT(CLR_GFX_Bitmap::CreateInstance( ref, bm ));

    TINYCLR_CHECK_HRESULT(CLR_GFX_Bitmap::GetInstanceFromHeapBlock (ref, bitmap));

    TINYCLR_CHECK_HRESULT(decoder->GifStartDecompress( bitmap ));

    TINYCLR_CLEANUP();

    if (decoder) CLR_RT_Memory::Release( decoder );

    TINYCLR_CLEANUP_END();
}
Пример #11
0
HRESULT CLR_GFX_Bitmap::CreateInstanceJpeg( CLR_RT_HeapBlock& ref, const CLR_UINT8* data, const CLR_UINT32 size )
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    TINYCLR_HEADER();

    jpeg_decompress_struct        cinfo;
    CLR_GFX_Bitmap*               bitmap = NULL;
    CreateInstanceJpegHelperParam param;
    GFX_Rect                      rect;

    param.curBuffer = NULL;

    // Set up the error handling
    JPEGErrorManager errorManager;
    cinfo.err                   = jpeg_std_error( &errorManager.pub );
    errorManager.pub.error_exit = JPEGErrorHandler;

#if 0
    if(setjmp( (long long *)errorManager.setjmpBuffer ))
#else
    if(setjmp(errorManager.setjmpBuffer ))
#endif
    {
        if (cinfo.err->msg_code == JERR_OUT_OF_MEMORY)
        {
            TINYCLR_SET_AND_LEAVE( CLR_E_OUT_OF_MEMORY );
        }
        else
        {
            TINYCLR_SET_AND_LEAVE( CLR_E_FAIL );
        }
    }

    // Create the decompression engine
    jpeg_create_decompress( &cinfo );
    jpeg_byte_array_src   ( &cinfo, (UINT8*)data, size );
    jpeg_read_header      ( &cinfo, TRUE );

    // Set output to 16bit 5-6-5 RGB format
    // We can add support for other bit-depth in the future
    cinfo.out_color_space     = JCS_RGB;
    cinfo.do_fancy_upsampling = FALSE;

    jpeg_start_decompress( &cinfo );

    // At this point cinfo would have all the correct output dimension info
    CLR_GFX_BitmapDescription bm;
    if(bm.BitmapDescription_Initialize( cinfo.output_width, cinfo.output_height, CLR_GFX_BitmapDescription::c_NativeBpp ) == false)
    {
        // if the resulting bitmap doesn't match our constraints, stop the decompression
        TINYCLR_SET_AND_LEAVE( CLR_E_INVALID_PARAMETER );
    }

    // Allocate the memory that the decompressed bitmap would need
    TINYCLR_CHECK_HRESULT(CLR_GFX_Bitmap::CreateInstance( ref, bm ));

    TINYCLR_CHECK_HRESULT(CLR_GFX_Bitmap::GetInstanceFromHeapBlock (ref, bitmap));

    // Do the actual decompression
    rect.left = 0;
    rect.top = 0;
    rect.right = cinfo.output_width - 1;
    rect.bottom = cinfo.output_height - 1;

    param.curBuffer = (CLR_UINT8*)CLR_RT_Memory::Allocate( cinfo.output_width * 3 );
    CHECK_ALLOCATION(param.curBuffer);
    param.buffer    = (JSAMPARRAY)&(param.curBuffer);
    param.cinfo     = &cinfo;

    bitmap->SetPixelsHelper( rect, PAL_GFX_Bitmap::c_SetPixelsConfig_NoClip | PAL_GFX_Bitmap::c_SetPixelsConfig_NoClipChecks, &CreateInstanceJpegHelper, &param );

    TINYCLR_CLEANUP();

    if (param.curBuffer) CLR_RT_Memory::Release( param.curBuffer );
    jpeg_destroy_decompress( &cinfo );

    TINYCLR_CLEANUP_END();
}
Пример #12
0
CLR_UINT32 CLR_GFX_FontDescriptionEx::GetAntiAliasSize() const
{
    NATIVE_PROFILE_CLR_GRAPHICS();
    return ROUNDTOMULTIPLE(m_antiAliasSize, CLR_UINT32);
}