Les Snippets

Connexion

Image en niveaux de gris

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 26/03/2006 14:02:43 et initié par MorpionMx [Liste]
Date de mise à jour : 14/05/2007 10:12:47
Vue : 23304
Catégorie(s) : Graphique
Langages dispo pour ce code :
- C# 1.x, C# 2.x
- VB 2005, VB.NET 1.x
- C# 1.x, C# 2.x
- VB 2005, VB.NET 1.x
- VB6
- VB6
- Java
- Assembleur x86
- Delphi 5
- Java
- C++, C++ .NET 1.x, C++ .NET 2.x
- Delphi 5
- Delphi 5
- Voir tous les langages pour ce code snippet



Langage : Delphi 5
Date ajout : 03/07/2008
Posté par f0xi [Liste]
type
  pByteQuad = ^ByteQuad;
  ByteQuad  = array[0..3] of byte;

procedure GrayByMinMax(src, dest : TBitmap);
var X : integer;
    pPix : pByteQuad;
    Bo,Bm,Bx : byte;
begin
  if Src.PixelFormat <> pf32bit then
  begin
    Src.PixelFormat  := pf32Bit;
    Dest.PixelFormat := pf32Bit;
  end;
  Dest.Assign(Src);
  pPix := Dest.ScanLine[Dest.Height-1];
  for X := 0 to (Dest.Width*Dest.Height)-1 do
  begin
    if pPix^[0] > pPix^[2] then
    begin
      Bx := pPix^[0];
      Bm := pPix^[2];
    end
    else
    begin
      Bx := pPix^[2];
      Bm := pPix^[0];
    end;
    if pPix^[1] > Bx then
      Bx := pPix^[1]
    else
    if pPix^[1] < Bm then
      Bm := pPix^[1];

    Bo := (Bx + Bm) shr 1;
    pPix^[0] := Bo; // B
    pPix^[1] := Bo; // G
    pPix^[2] := Bo; // R
    inc(pPix);
  end;
end;
{ ------- }
procedure GrayByRGBAverage(src, dest : TBitmap);
var X   : integer;
    pPix  : pByteQuad;
    Bo    : byte;
begin
  if Src.PixelFormat <> pf32bit then
  begin
    Src.PixelFormat  := pf32Bit;
    Dest.PixelFormat := pf32Bit;
  end;
  Dest.Assign(Src);
  pPix := Dest.ScanLine[Dest.Height-1];
  for X := 0 to (Dest.Width*Dest.Height)-1 do
  begin
    Bo  := (((pPix^[0] + pPix^[1]) shr 1) + pPix^[2]) shr 1;
    pPix^[0] := Bo; // B
    pPix^[1] := Bo; // G
    pPix^[2] := Bo; // R
    inc(pPix);
  end;
end;
{ ------- }
procedure TrueGrayScale(Src : TBitmap; Dest : TBitmap);
var
  X  : integer;
  Bo : integer;
  pPix : pByteQuad;
  PCLR : array[0..255] of single;
  PCLG : array[0..255] of single;
  PCLB : array[0..255] of single;
const
  LumRed   = 0.2125; // % of red
  LumGreen = 0.7154; // % of green
  LumBlue  = 0.0721; // % of blue
                     // = 100% (1.0)
begin
  if Src.PixelFormat <> pf32bit then
  begin
    Src.PixelFormat  := pf32Bit;
    Dest.PixelFormat := pf32Bit;
  end;
  Dest.Assign(Src);
  { PreCalculs }
  for X := 0 to 255 do
  begin
    PCLR[X] := X*LumRed;
    PCLG[X] := X*LumGreen;
    PCLB[X] := X*LumBlue;
  end;
  pPix := Dest.ScanLine[Dest.Height-1];
  for X := 0 to (Dest.Width*Dest.Height)-1 do
  begin
    Bo := byte(Round(PCLB[pPix^[0]] + PCLG[pPix^[1]] + PCLR[pPix^[2]]));
    pPix^[0] := Bo;
    pPix^[1] := Bo;
    pPix^[2] := Bo;
    inc(pPix);
  end;
end;



Snippets en rapport avec : Image, Picture, Niveau, Gris, Grayscale



Codes sources en rapport avec : Image, Picture, Niveau, Gris, Grayscale

{JAVA / J2EE} FAIRE DEFILER UNE IMAGE
...

{Visual Basic, VB6, VB.NET, VB 2005} CONVERTIR UNE IMAGE EN NIVEAU DE GRIS
On peut convertir une image couleur en niveau de gris via une formule empirique liée aux composantes...

{PHP} CRÉE UNE IMAGE DE PILE DE MINIATURES EN UTILISANT LA BIBLIOTHÈQUE GD
Tout est dans le titre. Regarder la capture pour mieux comprendre. N'hésitez pas à me contacter ...

{Visual Basic, VB6, VB.NET, VB 2005} LOUPE PICTURE BOX
AUTEUR: ProgElecT SOURCE: http://www.developpez.net/forums/d208213/autres-langages/general-visual...

{Visual Basic, VB6, VB.NET, VB 2005} REDIMENSIONNER IMAGE + COMPRESSION EN JPG ( AVEC OPTION )
Bonjour, Ce controle utilisateur reprend pour plus de simplicité la methode de redimensionnement ...

{PHP} REDIMENSIONNEMENT D'UNE IMAGES, GIF, PNG, JPEG, JPG
J'éspère que ce code vous sera utile, je n'ai pas encore eu de problème avec ce code, je l'ai amélio...

{Visual Basic, VB6, VB.NET, VB 2005} ROTATION IMAGE AVEC GDI+ (EXEMPLES ET QUESTIONS)
Quelques humbles exemples à partir du source de Renfield que j'espère n'avoir pas trop massacré, pou...

{Delphi} CHARGER DES IMAGES A PARTIR D'UNE DLL
Charger des images a partir d'une DLL...

{C / C++ / C++.NET} ECRAN DE VEILLE (LOAD IMAGE REPERTOIRE)
Bonjour, Je recherchais un écran de veille paramétrable assez facilement, ne le trouvant pas j'ai...

{Javascript / DHTML} DIAPORAMA PHP / JS
Bonjour, voila ne trouvant pas de diaporama à mon goût, j'ai décidé d'en faire un moi même ;) C'est...