PfRenderCx

hi everyone

I’m using PfRenderCx to render text using fractional scaling, It almost
work, to the exception that I don’t know what type the bmptr is in the
callback.
the bpp argument say ‘8’ which isn’t in the docs.

I assume the bmptr is a type of gradient, Pg_IMAGE_GRADIENT_BYTE, and
drawing the imgae using that almost works, I get really wacko colors etc.
How do I setup the Palette correctly? I tried using the PgSet…Color
with no success. How do I create a gradient palette?

/Johan Björk

Johan Björk wrote:

hi everyone

I’m using PfRenderCx to render text using fractional scaling, It almost
work, to the exception that I don’t know what type the bmptr is in the
callback.
the bpp argument say ‘8’ which isn’t in the docs.

I assume the bmptr is a type of gradient, Pg_IMAGE_GRADIENT_BYTE, and
drawing the imgae using that almost works, I get really wacko colors etc.
How do I setup the Palette correctly? I tried using the PgSet…Color
with no success. How do I create a gradient palette?

/Johan Björk

btw, for the docs people, It’d be really nice if you could add that

for the PfRender function to work, there MUST be Shared memory allocated
in the font context, which the default one does not have by default.
took me a while to figure, errno = Invalid Argument :stuck_out_tongue_winking_eye:

/Johan

Johan Bj?rk <phearbear@home.se> wrote:
: btw, for the docs people, It’d be really nice if you could add that
: for the PfRender function to work, there MUST be Shared memory allocated
: in the font context, which the default one does not have by default.
: took me a while to figure, errno = Invalid Argument :stuck_out_tongue_winking_eye:

I’ll pass this on to the writer. Thanks for the tip.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

<phearbear@home.se> wrote:

hi everyone

I’m using PfRenderCx to render text using fractional scaling, It almost
work, to the exception that I don’t know what type the bmptr is in the
callback.
the bpp argument say ‘8’ which isn’t in the docs.

I assume the bmptr is a type of gradient, Pg_IMAGE_GRADIENT_BYTE, and
drawing the imgae using that almost works, I get really wacko colors etc.
How do I setup the Palette correctly? I tried using the PgSet…Color
with no success. How do I create a gradient palette?

8bpp indicates a 256 gray scale map. You can do the following
to display it as a “pixmap”, but the graphics driver actually
uses it as an alphamap. I do not recommend taking the alphamap
route, since it is possible to exceed the size of the draw buffer.
All the graphics driver alpha requests are within the same
process, therefore it does not have to worry about this limitation.

If you really want the alphamap code, I will have to find it.
I did it awhile back, and cannot easily locate it.

Regards.


void render_cb(void * ctx, const PhPoint_t * pktsPnt, const FontRender * pktsRender)
{ PhImage_t tsImage;
PhPoint_t tsPos = { 0, 0 };
PgColor_t palette[2] = { Pg_WHITE, Pg_BLACK };

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = pktsRender->size.x;
tsImage.size.h = pktsRender->size.y;
tsImage.bpl = pktsRender->bpl;
tsImage.image = pktsRender->bmptr;
tsImage.palette = palette;
tsImage.colors = 2;

if(pktsRender->bpp == 1)
{ tsImage.palette = NULL;
tsImage.type = Pg_BITMAP_BACKFILL;
}
else if(pktsRender->bpp == 4)
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_NIBBLE;
}
else if(pktsRender->bpp == :sunglasses:
{ if(pktsRender->flags & FONTRENDER_RGB_PIXMAP) // You may have to skip this part of the if,
{ tsImage.palette = NULL; // it may not be defined on all systems.
tsImage.type = Pg_IMAGE_DIRECT_888; //
} //
else //
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_BYTE;
}
}

if(PgDrawPhImagemx(&tsPos, &tsImage, 0x00) == -1)
{ printf(“Ouch!!\n”);
}

PgFFlush(1);

return;
}

I located the alphamap code. Ensure you set your draw buffer
to 0xFFFF. Remember, it is possible to still blow the draw buffer
if the map is too large, and there is no way to verify that you
blew the buffer. You can use the ctx for anything you want,
I just used it for a success/failure boolean. As mentioned
in my previous post, you may have to comment out the RGB part
of the ‘if’ statement.

Regards.

static void func(void * ctx, const PhPoint_t *pos, const FontRender * render)
{ int * bad = (int *)ctx;

if(render->bpp == 1)
{ PhDrawContext_t *cur_dc = (Ph->draw_context);
PhImage_t tsImage;
PgColor_t palette[2] = { Pg_WHITE, CUR_GC->text.com.primary };

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = render->size.x;
tsImage.size.h = render->size.y;
tsImage.bpl = render->bpl;
tsImage.image = render->bmptr;
tsImage.palette = palette;
tsImage.colors = 2;
tsImage.type = Pg_BITMAP_TRANSPARENT;


if(PgDrawPhImagemx(pos, &tsImage, 0x00) == -1)
{ (*bad) = 1;
}
}
else if(render->bpp == 4)
{ PhDrawContext_t *cur_dc = (Ph->draw_context);
PhImage_t tsImage;

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = render->size.x;
tsImage.size.h = render->size.y;
tsImage.bpl = render->bpl;
tsImage.image = render->bmptr;
tsImage.palette = NULL;
tsImage.colors = 0;
tsImage.type = Pg_IMAGE_GBLEND_NIBBLE;

if(PgDrawPhImagemx(pos, &tsImage, 0x00) == -1)
{ (*bad) = 1;
}
}
else if(render->bpp == :sunglasses:
{ if(render->flags & FONTRENDER_RGB_PIXMAP)
{ PhImage_t tsImage;

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = render->size.x;
tsImage.size.h = render->size.y;
tsImage.bpl = render->bpl;
tsImage.image = render->bmptr;
tsImage.colors = 0;
tsImage.palette = NULL;
tsImage.type = Pg_IMAGE_DIRECT_888;

if(PgDrawPhImagemx(pos, &tsImage, 0x00) == -1)
{ (*bad) = 1;
}
}
else
{ PgMap_t alpha;
PgColor_t old;
PhDrawContext_t *cur_dc = (Ph->draw_context);
PhRect_t rect;

rect.ul.x = pos->x;
rect.ul.y = pos->y;
rect.lr.x = (rect.ul.x + render->size.x) - 1;
rect.lr.y = (rect.ul.y + render->size.y) - 1;

PgAlphaOn();
alpha.map = render->bmptr;
alpha.dim.w = render->size.x;
alpha.dim.h = render->size.y;
PgSetAlphaBlend(&alpha, 0x00);
old = PgSetFillColor(CUR_GC->text.com.primary);
PgDrawRect(&rect, Pg_DRAW_FILL);
PgSetFillColor(old);
PgSetAlphaBlend(NULL, 0x00);
PgAlphaOff();
}
}
else
{ (*bad) = 1;
}

return;
}

Derek Leach <dleach@dleach.qnx.com> wrote:

phearbear@home.se> > wrote:
hi everyone

I’m using PfRenderCx to render text using fractional scaling, It almost
work, to the exception that I don’t know what type the bmptr is in the
callback.
the bpp argument say ‘8’ which isn’t in the docs.

I assume the bmptr is a type of gradient, Pg_IMAGE_GRADIENT_BYTE, and
drawing the imgae using that almost works, I get really wacko colors etc.
How do I setup the Palette correctly? I tried using the PgSet…Color
with no success. How do I create a gradient palette?

8bpp indicates a 256 gray scale map. You can do the following
to display it as a “pixmap”, but the graphics driver actually
uses it as an alphamap. I do not recommend taking the alphamap
route, since it is possible to exceed the size of the draw buffer.
All the graphics driver alpha requests are within the same
process, therefore it does not have to worry about this limitation.

If you really want the alphamap code, I will have to find it.
I did it awhile back, and cannot easily locate it.

Regards.



void render_cb(void * ctx, const PhPoint_t * pktsPnt, const FontRender * pktsRender)
{ PhImage_t tsImage;
PhPoint_t tsPos = { 0, 0 };
PgColor_t palette[2] = { Pg_WHITE, Pg_BLACK };

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = pktsRender->size.x;
tsImage.size.h = pktsRender->size.y;
tsImage.bpl = pktsRender->bpl;
tsImage.image = pktsRender->bmptr;
tsImage.palette = palette;
tsImage.colors = 2;

if(pktsRender->bpp == 1)
{ tsImage.palette = NULL;
tsImage.type = Pg_BITMAP_BACKFILL;
}
else if(pktsRender->bpp == 4)
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_NIBBLE;
}
else if(pktsRender->bpp == > :sunglasses:
{ if(pktsRender->flags & FONTRENDER_RGB_PIXMAP) // You may have to skip this part of the if,
{ tsImage.palette = NULL; // it may not be defined on all systems.
tsImage.type = Pg_IMAGE_DIRECT_888; //
} //
else //
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_BYTE;
}
}

if(PgDrawPhImagemx(&tsPos, &tsImage, 0x00) == -1)
{ printf(“Ouch!!\n”);
}

PgFFlush(1);

return;
}

Thanks alot, this seem to work just great.
Got a bit of a problem with the text width measure still, replying to
the above post now…


/Johan

Derek Leach wrote:

phearbear@home.se> > wrote:

hi everyone


I’m using PfRenderCx to render text using fractional scaling, It almost
work, to the exception that I don’t know what type the bmptr is in the
callback.
the bpp argument say ‘8’ which isn’t in the docs.


I assume the bmptr is a type of gradient, Pg_IMAGE_GRADIENT_BYTE, and
drawing the imgae using that almost works, I get really wacko colors etc.
How do I setup the Palette correctly? I tried using the PgSet…Color
with no success. How do I create a gradient palette?


8bpp indicates a 256 gray scale map. You can do the following
to display it as a “pixmap”, but the graphics driver actually
uses it as an alphamap. I do not recommend taking the alphamap
route, since it is possible to exceed the size of the draw buffer.
All the graphics driver alpha requests are within the same
process, therefore it does not have to worry about this limitation.

If you really want the alphamap code, I will have to find it.
I did it awhile back, and cannot easily locate it.

Regards.


void render_cb(void * ctx, const PhPoint_t * pktsPnt, const FontRender * pktsRender)
{ PhImage_t tsImage;
PhPoint_t tsPos = { 0, 0 };
PgColor_t palette[2] = { Pg_WHITE, Pg_BLACK };

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = pktsRender->size.x;
tsImage.size.h = pktsRender->size.y;
tsImage.bpl = pktsRender->bpl;
tsImage.image = pktsRender->bmptr;
tsImage.palette = palette;
tsImage.colors = 2;

if(pktsRender->bpp == 1)
{ tsImage.palette = NULL;
tsImage.type = Pg_BITMAP_BACKFILL;
}
else if(pktsRender->bpp == 4)
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_NIBBLE;
}
else if(pktsRender->bpp == > :sunglasses:
{ if(pktsRender->flags & FONTRENDER_RGB_PIXMAP) // You may have to skip this part of the if,
{ tsImage.palette = NULL; // it may not be defined on all systems.
tsImage.type = Pg_IMAGE_DIRECT_888; //
} //
else //
{ palette[0] = Pg_WHITE;
palette[1] = Pg_BLACK;
tsImage.type = Pg_IMAGE_GRADIENT_BYTE;
}
}

if(PgDrawPhImagemx(&tsPos, &tsImage, 0x00) == -1)
{ printf(“Ouch!!\n”);
}

PgFFlush(1);

return;
}

Hi

I was using the Alpha map code waiting for something bad (r) to happen,
and it kinda did when I gave it too many too large characters…
So I went to try the pixmap method :


PhImage_t tsImage;
PgColor_t palette[2] =
{Pg_TRANSPARENT,qGR->getCurrentGC()->text.com.primary };
//If I use Pg_WHITE it works, but I want a transparent background…

memset(&tsImage, 0x00, sizeof(PhImage_t));
tsImage.size.w = render->size.x;
tsImage.size.h = render->size.y;
tsImage.bpl = render->bpl;
tsImage.image = (char*)render->bmptr;
tsImage.palette = palette;
tsImage.colors = 2;
tsImage.type = Pg_IMAGE_GRADIENT_BYTE;

PgDrawPhImagemx(&pnt, &tsImage, 0x00);
PgFlush();


As the comment say, It doesn’t seem to work when using Pg_TRANSPARENT.
When using Pg_TRANSPARENT it becomes… almost randomlike.
On some places It has a transparent background, sometimes It gets a gray
background and sometimes black.
Does it use the palette supplied in the PhImage_t? It seems to happen
mostly when I ‘recently’ made some draw calls with a diffrent back
color. I do PgSetFillColor(Pg_TRANSPARENT) and PgSetTextColor() before
the call to PfRenderCx…
How can I make it transparent?

TIA
Johan

Johan Björk <phearbear@home.se> wrote:
[snip]

As the comment say, It doesn’t seem to work when using Pg_TRANSPARENT.
When using Pg_TRANSPARENT it becomes… almost randomlike.
On some places It has a transparent background, sometimes It gets a gray
background and sometimes black.
Does it use the palette supplied in the PhImage_t? It seems to happen
mostly when I ‘recently’ made some draw calls with a diffrent back
color. I do PgSetFillColor(Pg_TRANSPARENT) and PgSetTextColor() before
the call to PfRenderCx…
How can I make it transparent?

Hah! :slight_smile: I knew I should have mentioned this … drum roll please …

PhMakeTransBitmap
PhMakeTransparent

Regards.

Derek Leach wrote:

Johan Björk <> phearbear@home.se> > wrote:
[snip]

As the comment say, It doesn’t seem to work when using Pg_TRANSPARENT.
When using Pg_TRANSPARENT it becomes… almost randomlike.
On some places It has a transparent background, sometimes It gets a gray
background and sometimes black.
Does it use the palette supplied in the PhImage_t? It seems to happen
mostly when I ‘recently’ made some draw calls with a diffrent back
color. I do PgSetFillColor(Pg_TRANSPARENT) and PgSetTextColor() before
the call to PfRenderCx…
How can I make it transparent?


Hah! > :slight_smile: > I knew I should have mentioned this … drum roll please …

PhMakeTransBitmap
PhMakeTransparent

Regards.

Hey again
Stuff just got scary again…
I need to print the stuff i’m rendering with PfRenderCx.
Using alphamaps, stuff didn’t show at all in the .phs I created.
(All My tests are done with ‘preview’ and render to a .phs, don’t have a
supported printer)
Adding a check if i’m rendering to a print context, and if so, use the
Grayscale method stuff atleast is visible.
http://194.236.217.9/snap2.jpg
Looks pretty horrid though (Comparing for example a .phs created in ped,
you can zoom up to 300% and it still looks good…) . I need to do some
magic when rendering to a printing context?

/Johan Björk

Johan Bjork <phearbear@home.se> wrote:
[snip]

Hey again
Stuff just got scary again…
I need to print the stuff i’m rendering with PfRenderCx.
Using alphamaps, stuff didn’t show at all in the .phs I created.
(All My tests are done with ‘preview’ and render to a .phs, don’t have a
supported printer)
Adding a check if i’m rendering to a print context, and if so, use the
Grayscale method stuff atleast is visible.
http://194.236.217.9/snap2.jpg
Looks pretty horrid though (Comparing for example a .phs created in ped,
you can zoom up to 300% and it still looks good…) . I need to do some
magic when rendering to a printing context?

/Johan Bjork

I believe printer can override the string render routine, in order to
optimize for the target device … but I am under the impression, that
these routines just use PfRenderCx to generate the text …

Someone else will need to pipe up on this one for a better explanation,
but looking at libphrender, it appears they optimize the palette for
printing, creating a smoother gradient.

Regards.