# Image not rendering correctly on Arduino Giga Display

**URL:** <https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852>\
**Category:** Arduino Boards\
**Created:** [October 17, 2023, 9:10am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852 "2023-10-17T09:10:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 17, 2023, 9:10am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/1 "2023-10-17T09:10:01Z")

</div>

I am trying to display a 800x480 JPEG image loaded from a file on an Arduino Giga Display shield using the code below.

 ![test](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/8/86b6155d51fa8675f2aaf5d98d2ba1b4cdc2ccf5.jpeg)

```auto
import image
import display

lcd = display.DSIDisplay(
    framesize=display.FWVGA, portrait=True, refresh=60, controller=display.ST7701()
)

img = image.Image('test.jpg', copy_to_fb=True)
lcd.write(img)

while True:
    pass

```

It displays a cropped image in the portrait orientation.

 ![test_p_t](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/d/df4482a5627b43e3b052ce9744157a79ef611b9b.jpeg)

If I set the `portrait=False` in the `display.DSIDisplay` initialization it fills the display with 4 pieces of the image.

 ![test_p_f](https://canada1.discourse-cdn.com/flex029/uploads/openmv1/original/2X/1/12290d73f3418bcf559da1d743b3cd78bd9a257c.jpeg)

I can use the following code to transpose the image but it slows down the fps terribly so I wanted to use previous code with correct rendering/orientation.

```auto
img.to_rgb565()
img.replace(transpose=True)

```

---

<div class="post-metadata">

**Author:** ![iabdalkader](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/iabdalkader/32/1169_2.png) [@iabdalkader](https://forums.openmv.io/u/iabdalkader)\
**Post date:** [October 17, 2023, 10:48am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/2 "2023-10-17T10:48:31Z")

</div>

> [@yokonav](#):
>
> `portrait=False` in the `display.DSIDisplay`

This is a flag for the display driver to rotate the display settings/config, you should not change it (it’s a config for the display). This display can’t be rotated it’s 480x800, the only way to display that image is with `img.replace(transpose=True)`

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 17, 2023, 2:35pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/3 "2023-10-17T14:35:55Z")

</div>

Hi, you should reformat the jpeg to the right orientation.

(Unfortunately, since the display is rotated from what you’d want normally the MCU has to do a ton of extra work to display things)

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 18, 2023, 4:21am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/4 "2023-10-18T04:21:06Z")

</div>

Hi @kwagyeman @iabdalkader

Now I am using the code below.

```auto

while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    img.to_rgb565()
    img.replace(transpose=True)
    lcd.write(img)

```

It works but it is slow. I assume `to_rgb565` method uses software jpeg decoder.  
Now I have enabled the hardware jpeg decoder and built the firmware from source.  
The code below works flawlessly and it is considerably fast! I believe this time` lcd.write` method must be using the hardware jpeg decoder.

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    lcd.write(img)

```

But when I include the code for transposing the image (the same code I used with software jpeg decoder), it stalls after a few frames. I checked and found it always stalls at the 4th frame. I tried to skip first few frames (to verify if any frame may have some issue) but it still stalls at the 4th frame wherever I start. How is the data being handled by the ` img.to_rgb565()` and` lcd.write(img)` methods?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 18, 2023, 8:17pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/5 "2023-10-18T20:17:11Z")

</div>

To RGB565 and LCD write do the same thing internally. They decode the jpeg to RGB565. Both use the hardware decoder. All jpeg logic passes through the hardware decoder when enabled.

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    lcd.write(img)

```

So, the above works with the hardware decoder? What code stalls?

There might be bugs in that PR to enable the hardware decoder since it hasn’t been merged.

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 18, 2023, 9:50pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/6 "2023-10-18T21:50:25Z")

</div>

Yes, the code below works with hardware decoder enabled.

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    lcd.write(img)

```

But the code below does not work and stalls at ` img.to_rgb565()` after a few frames.

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    img.to_rgb565()
    img.replace(transpose=True)
    lcd.write(img)

```

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 18, 2023, 10:10pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/7 "2023-10-18T22:10:16Z")

</div>

What does:

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    img.to_rgb565()
    lcd.write(img)

```

Do - I expect it to stall? Both to\_rgb565 and write will use the jpeg decoder to decode the image to RGB565.

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 18, 2023, 10:35pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/8 "2023-10-18T22:35:41Z")

</div>

Yes, the code below also stalls at img.to\_rgb565().

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    img.to_rgb565()
    lcd.write(img)

```

And, this also stalls:

```auto
while True:
    buf = get_jpeg_frame(); # some method to fetch streaming jpeg data frame
    img = image.Image(800, 480, image.JPEG, buffer=buf, copy_to_fb=True)
    img.to_rgb565()

```

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 18, 2023, 11:39pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/9 "2023-10-18T23:39:36Z")

</div>

Okay, will try to look at this and fix the issue. Shouldn’t take long. There’s a lot of issues with the PR I need to address though to actually merge it into main which I can’t tackle right now.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 19, 2023, 12:41am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/10 "2023-10-19T00:41:52Z")

</div>

Hi, can you provide the image file you are using? Also, how did you get the hardware decoder working. Did you branch off my [PR](https://github.com/openmv/openmv/pull/1604) or enable the hardware decoder in jpegd.c that’s already in the firmware?

I remember having to fight a stalling issue in my PR that kept causing the thing to crash. I believe I fixed it in my PR though.

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 19, 2023, 2:44am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/11 "2023-10-19T02:44:43Z")

</div>

Hi @kwagyeman,

I forked the master branch and enabled the hardware decoder in the jpegd.c file.  
I built it using the git Actions for the Arduino Giga R1 only. You can use the firmware from the latest Development Release:

> **[GitHub - metanav/openmv: OpenMV Camera Module](https://github.com/metanav/openmv)**
>
> OpenMV Camera Module. Contribute to metanav/openmv development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 19, 2023, 4:10am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/12 "2023-10-19T04:10:57Z")

</div>

Yeah, okay, I know what the issue you are running is. The jpeg decoder hardware is just locking up. I ran into this myself. In my PR I was able to fix this.

Can you share the image you are using? I need to reproduce.

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 19, 2023, 4:33am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/13 "2023-10-19T04:33:42Z")

</div>

Here is the image file: [https://github.com/metanav/openmv/blob/master/test.jpg](https://github.com/metanav/openmv/blob/master/test.jpg)

You can reproduce it using the code below:

```auto
import image
import display

lcd = display.DSIDisplay(
    framesize=display.FWVGA, portrait=True, refresh=60, controller=display.ST7701()
)

count = 0
while True:
    img = image.Image('test.jpg', copy_to_fb=True)
    img.to_rgb565()
    img.replace(transpose=True)
    lcd.write(img)
    count += 1
    print(count)

```

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 19, 2023, 2:10pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/14 "2023-10-19T14:10:58Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 23, 2023, 9:16am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/15 "2023-10-23T09:16:28Z")

</div>

Hi @kwagyeman

Did you get a chance to merge the PR?

Thanks!

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 23, 2023, 5:30pm UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/16 "2023-10-23T17:30:11Z")

</div>

It’s going to take a while. I might have the changes done this week.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 26, 2023, 12:37am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/17 "2023-10-26T00:37:50Z")

</div>

Hi, I fixed my PR and it’s working. The attached binary should unblock you:

```auto
import image
import display
import time

lcd = display.RGBDisplay()

count = 0
clock = time.clock() # Create a clock object to track the FPS.
while True:
    clock.tick() # Update the FPS clock.
    img = image.Image('test.jpg', copy_to_fb=True)
    #img.to_rgb565()
    #img.replace(transpose=True)
    lcd.write(img)
    count += 1
    print(count)
    print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected

```

This is my code for the OpenMV Cam Pure Thermal which has a screen like the Portenta. I get 46 FPS with the above code, and then 16 FPS if I enable to\_rgb565() and transpose(). to\_rgb565() without transpose is 36 fps. Anyway, the system does not get stuck.

[firmware.zip](https://forums.openmv.io/uploads/short-url/NLOQumZzf973ZWNi5u3LsIaO3j.zip) (1.1 MB)

This firmware is for the Arduino GIGA. It is rebased off main with my PR as of 10/25/2023.

…

I need to refactor quite a few things with this PR before it will be officially merged.

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 26, 2023, 1:48am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/18 "2023-10-26T01:48:33Z")

</div>

Thanks a lot, @kwagyeman! I am going to test it soon.

---

<div class="post-metadata">

**Author:** ![yokonav](https://avatars.discourse-cdn.com/v4/letter/y/87869e/32.png) [@yokonav](https://forums.openmv.io/u/yokonav)\
**Post date:** [October 26, 2023, 5:06am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/19 "2023-10-26T05:06:06Z")

</div>

Hi @kwagyeman,

I’ve tested the firmware you shared and it works really well. Thank you! The problem with the Arduino Giga R1 Display is we need to transpose the image that is a bottleneck now. Can you suggest how to improve the performance of the transpose? Can we use CMSIS DSP matrix transpose methods?

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [October 26, 2023, 6:11am UTC](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852/20 "2023-10-26T06:11:04Z")

</div>

It’s already been speed up. It used to be 5 FPS.

The solution is that you need to not transpose. Rotate the images before you send them to the system. Transpose completely butchers the memory architecture. It’s literally just the processor copying bytes. But, it’s a row access per column. So, it’s extremely inefficient memory wise.

An alternative is for write() to support transpose. This is a todo. It would speed things up by making it able to do this for you. However, I cannot promise a fast ETA on that.

[Next page](https://forums.openmv.io/t/image-not-rendering-correctly-on-arduino-giga-display/8852.md?page=2)
