2 using System.Collections.Generic;
7 namespace DirectOutput.General.BitmapHandling
42 if (X < Width && Y < Height)
76 SourceLeft = SourceLeft.Limit(0, Width - 1);
77 SourceTop = SourceTop.Limit(0, Height - 1);
78 SourceWidth = (SourceWidth < 0 ? Width - SourceLeft : SourceWidth);
79 SourceHeight = (SourceHeight < 0 ? Height - SourceTop : SourceHeight);
80 ResultWidth = ResultWidth.Limit(0,
int.MaxValue);
81 ResultHeight = ResultHeight.Limit(0,
int.MaxValue);
87 switch (DataExtractMode)
97 float PixelSourceWidth = (float)SourceWidth / ResultWidth;
98 float PixelSourceHeight = (float)SourceHeight / ResultHeight;
99 float PixelSourceCount = PixelSourceWidth * PixelSourceHeight;
102 for (
int y = 0; y < ResultHeight; y++)
104 float PixelSourceTop = SourceTop+ y * PixelSourceHeight;
105 float PixelSourceBottom = PixelSourceTop + PixelSourceHeight;
108 for (
int x = 0; x < ResultWidth; x++)
112 float PixelSourceLeft = SourceLeft+x * PixelSourceWidth;
113 float PixelSourceRight = PixelSourceLeft + PixelSourceWidth;
119 if (!PixelSourceTop.IsIntegral())
122 if (!PixelSourceLeft.IsIntegral())
124 PixelData PD = GetPixel((
int)PixelSourceLeft.Floor(), (int)PixelSourceTop.Floor());
125 Weight = (PixelSourceTop.Ceiling() - PixelSourceTop) * (PixelSourceLeft.Ceiling() - PixelSourceLeft);
126 Red += PD.
Red * Weight;
127 Green += PD.
Green * Weight;
128 Blue += PD.
Blue * Weight;
129 Alpha += PD.
Alpha * Weight;
133 PSR = (int)PixelSourceRight.Floor();
134 Weight = (PixelSourceTop.Ceiling() - PixelSourceTop);
135 for (
int xs = (
int)PixelSourceLeft.Ceiling(); xs < PSR; xs++)
137 PixelData PD = GetPixel(xs, (
int)PixelSourceTop.Floor());
138 Red += PD.
Red * Weight;
139 Green += PD.
Green * Weight;
140 Blue += PD.
Blue * Weight;
141 Alpha += PD.
Alpha * Weight;
145 if (!PixelSourceRight.IsIntegral())
147 Weight = (PixelSourceTop.Ceiling() - PixelSourceTop) * (PixelSourceRight - PixelSourceRight.Floor());
148 PixelData PD = GetPixel((
int)PixelSourceRight.Floor(), (int)PixelSourceTop.Floor());
149 Red += PD.
Red * Weight;
150 Green += PD.
Green * Weight;
151 Blue += PD.
Blue * Weight;
152 Alpha += PD.
Alpha * Weight;
156 PSB = (int)PixelSourceBottom.Floor();
157 PSR = (int)PixelSourceRight.Floor();
158 for (
int ys = (
int)PixelSourceTop.Ceiling(); ys < PSB; ys++)
161 if (!PixelSourceLeft.IsIntegral())
163 PixelData PD = GetPixel((
int)PixelSourceLeft.Floor(), ys);
164 Weight = (PixelSourceLeft.Ceiling() - PixelSourceLeft);
165 Red += PD.
Red * Weight;
166 Green += PD.
Green * Weight;
167 Blue += PD.
Blue * Weight;
168 Alpha += PD.
Alpha * Weight;
172 for (
int xs = (
int)PixelSourceLeft.Ceiling(); xs < PSR; xs++)
182 if (!PixelSourceRight.IsIntegral())
184 Weight = (PixelSourceRight - PSR);
186 Red += PD.
Red * Weight;
187 Green += PD.
Green * Weight;
188 Blue += PD.
Blue * Weight;
189 Alpha += PD.
Alpha * Weight;
194 if (!PixelSourceBottom.IsIntegral())
196 PSB = (int)PixelSourceBottom.Floor();
197 PSR = (int)PixelSourceRight.Floor();
200 if (!PixelSourceLeft.IsIntegral())
202 PixelData PD = GetPixel((
int)PixelSourceLeft.Floor(), PSB);
203 Weight = (PixelSourceBottom - PSB) * (PixelSourceLeft.Ceiling() - PixelSourceLeft);
204 Red += PD.
Red * Weight;
205 Green += PD.
Green * Weight;
206 Blue += PD.
Blue * Weight;
207 Alpha += PD.
Alpha * Weight;
213 Weight = (PixelSourceBottom - PSB);
214 for (
int xs = (
int)PixelSourceLeft.Ceiling(); xs < PSR; xs++)
217 Red += PD.
Red * Weight;
218 Green += PD.
Green * Weight;
219 Blue += PD.
Blue * Weight;
220 Alpha += PD.
Alpha * Weight;
224 if (!PixelSourceRight.IsIntegral())
226 Weight = (PixelSourceBottom - PSB) * (PixelSourceRight - PSR);
228 Red += PD.
Red * Weight;
229 Green += PD.
Green * Weight;
230 Blue += PD.
Blue * Weight;
231 Alpha += PD.
Alpha * Weight;
234 D[x, y] =
new PixelData((byte)(Red / PixelSourceCount).Limit(0, 255), (byte)(Green / PixelSourceCount).Limit(0, 255), (byte)(Blue / PixelSourceCount).Limit(0, 255), (byte)(Alpha / PixelSourceCount).Limit(0, 255));
244 float XSourceBase = 0;
246 float XStep = (float)SourceWidth / ResultWidth;
247 float YStep = (float)SourceHeight / ResultHeight;
251 XSourceBase = XStep / 2;
255 for (
int y = 0; y < ResultHeight; y++)
257 XSource = XSourceBase;
258 for (
int x = 0; x < ResultWidth; x++)
260 D[x, y] = GetPixel(XSource.RoundToInt(), YSource.RoundToInt());
280 public void SetFrameSize(
int Width,
int Height)
282 Pixels =
new PixelData[Width.Limit(0,
int.MaxValue), Height.Limit(0,
int.MaxValue)];
289 private int _Width = 0;
306 private int _Height = 0;
317 return Pixels.GetLength(1);
326 public void Load(Image Image)
328 Load(
new Bitmap(Image));
335 public void Load(Bitmap Bitmap)
341 SetFrameSize(Bitmap.Width, Bitmap.Height);
345 int h = Bitmap.Height;
346 int w = Bitmap.Width;
348 for (
int y = 0; y < h; y++)
350 for (
int x = 0; x < w; x++)