Robert Murrell
11/08/2010 11:13 AM
post73863
|
Since sample code or tutorials are not available, I'll try a more specific question.
I'm trying to display a BMP file. The file format is IMG_FMT_PAL1. My layer format is GF_FORMAT_BGR888. My call to
gf_surface_attach is failing with GF_ERR_PARM. I'm guessing (because its not documented) that I need to convert the
image before trying to attach it. I have found the img_dtransform* and img_convert* functions, but there are no
examples on how or when to use them. I'm also reading conflicting information on which functions support pallet-based
images. How do I display a BMP file? I am using 6.5.0
P.S. These functions should be called Primitive Graphics instead of Advanced Graphics, because I am writing an awful lot
of code to do simple things.
|
|
|
Derek Leach
|
RE: How to display an image.
|
Derek Leach
11/08/2010 11:17 AM
post73865
|
RE: How to display an image.
What about gf_draw_bitmap()?
-----Original Message-----
From: Robert Murrell [mailto:community-noreply@qnx.com]
Sent: November 8, 2010 11:14 AM
To: advanced-graphics
Subject: How to display an image.
Since sample code or tutorials are not available, I'll try a more
specific question.
I'm trying to display a BMP file. The file format is IMG_FMT_PAL1. My
layer format is GF_FORMAT_BGR888. My call to gf_surface_attach is
failing with GF_ERR_PARM. I'm guessing (because its not documented)
that I need to convert the image before trying to attach it. I have
found the img_dtransform* and img_convert* functions, but there are no
examples on how or when to use them. I'm also reading conflicting
information on which functions support pallet-based images. How do I
display a BMP file? I am using 6.5.0
P.S. These functions should be called Primitive Graphics instead of
Advanced Graphics, because I am writing an awful lot of code to do
simple things.
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post73863
|
|
|
Robert Murrell
|
Re: RE: How to display an image.
|
Robert Murrell
11/08/2010 11:30 AM
post73874
|
Re: RE: How to display an image.
> What about gf_draw_bitmap()?
>
I have that working for the IMG_FMT_PAL1 in a legacy function. But I want to make a generic function that will take BMP
, GIF, JPG, and PNG images passed by file name and display them. BMP files have several pallet sizes that will not work
for gf_draw_bitmap. How do I do this?
|
|
|
Derek Leach
|
RE: RE: How to display an image.
|
Derek Leach
11/08/2010 12:00 PM
post73893
|
RE: RE: How to display an image.
Do you mean GIF files have several palette sizes?
-----Original Message-----
From: Robert Murrell [mailto:community-noreply@qnx.com]
Sent: November 8, 2010 11:30 AM
To: advanced-graphics
Subject: Re: RE: How to display an image.
> What about gf_draw_bitmap()?
>
I have that working for the IMG_FMT_PAL1 in a legacy function. But I
want to make a generic function that will take BMP, GIF, JPG, and PNG
images passed by file name and display them. BMP files have several
pallet sizes that will not work for gf_draw_bitmap. How do I do this?
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post73874
|
|
|
Robert Murrell
|
Re: RE: RE: How to display an image.
|
Robert Murrell
11/08/2010 12:11 PM
post73896
|
Re: RE: RE: How to display an image.
No. BMP files come in IMG_FMT_PAL1, IMG_FMT_PAL4, and IMG_FMT_PAL8 flavors. As I remember, GIF files are only
IMG_FMT_PAL8.
|
|
|
Derek Leach
|
RE: RE: RE: How to display an image.
|
Derek Leach
11/08/2010 12:13 PM
post73897
|
RE: RE: RE: How to display an image.
I stand corrected.
-----Original Message-----
From: Robert Murrell [mailto:community-noreply@qnx.com]
Sent: November 8, 2010 12:11 PM
To: advanced-graphics
Subject: Re: RE: RE: How to display an image.
No. BMP files come in IMG_FMT_PAL1, IMG_FMT_PAL4, and IMG_FMT_PAL8
flavors. As I remember, GIF files are only IMG_FMT_PAL8.
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post73896
|
|
|
Derek Leach
|
RE: RE: How to display an image.
|
Derek Leach
11/08/2010 12:01 PM
post73894
|
RE: RE: How to display an image.
Also please post your code snippet using gf_surface_attach().
-----Original Message-----
From: Robert Murrell [mailto:community-noreply@qnx.com]
Sent: November 8, 2010 11:30 AM
To: advanced-graphics
Subject: Re: RE: How to display an image.
> What about gf_draw_bitmap()?
>
I have that working for the IMG_FMT_PAL1 in a legacy function. But I
want to make a generic function that will take BMP, GIF, JPG, and PNG
images passed by file name and display them. BMP files have several
pallet sizes that will not work for gf_draw_bitmap. How do I do this?
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post73874
|
|
|
Robert Murrell
|
Re: RE: RE: How to display an image.
|
Robert Murrell
11/08/2010 12:15 PM
post73898
|
Re: RE: RE: How to display an image.
This code is basically the sample code snippets from the Users Guide strung together with some guesses added to get it
to compile.
void DRAW::DrawImg(char *fname)
{
int stats;
img_lib_t ilib = NULL;
img_t img;
gf_palette_t palette;
gf_surface_t img_surf;
img.flags = 0;
if ((stats = img_lib_attach(&ilib)) == IMG_ERR_OK) {
stats = img_load_file(ilib, fname, NULL, &img);
img_lib_detach(ilib);
if (img.format & IMG_FMT_PALETTE) {
/* setup palette if necessary */
palette.ncolors = img.npalette;
palette.colors = img.palette;
} else if (img.format == IMG_FMT_G8) {
/* we can render G8 images in GF by using a palette of grays */
palette.ncolors = 256;
palette.colors = (img_color_t*)g8pal;
}
if ((stats = gf_surface_attach(&img_surf, gdev,
img.w, img.h, img.access.direct.stride, (gf_format_t)img.format,
&palette, img.access.direct.data, 0)) == GF_ERR_OK) {
if (img.flags & IMG_TRANSPARENCY) {
/* we can handle transparency in GF using chroma */
gf_chroma_t chroma;
memset(&chroma, 0, sizeof chroma);
chroma.mode = GF_CHROMA_OP_SRC_MATCH | GF_CHROMA_OP_NO_DRAW;
if (img.format & IMG_FMT_PALETTE) {
chroma.color0 = img.palette[img.transparency.index];
} else if (IMG_FMT_BPP(img.format) < 24) {
chroma.color0 = img.transparency.rgb16;
} else {
chroma.color0 = img.transparency.rgb32;
}
gf_context_set_chroma(context, &chroma);
}
if (img.format & IMG_FMT_ALPHA) {
gf_alpha_t alpha;
memset(&alpha, 0, sizeof alpha);
alpha.mode = GF_ALPHA_M1_SRC_PIXEL_ALPHA | GF_BLEND_SRC_M1 |
GF_BLEND_DST_1mM1;
gf_context_set_alpha(context, &alpha);
}
stats = gf_draw_begin( context );
//render image on a surface
gf_draw_blit2(context, img_surf, NULL,
0, 0, img.w - 1, img.h - 1, Pen.X, Pen.Y);
gf_draw_finish(context);
/* unlock the h/w */
gf_draw_end(context);
if (img.format & IMG_FMT_ALPHA) {
gf_context_disable_alpha(context);
}
if (img.flags & IMG_TRANSPARENCY) {
gf_context_disable_chroma(context);
}
/* release the attached surface; we're not going to blit from it any
more (in real life this surface could be recycled if needed) */
gf_surface_free(img_surf);
free(img.access.direct.data);
}
}
if (stats) {
printf("Image error: %d\n", stats);//debug
}
}
|
|
|
Derek Leach
|
RE: RE: RE: How to display an image.
|
Derek Leach
11/08/2010 12:39 PM
post73905
|
RE: RE: RE: How to display an image.
Ok, I think I know the issue, the is not GF_FORMAT_PAL1, only PAL8, so
the call errors out.
My best suggestion would be to force the output format in the img_t
before call img_load_file().
img.format = IMG_FMT_BGRA8888;
img.flags |= IMG_FORMAT;
stats = img_load_file(ilib, fname, NULL, &img);
See it that makes it work better ...
-----Original Message-----
From: Robert Murrell [mailto:community-noreply@qnx.com]
Sent: November 8, 2010 12:16 PM
To: advanced-graphics
Subject: Re: RE: RE: How to display an image.
This code is basically the sample code snippets from the Users Guide
strung together with some guesses added to get it to compile.
void DRAW::DrawImg(char *fname)
{
int stats;
img_lib_t ilib = NULL;
img_t img;
gf_palette_t palette;
gf_surface_t img_surf;
img.flags = 0;
if ((stats = img_lib_attach(&ilib)) == IMG_ERR_OK) {
stats = img_load_file(ilib, fname, NULL, &img);
img_lib_detach(ilib);
if (img.format & IMG_FMT_PALETTE) {
/* setup palette if necessary */
palette.ncolors = img.npalette;
palette.colors = img.palette;
} else if (img.format == IMG_FMT_G8) {
/* we can render G8 images in GF by using a
palette of grays */
palette.ncolors = 256;
palette.colors = (img_color_t*)g8pal;
}
if ((stats = gf_surface_attach(&img_surf, gdev,
img.w, img.h, img.access.direct.stride,
(gf_format_t)img.format,
&palette, img.access.direct.data, 0)) ==
GF_ERR_OK) {
if (img.flags & IMG_TRANSPARENCY) {
/* we can handle transparency in GF
using chroma */
gf_chroma_t chroma;
memset(&chroma, 0, sizeof chroma);
chroma.mode = GF_CHROMA_OP_SRC_MATCH |
GF_CHROMA_OP_NO_DRAW;
if (img.format & IMG_FMT_PALETTE) {
chroma.color0 =
img.palette[img.transparency.index];
} else if (IMG_FMT_BPP(img.format) < 24)
{
chroma.color0 =
img.transparency.rgb16;
} else {
chroma.color0 =
img.transparency.rgb32;
}
gf_context_set_chroma(context, &chroma);
}
if (img.format & IMG_FMT_ALPHA) {
gf_alpha_t alpha;
memset(&alpha, 0, sizeof alpha);
alpha.mode = GF_ALPHA_M1_SRC_PIXEL_ALPHA
| GF_BLEND_SRC_M1 |
GF_BLEND_DST_1mM1;
gf_context_set_alpha(context, &alpha);
}
stats = gf_draw_begin( context );
//render image on a surface
gf_draw_blit2(context, img_surf, NULL,
0, 0, img.w - 1, img.h - 1,
Pen.X, Pen.Y);
gf_draw_finish(context);
/* unlock the h/w */
gf_draw_end(context);
if (img.format & IMG_FMT_ALPHA) {
gf_context_disable_alpha(context);
}
if (img.flags & IMG_TRANSPARENCY) {
gf_context_disable_chroma(context);
}
/* release the attached surface; we're not going
to blit from it any
more (in real life this surface could be
recycled if needed) */
gf_surface_free(img_surf);
free(img.access.direct.data);
}
}
if (stats) {
printf("Image error: %d\n", stats);//debug
}
}
_______________________________________________
Advanced Graphics
http://community.qnx.com/sf/go/post73898
|
|
|
Robert Murrell
|
Re: RE: RE: RE: How to display an image.
|
Robert Murrell
11/08/2010 1:09 PM
post73916
|
Re: RE: RE: RE: How to display an image.
> Ok, I think I know the issue, the is not GF_FORMAT_PAL1, only PAL8, so
> the call errors out.
>
> My best suggestion would be to force the output format in the img_t
> before call img_load_file().
>
> img.format = IMG_FMT_BGRA8888;
> img.flags |= IMG_FORMAT;
>
> stats = img_load_file(ilib, fname, NULL, &img);
>
> See it that makes it work better ...
I still get the same error. For your reference, I have attached the actual BMP file that I am trying to load.
|
|
|
|