BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: Image corruption  (Read 12272 times)

T.Pierret

  • Newbie
  • *
  • Posts: 22
    • View Profile
Image corruption
« on: June 23, 2020, 08:36:57 AM »

Hi,

I wrote a small application for tests of an EVE-controlled screen. The result was not too bad till I added a splash screen as a JPEG image. Afterwards all the icons just changed to garbage.
I'm doing something wrong !
Here is the canvas :
1°/ Load the JPEG image for the splash screen
Code: [Select]
uint16_t sentSize = 0u, len;
const uint16_t MaxLen = 512u;

cmdOffset = ft_wait4CoproReady()
ft_write32( RAM_CMD + cmdOffset, CMD_LOADIMAGE );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, RAM_G );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, OPT_NODL );
ft_incCmdOffset( 4u );
while ( sentSize < splash.data_size )
{
  len = splash.data_size - sentSize;
  if ( len > MaxLen ) len = MaxLen;
  /* Wait for space to write the next chunk */
  while ( !ft_checkFreeSpaceInFifo( len ) );
  ft_writeMem( RAM_CMD + cmdOffset, &splash.data[sentSize], len );
  ft_incCmdOffset( len );
  sentSize += len;
  ft_write16( REG_CMD_WRITE, cmdOffset );
}

2°/ Display the JPEG image
Code: [Select]
cmdOffset = ft_wait4CoproReady()
ft_write32( RAM_CMD + cmdOffset, CMD_DLSTART );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, SAVE_CONTEXT() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CMD_SETBITMAP );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, RAM_G );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset,
                    (((uint32_t) splash.width << 16) | ((uint32_t) RGB565 & 0xFFFFU)) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, (uint32_t) splash.height );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, BEGIN(BITMAPS) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, VERTEX2II(0, 0, 0, 0) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, END() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, RESTORE_CONTEXT() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, DISPLAY() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CMD_SWAP );
ft_incCmdOffset( 4u );
ft_write16( REG_CMD_WRITE, cmdOffset );

3°/ Load the icon (compressed ARGB2 image):
Code: [Select]
address = RAM_G + ( (uint32_t) splash.width * (uint32_t) splash.height * 2U );
cmdOffset = ft_wait4CoproReady()
ft_write32( RAM_CMD + cmdOffset, CMD_INFLATE );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, address );
ft_incCmdOffset( 4u );
while ( sentSize < icon.data_size )
{
  len = icon.data_size - sentSize;
  if ( len > MaxLen ) len = MaxLen;
  /* Wait for space to write the next chunk */
  while ( !ft_checkFreeSpaceInFifo( len ) );
  ft_writeMem( RAM_CMD + cmdOffset, &icon.data[sentSize], len );
  ft_incCmdOffset( len );
  sentSize += len;
  ft_write16( REG_CMD_WRITE, cmdOffset );
}
ft_wait4CoproReady();
ft_write32( RAM_CMD + cmdOffset, CMD_GETPTR );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, 0U );
ft_incCmdOffset( 4u );
ft_write16( REG_CMD_WRITE, cmdOffset );
ft_read32( RAM_CMD + cmdOffset - 4U, &address);

4°/ Display the icon:
Code: [Select]
ft_wait4CoproReady();
ft_write32( RAM_CMD + cmdOffset, CMD_DLSTART );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CLEAR_COLOR_RGB(10, 10, 60) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CLEAR(1 ,1 ,1) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, SAVE_CONTEXT() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, BITMAP_SOURCE( address ) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, BITMAP_LAYOUT( ARGB2, icon.stride, icon.height ) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, BITMAP_SIZE( NEAREST, BORDER, BORDER, icon.width, icon.height ) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, BEGIN( BITMAPS ) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, VERTEX2F( x * 16, y * 16 ) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, END() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, DISPLAY() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CMD_SWAP );
ft_incCmdOffset( 4u );
ft_write16( REG_CMD_WRITE, cmdOffset );

If the step 2 (display splash) is not executed, the icon is correctly display. If displayed, the icon is changed into garbage.

Could someone explain this behaviour ?

Thanks in advance.
Regards.
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 745
    • View Profile
Re: Image corruption
« Reply #1 on: June 23, 2020, 09:22:18 AM »

Hi,

Your code 2 is missing a clear (1,1,1) which could cause issues.

In general, each new screen should begin with a clear (1,1,1)     (and in most cases you may wish to set clear_color_rgb first too)

And should end with a display and a swap.


Code: [Select]
cmdOffset = ft_wait4CoproReady()
ft_write32( RAM_CMD + cmdOffset, CMD_DLSTART );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CLEAR_COLOR_RGB(10, 10, 60) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CLEAR(1 ,1 ,1) );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CMD_DLSTART );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, SAVE_CONTEXT() );
ft_incCmdOffset( 4u );
ft_write32( RAM_CMD + cmdOffset, CMD_SETBITMAP );
.....


Also, bear in mind that large full screen images can be large and may take most of the RAM_G. However, after the application starts (and assuming you don't want the splash screen after that) you can load more things into the same area and overwrite it.

Best Regards, BRT Community
Logged

pauljiao

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Image corruption
« Reply #2 on: June 23, 2020, 09:32:28 AM »

Several comments:
1)  is the JPEG image displayed correctly before the icon is shown?
2)  Suggest to use cmd_setbitmap at 4th step (Display Icon) because it will take care of bitmap_layout_h/bitmap_size_h, which was generated in JPEG image loading.  If not, better send
bitmap_layout_h and bitmap_size_h with bitmap_layout and bitmap_size commands.  Otherwsise,
it may have issues if these commands have affected the graphics context.
Logged

T.Pierret

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Image corruption
« Reply #3 on: June 23, 2020, 11:38:34 AM »

Hi,

Thanks for the answers.

Quote
Your code 2 is missing a clear (1,1,1) which could cause issues.
Ok. I addedd the 2 statements, but this does not change the behaviour. The JPEG image is always well displayed (splash) and then the icon (where the statements were already present) are corrupted.

Quote
is the JPEG image displayed correctly before the icon is shown?
Yes.
Quote
Suggest to use cmd_setbitmap at 4th step
This solved the issue ! Many thanks.
For my knowledge:
1/ what is the role of those commands ?
2/ in the documentation, they are viewed as extension commands for large images. In the current case, the splash image is 800x480 and the icons, 80x80. Why are they requested however ?

Many thanks again for your support.
Best regards
Logged

pauljiao

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Image corruption
« Reply #4 on: June 24, 2020, 03:39:07 AM »

T.Pierret, Glad to know your issue is fixed.

The coprocessor command cmd_setbitmap is just to generate a series of display list for graphics engine:
Code: [Select]
bitmap_source()
bitmap_layout()
bitmap_layout_h
bitmap_size
bitmap_size_h
bitmap_ext_format (if required)



Quote
In the current case, the splash image is 800x480 and the icons, 80x80. Why are they requested however?

The bitmap_size_h/bitmap_layout_h set by splash image(larger image) changed the graphics context and it kept effective until it is changed by the following display list. I think it may cause the issue of displaying smaller icon.
Logged

T.Pierret

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Image corruption
« Reply #5 on: June 25, 2020, 07:39:15 AM »

Many thanks again for your support !
Logged