Home > Archive > Kylix > August 2005 > X-less Bitmap
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi,
Is anybody interested in a solution for editing Bitmaps completely
without X/Qt ?
I've written an TXLBitmap (XLess) which:
- Can Read JPEG, BMP, PNG, GIF (with the help of some existing free
code, included)
- Can Write JPEG, BMP, PNG (with the help of some existing free code,
included)
- Can do Antialiased Textout (Bitmapped Fonts are generated under Qt and
afterwards loaded without X-Server)
- Has Scanline Access (32bit) and is TBitmap compatible on a low level.
- Has some basic Canvas Methods like Pixels, MoveTo, LineTo, FillRect,
Rectangle, Circle, Draw, TextExtent.
These can be extended by anything you like. You have Scanline and
Pixels[X,Y] access for this.
It's ideal for Webserver Application or whenever you have no X-Server
Running.
Everything is in Delphi code. It works without setting up any library paths.
It might also be interesting for shipping applications which use special
fonts that you don't want the user to
install. You can use any fonts that you have in Kylix (They're
antialiased!) and ship them with the application.
It works rather fast and it would be easy to add special features to the
glyphs like spacing, rotation etc.
Assigning to a CLX-32bit-Bitmap and vice-versa is fast and easy:
Image1.Picture.Bitmap.Width:=XLbmp.Width;
Image1.Picture.Bitmap.Height:=XLbmp.Height;
Move(XLbmp.ScanLine[0]^,Image1.Picture.Bitmap.Scanline[0]^,XLbmp.Width*XLbmp.Height*4);
A very simple example looks like this: http://www.theo.ch/kylix/webcgi.png
To get an idea how to use it: This is the code which produced the above
image in a Kylix CGI App (Snippet):
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
i, x, y: integer;
Rec:TRect;
Text:String;
Guid:TGuid;
begin
fBmp:=TXLBitmap.create(fFontsPath);
fBmp.LoadFromFile('/home/theo/bag.png');
fBmp.Canvas.Font.Name:='Arial';
fBmp.Canvas.Font.Size:=12;
Text:=#169+' '+DateToStr(Now)+' Theo Lustenberger';
fBmp.Canvas.TextExtent(Text,Rec);
X:=fBmp.Width - Rec.Right-6;
Y:=fBmp.Height - Rec.Bottom-3;
OffsetRect(Rec,X,Y);
Rec.Right:=Rec.Right+3;
Rec.Left:=Rec.Left-3;
fBmp.Canvas.Brush.Color:=$FFFFEA;
fBmp.Canvas.FillRect(Rec);
fBmp.Canvas.TextOut(X,Y,Text);
CreateGuid(Guid);
fFileName:='/tmp/'+GuidToString(Guid)+'.png';
fBmp.SaveToFile(fFileName);
fBmp.free;
fStrm:= TFileStream.create(fFileName,fmOpenRead);
Response.ContentType:='image/png';
Response.ContentStream:=fStrm;
if FileExists(fFileName) then DeleteFile(FFileName);
end;
If anybody is interested, I'll publish the code. Be warned: it's more a
"how-to" than something that should
be used unrevisited in a production environment.
Regards Theo
| |
| juliusz 2005-08-16, 10:04 pm |
| theo wrote:
> Hi,
>
> Is anybody interested in a solution for editing Bitmaps completely
> without X/Qt ?
> I've written an TXLBitmap (XLess) which:
>
Absolutely, I am very interested. Who wouldn't be?
juliusz
| |
|
| "theo" <nospam@for.me> wrote in message
news:43029bc3@newsgroups.borland.com...
> Is anybody interested in a solution for editing Bitmaps completely without
> X/Qt ?
> I've written an TXLBitmap (XLess) which:
>[...]
Can it work with different PixelFormats? What about indexed color images,
like pl8bit or grayscaled?
| |
|
| juliusz schrieb:
>
> Absolutely, I am very interested. Who wouldn't be?
>
> juliusz
OK, I'm fixing a few things, make some demos and then post a
download-link to this group.
| |
| Simon Kissel 2005-08-17, 5:08 pm |
| > Is anybody interested in a solution for editing Bitmaps completely=20
> without X/Qt ?
> I've written an TXLBitmap (XLess) which:
I've also created myself a TServerBitmap class some time ago. Includes
TrueType font rendering and a few other things. I might donate some of =
my
code to your library.
What internal format(s) do you support?
Simon
| |
|
| Simon Kissel schrieb:
>
>
> I've also created myself a TServerBitmap class some time ago. Includes
> TrueType font rendering and a few other things. I might donate some of my
> code to your library.
>
> What internal format(s) do you support?
>
Only pf32bit. And the fonts are bitmapped (Created under Qt).
It would be interesting to have a look at your solution.
Theo
| |
|
| Ender schrieb:
>
> Can it work with different PixelFormats? What about indexed color
> images, like pl8bit or grayscaled?
No. Only 32bit internally. But you can save PNGs with transparency
and/or as 8bit or grayscaled.
Or you can improve it yourself...:-)
| |
| Marco van de Voort 2005-08-18, 4:09 am |
| On 2005-08-17, theo <nospam@for.me> wrote:
People interested in the matter might also be interested in fpimage, FPC's
LGPL picture handling classes:
http://www.freepascal.org/cgi-bin/v...runk/fcl/image/
I zipped the directory to http://www.stack.nl/~marcov/fpimage.zip
to my knowledge the only simple program is the included imgconv, though
lazarus problably also uses it.
The libs might depend on deeper units in the FPC tree though (like libpng
headers etc).
However all this should be reasonably adaptable to Delphi/Kylix with only
minor changes.
| |
|
| "theo" <nospam@for.me> wrote in message
news:43035403$1@newsgroups.borland.com...
> No. Only 32bit internally. But you can save PNGs with transparency and/or
> as 8bit or grayscaled.
> Or you can improve it yourself...:-)
Have you looked at Graphics32 library?
http://www.graphics32.org
| |
|
| > Ender schrieb:
"theo" <nospam@for.me>[color=darkred]
> No. Only 32bit internally. But you can save PNGs with transparency and/or
> as 8bit or grayscaled.
> Or you can improve it yourself...:-)
I think the most difficult thing in the implementation of such class is
management of different pixel formats. To achieve sufficient speed and
memory usage. When you need work with relatively large images like scanned
documents this become very important. Let's imagine we scan a simple B/W
document of size A4 at 300 dpi.
A4, 300 dpi: 8.27 x 300 x 10.61 x 300 = 7 897 023 pixels
B/W: ~ less than 1Mb
Grayscale: ~ 7.5Mb
32bit-color: ~ 30Mb
The difference is significant.
| |
|
|
|
| Ender schrieb:
>
>
> I think the most difficult thing in the implementation of such class is
> management of different pixel formats. To achieve sufficient speed and
> memory usage. When you need work with relatively large images like
> scanned documents this become very important. Let's imagine we scan a
> simple B/W document of size A4 at 300 dpi.
You're absolutely right. But this was not the purpose.
TXLBitmap is mainly a wrapper for TXLessFonts.
Everything needs to work without X/Qt.
The image-reading/writing units I've found (JPEG, PNG etc) all have only
32 bit interfaces. So supporting other pixelformats is rather usesless
here and a hard work anyway.
| |
|
| theo schrieb:
> juliusz schrieb:
>
>
>
> OK, I'm fixing a few things, make some demos and then post a
> download-link to this group.
Download Link is here:
http://www.theo.ch/kylix/XLship.zip
I hope all necessary files came with.
Firstly compile the file in the "encoder" folder. This will create the
fonts.
Then you might check what works with the Project in the "Test" folder.
This is demo and documentation at the same time. If you read the source,
you'll understand how to use it.
If you need a demo for a CGI, look at cgidemo. (change the paths).
Be aware that it was not designed for using under Qt, but might be
faster in some cases (see demo).
The TXLBitmap is very simple. It is only there as a "container" for the
fonts and to load image formats.
You can easily extend it yourself, be it by copying code from Graphics32
or any other source.
This is a fun project, I worked a w (nightly) for it.
It's not complete or bug-free.
The encoder seems to have memory problems somewhere, but you only need
it to encode the fonts once. The decoding part seems memory-stable.
Have Fun!
Theo
| |
| juliusz 2005-08-21, 2:57 am |
| theo wrote:
> Download Link is here:
> http://www.theo.ch/kylix/XLship.zip
> ..
> Have Fun!
> Theo
It surely is innovative!
Thanks for the code, Theo.
juliusz
| |
| raktzo 2005-08-25, 7:04 pm |
| ...I knew...after my own...
Can I've a link? Or help this object?
I'm intrested to some solution, how to work with system font, or Canvas, or
other graphical objects
Bye,
Raktzo
| |
|
| raktzo schrieb:
> ..I knew...after my own...
> Can I've a link? Or help this object?
The link is above in this thread with a simple "readme". Here again the
link http://www.theo.ch/kylix/XLship.zip
I'll update the version soon.
The next version will be able to produce anti-aliased font-images for
alpha channelled PNG's
See demo:
http://www.theo.ch/kylix/pngalphademo.png
Or see it your Browser: (Mozilla, Konqueror, Safari will do, not sure
about IE)
http://www.theo.ch/kylix/alphtest.htm
This font-image is not aware of the background at creation time.
It saves alpha-blending info in the PNG.
Modern Browsers can combine (blend) these images with the background at
rendering time.
The HTML for the above demo looks like:
<html>
<body background="bag.png">
<br><br><br><br>
<a href=""><img src="testalph.png" border=0></a>
</html>
So you see that the background is a different image than the font-image
placed on it, although it looks like combined in a imaging tool.
| |
|
| Here's an update:
http://www.theo.ch/kylix/ (at the bottom of "Components")
New:
- Demos for VCL, Lazarus and CLX
- Save text with your fonts to PNG with alpha-transparency. These will
look fine on any background in newer browsers (Mozilla/Firefox,
Konqueror/Safari, IE..)
- Watermarks
|
|
|
|
|