• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Galfar

346
That is just how some browsers display PNGs with alpha. Try to open it in some
image editor (that supports PNGs with alpha).
347
Here is code for ellipse that changes alpha of A8R8G8B8 image:

procedure DrawPixelAlpha(Canvas: TImagingCanvas; X, Y: Integer; Alpha: Byte);
var
  ColRec: TColor32Rec;
begin
  ColRec.Color := Canvas.Pixels32[X, Y];
  ColRec.A := Alpha;
  Canvas.Pixels32[X, Y] := ColRec.Color;
end;

procedure DrawAlphaEllipse(Canvas: TImagingCanvas; const Rect: TRect; Alpha: Byte; Fill: Boolean);
var
RadX, RadY, DeltaX, DeltaY, R, RX, RY: LongInt;
X1, X2, Y1, Y2, Bpp, OldY, I: LongInt;
Color: PColor32Rec;
begin
  X1 := Rect.Left;
  X2 := Rect.Right;
  Y1 := Rect.Top;
  Y2 := Rect.Bottom;

  SwapMin(X1, X2);
  SwapMin(Y1, Y2);

  RadX := (X2 - X1) div 2;
  RadY := (Y2 - Y1) div 2;

  Y1 := Y1 + RadY;
  Y2 := Y1;
  OldY := Y1;

  DeltaX := (RadX * RadX);
  DeltaY := (RadY * RadY);
  R  := RadX * RadY * RadY;
  RX := R;
  RY := 0;

  if Fill then
  begin
    for I := X1 to X2 do
      DrawPixelAlpha(Canvas, I, Y1, Alpha);
  end;

  DrawPixelAlpha(Canvas, X1, Y1, Alpha);
  DrawPixelAlpha(Canvas, X2, Y1, Alpha);

  while RadX > 0 do
  begin
    if R > 0 then
    begin
      Inc(Y1);
      Dec(Y2);
      Inc(RY, DeltaX);
      Dec(R, RY);
    end;
    if R <= 0 then
    begin
      Dec(RadX);
      Inc(X1);
      Dec(X2);
      Dec(RX, DeltaY);
      Inc(R, RX);
    end;

    if (OldY <> Y1) and Fill then
    begin
      for I := X1 to X2 do
        DrawPixelAlpha(Canvas, I, Y1, Alpha);
      for I := X1 to X2 do
        DrawPixelAlpha(Canvas, I, Y2, Alpha);
    end;
    OldY := Y1;

    DrawPixelAlpha(Canvas, X1, Y1, Alpha);
    DrawPixelAlpha(Canvas, X2, Y1, Alpha);
    DrawPixelAlpha(Canvas, X1, Y2, Alpha);
    DrawPixelAlpha(Canvas, X2, Y2, Alpha);
  end;
end;

Here is how to use it to draw alpha ellipses and squares/rectangles (filled):

// draw ellipse
DrawAlphaEllipse(Canvas, Rect(16, 64, 240, 192), 55, True);
// draw square
for I := 128 to 255 do
  for J := 128 to 255 do
    DrawPixelAlpha(Canvas, I, J, 200);

Resulting image is attached to this post.


348
I'll start from the last:

3) Simplest way would be to create new smaller image and copy piece of the original image
onto it. Then you can create D3D texture out of the smaller one.

var
  OrigImage, SmallImage: TSingleImage;
  Texture: IDirect3DTexture9;
  D3DDevice: IDirect3DDevice9;

.... init D3D ....
.... create orig image, say 1024x1024 pixels ....
SmallImage := TSingleImage.CreateFromParams(256, 256, OrigImage.Format); // create small image
OrigImage.CopyTo(512, 512, SmallImage.Width, SmallImage.Height, SmallImage, 0, 0); // copy from orig to small
CreateD3DTextureFromImage(SmallImage.ImageDataPointer^, D3DDevice, Texture); // create texture from small image


2) There is no Imaging function for this now but I'll add one in the future. Meanwhile you can use regular D3D texture updates using IDirect3DTexture9.LockRect method.

var
  Image: TSingleImage;
  Texture: IDirect3DTexture9;
  Rect: TD3DLockedRect;
  PixelPtr, DestPtr: Pointer;
  X, Y, I, LineBytes, TextureSize: Integer;  // say TextureSize is 128, [X, Y] is source position in image

  .... create your texture and image ....
  Texture.LockRect(0, Rect, nil, 0);  // lock texture
 
  LineBytes := Image.FormatInfo.GetPixelsSize(Image.FormatInfo.Format, TextureSize, 1);
 
  for I := 0 to TextureSize - 1 do
  begin
    Move(Image.PixelPointers[X, Y + I]^,                           // move pixels from image to texture
        PByteArray(Rect.pBits)[I * Rect.Pitch], LineBytes);
  end;

  Texture.UnlockRect(0);  // unlock texture

Note that this will work only for non DXTC formats (PixelPointers doesn't work for them).

1) Do you need it working for all data formats or just for one like A8R8G8B8? And do you need it filled or just outlined?
349
Ok, so I will put the new stuff in a comment to ImagingComponents along with some note.
After the new Lazarus release new stuff will be set as compiled code and old will be put in comment
with note (so someone still using older Laz could find what to do to get it working).
350
Thanks for the patch. I'll update the source in SVN. Do you happen to know if there is a way to detect Lazarus version during compile time? So that it won't break for people using older Lazarus (it would use old RawImage interface).
351
Help & Questions / Re: 1 bit image output
7 August 2007, 23:41:12
I have looked at Tesseract's API and found TessDllBeginPageBPP function which accepts 1, 8, and 24 bit images so I guess 1 bit images are not the only option (using DLL).
Command line app seems to read only TIFFs but it is not limited to 1 bit per pixel either.
I have not tested it though so I may be wrong.
352
So it is crashing only in Suse and Windows work ok?
I'll install Suse somewhere and try it. Works ok in Mandrake and Fedora though.

How do you want your image displayed? On VCL form or do you use OpenGL/DirectX/..?
If VCL is you case you can use DisplayImage or DisplayImageData functions or
TImagingGraphic class (Delphi's TBitmap descendant).


353
Could you please send me that image so I could test it?

Stack trace says it fails in TTextureFileFormat.TestFormat so you can disable
this file format and see if it helps. You can do it by commenting out
line with {$DEFINE LINK_ELDER}
in Imaging\Extras\Extensions\ImagingExtras.pas unit.
354
Help & Questions / Re: 1 bit image output
20 July 2007, 13:23:49
Lua binding sounds good, I'm interested. Please send it to me when it is ready (some small example would be nice too). I will add it to Extras directory.
355
Help & Questions / Re: 1 bit image output
6 July 2007, 22:56:50
Here is the code to convert image to 1 bit per pixel black and white image:


var
  Img: TSingleImage;
  Src, Bitmap: PByte;
begin

... load or create image ...

// First convert image to 8bpp grayscale
Img.Format := ifGray8;
Src := Img.Bits;

// Create bilevel image using 128 as treshold
for Y := 0 to Img.Height - 1 do
  for X := 0 to Img.Width - 1 do
  begin
    if Src^ > 128 then
      Src^ := 255
    else
      Src^ := 0;
    Inc(Src);
  end;

// Allocate memory for 1bpp image
WidthBytes := (Img.Width + 7) div 8;  // Scanlines size must be byte-aligned
GetMem(Bitmap, WidthBytes * Img.Height);
FillChar(Bitmap^, WidthBytes * Img.Height, 0);  // Needed by conversion code
Src := Img.Bits;

// Now copy pixels to Bitmap
for Y := 0 to Img.Height - 1 do
  for X := 0 to Img.Width - 1 do
  begin
    Bitmap[Y * WidthBytes + X div 8] := Bitmap[Y * WidthBytes + X div 8] or // OR current value of byte with following:
      (Src^ and 1)  // To make 1 from 255, 0 remains 0
      shl (7 - (X mod 8));  // Put current bit to proper place in byte

    Inc(Src);
  end;

Now you have 1bpp image in Bitmap memory. You may need to use different treshold than 128 for
different images.

QuoteJust have to look at the API.

Do you have some link to where can I get it? I've tried google but not found anything useful.


356
Help & Questions / Re: 1 bit image output
4 July 2007, 18:00:18
Do you need 1bit images only in memory or saved to files too?
If only keeping them in memory is needed I can post here how to do it.
Otherwise file format saver would have to be modified.
I am planning native support for 1/2/4 bit images in entire library (not only loading)
in the future but it would take time.

Does Triss only accept 1bit images or some other bilevel or similar formats too?
357
Version 0.24.0 of Imaging has been released today!
As stated in the previous development progress topic main addition
are new file formats.

Main news/changes in 0.24.0:
  - New image file format support: GIF (native), TIFF (libtiff), PSD (native).
  - New image data format: BTC (block truncation coding).
  - File format compatibility fixes (for BMP, JPEG, and DDS)
    and platform/compiler support fixes (Win64, UNIX, FPC, ...).
  - Bug fixes and some enhancements (buffered file IO, ...).
  - More

Head to Imaging Homepage for downloads and updated documentation.
358
I have changed it to {$ALIGN ON} and uploaded it to SVN.
Please let me know if it is ok (as I don't have Delphi 5 or older).
360
OK thanks, it works now. I will upload it to SVN after 0.24 release.
SMF spam blocked by CleanTalk