include "draw.s7i";
const type: pixelArray is array [1 ..] pixel;
const type: pixelImage is array [1 ..] pixelArray;
const proc: setPixels (inout pixelArray: imageLine, in integer: startColumn,
in integer: stopColumn, in pixel: currentPixel) is func
local
var integer: column is 0;
begin
for column range startColumn to stopColumn do
imageLine[column] := currentPixel;
end for;
end func;
const func PRIMITIVE_WINDOW: getPixmap (ref pixelImage: image) is action "DRW_GET_PIXMAP_FROM_PIXELS";
const func pixelImage: getPixelImage (in PRIMITIVE_WINDOW: aWindow) is action "DRW_GET_PIXEL_ARRAY";
const func pixelImage: getRotated90 (in pixelImage: image) is func
result
var pixelImage: rotatedImage is pixelImage.value;
local
var integer: srcLine is 0;
var integer: firstDestLine is 0;
var integer: destLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: destColumn is 1;
begin
rotatedImage := pixelImage[.. length(image[1])] times
pixelArray[.. length(image)] times pixel.value;
firstDestLine := length(image[1]);
lastSrcColumn := length(image[1]);
for srcLine range 1 to length(image) do
destLine := firstDestLine;
for srcColumn range 1 to lastSrcColumn do
rotatedImage[destLine][destColumn] := image[srcLine][srcColumn];
decr(destLine);
end for;
incr(destColumn);
end for;
end func;
const proc: rotate90 (inout pixelImage: image) is func
begin
image := getRotated90(image);
end func;
const func pixelImage: getRotated180 (in pixelImage: image) is func
result
var pixelImage: rotatedImage is pixelImage.value;
local
var integer: srcLine is 0;
var integer: destLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: firstDestColumn is 0;
var integer: destColumn is 1;
begin
rotatedImage := pixelImage[.. length(image)] times
pixelArray[.. length(image[1])] times pixel.value;
destLine := length(image);
lastSrcColumn := length(image[1]);
firstDestColumn := length(image[1]);
for srcLine range 1 to succ(length(image)) div 2 do
destColumn := firstDestColumn;
for srcColumn range 1 to lastSrcColumn do
rotatedImage[destLine][destColumn] := image[srcLine][srcColumn];
decr(destColumn);
end for;
decr(destLine);
end for;
end func;
const proc: rotate180 (inout pixelImage: image) is func
local
var integer: srcLine is 0;
var integer: destLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: firstDestColumn is 0;
var integer: destColumn is 1;
var pixel: aPixel is pixel.value;
begin
destLine := length(image);
lastSrcColumn := length(image[1]);
firstDestColumn := length(image[1]);
for srcLine range 1 to succ(length(image)) div 2 do
destColumn := firstDestColumn;
for srcColumn range 1 to lastSrcColumn do
aPixel := image[srcLine][srcColumn];
image[srcLine][srcColumn] := image[destLine][destColumn];
image[destLine][destColumn] := aPixel;
decr(destColumn);
end for;
decr(destLine);
end for;
end func;
const func pixelImage: getRotated270 (in pixelImage: image) is func
result
var pixelImage: rotatedImage is pixelImage.value;
local
var integer: srcLine is 0;
var integer: destLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: destColumn is 1;
begin
rotatedImage := pixelImage[.. length(image[1])] times
pixelArray[.. length(image)] times pixel.value;
lastSrcColumn := length(image[1]);
destColumn := length(image);
for srcLine range 1 to length(image) do
destLine := 1;
for srcColumn range 1 to lastSrcColumn do
rotatedImage[srcColumn][destColumn] := image[srcLine][srcColumn];
end for;
decr(destColumn);
end for;
end func;
const proc: rotate270 (inout pixelImage: image) is func
begin
image := getRotated270(image);
end func;
const proc: mirrorHorizontally (inout pixelImage: image) is func
local
var integer: srcLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: firstDestColumn is 0;
var integer: destColumn is 1;
var pixel: aPixel is pixel.value;
begin
lastSrcColumn := succ(length(image[1])) div 2;
firstDestColumn := length(image[1]);
for srcLine range 1 to length(image) do
destColumn := firstDestColumn;
for srcColumn range 1 to lastSrcColumn do
aPixel := image[srcLine][srcColumn];
image[srcLine][srcColumn] := image[srcLine][destColumn];
image[srcLine][destColumn] := aPixel;
decr(destColumn);
end for;
end for;
end func;
const proc: mirrorVertically (inout pixelImage: image) is func
local
var integer: srcLine is 0;
var integer: destLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var pixel: aPixel is pixel.value;
begin
destLine := length(image);
lastSrcColumn := length(image[1]);
for srcLine range 1 to succ(length(image)) div 2 do
for srcColumn range 1 to lastSrcColumn do
aPixel := image[srcLine][srcColumn];
image[srcLine][srcColumn] := image[destLine][srcColumn];
image[destLine][srcColumn] := aPixel;
end for;
decr(destLine);
end for;
end func;
const func pixelImage: getRotated90AndMirroredHorizontally (in pixelImage: image) is func
result
var pixelImage: destImage is pixelImage.value;
local
var integer: srcLine is 0;
var integer: firstDestLine is 0;
var integer: destLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: destColumn is 1;
begin
destImage := pixelImage[.. length(image[1])] times
pixelArray[.. length(image)] times pixel.value;
firstDestLine := length(image[1]);
lastSrcColumn := length(image[1]);
destColumn := length(image);
for srcLine range 1 to length(image) do
destLine := firstDestLine;
for srcColumn range 1 to lastSrcColumn do
destImage[destLine][destColumn] := image[srcLine][srcColumn];
decr(destLine);
end for;
decr(destColumn);
end for;
end func;
const func pixelImage: getRotated270AndMirroredHorizontally (in pixelImage: image) is func
result
var pixelImage: destImage is pixelImage.value;
local
var integer: srcLine is 0;
var integer: srcColumn is 0;
var integer: lastSrcColumn is 0;
var integer: destColumn is 1;
begin
destImage := pixelImage[.. length(image[1])] times
pixelArray[.. length(image)] times pixel.value;
lastSrcColumn := length(image[1]);
for srcLine range 1 to length(image) do
for srcColumn range 1 to lastSrcColumn do
destImage[srcColumn][destColumn] := image[srcLine][srcColumn];
end for;
incr(destColumn);
end for;
end func;