From: Colin D Bennett <colin@gibibit.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] GSoC #09 Bitmap scaling
Date: Wed, 29 Oct 2008 20:20:00 -0700 [thread overview]
Message-ID: <20081029202000.66f38131@gibibit.com> (raw)
In-Reply-To: <48F5FF64.6010500@nic.fi>
[-- Attachment #1: Type: text/plain, Size: 3839 bytes --]
On Wed, 15 Oct 2008 17:34:12 +0300
Vesa Jääskeläinen <chaac@nic.fi> wrote:
> Colin D Bennett wrote:
> > On Tue, 14 Oct 2008 00:11:42 +0300
> > Vesa Jääskeläinen <chaac@nic.fi> wrote:
> >> As we have same handle all the time for bitmap we can just
> >> continue to use it as is. If we would make new instance of it,
> >> would either need to delete previous one and replace its usage
> >> with new one. Of course use case here affects.
> >
> > Ok. That's fine. I'm still a little confused about the purpose of
> > lock/unlock, however. Is it basically a way of catching mistakes in
> > the code where we accidentally try to modify bitmap data when we
> > don't want to? I guess what I'm asking is, do lock/unlock do
> > anything more than set a flag that is checked, as in: (pseudocode)
> >
> >
> > void *get_ptr(bitmap b)
> > {
> > if (b.optimized) return error();
> > return b.ptr;
> > }
> > void optimize(bitmap b)
> > {
> > if (b.locked) error();
> > /* optimize b... */
> > }
> > void lock(bitmap b)
> > {
> > if (b.locked) error();
> > b.locked = 1;
> > }
> > void unlock(bitmap b) { b.locked = 0; }
>
> No, more like:
>
> void *lock(bitmap b)
> {
> if (b.locked) return NULL;
> if (b.optimized) return NULL;
>
> b.locked = 1;
>
> return b.dataptr;
> }
>
> void unlock(bitmap b)
> {
> b.locked = 0;
> }
>
> grub_err_t optimize(bitmap b, rendertarget r)
> {
> if (b.locked) return error;
> if (b.optimized) return error;
>
> // do magic
> b.optimized = 1;
>
> return success;
> }
>
> Now one would use it like:
>
> ptr = lock();
> if (ptr)
> {
> // modify it.
> ptr[0] = blue;
> ptr[1] = green;
> ptr[2] = red;
> if (has_alpha)
> ptr[3] = alpha;
>
> unlock();
> }
Any more thoughts on this? I can try to implement the bitmap
optimization when I have a chance, but I wondered if you had any more
insights into how you think it should work before I got to the effort
of implementing it. Perhaps if we were to modify some of the "user"
code to use bitmap optimization, we could see how the proposed API
works out, and whether there are any things we could do better to make
it easier for the users of the bitmap API, since there are many users
and only one bitmap API that has to do the dirty work. It would be
nice if the API made simple, common tasks are made easy for users.
Do you think we should return a uint8_t* from the lock() function? The
other option is to return a basic structure to the caller that provides
the necessary information to manipulate the data in the 'unoptimized'
format (perhaps we could call it the 'intermediate representation' or
common format to avoid the cumbersome 'unoptimized' term).
User code that uses the "accessible" or "portable" standard bitmap
format for manipulation does not need most of the stuff in the bitmap's
mode_info struct, so it might simplify the task of user code if we had
a structure with just the data relevant to manipulation of these
accessible bitmaps.
For instance:
struct common_bitmap // An RGB/RGBA bitmap in the standard format.
{
uint8_t *data; // Pixel data in BGR[A] order
int width; // Width in pixels
int height; // Height in pixels (number of rows in DATA)
int stride; // Number of bytes per row in DATA
bool has_alpha; // Alpha channel? 0 => BGR, 1 => BGRA
};
Then user code could do something like this:
struct bitmap *
prepare_frob_bitmap (render_target target)
{
struct bitmap *bitmap;
struct common_bitmap work;
create_bitmap (&bitmap, 640, 480, NO_ALPHA);
bitmap_lock (bitmap, &work);
do_something_to_bitmap (&work);
bitmap_unlock (bitmap);
bitmap_optimize (bitmap, target);
}
Regards,
Colin
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
prev parent reply other threads:[~2008-10-30 3:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-31 7:01 [PATCH] GSoC #09 Bitmap scaling Colin D Bennett
2008-08-31 16:21 ` Vesa Jääskeläinen
2008-08-31 16:24 ` Vesa Jääskeläinen
2008-09-02 15:42 ` Vesa Jääskeläinen
2008-10-03 20:16 ` Vesa Jääskeläinen
2008-10-13 17:00 ` Colin D Bennett
2008-10-13 18:27 ` Vesa Jääskeläinen
2008-10-13 20:00 ` Colin D Bennett
2008-10-13 21:11 ` Vesa Jääskeläinen
2008-10-15 5:42 ` Colin D Bennett
2008-10-15 14:34 ` Vesa Jääskeläinen
2008-10-30 3:20 ` Colin D Bennett [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081029202000.66f38131@gibibit.com \
--to=colin@gibibit.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.