Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(draw): use image area to check if decoded image usable #4948

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

XuNeo
Copy link
Collaborator

@XuNeo XuNeo commented Dec 6, 2023

Description of the feature or fix

Fix #4838
When using get_area_cb, need to detect if the decoded image is ready to be used again(normally no).

I thought _lv_area_is_in should be used to check decoded image fully covers the area to draw, but test show area to draw may larger than image.

Thus use _lv_area_intersect instead.

Now I have firstly intersect areas with full image, and then check if area to draw is inside decoded image area.

Checkpoints

Be sure the following conventions are followed:

  • Follow the Styling guide
  • Prefer enums instead of macros. If inevitable to use defines export them with LV_EXPORT_CONST_INT(defined_value) right after the define.
  • In function arguments prefer type name[] declaration for array parameters instead of type * name
  • Use typed pointers instead of void * pointers
  • Do not malloc into a static or global variables. Instead declare the variable in lv_global_t structure in lv_global.h and mark the variable with (LV_GLOBAL_DEFAULT()->variable) when it's used. See a detailed description here.
  • Widget constructor must follow the lv_<widget_name>_create(lv_obj_t * parent) pattern.
  • Widget members function must start with lv_<module_name> and should receive lv_obj_t * as first argument which is a pointer to widget object itself.
  • structs should be used via an API and not modified directly via their elements.
  • struct APIs should follow the widgets' conventions. That is to receive a pointer to the struct as the first argument, and the prefix of the struct name should be used as the prefix of the function name too (e.g. lv_disp_set_default(lv_disp_t * disp))
  • Functions and structs which are not part of the public API must begin with underscore in order to mark them as "private".
  • Arguments must be named in H files too.
  • To register and use callbacks one of the following needs to be followed (see a detailed description here):
    • For both the registration function and the callback pass a pointer to a struct as the first argument. The struct must contain void * user_data field.
    • The last argument of the registration function must be void * user_data and the same user_data needs to be passed as the last argument of the callback.
    • Callback types not following these conventions should end with xcb_t.

@XuNeo XuNeo marked this pull request as draft December 6, 2023 16:03
@XuNeo XuNeo force-pushed the fix-bar-code-get-area-cb branch from 0528328 to 4393793 Compare December 6, 2023 16:34
@XuNeo XuNeo marked this pull request as ready for review December 6, 2023 16:36
@kisvegabor
Copy link
Member

It depends on #4833, right?

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 7, 2023

Yes. Only with draw_buf for decoded image, we can get info of decoded image.
Could you please review if the method works? Why the area to draw could be larger than image itself?

4393793#diff-242f305692436f289db7b3cdda6298157b9ab35835506b88b28a86b1524051abR266-R274

@kisvegabor
Copy link
Member

Can you send a code snippet in which the are to draw is really larger than the image area?

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 9, 2023

The barcode could be used to reproduce it. Do change LV_BIN_DECODER_RAM_LOAD to 0 to test it.

Comment out this line 274 4393793#diff-242f305692436f289db7b3cdda6298157b9ab35835506b88b28a86b1524051abR274
and you will see logs to report area not ready.

void test_barcode_normal(void)
{
    lv_obj_t * barcode = lv_barcode_create(lv_scr_act());
    lv_obj_center(barcode);

    lv_color_t dark_color = lv_color_black();
    lv_color_t light_color = lv_color_white();
    uint16_t scale = 2;

    lv_barcode_set_dark_color(barcode, dark_color);
    lv_barcode_set_light_color(barcode, light_color);
    lv_barcode_set_scale(barcode, scale);

    lv_result_t res;
    lv_image_dsc_t * image_dsc;
    lv_barcode_set_direction(barcode, LV_DIR_HOR);
    res = lv_barcode_update(barcode, "https://lvgl.io");
    image_dsc = lv_canvas_get_image(barcode);

    lv_obj_set_size(barcode, image_dsc->header.w, 50);

    lv_barcode_set_direction(barcode, LV_DIR_VER);
    res = lv_barcode_update(barcode, "https://lvgl.io");

    image_dsc = lv_canvas_get_image(barcode);

    lv_obj_set_size(barcode, 50, image_dsc->header.h);

}

@kisvegabor
Copy link
Member

I think there is an other issue here as well.

The barcode with LV_COLOR_DEPTH 32 and LV_BIN_DECODER_RAM_LOAD 0 looks like this:

image

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 11, 2023

The barcode with LV_COLOR_DEPTH 32 and LV_BIN_DECODER_RAM_LOAD 0 looks like this:

Could you try with LV_BIN_DECODER_RAM_LOAD to 1 and check out code XuNeo:fix-bar-code-get-area-cb? I'll resolve the conflict later.
The issue is fixed on my local and will push once the draw buffer things merged. And then we can enable it on CI.

@XuNeo XuNeo force-pushed the fix-bar-code-get-area-cb branch from 4393793 to 0a12e65 Compare December 11, 2023 16:15
@kisvegabor
Copy link
Member

It works well on my end too.

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 12, 2023

Comment out this line 274 4393793#diff-242f305692436f289db7b3cdda6298157b9ab35835506b88b28a86b1524051abR274
and you will see logs to report area not ready.

Hi Gabor,
This PR has made it to work by clipping the area to the whole image area and then compare if it's inside decoded image area.
You need to comment out above code to see the error.

@kisvegabor
Copy link
Member

I've commented out
image

Enabled LV_BIN_DECODER_RAM_LOAD 1 but I can't see any error.

The areas look good, and clipped when I move the cursor on the bar code.

I can't see and logged errors either.

Exactly for what issue shall I look for?

@XuNeo XuNeo force-pushed the fix-bar-code-get-area-cb branch from 0a12e65 to c10fe8d Compare December 12, 2023 09:38
@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 12, 2023

Enabled LV_BIN_DECODER_RAM_LOAD 1 but I can't see any error.

That's really interesting. I'm not sure which commit has fixed it.

However, now with online latest code + this PR, I can now reproduce the issue steadily with LV_BIN_DECODER_RAM_LOAD configured to 0.

[Warn]  (0.020, +20)     lv_image_set_src: failed to get image info: 0x60e000000a50 lv_image.c:174
[User]  (0.021, +1)      img_decode_and_draw: area not ready lv_draw_sw_img.c:285
[User]  (0.021, +0)      img_decode_and_draw: area not ready lv_draw_sw_img.c:285
[User]  (0.021, +0)      img_decode_and_draw: area not ready lv_draw_sw_img.c:285
[User]  (0.021, +0)      img_decode_and_draw: area not ready lv_draw_sw_img.c:285
[User]  (0.021, +0)      img_decode_and_draw: area not ready lv_draw_sw_img.c:285

@kisvegabor
Copy link
Member

I've tested it an I think this is what happens:

Let's we have a 100x1 image, which is tiled to get a 100x20 image. For the sake of simplicity lets say the image is at 0;0.

Now we invalidate the (50;10)(60;15) area. So we need to decode x=50..60 and draw it 6 times (y=10..15). In the first run it's correctly detected that the image is not decoded yet, so that 11 pixel (x=50..60) are decoded. However in the next run here it's assumed that the whole image was decoded which is not true.

So we need to keep relative_decoded_area accross calls of img_decode_and_draw. Maybe saving it in decoder_dsc?

@XuNeo XuNeo marked this pull request as draft December 19, 2023 11:20
@lvgl-bot
Copy link

lvgl-bot commented Jan 3, 2024

We need some feedback on this pull request.

Now we mark this as "stale" because there was no activity here for 14 days.

Remove the "stale" label or comment else this will be closed in 7 days.

@lvgl-bot lvgl-bot added the stale label Jan 3, 2024
@kisvegabor
Copy link
Member

Is it already resolved by some other PRs?

@XuNeo
Copy link
Collaborator Author

XuNeo commented Jan 3, 2024

It's still ongoing. Will go back too it in following days.

@lvgl-bot lvgl-bot removed the stale label Jan 4, 2024
@lvgl-bot
Copy link

We need some feedback on this pull request.

Now we mark this as "stale" because there was no activity here for 14 days.

Remove the "stale" label or comment else this will be closed in 7 days.

@lvgl-bot lvgl-bot added the stale label Jan 18, 2024
@kisvegabor
Copy link
Member

Shall we pin this issue?

@XuNeo
Copy link
Collaborator Author

XuNeo commented Jan 18, 2024

No need, I shall dig into it right now.

@XuNeo XuNeo force-pushed the fix-bar-code-get-area-cb branch from c10fe8d to 534c4e1 Compare January 18, 2024 12:24
Fix lvgl#4838

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
@XuNeo XuNeo force-pushed the fix-bar-code-get-area-cb branch from 534c4e1 to 8c1e843 Compare January 18, 2024 12:25
@XuNeo XuNeo marked this pull request as ready for review January 18, 2024 12:25
@XuNeo
Copy link
Collaborator Author

XuNeo commented Jan 18, 2024

Hi @kisvegabor
The code is working. I store the decoded image area between decoder open and close. Please help to review it.

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what we needed!

@kisvegabor kisvegabor merged commit 578a5e7 into lvgl:master Jan 18, 2024
16 checks passed
@XuNeo XuNeo deleted the fix-bar-code-get-area-cb branch January 18, 2024 13:53
@XuNeo
Copy link
Collaborator Author

XuNeo commented Jan 18, 2024

Cool.
The next thing is to add option LV_BIN_DECODER_RAM_LOAD = 0in CI to make sure it always works.
Could you do that?

@kisvegabor
Copy link
Member

I've opened #5396 to discuss what kind of test configs are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test barcode won't work with get_area_cb
3 participants