Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -1,51 +1,51 @@
|
|||
Bitmap_FloodFill:
|
||||
;input:
|
||||
;r0 = color to fill screen with (15-bit color)
|
||||
STMFD sp!,{r0-r12,lr}
|
||||
|
||||
MOV R2,#160
|
||||
MOV R4,#0x06000000
|
||||
;input:
|
||||
;r0 = color to fill screen with (15-bit color)
|
||||
STMFD sp!,{r0-r12,lr}
|
||||
|
||||
MOV R2,#160
|
||||
MOV R4,#0x06000000
|
||||
outerloop_floodfill:
|
||||
MOV R1,#240 ;restore inner loop counter
|
||||
MOV R1,#240 ;restore inner loop counter
|
||||
innerloop_floodfill:
|
||||
strH r0,[r4]
|
||||
add r4,r4,#2 ;next pixel
|
||||
subs r1,r1,#1 ;decrement loop counter
|
||||
bne innerloop_floodfill
|
||||
subs r2,r2,#1
|
||||
bne outerloop_floodfill
|
||||
|
||||
LDMFD sp!,{r0-r12,pc}
|
||||
|
||||
strH r0,[r4]
|
||||
add r4,r4,#2 ;next pixel
|
||||
subs r1,r1,#1 ;decrement loop counter
|
||||
bne innerloop_floodfill
|
||||
subs r2,r2,#1
|
||||
bne outerloop_floodfill
|
||||
|
||||
LDMFD sp!,{r0-r12,pc}
|
||||
|
||||
Bitmap_Locate:
|
||||
;given x and y coordinates, offsets vram addr to that pixel on screen.
|
||||
;input:
|
||||
;r0 = x
|
||||
;r1 = y
|
||||
;output: r2 = vram area
|
||||
STMFD sp!,{r4-r12,lr}
|
||||
mov r2,#0x06000000 ;vram base
|
||||
;input:
|
||||
;r0 = x
|
||||
;r1 = y
|
||||
;output: r2 = vram area
|
||||
STMFD sp!,{r4-r12,lr}
|
||||
mov r2,#0x06000000 ;vram base
|
||||
|
||||
|
||||
mov r4,#240*2 ;240 pixels across, 2 bytes per pixel
|
||||
mul r1,r4,r1
|
||||
add r2,r2,r1 ;add y*480
|
||||
add r2,r2,r0,lsl #1 ;add x*2
|
||||
LDMFD sp!,{r4-r12,pc}
|
||||
|
||||
|
||||
mov r4,#240*2 ;240 pixels across, 2 bytes per pixel
|
||||
mul r1,r4,r1
|
||||
add r2,r2,r1 ;add y*480
|
||||
add r2,r2,r0,lsl #1 ;add x*2
|
||||
LDMFD sp!,{r4-r12,pc}
|
||||
|
||||
Bitmap_StorePixel:
|
||||
;input: r3 = color
|
||||
;r0 = x
|
||||
;r1 = y
|
||||
bl Bitmap_Locate
|
||||
strH r3,[r2] ;store the pixel color in video memory
|
||||
bx lr
|
||||
|
||||
;input: r3 = color
|
||||
;r0 = x
|
||||
;r1 = y
|
||||
bl Bitmap_Locate
|
||||
strH r3,[r2] ;store the pixel color in video memory
|
||||
bx lr
|
||||
|
||||
Bitmap_GetPixel:
|
||||
;retrieves the color of the pixel at [r2] and stores its color value in r3.
|
||||
;r0 = x
|
||||
;r1 = y
|
||||
;output in r3
|
||||
bl Bitmap_Locate
|
||||
ldrH r3,[r2]
|
||||
bx lr
|
||||
;r0 = x
|
||||
;r1 = y
|
||||
;output in r3
|
||||
bl Bitmap_Locate
|
||||
ldrH r3,[r2]
|
||||
bx lr
|
||||
|
|
|
|||
17
Task/Bitmap/Ada/bitmap-1.adb
Normal file
17
Task/Bitmap/Ada/bitmap-1.adb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package Bitmap_Store is
|
||||
type Luminance is mod 2**8;
|
||||
type Pixel is record
|
||||
R, G, B : Luminance := Luminance'First;
|
||||
end record;
|
||||
Black : constant Pixel := (others => Luminance'First);
|
||||
White : constant Pixel := (others => Luminance'Last);
|
||||
type Image is array (Positive range <>, Positive range <>) of Pixel;
|
||||
|
||||
procedure Fill (Picture : in out Image; Color : Pixel);
|
||||
|
||||
procedure Print (Picture : Image);
|
||||
|
||||
type Point is record
|
||||
X, Y : Positive;
|
||||
end record;
|
||||
end Bitmap_Store;
|
||||
20
Task/Bitmap/Ada/bitmap-2.adb
Normal file
20
Task/Bitmap/Ada/bitmap-2.adb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
package body Bitmap_Store is
|
||||
|
||||
procedure Fill (Picture : in out Image; Color : Pixel) is
|
||||
begin
|
||||
for p of Picture loop x:= Color;end loop;
|
||||
end Fill;
|
||||
|
||||
procedure Print (Picture : Image) is
|
||||
begin
|
||||
for I in Picture'Range (1) loop
|
||||
for J in Picture'Range (2) loop
|
||||
Put (if Picture (I, J) = White then ' ' else 'H');
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
end Print;
|
||||
|
||||
end Bitmap_Store;
|
||||
7
Task/Bitmap/Ada/bitmap-3.adb
Normal file
7
Task/Bitmap/Ada/bitmap-3.adb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
use Bitmap_Store; with Bitmap_Store;
|
||||
...
|
||||
X : Image (1..64, 1..64);
|
||||
begin
|
||||
Fill (X, (255, 255, 255));
|
||||
X (1, 2) := (R => 255, others => 0);
|
||||
X (3, 4) := X (1, 2);
|
||||
|
|
@ -21,13 +21,13 @@ background := black
|
|||
if !BitmapType
|
||||
BitmapType
|
||||
:= Object("fill", "Bitmap_Fill"
|
||||
,"write", "Bitmap_write_ppm3")
|
||||
,"write", "Bitmap_write_ppm3")
|
||||
|
||||
img := Object("width", width
|
||||
img := Object("width", width
|
||||
,"height", height
|
||||
, "base" , BitmapType)
|
||||
|
||||
img._SetCapacity(height) ; an array of rows
|
||||
img._SetCapacity(height) ; an array of rows
|
||||
img.fill(background)
|
||||
Return img
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ void fill_img(image img,
|
|||
color_component g,
|
||||
color_component b );
|
||||
void put_pixel_unsafe(
|
||||
image img,
|
||||
image img,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
color_component r,
|
||||
color_component g,
|
||||
color_component b );
|
||||
void put_pixel_clip(
|
||||
image img,
|
||||
image img,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
color_component r,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ void fill_img(
|
|||
}
|
||||
|
||||
void put_pixel_unsafe(
|
||||
image img,
|
||||
image img,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
color_component r,
|
||||
|
|
@ -46,7 +46,7 @@ void put_pixel_unsafe(
|
|||
}
|
||||
|
||||
void put_pixel_clip(
|
||||
image img,
|
||||
image img,
|
||||
unsigned int x,
|
||||
unsigned int y,
|
||||
color_component r,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(import '[java.awt Color Graphics Image]
|
||||
'[java.awt.image BufferedImage])
|
||||
'[java.awt.image BufferedImage])
|
||||
|
||||
(defn blank-bitmap [width height]
|
||||
(BufferedImage. width height BufferedImage/TYPE_3BYTE_BGR))
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@
|
|||
(declare (type rgb-pixel-buffer buffer))
|
||||
(declare (type rgb-pixel pixel))
|
||||
(let* ((dimensions (array-dimensions buffer))
|
||||
(width (first dimensions))
|
||||
(height (second dimensions)))
|
||||
(width (first dimensions))
|
||||
(height (second dimensions)))
|
||||
(loop
|
||||
:for y :of-type fixnum :upfrom 0 :below height
|
||||
:do (loop
|
||||
:for x :of-type fixnum :upfrom 0 :below width
|
||||
:do (setf (rgb-pixel buffer x y) pixel)))
|
||||
:for x :of-type fixnum :upfrom 0 :below width
|
||||
:do (setf (rgb-pixel buffer x y) pixel)))
|
||||
buffer))
|
||||
|
|
|
|||
105
Task/Bitmap/Crystal/bitmap-1.cr
Normal file
105
Task/Bitmap/Crystal/bitmap-1.cr
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
record Color, r : UInt8, g : UInt8, b : UInt8 do
|
||||
def self.new (r : Int32, g : Int32, b : Int32)
|
||||
self.new r.to_u8, g.to_u8, b.to_u8
|
||||
end
|
||||
|
||||
def self.new (hex : Int32)
|
||||
self.new (hex >> 16 & 0xFF).to_u8, (hex >> 8 & 0xFF).to_u8, (hex & 0xFF).to_u8
|
||||
end
|
||||
|
||||
def to_i
|
||||
(r.to_i << 16) + (g.to_i << 8) + b.to_i
|
||||
end
|
||||
|
||||
def == (other : Color)
|
||||
self.to_i == other.to_i
|
||||
end
|
||||
|
||||
WHITE = new 0xFFFFFF
|
||||
BLACK = new 0x000000
|
||||
RED = new 0xFF0000
|
||||
GREEN = new 0x00FF00
|
||||
BLUE = new 0x0000FF
|
||||
end
|
||||
|
||||
class Pixmap
|
||||
getter width, height
|
||||
@data : Array(Color)
|
||||
|
||||
def initialize (@width : Int32, @height : Int32, bg_color = Color::BLACK)
|
||||
@data = Array.new(@width * @height, bg_color)
|
||||
end
|
||||
|
||||
def initialize (@width : Int32, @height : Int32, @data : Array(Color), copy = false)
|
||||
raise "Wrong bounds" unless @width * @height == @data.size
|
||||
@data = @data.dup if copy
|
||||
end
|
||||
|
||||
def initialize (other : self)
|
||||
@width = other.@width
|
||||
@height = other.@height
|
||||
@data = other.@data.dup
|
||||
end
|
||||
|
||||
def fill (color)
|
||||
@data.fill color
|
||||
end
|
||||
|
||||
def [] (x, y)
|
||||
raise "Outside bounds" unless 0 <= x < @width && 0 <= y < @height
|
||||
@data[y * @width + x]
|
||||
end
|
||||
|
||||
def []= (x, y, color)
|
||||
if 0 <= x < @width && 0 <= y < @height
|
||||
@data[y * @width + x] = color
|
||||
end
|
||||
color
|
||||
end
|
||||
|
||||
@@loaders = {} of String => Proc(IO, Pixmap)
|
||||
@@writers = {} of String | Nil => Proc(Pixmap, IO, Nil)
|
||||
|
||||
macro register_loader (ext, method)
|
||||
@@loaders[{{ext}}] = ->(io : IO) { {{method.id}}(io) }
|
||||
end
|
||||
|
||||
macro register_writer (ext, method)
|
||||
@@writers[{{ext}}] = ->(img : Pixmap, io : IO) { img.{{method.id}}(io) }
|
||||
end
|
||||
|
||||
def self.load (filename)
|
||||
ext = File.extname(filename)
|
||||
loader = @@loaders[ext]? || raise "No loader for '.#{ext}'"
|
||||
File.open(filename) do |f|
|
||||
loader.call(f)
|
||||
end
|
||||
end
|
||||
|
||||
def write (filename_or_io : Path | String | IO)
|
||||
if filename_or_io.is_a?(IO)
|
||||
writer = @@writers[nil]? || raise "No console writer"
|
||||
writer.call(self, filename_or_io)
|
||||
else
|
||||
ext = File.extname(filename_or_io)
|
||||
writer = @@writers[ext]? || raise "No writer for '#{ext}'"
|
||||
File.open(filename_or_io, "w") do |f|
|
||||
writer.call(self, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def write_poor_text (io)
|
||||
(0...@height).each do |y|
|
||||
(0...@width).each do |x|
|
||||
print case self[x, y]
|
||||
when Color::BLACK then '#'
|
||||
when Color::WHITE then ' '
|
||||
else 'X'
|
||||
end
|
||||
end
|
||||
puts
|
||||
end
|
||||
end
|
||||
register_writer nil, write_poor_text
|
||||
end
|
||||
9
Task/Bitmap/Crystal/bitmap-2.cr
Normal file
9
Task/Bitmap/Crystal/bitmap-2.cr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
require "./pixmap"
|
||||
|
||||
img = Pixmap.new(10, 5)
|
||||
(0...10).each do |x|
|
||||
img[x, x // 2] = Color::WHITE
|
||||
img[9-x, x // 2] = Color::RED
|
||||
end
|
||||
|
||||
img.write(STDOUT)
|
||||
|
|
@ -12,21 +12,21 @@ Image.Canvas.Brush.Color:=clBlue;
|
|||
Image.Canvas.FloodFill(55,55,clRed,fsBorder);
|
||||
{Draw random dots on the screen}
|
||||
for I:=1 to 1000 do
|
||||
begin
|
||||
X:=trunc((Random * 450) + 50);
|
||||
Y:=trunc((Random * 250) + 50);
|
||||
C:=RGB(Random(255),Random(255),Random(255));
|
||||
{draw 9 pixels for each point to make dots more visible}
|
||||
Image.Canvas.Pixels[X-1,Y-1]:=C;
|
||||
Image.Canvas.Pixels[X ,Y-1]:=C;
|
||||
Image.Canvas.Pixels[X+1,Y-1]:=C;
|
||||
Image.Canvas.Pixels[X-1,Y ]:=C;
|
||||
Image.Canvas.Pixels[X ,Y ]:=C;
|
||||
Image.Canvas.Pixels[X+1,Y ]:=C;
|
||||
Image.Canvas.Pixels[X-1,Y+1]:=C;
|
||||
Image.Canvas.Pixels[X ,Y+1]:=C;
|
||||
Image.Canvas.Pixels[X+1,Y+1]:=C;
|
||||
end;
|
||||
begin
|
||||
X:=trunc((Random * 450) + 50);
|
||||
Y:=trunc((Random * 250) + 50);
|
||||
C:=RGB(Random(255),Random(255),Random(255));
|
||||
{draw 9 pixels for each point to make dots more visible}
|
||||
Image.Canvas.Pixels[X-1,Y-1]:=C;
|
||||
Image.Canvas.Pixels[X ,Y-1]:=C;
|
||||
Image.Canvas.Pixels[X+1,Y-1]:=C;
|
||||
Image.Canvas.Pixels[X-1,Y ]:=C;
|
||||
Image.Canvas.Pixels[X ,Y ]:=C;
|
||||
Image.Canvas.Pixels[X+1,Y ]:=C;
|
||||
Image.Canvas.Pixels[X-1,Y+1]:=C;
|
||||
Image.Canvas.Pixels[X ,Y+1]:=C;
|
||||
Image.Canvas.Pixels[X+1,Y+1]:=C;
|
||||
end;
|
||||
{Draw lime-green line from corner to cornder}
|
||||
Image.Canvas.Pen.Color:=clLime;
|
||||
Image.Canvas.MoveTo(50,50);
|
||||
|
|
|
|||
23
Task/Bitmap/Euphoria/bitmap.eu
Normal file
23
Task/Bitmap/Euphoria/bitmap.eu
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
-- Some color constants:
|
||||
constant
|
||||
black = #000000,
|
||||
white = #FFFFFF,
|
||||
red = #FF0000,
|
||||
green = #00FF00,
|
||||
blue = #0000FF
|
||||
|
||||
-- Create new image filled with some color
|
||||
function new_image(integer width, integer height, atom fill_color)
|
||||
return repeat(repeat(fill_color,height),width)
|
||||
end function
|
||||
|
||||
-- Usage example:
|
||||
sequence image
|
||||
image = new_image(800,600,black)
|
||||
|
||||
-- Set pixel color:
|
||||
image[400][300] = red
|
||||
|
||||
-- Get pixel color
|
||||
atom color
|
||||
color = image[400][300] -- Now color is #FF0000
|
||||
|
|
@ -11,12 +11,12 @@ CENTER(ME)
|
|||
SHOW(ME)
|
||||
|
||||
BEGIN EVENTS
|
||||
SELECT CASE CBMSG
|
||||
CASE WM_LBUTTONDOWN ' Set color at current coords as hex literal
|
||||
PSET(FBSL.GETDC, LOWORD(CBLPARAM), HIWORD(CBLPARAM), &H0000FF) ' Red: Windows stores colors in BGR order
|
||||
CASE WM_RBUTTONDOWN ' Get color at current coords as hex literal
|
||||
FBSLSETTEXT(ME, "&H" & HEX(POINT(FBSL.GETDC, LOWORD(CBLPARAM), HIWORD(CBLPARAM))))
|
||||
CASE WM_CLOSE ' Clean up
|
||||
FBSL.RELEASEDC(ME, FBSL.GETDC)
|
||||
END SELECT
|
||||
SELECT CASE CBMSG
|
||||
CASE WM_LBUTTONDOWN ' Set color at current coords as hex literal
|
||||
PSET(FBSL.GETDC, LOWORD(CBLPARAM), HIWORD(CBLPARAM), &H0000FF) ' Red: Windows stores colors in BGR order
|
||||
CASE WM_RBUTTONDOWN ' Get color at current coords as hex literal
|
||||
FBSLSETTEXT(ME, "&H" & HEX(POINT(FBSL.GETDC, LOWORD(CBLPARAM), HIWORD(CBLPARAM))))
|
||||
CASE WM_CLOSE ' Clean up
|
||||
FBSL.RELEASEDC(ME, FBSL.GETDC)
|
||||
END SELECT
|
||||
END EVENTS
|
||||
|
|
|
|||
|
|
@ -1,57 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// A rectangle from 0,0 to 300,240.
|
||||
r := image.Rect(0, 0, 300, 240)
|
||||
// A rectangle from 0,0 to 300,240.
|
||||
r := image.Rect(0, 0, 300, 240)
|
||||
|
||||
// Create an image
|
||||
im := image.NewNRGBA(r)
|
||||
// Create an image
|
||||
im := image.NewNRGBA(r)
|
||||
|
||||
// set some color variables for convience
|
||||
var (
|
||||
red = color.RGBA{0xff, 0x00, 0x00, 0xff}
|
||||
blue = color.RGBA{0x00, 0x00, 0xff, 0xff}
|
||||
)
|
||||
// set some color variables for convience
|
||||
var (
|
||||
red = color.RGBA{0xff, 0x00, 0x00, 0xff}
|
||||
blue = color.RGBA{0x00, 0x00, 0xff, 0xff}
|
||||
)
|
||||
|
||||
// Fill with a uniform color
|
||||
draw.Draw(im, r, &image.Uniform{red}, image.ZP, draw.Src)
|
||||
// Fill with a uniform color
|
||||
draw.Draw(im, r, &image.Uniform{red}, image.ZP, draw.Src)
|
||||
|
||||
// Set individual pixels
|
||||
im.Set(10, 20, blue)
|
||||
im.Set(20, 30, color.Black)
|
||||
im.Set(30, 40, color.RGBA{0x10, 0x20, 0x30, 0xff})
|
||||
// Set individual pixels
|
||||
im.Set(10, 20, blue)
|
||||
im.Set(20, 30, color.Black)
|
||||
im.Set(30, 40, color.RGBA{0x10, 0x20, 0x30, 0xff})
|
||||
|
||||
// Get the values of specific pixels as color.Color types.
|
||||
// The color will be in the color.Model of the image (in this
|
||||
// case color.NRGBA) but color models can convert their values
|
||||
// to other models.
|
||||
c1 := im.At(0, 0)
|
||||
c2 := im.At(10, 20)
|
||||
// Get the values of specific pixels as color.Color types.
|
||||
// The color will be in the color.Model of the image (in this
|
||||
// case color.NRGBA) but color models can convert their values
|
||||
// to other models.
|
||||
c1 := im.At(0, 0)
|
||||
c2 := im.At(10, 20)
|
||||
|
||||
// or directly as RGB components (scaled values)
|
||||
redc, greenc, bluec, _ := c1.RGBA()
|
||||
redc, greenc, bluec, _ = im.At(30, 40).RGBA()
|
||||
// or directly as RGB components (scaled values)
|
||||
redc, greenc, bluec, _ := c1.RGBA()
|
||||
redc, greenc, bluec, _ = im.At(30, 40).RGBA()
|
||||
|
||||
// Images can be read and writen in various formats
|
||||
var buf bytes.Buffer
|
||||
err := png.Encode(&buf, im)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Images can be read and writen in various formats
|
||||
var buf bytes.Buffer
|
||||
err := png.Encode(&buf, im)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("Image size:", im.Bounds().Dx(), "×", im.Bounds().Dy())
|
||||
fmt.Println(buf.Len(), "bytes when encoded as PNG.")
|
||||
fmt.Printf("Pixel at %7v is %v\n", image.Pt(0, 0), c1)
|
||||
fmt.Printf("Pixel at %7v is %#v\n", image.Pt(10, 20), c2) // %#v shows type details
|
||||
fmt.Printf("Pixel at %7v has R=%d, G=%d, B=%d\n",
|
||||
image.Pt(30, 40), redc, greenc, bluec)
|
||||
fmt.Println("Image size:", im.Bounds().Dx(), "×", im.Bounds().Dy())
|
||||
fmt.Println(buf.Len(), "bytes when encoded as PNG.")
|
||||
fmt.Printf("Pixel at %7v is %v\n", image.Pt(0, 0), c1)
|
||||
fmt.Printf("Pixel at %7v is %#v\n", image.Pt(10, 20), c2) // %#v shows type details
|
||||
fmt.Printf("Pixel at %7v has R=%d, G=%d, B=%d\n",
|
||||
image.Pt(30, 40), redc, greenc, bluec)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
allocateImg := proc(width, height)
|
||||
return Array(1..width, 1..height, 1..3);
|
||||
return Array(1..width, 1..height, 1..3);
|
||||
end proc:
|
||||
fillColor := proc(img, rgb::list)
|
||||
local i;
|
||||
for i from 1 to 3 do
|
||||
img[..,..,i] := map(x->rgb[i], img[..,..,i]):
|
||||
end do:
|
||||
local i;
|
||||
for i from 1 to 3 do
|
||||
img[..,..,i] := map(x->rgb[i], img[..,..,i]):
|
||||
end do:
|
||||
end proc:
|
||||
setColor := proc(x, y, img, rgb::list)
|
||||
local i:
|
||||
for i from 1 to 3 do
|
||||
img[x,y,i] := rgb[i]:
|
||||
end do:
|
||||
local i:
|
||||
for i from 1 to 3 do
|
||||
img[x,y,i] := rgb[i]:
|
||||
end do:
|
||||
end proc:
|
||||
getColor := proc(x,y,img)
|
||||
local rgb,i:
|
||||
rgb := Array(1..3):
|
||||
for i from 1 to 3 do
|
||||
rgb(i) := img[x,y,i]:
|
||||
end do:
|
||||
return rgb:
|
||||
local rgb,i:
|
||||
rgb := Array(1..3):
|
||||
for i from 1 to 3 do
|
||||
rgb(i) := img[x,y,i]:
|
||||
end do:
|
||||
return rgb:
|
||||
end proc:
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ img = Image.create(width, height, colr)
|
|||
// Create a diagonal line of multiple colors. Uses
|
||||
// Cartesian coordinates so (0, 0) is lower left corner.
|
||||
for i in range(0, 255)
|
||||
img.setPixel i, i, color.rgb(i, i, i)
|
||||
img.setPixel i, i, color.rgb(i, i, i)
|
||||
end for
|
||||
|
||||
// Get pixel color as RGBA hex values
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ define
|
|||
C = {Array.new 1 Height unit}
|
||||
in
|
||||
for Row in 1..Height do
|
||||
C.Row := {Array.new 1 Width Init}
|
||||
C.Row := {Array.new 1 Width Init}
|
||||
end
|
||||
|
||||
array2d(width:Width
|
||||
height:Height
|
||||
contents:C)
|
||||
height:Height
|
||||
contents:C)
|
||||
end
|
||||
|
||||
fun {Get array2d(contents:C ...) X Y}
|
||||
|
|
@ -27,9 +27,9 @@ define
|
|||
|
||||
proc {Transform array2d(contents:C width:W height:H ...) Fun}
|
||||
for Y in 1..H do
|
||||
for X in 1..W do
|
||||
C.Y.X := {Fun C.Y.X}
|
||||
end
|
||||
for X in 1..W do
|
||||
C.Y.X := {Fun C.Y.X}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -117,14 +117,14 @@ Procedure CreateBmpFile32(directory: string; FileName: string;
|
|||
{ fill the pixel data area }
|
||||
for y := (height - 1) downto 0 do
|
||||
begin
|
||||
for x := 0 to (width - 1) do
|
||||
begin { Pixel(x,y) }
|
||||
color32.Blue := 255;
|
||||
color32.Green := 0;
|
||||
color32.Red := 0;
|
||||
color32.Alfa := 0;
|
||||
BlockWrite(bmpFile, color32, 4);
|
||||
end; { for x ... }
|
||||
for x := 0 to (width - 1) do
|
||||
begin { Pixel(x,y) }
|
||||
color32.Blue := 255;
|
||||
color32.Green := 0;
|
||||
color32.Red := 0;
|
||||
color32.Alfa := 0;
|
||||
BlockWrite(bmpFile, color32, 4);
|
||||
end; { for x ... }
|
||||
end; { for y ... }
|
||||
Close(bmpFile);
|
||||
end; { with bmpInfoHeader, bmpFileHeader }
|
||||
|
|
|
|||
23
Task/Bitmap/Pluto/bitmap-1.pluto
Normal file
23
Task/Bitmap/Pluto/bitmap-1.pluto
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
local canvas = require "canvas"
|
||||
|
||||
-- Create a new canvas object: 400 pixels wide and 400 pixels high.
|
||||
local c = canvas.new(400, 400)
|
||||
|
||||
-- Color the whole canvas blue.
|
||||
c:fill(0xff0000)
|
||||
|
||||
-- Draw a red square in the middle.
|
||||
for i = 1, 51 do
|
||||
for j = 1, 51 do
|
||||
c:set(174 + i, 174 + j, 0x0000ff)
|
||||
end
|
||||
end
|
||||
|
||||
-- Print to the terminal the color (as an integer) of a pixel.
|
||||
print(c:get(200, 200)) -- 255
|
||||
|
||||
-- Convert the canvas to a BMP image.
|
||||
local image = c:tobmp()
|
||||
|
||||
-- Save the image to a file.
|
||||
io.contents("mybmp.bmp", image)
|
||||
16
Task/Bitmap/Pluto/bitmap-2.pluto
Normal file
16
Task/Bitmap/Pluto/bitmap-2.pluto
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
require "bitmap"
|
||||
|
||||
-- Create a new bitmap object: 400 pixels wide and 400 pixels high
|
||||
local bmp = bitmap.of(400, 400, color.blue, "mybmp")
|
||||
|
||||
-- Draw a red square in the middle.
|
||||
bmp:square(200, 200, 50, color.red, 0, true)
|
||||
|
||||
-- Print to the terminal the color (as an integer) of a pixel.
|
||||
print(bmp:get(200, 200)) -- 255
|
||||
|
||||
-- View the image using the default viewer for the platform.
|
||||
bmp:view()
|
||||
|
||||
-- Save the image to the file mybmp.bmp in the current directory.
|
||||
bmp:save()
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
:- module(bitmap, [
|
||||
new_bitmap/3,
|
||||
fill_bitmap/3,
|
||||
get_pixel0/3,
|
||||
set_pixel0/4 ]).
|
||||
new_bitmap/3,
|
||||
fill_bitmap/3,
|
||||
get_pixel0/3,
|
||||
set_pixel0/4 ]).
|
||||
|
||||
:- use_module(library(lists)).
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
% Convenience Predicates
|
||||
replicate(Term,Times,L):-
|
||||
length(L,Times),
|
||||
maplist(=(Term),L).
|
||||
length(L,Times),
|
||||
maplist(=(Term),L).
|
||||
|
||||
replace0(N,OL,E,NL):-
|
||||
nth0(N,OL,_,TL),
|
||||
nth0(N,NL,E,TL).
|
||||
nth0(N,OL,_,TL),
|
||||
nth0(N,NL,E,TL).
|
||||
%-----------------------------------------------------------------------------%
|
||||
% Bitmap Utilities
|
||||
%
|
||||
|
|
@ -25,27 +25,27 @@ replace0(N,OL,E,NL):-
|
|||
% in other bitmap tasks it is assumed to be a list [R,G,B] where
|
||||
% each is an int between 0 and 255, in code:
|
||||
rgb_pixel(RGB):-
|
||||
length(RGB,3),
|
||||
maplist(integer,RGB),
|
||||
maplist(between(0,255),RGB).
|
||||
length(RGB,3),
|
||||
maplist(integer,RGB),
|
||||
maplist(between(0,255),RGB).
|
||||
|
||||
%new_bitmap(Bitmap,Dimensions,RGB)
|
||||
new_bitmap([[X,Y],Pixels],[X,Y],RGB) :-
|
||||
replicate(RGB,X,Row),
|
||||
replicate(Row,Y,Pixels).
|
||||
|
||||
replicate(RGB,X,Row),
|
||||
replicate(Row,Y,Pixels).
|
||||
|
||||
%fill_bitmap(New_Bitmap,Bitmap,RGB)
|
||||
fill_bitmap(New_Bitmap,[[X,Y],_],RGB) :-
|
||||
new_bitmap(New_Bitmap,[X,Y],RGB).
|
||||
new_bitmap(New_Bitmap,[X,Y],RGB).
|
||||
|
||||
%here get and set use 0 based indexing
|
||||
%get_pixel0(Bitmap,Coordinates,RGB)
|
||||
get_pixel0([[_DimX,_DimY],Pixels],[X,Y],RGB) :-
|
||||
nth0(Y,Pixels,Row),
|
||||
nth0(X,Row,RGB).
|
||||
nth0(Y,Pixels,Row),
|
||||
nth0(X,Row,RGB).
|
||||
|
||||
%set_pixel0(New Bitmap, Bitmap, Coordinates, RGB)
|
||||
set_pixel0([[DimX,DimY],New_Pixels],[[DimX,DimY],Pixels],[X,Y],RGB) :-
|
||||
nth0(Y,Pixels,Row),
|
||||
replace0(X,Row,RGB,New_Row),
|
||||
replace0(Y,Pixels,New_Row,New_Pixels).
|
||||
nth0(Y,Pixels,Row),
|
||||
replace0(X,Row,RGB,New_Row),
|
||||
replace0(Y,Pixels,New_Row,New_Pixels).
|
||||
|
|
|
|||
|
|
@ -7,16 +7,16 @@ class Bitmap {
|
|||
@!data = $p.clone xx ($!width*$!height)
|
||||
}
|
||||
method pixel(
|
||||
$i where ^$!width,
|
||||
$j where ^$!height
|
||||
--> Pixel
|
||||
$i where ^$!width,
|
||||
$j where ^$!height
|
||||
--> Pixel
|
||||
) is rw { @!data[$i + $j * $!width] }
|
||||
|
||||
method set-pixel ($i, $j, Pixel $p) {
|
||||
self.pixel($i, $j) = $p.clone;
|
||||
self.pixel($i, $j) = $p.clone;
|
||||
}
|
||||
method get-pixel ($i, $j) returns Pixel {
|
||||
self.pixel($i, $j);
|
||||
self.pixel($i, $j);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ CREATE form AS QForm
|
|||
Height = 480
|
||||
CREATE canvas AS QCanvas
|
||||
Height = form.ClientHeight
|
||||
Width = form.ClientWidth
|
||||
OnPaint = PaintCanvas
|
||||
Width = form.ClientWidth
|
||||
OnPaint = PaintCanvas
|
||||
END CREATE
|
||||
END CREATE
|
||||
|
||||
|
|
|
|||
58
Task/Bitmap/Rebol/bitmap.rebol
Normal file
58
Task/Bitmap/Rebol/bitmap.rebol
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
;; make image using pair
|
||||
img: make image! 2x2
|
||||
;; make image using pair and RGB tuple
|
||||
img: make image! [2x2 255.0.0]
|
||||
;; make image using pair and RGBA tuple"
|
||||
img: make image! [2x2 255.0.0.10]
|
||||
|
||||
;; Rebol3's construction syntax
|
||||
img1: #(image! 4x4) ;; white by default
|
||||
img2: #(image! 2x2 0.0.0) ;; black image
|
||||
|
||||
;; Raw binary access:
|
||||
probe img1/rgb
|
||||
;== #{
|
||||
;== FFFFFFFFFFFFFFFFFFFFFFFF
|
||||
;== FFFFFFFFFFFFFFFFFFFFFFFF
|
||||
;== FFFFFFFFFFFFFFFFFFFFFFFF
|
||||
;== FFFFFFFFFFFFFFFFFFFFFFFF}
|
||||
|
||||
;; Blit image to image
|
||||
change at img1 2x2 img2
|
||||
probe img1/rgb
|
||||
;== #{
|
||||
;== FFFFFFFFFFFFFFFFFFFFFFFF
|
||||
;== FFFFFF000000000000FFFFFF
|
||||
;== FFFFFF000000000000FFFFFF
|
||||
;== FFFFFFFFFFFFFFFFFFFFFFFF}
|
||||
|
||||
;; Pixel access
|
||||
img1/1 ;== 255.255.255.255
|
||||
img2/1 ;== 0.0.0.255
|
||||
img1/2x2 ;== 0.0.0.255
|
||||
|
||||
;; Other binary accessors:
|
||||
img: #(image! 2x1)
|
||||
img/1: 1.2.3.100
|
||||
img/2: 4.5.6.200
|
||||
img/rgba ;== #{01020364040506C8}
|
||||
img/rgbo ;== #{0102039B04050637}
|
||||
img/argb ;== #{64010203C8040506}
|
||||
img/orgb ;== #{9B01020337040506}
|
||||
img/bgra ;== #{03020164060504C8}
|
||||
img/bgro ;== #{0302019B06050437}
|
||||
img/abgr ;== #{64030201C8060504}
|
||||
img/obgr ;== #{9B03020137060504}
|
||||
img/opacity ;== #{9B37}
|
||||
img/alpha ;== #{64C8}
|
||||
|
||||
;; Drawing may be done using extensions like Blend2D
|
||||
import blend2d ;@@ https://github.com/Siskin-framework/Rebol-Blend2D
|
||||
img: draw 100x100 [
|
||||
fill red
|
||||
pen black
|
||||
line-width 10
|
||||
circle 50x50 20
|
||||
fill none
|
||||
line 0x0 100x100
|
||||
]
|
||||
|
|
@ -2,37 +2,37 @@ RGB ::= (R: int(0), G: int(0), B: int(0));
|
|||
|
||||
newBitmap: int * int -> RGB(2);
|
||||
newBitmap(width, height)[y, x] :=
|
||||
(R: 0, G: 0, B: 0)
|
||||
foreach y within 1 ... height,
|
||||
x within 1 ... width;
|
||||
(R: 0, G: 0, B: 0)
|
||||
foreach y within 1 ... height,
|
||||
x within 1 ... width;
|
||||
|
||||
fill: RGB(2) * RGB -> RGB(2);
|
||||
fill(bitmap(2), color)[y, x] :=
|
||||
color
|
||||
foreach y within 1 ... size(bitmap),
|
||||
x within 1 ... size(bitmap[y]);
|
||||
color
|
||||
foreach y within 1 ... size(bitmap),
|
||||
x within 1 ... size(bitmap[y]);
|
||||
|
||||
setColorAt: RGB(2) * int * int * RGB -> RGB(2);
|
||||
setColorAt(bitmap(2), x, y, color)[Y, X] :=
|
||||
color when Y = y and X = x
|
||||
else
|
||||
bitmap[Y, X];
|
||||
|
||||
getColorAt: RGB(2) * int * int -> RGB;
|
||||
color when Y = y and X = x
|
||||
else
|
||||
bitmap[Y, X];
|
||||
|
||||
getColorAt: RGB(2) * int * int -> RGB;
|
||||
getColorAt(bitmap(2), x, y) := bitmap[y, x];
|
||||
|
||||
lightGreen := (R: 51, G: 255, B: 51);
|
||||
lightRed := (R: 255, G: 51, B: 51);
|
||||
|
||||
main(args(2)) :=
|
||||
let
|
||||
width := 1920;
|
||||
height := 1200;
|
||||
|
||||
cleanImage := newBitmap(width, height);
|
||||
|
||||
filledGreen := fill(cleanImage, lightGreen);
|
||||
|
||||
redCenter := setColorAt(filledGreen, width / 2, height / 2, lightRed);
|
||||
in
|
||||
getColorAt(redCenter, width / 2, height / 2);
|
||||
let
|
||||
width := 1920;
|
||||
height := 1200;
|
||||
|
||||
cleanImage := newBitmap(width, height);
|
||||
|
||||
filledGreen := fill(cleanImage, lightGreen);
|
||||
|
||||
redCenter := setColorAt(filledGreen, width / 2, height / 2, lightRed);
|
||||
in
|
||||
getColorAt(redCenter, width / 2, height / 2);
|
||||
|
|
|
|||
3
Task/Bitmap/Uiua/bitmap.uiua
Normal file
3
Task/Bitmap/Uiua/bitmap.uiua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
↯ 50_50_3 Red # Fill with red.
|
||||
⍜(⊡25_25|⋅White) # Add white spot.
|
||||
⊸⊡0_0 # Get pixel [0 0].
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#11 = 400 // Width of the image
|
||||
#12 = 300 // Height of the image
|
||||
#11 = 400 // Width of the image
|
||||
#12 = 300 // Height of the image
|
||||
|
||||
// Create an empty RGB image and fill it with black color
|
||||
//
|
||||
|
|
@ -13,16 +13,16 @@ Repeat(#11 * #12) {
|
|||
|
||||
// Fill the image with dark blue color
|
||||
//
|
||||
#5 = 0 // Red
|
||||
#6 = 0 // Green
|
||||
#7 = 64 // Blue
|
||||
#5 = 0 // Red
|
||||
#6 = 0 // Green
|
||||
#7 = 64 // Blue
|
||||
Call("FILL_IMAGE")
|
||||
|
||||
// Draw one pixel in orange color
|
||||
//
|
||||
#1 = 100 // x
|
||||
#2 = 50 // y
|
||||
#5 = 255 #6 = 128 #7 = 0 // Orange color
|
||||
#1 = 100 // x
|
||||
#2 = 50 // y
|
||||
#5 = 255 #6 = 128 #7 = 0 // Orange color
|
||||
Call("DRAW_PIXEL")
|
||||
|
||||
// Get the color of a pixel
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ backcolor 255, 0, 0 // red
|
|||
|
||||
clear window
|
||||
|
||||
color 0, 255, 0 // green
|
||||
color 0, 255, 0 // green
|
||||
dot 100, 100
|
||||
|
||||
c$ = getbit$(100, 100, 100, 100) // get color area 1x1 pixel
|
||||
c$ = getbit$(100, 100, 100, 100) // get color area 1x1 pixel
|
||||
print c$
|
||||
|
|
|
|||
96
Task/Bitmap/Zig/bitmap.zig
Normal file
96
Task/Bitmap/Zig/bitmap.zig
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub const Rgb = struct {
|
||||
r: u8,
|
||||
g: u8,
|
||||
b: u8,
|
||||
};
|
||||
|
||||
pub const PixelOutOfBounds = error{PixelOutOfBounds};
|
||||
|
||||
pub const Bitmap = struct {
|
||||
width: usize,
|
||||
height: usize,
|
||||
pixels: []Rgb,
|
||||
|
||||
// The ! next to the return type communicates that the function may return an error
|
||||
pub fn new(allocator: std.mem.Allocator, width: usize, height: usize) !Bitmap {
|
||||
// In Zig libraries that allocate receive an allocator
|
||||
// instead of choosing one themselves
|
||||
var pixels = try allocator.alloc(Rgb, width * height);
|
||||
|
||||
for (0..width*height) | i | {
|
||||
pixels[i] = Rgb { .r = 0, .g = 0, .b = 0 };
|
||||
}
|
||||
|
||||
return Bitmap {
|
||||
.width = width,
|
||||
.height = height,
|
||||
.pixels = pixels,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn free(self: Bitmap, allocator: std.mem.Allocator) void {
|
||||
allocator.free(self.pixels);
|
||||
}
|
||||
|
||||
pub fn fill(self: *Bitmap, color: Rgb) void {
|
||||
for (0..self.width*self.height) | i | {
|
||||
self.pixels[i] = color;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_pixel_unchecked(self: Bitmap, x: usize, y: usize) Rgb {
|
||||
return self.pixels[self.height * y + x];
|
||||
}
|
||||
|
||||
pub fn get_pixel(self: Bitmap, x: usize, y: usize) !Rgb {
|
||||
if (self.width <= x or self.height <= y) {
|
||||
return error.PixelOutOfBounds;
|
||||
}
|
||||
|
||||
return self.get_pixel_unchecked(x, y);
|
||||
}
|
||||
|
||||
pub fn set_pixel_unchecked(self: *Bitmap, x: usize, y: usize, color: Rgb) void {
|
||||
self.pixels[self.height * y + x] = color;
|
||||
}
|
||||
|
||||
pub fn set_pixel(self: *Bitmap, x: usize, y: usize, color: Rgb) !void {
|
||||
if (self.width <= x or self.height <= y) {
|
||||
return error.PixelOutOfBounds;
|
||||
}
|
||||
|
||||
return self.set_pixel_unchecked(x, y, color);
|
||||
}
|
||||
};
|
||||
|
||||
test "putting a pixel gets the pixel" {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var bm = try Bitmap.new(allocator, 10, 10);
|
||||
defer bm.free(allocator);
|
||||
|
||||
try bm.set_pixel(4, 4, Rgb {.r=255, .g=0, .b=0});
|
||||
|
||||
const pixel = try bm.get_pixel(4, 4);
|
||||
|
||||
try std.testing.expectEqual(255, pixel.r);
|
||||
}
|
||||
|
||||
test "filling a pixel gets all the pixels" {
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var bm = try Bitmap.new(allocator, 10, 10);
|
||||
defer bm.free(allocator);
|
||||
|
||||
bm.fill(Rgb {.r=255, .g=0, .b=0});
|
||||
|
||||
for (0..10) | x | {
|
||||
for (0..10) | y | {
|
||||
try std.testing.expectEqual(255, bm.get_pixel_unchecked(x, y).r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,16 @@
|
|||
class PPM{ // (0,0) is logically bottom left
|
||||
class PPM{ // (0,0) is logically bottom left
|
||||
fcn init(width,height){
|
||||
sz:=width*height*3;
|
||||
var [const]
|
||||
data=sz.pump(Data(sz),0), // initialize to Black (RGB=000)
|
||||
w=width, h=height;
|
||||
w=width, h=height;
|
||||
}
|
||||
fcn fill(rgb){
|
||||
sz:=data.len()/3;
|
||||
data.clear(); sz.pump(data,T(Void,rgb.toBigEndian(3)));
|
||||
}
|
||||
fcn __sGet(x,y) { data.toBigEndian(3*y*w + 3*x,3); } //ppm[x,y]
|
||||
fcn __sSet(rbg,x,y){ data[3*y*w + 3*x,3]=rbg.toBigEndian(3); } //ppm[x,y]=rgb
|
||||
fcn __sSet(rbg,x,y){ data[3*y*w + 3*x,3]=rbg.toBigEndian(3); } //ppm[x,y]=rgb
|
||||
fcn write(out){ // write bottom to top to move (0,0) from bottom left to bottom left
|
||||
out.write("P6\n#rosettacode PPM\n%d %d\n255\n".fmt(w,h));
|
||||
[h-1..0, -1].pump(out,'wrap(h){ data.seek(3*h*w); data.read(3*w) });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue