AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Help with Graphics32
Thema durchsuchen
Ansicht
Themen-Optionen

Help with Graphics32

Ein Thema von WojTec · begonnen am 19. Jan 2010 · letzter Beitrag vom 22. Jan 2010
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Help with Graphics32

  Alt 19. Jan 2010, 13:24
Hello,

I'm new on GR32 and need some help with it.

So, currently I'm using TBitmap to process image and now I want to port projects to GR32 library, because it has nice componens to display, is very fast, have layers, nice objects to create transformation and generaly is very powerful.

These are my questions:

- How to add effect to layer? For example in background layer I have some color image. Now I want to remove colors from its part. When I decide this area without colors is in wrong place, I move layer to correct one and old area again is in colors and new without. But I don't understand how to do it... I know only how to do it with TBitmap/TBitmap32 (mean with "flat" image - see sample code below)...

- How to add antialiasing to custom generated image (generator similar to the one from texture blending demo)?

- How to save GR32 drawing to file and load from it (with layers! - something like Photoshop doing with their PSD files). I know how to export layered drawing to image (eg. BMP, PNG, etc.), but what about "project file"?

I'm asking this stupid questions, because I not found any solution or demo. GR32 is great, but support for it worst than bad... I hope you understand my not very well EN and could help?

PS: This is example filter for flat image:

Delphi-Quellcode:
procedure CreateGrey(ASource: TBitmap32);
var
  Row: PColorBGRA;
  I, J: Integer;
begin
  Row := PColorBGRA(@ASource.Bits[0]);

  for I := 0 to ASource.Height - 1 do
  begin
    for J := 0 to ASource.Width - 1 do
    begin
      Row.R := (Row.R + Row.G + Row.B) div 3;
      Row.G := Row.R;
      Row.B := Row.R;

      Inc(Row);
    end;
  end;

  ASource.Changed;
end;
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#2

Re: Help with Graphics32

  Alt 19. Jan 2010, 15:24
Zitat von WojTec:
I hope you understand my not very well EN
It's better than most in a non-english community

Do you mean with your first question, that you want to have some sort of a mask, and everything under it should turn into grayscales? If so, you'd be best served with more bitmaps than just one. One containing the original image, one containing the mask, and a third that has the combined result. On the way to the result, you have parameters such as an offset to the mask under your control. But there is no such thing as attaching a filter to a layer. A layer is nothing more than second bitmap on top of another, and as such may only hold color-values like every ordinary bitmap.

As for AA, I don't know the texture blending demo, but it would help if you could clearify what "AA" means to you here. Usually, when relating to bitmaps, AA is nothing more than a smoothing filter, or a downscaling + some proper interpolation.

Saving in layers is not supported natively, there is no .GR32 Format or anything like that. You would have to either save each layer as a separate lile, implement your own export-filter for a format that supports layers (lots of format descriptions can be found here), or you develop your very own bitmap file format that supports all the features you may need.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Help with Graphics32

  Alt 19. Jan 2010, 18:17
Q1 is solved. This is more simple I thought! Must handle layer OnPain event, like this:
Delphi-Quellcode:
var
  DstRect: TFloatRect;
  R: TRect;
  B: TBitmap32;
begin
  with TPositionedLayer(Sender) do
  begin
    DstRect := GetAdjustedLocation;
    R := MakeRect(DstRect);

    if not Buffer.MeasuringMode then
    begin
      B := TBitmap32.Create;
      try
        B.SetSize(...); // size = layer size of course
        B.Canvas.CopyRect(...); // here copy from buffer

        // Image processing here

        B.DrawTo(Buffer, R); // Now can display
      finally
        B.Free;
      end;
    end;
    Buffer.Changed;
  end;
end;
Q2: Looka at this image (fragment of 1600x1200 image in scale 1:1):
http://i50.tinypic.com/1588boy.png
Edge should be smooth.
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#4

Re: Help with Graphics32

  Alt 19. Jan 2010, 19:05
Do you create these images from some form of parametric math, or do you have them "as is" as plain bitmaps? In the first case, you could just use so called "supersampling", which basically means: Render your image larger than it should be in the end, and downscale it with a nice filter. GR32 brings some very nice scaling filters along. In the latter case, you have a much much more serious problem, which cannot be solved this easily - especially not with affecting the image as a whole in a manner that it becomes blurry in all places.

A first step into the direction of an "intelligent" blur-filter is to use a crude form of edge-detection. You could, for example, filter the whole image using a Bei Google suchenSobel operator, and use the outcome as a mask that defines where to blur by how much. The blurring could be a gaussian filter with it's radius controlled per pixel by this mask.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#5

Re: Help with Graphics32

  Alt 19. Jan 2010, 20:38
Yes, images are rendered at runtime with math params. How much bigger should be rendered image to effective resample it to wanted size? For example if final size will be 1600x1200, render area should be lets say +10%?

Also I have another problem. I have these two procedures (extracted from ImageE program based on GR32 1.5).

Delphi-Quellcode:
procedure GreyScaleDilation(Bitmap: TBitmap32);
var
  i, j: Integer;
  D, S: PColor32;
  dst: TBitmap32;
  b, r, g, max: Byte;
  sz: array of Integer;
  sznr: Integer;
begin
  dst := TBitmap32.Create;
  dst.SetSize(Bitmap.Width, Bitmap.Height);
  // init;
  S := @Bitmap.Bits[0];
  sznr := Bitmap.Width * Bitmap.Height;
  sz := nil;
  SetLength(sz, sznr);

  for i := 0 to sznr - 1 do
  begin
    b := (S^ and $FF);
    g := (S^ shr 8) and $FF;
    r := (S^ shr 16) and $FF;
    max := Round((b + g + r) div 3);
    sz[i] := max;
    Inc(S);
  end;

  D := @dst.Bits[0];
  for j := 1 to Bitmap.Height - 1 do
  begin
    for i := 1 to Bitmap.Width - 1 do
    begin
      max := sz[(j * (Bitmap.Width - 1)) + i];

      if (sz[(j * (Bitmap.Width - 1)) + i - 1] > max) then
        max := sz[(j * (Bitmap.Width - 1)) + i - 1];
      if (sz[(j * (Bitmap.Width - 1)) + i + 1] > max) then
        max := sz[(j * (Bitmap.Width - 1)) + i + 1];
      if (sz[((j - 1) * (Bitmap.Width - 1)) + i] > max) then
        max := sz[((j - 1) * (Bitmap.Width - 1)) + i];
      if (sz[((j + 1) * (Bitmap.Width - 1)) + i] > max) then
        max := sz[((j + 1) * (Bitmap.Width - 1)) + i];

      if (sz[((j - 1) * (Bitmap.Width - 1)) + i - 1] > max) then
        max := sz[((j - 1) * (Bitmap.Width - 1)) + i - 1];
      if (sz[((j + 1) * (Bitmap.Width - 1)) + i - 1] > max) then
        max := sz[((j + 1) * (Bitmap.Width - 1)) + i - 1];
      if (sz[((j - 1) * (Bitmap.Width - 1)) + i + 1] > max) then
        max := sz[((j - 1) * (Bitmap.Width - 1)) + i + 1];
      if (sz[((j + 1) * (Bitmap.Width - 1)) + i + 1] > max) then
        max := sz[((j + 1) * (Bitmap.Width - 1)) + i + 1];

      // if max>$ff then max:=$ff;

      D^ := $FF000000 + max shl 16 + max shl 8 + max;
      Inc(D);
    end;
  end;

  Bitmap.Assign(dst);
  Bitmap.Changed;
end;

procedure GreyScaleErosion(Bitmap: TBitmap32);
var
  i, j: Integer;
  D, S: PColor32;
  dst: TBitmap32;
  b, r, g, min: Byte;
  sz: array of Integer;
  sznr: Integer;
begin
  dst := TBitmap32.Create;
  dst.SetSize(Bitmap.Width, Bitmap.Height);
  // init;
  S := @Bitmap.Bits[0];
  sznr := Bitmap.Width * Bitmap.Height;
  sz := nil;
  SetLength(sz, sznr);

  for i := 0 to sznr - 1 do
  begin
    b := (S^ and $FF);
    g := (S^ shr 8) and $FF;
    r := (S^ shr 16) and $FF;
    min := Round((b + g + r) div 3);
    sz[i] := min;
    Inc(S);
  end;

  D := @dst.Bits[0];
  for j := 1 to Bitmap.Height - 1 do
  begin
    for i := 1 to Bitmap.Width - 1 do
    begin
      min := sz[(j * (Bitmap.Width - 1)) + i];

      if (sz[(j * (Bitmap.Width - 1)) + i - 1] < min) then
        min := sz[(j * (Bitmap.Width - 1)) + i - 1];
      if (sz[(j * (Bitmap.Width - 1)) + i + 1] < min) then
        min := sz[(j * (Bitmap.Width - 1)) + i + 1];
      if (sz[((j - 1) * (Bitmap.Width - 1)) + i] < min) then
        min := sz[((j - 1) * (Bitmap.Width - 1)) + i];
      if (sz[((j + 1) * (Bitmap.Width - 1)) + i] < min) then
        min := sz[((j + 1) * (Bitmap.Width - 1)) + i];

      if (sz[((j - 1) * (Bitmap.Width - 1)) + i - 1] < min) then
        min := sz[((j - 1) * (Bitmap.Width - 1)) + i - 1];
      if (sz[((j + 1) * (Bitmap.Width - 1)) + i - 1] < min) then
        min := sz[((j + 1) * (Bitmap.Width - 1)) + i - 1];
      if (sz[((j - 1) * (Bitmap.Width - 1)) + i + 1] < min) then
        min := sz[((j - 1) * (Bitmap.Width - 1)) + i + 1];
      if (sz[((j + 1) * (Bitmap.Width - 1)) + i + 1] < min) then
        min := sz[((j + 1) * (Bitmap.Width - 1)) + i + 1];

      // if max>$ff then max:=$ff;

      D^ := $FF000000 + min shl 16 + min shl 8 + min;
      Inc(D);
    end;
  end;

  Bitmap.Assign(dst);
  Bitmap.Changed;
end;
Something is wrong with algorithms and I can't fix it. Processed image has black lines on bottom. Could you cast a glance on this code?
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#6

Re: Help with Graphics32

  Alt 19. Jan 2010, 23:13
10% are by far too few. Twice the size (four times the area) would provide a marginal improvement, 4x is okayish, 8x is good and from 16x on you get "production quality" results, though anything beyond 32x latest should pretty much make no visible difference no more.
If your rendering is such that you can pick any (x,y)-value and get the color at this position back (like raytracing for example), you won't have to actually render to that sizes, but could just sample multiple times for one pixel, each time with a sub-pixel offset, and average those. If it's drawing like with LineTo() and such, then you'd be better off really doing it with the oversized version.

The functions' i- and j-loops start with 1. I belive they should go from 0, but then you have to make sure that whenever (i-1) and/or (j-1) occurs, you need to clamp to 0, because negative indexes won't do very well . This at least would be my first shot, I haven't and currently cannot test it myself.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#7

Re: Help with Graphics32

  Alt 22. Jan 2010, 12:15
Thanks friend, you helped me But two above procedures subject is open, I don't know how to fix it
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:18 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz