Board index » kylix » Re: X-less Bitmap

Re: X-less Bitmap


2005-08-17 06:59:32 AM
kylix2
theo wrote:
Quote
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
 
 

Re:Re: X-less Bitmap

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: 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
 

Re:Re: X-less Bitmap

"theo" < XXXX@XXXXX.COM >wrote in message
Quote
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?
 

{smallsort}

Re:Re: X-less Bitmap

juliusz schrieb:
Quote
>

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.
 

Re:Re: X-less Bitmap

Quote
Is anybody interested in a solution for editing Bitmaps completely
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
 

Re:Re: X-less Bitmap

Ender schrieb:
Quote

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...:-)
 

Re:Re: X-less Bitmap

Simon Kissel schrieb:
Quote


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
 

Re:Re: X-less Bitmap

On 2005-08-17, theo < XXXX@XXXXX.COM >wrote:
People interested in the matter might also be interested in fpimage, FPC's
LGPL picture handling classes:
www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/fcl/image/
I zipped the directory to 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.
 

Re:Re: X-less Bitmap

"theo" < XXXX@XXXXX.COM >wrote in message
Quote
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?
www.graphics32.org
 

Re:Re: X-less Bitmap

Quote
Ender schrieb:
>Can it work with different PixelFormats? What about indexed color images,
>like pl8bit or grayscaled?
"theo" < XXXX@XXXXX.COM >
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.
 

Re:Re: X-less Bitmap

Ender schrieb:
Quote


Have you looked at Graphics32 library?
www.graphics32.org
Yes, great stuff but not Qt-free.
 

Re:Re: X-less Bitmap

Ender schrieb:
Quote


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.
 

Re:Re: X-less Bitmap

theo schrieb:
Quote
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:
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 week (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
 

Re:Re: X-less Bitmap

theo wrote:
Quote
Download Link is here:
www.theo.ch/kylix/XLship.zip
..
Have Fun!
Theo
It surely is innovative!
Thanks for the code, Theo.
juliusz
 

Re:Re: X-less Bitmap

..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