OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:58 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: UEFI Image Resizing
PostPosted: Thu Dec 16, 2021 1:31 pm 
Offline

Joined: Tue Nov 09, 2021 11:40 am
Posts: 18
I'm working on developing a graphical bootloader, and the first core component will be rendering the background layer. I want to support a single PNG with the same aspect ratio as the display being scaled up or down accordingly in size. I've been working on some of my own code to do this, but I've found it to be unusably slow (and it's only halfway done!). I've been trying to integrate GOP's `blt` function as well as an open source PNG decoder bzt sent me. What's the best way to handle image resizing? Is there any library I could integrate for other image manipulation functions (such as Gaussian blur)?


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Thu Dec 16, 2021 8:23 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
amyipdev wrote:
I've been working on some of my own code to do this, but I've found it to be unusably slow (and it's only halfway done!).

Is it any faster outside UEFI? (Image processing is entirely self-contained, so you should have no trouble gluing your code to libpng or something to benchmark it.)

amyipdev wrote:
What's the best way to handle image resizing?

Find an existing library that handles the type of interpolation you want to use.

amyipdev wrote:
Is there any library I could integrate for other image manipulation functions (such as Gaussian blur)?

Sure. What language and license are you looking for?


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Fri Dec 17, 2021 12:29 am 
Offline

Joined: Tue Nov 09, 2021 11:40 am
Posts: 18
(couldn't quote since sending from mobile)

I'll try outside UEFI later but I don't see any potential performance improvement (aside from being able to use >SSE2).

I've seen some libraries that could help but many seem far too large and complex to integrate for a bootloader (ImageMagick comes to mind).

As for the rest, C as the language, and GPL2 would be preferred but I cab work with Unilicense and MIT (certain BSD ones also work, I'll double check if something good is in BSD). If it's just for image resizing that's fine, I found an efficient Gaussian algorithm that I can reimplements myself.


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Sat Dec 18, 2021 12:23 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
amyipdev wrote:
I've seen some libraries that could help but many seem far too large and complex to integrate for a bootloader (ImageMagick comes to mind).

If the license is permissive enough, you can copy the code without using the entire library.

amyipdev wrote:
As for the rest, C as the language, and GPL2 would be preferred but I cab work with Unilicense and MIT (certain BSD ones also work, I'll double check if something good is in BSD).

How about stb_image_resize.h?


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Sat Dec 18, 2021 9:58 am 
Offline

Joined: Tue Nov 09, 2021 11:40 am
Posts: 18
Octocontrabass wrote:
amyipdev wrote:
I've seen some libraries that could help but many seem far too large and complex to integrate for a bootloader (ImageMagick comes to mind).

If the license is permissive enough, you can copy the code without using the entire library.


That's probably ideal. Often I just submodule in libraries, with exceptions (I needed to patch tomlc99, for example, as it's dependent on a C standard library implementation, so I couldn't submodule it in).

Octocontrabass wrote:
amyipdev wrote:
As for the rest, C as the language, and GPL2 would be preferred but I cab work with Unilicense and MIT (certain BSD ones also work, I'll double check if something good is in BSD).

How about stb_image_resize.h?


Looks great, thanks!


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Wed Dec 22, 2021 11:58 am 
Offline

Joined: Tue Nov 09, 2021 11:40 am
Posts: 18
@Octocontrabass

Is STB going to work within UEFI? I'm using POSIX-UEFI and I see that it seems to require stdlib (stdio can be declared out).


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Wed Dec 22, 2021 8:54 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
amyipdev wrote:
Is STB going to work within UEFI?

As long as you provide all of the functions it depends on, yes.

amyipdev wrote:
I'm using POSIX-UEFI

POSIX-UEFI is a cool project, but I'm not sure I trust the code quality. Instead of fixing the issue that causes this warning to appear, bzt disabled the warning. Same for these warnings.

amyipdev wrote:
and I see that it seems to require stdlib

It only uses malloc() and free(). You can define STBIR_MALLOC and STBIR_FREE to make it use something else, like AllocatePool/FreePool.


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Wed Dec 22, 2021 11:25 pm 
Offline

Joined: Tue Nov 09, 2021 11:40 am
Posts: 18
Alright, thanks for the clarification. I definitely don't trust the code quality of POSIX-UEFI either - heck it didn't even cast right for printf integers, cutting off everything at 32 bits - but it works and I honestly don't mind it.

malloc and free are the only stdlib functions used throughout the entire STB? Alright then, POSIX-UEFI already has malloc and free so I should be all good to go. Thanks!


Top
 Profile  
 
 Post subject: Re: UEFI Image Resizing
PostPosted: Thu Dec 23, 2021 4:12 pm 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
Every time I look at the code in POSIX-UEFI I find bugs. For example it loads your kernel at some fixed memory address without first allocating that memory or making sure it is free. It's fine if you are just toying around and don't want to learn how to use UEFI... But if you want your code to be reliable in any ways, I would move away from it.

For malloc/free, you can use dlmalloc. It is not hard to implement a mmap() function that uses UEFI to allocate chunks of memory and that's all that is required to use dlmalloc within an UEFI application.

For printf(), there are many options. Here is one: https://github.com/mpaland/printf. You simply need to write a small function that outputs a character to the UEFI console.

For memcpy/strcpy/etc: if you find writing these yourself to be challenging in any way, then I would argue that it will be good practice for you to do it. Otherwise it takes 15 minutes to write them all.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 60 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group