Tema: Histograma
Ver Mensaje Individual
  #2  
Antiguo 05-07-2008
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 22
cHackAll Va por buen camino
Es un poco dificil ayudar cuando no se "tiene" el código completo; "undeclared identifier; pRGBTripleArray" !!! y bueno tambien vale la pena comentar el mismo problema acerca de las variables globales!

Eh aqui una posible solucion... tiene alguna falla pero no la puedo probar con el "original", por lo anteriormente comentado!

Código Delphi [-]
function GetHistogram(Image: TImage; UseMax: LongBool = True): TBitmap;
type
 RGBStruct = packed record
  b, g, r: byte;
 end;
var
 Color: ^RGBStruct;
 Count, Max: Cardinal;
 Index, Position, r, g, b: Byte;
 Histogram: array [0..255] of record
  r, g, b: Cardinal;
 end;
 Value: TColor;
begin
 Max := 0;
 Result := TBitmap.Create;
 Result.Assign(Image.Picture.Graphic);
 Result.PixelFormat := pf24bit;
 Count := Result.Width * Result.Height;
 Color := Result.ScanLine[Result.Height - 1];
 FillChar(Histogram, SizeOf(Histogram), 0);
 while LongBool(Count) do
  begin
   Inc(Histogram[Color.r].r);
   Inc(Histogram[Color.g].g);
   Inc(Histogram[Color.b].b);
   if UseMax then
    begin
     if Color.r > Max then Max := Color.r;
     if Color.g > Max then Max := Color.g;
     if Color.b > Max then Max := Color.b;
    end;
   Inc(Color);
   Dec(Count);
  end;
 Result.Width := 256;
 Result.Height := 256;
 if not UseMax then Inc(Max);
 for Index := 0 to 255 do
  begin
   Histogram[Index].r := (Histogram[Index].r * 100) div Max;
   Histogram[Index].g := (Histogram[Index].g * 100) div Max;
   Histogram[Index].b := (Histogram[Index].b * 100) div Max;
   for Position := 0 to 255 do
    begin
     r := Byte(Position <= Histogram[Index].r) * 255;
     g := Byte(Position <= Histogram[Index].g) * 255;
     b := Byte(Position <= Histogram[Index].b) * 255;
     if (r > 0) and (g > 0) and (b > 0) then
      Value := RGB(r, g, b)
     else
      Value := clGray shr 1;
     Result.Canvas.Pixels[Index, Position] := Value;
    end;
  end;
end;

Toma una atencion principal en la cantidad de bucles; y en el uso del ScanLine.

Un Saludo
Responder Con Cita