Subject: Delphi 環境とC++Builder環境 Date: Sun, 13 Jul 2008 12:39:24 +0900 From: seizo To: Delphi@ml.users.gr.jp 槻 誠三(けやき せいぞう)です。 いつもお世話になっています。 基本的な質問、並びに長文で大変恐縮です。 Bitmap 形式の画像の明るさを補正する場合に例えば、Canvas.Pixels を使って procedure TForm1.BrightP(Bitmap: TBitmap; Ratio: Integer); var x, y: Integer; Pixel: Integer; R, G, B: Integer; begin if (Ratio < 0) or (Ratio > 200) then // 変更する明るさの % 値 Exit; // 0 % 〜 200 % for y := 0 to Bitmap.Height - 1 do begin for x := 0 to Bitmap.Width - 1 do begin Pixel := TColor(Bitmap.Canvas.Pixels[x][y]); R := Pixel and $000000FF; // Red G := (Pixel and $0000FF00) shr 8; // Green B := (Pixel and $00FF0000) shr 16; // Blue R := R * Ratio div 100 if R > 255 then R := 255 else if R < 0 then R := 0; G := G * Ratio div 100 if G > 255 then G := 255 else if G < 0 then G := 0; B := B * Ratio div 100 if B > 255 then B := 255 else if B < 0 then B := 0; Pixel := R or (G shl 8) or (B shl 16); Bitmap.Canvas.Pixels[x][y] = TColor(Pixel); end; end; end; のようにやると大変時間がかかるので、ScanLine を使おうと思って 次の様なコードを書いてみました。 procedure TForm1.BrightS(Bitmap: TBitmap; Ratio: Integer); var x, y: Integer; R, G, B: Integer; P : PByteArray; begin if (Ratio < 0) or (Ratio > 200) then // 変更する明るさの % 値 Exit; // 0 % 〜 200 % for y := 0 to Bitmap.Height - 1 do begin P := Bitmap.ScanLine[y]; for x := 0 to Bitmap.Width - 1 do begin R := P[x * 3]; // Red G := P[x * 3 + 1]; // Green B := P[x * 3 + 2]; // Blue R := R * Ratio div 100 if R > 255 then R := 255 else if R < 0 then R := 0; G := G * Ratio div 100 if G > 255 then G := 255 else if G < 0 then G := 0; B := B * Ratio div 100 if B > 255 then B := 255 else if B < 0 then B := 0; P[x * 3] := R; // Red P[x * 3 + 1] := G; // Green P[x * 3 + 2] := B; // Blue end; end; end; ところが、この BrightS 手続きは、Bitmap.PixelFormat = pf24bit の とき、すなわち 24 ビットカラーを前提としたコードです。 PixelFormat が他の値の時の対処のしかたが分かりません。 たとえば、pf8bit 256色カラーのときなんかはそもそも、Red, Green, Blue の 3 要素に分ける事が可能なんでしょうか。また逆に pf32bit の場合は、 最上位の 8 ビットは何に使われているんでしょうか。 どなたかお助け下さい。 2008.09.28(Sun) 22:01 槻 誠三(けやき せいぞう)