forked from dmtrKovalenko/odiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/dmtrKovalenko/odiff
- Loading branch information
Showing
28 changed files
with
479 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
open Odiff.ImageIO; | ||
|
||
module IO: Odiff.ImageIO.ImageIO = { | ||
type rowPointers = int; | ||
type t = { | ||
rowPointers, | ||
bigarray: Bigarray.Array1.t(int32, Bigarray.int32_elt, Bigarray.c_layout), | ||
}; | ||
|
||
type row = int; | ||
let readDirectPixel = (~x: int, ~y: int, img) => { | ||
let pixel = (img.image.bigarray).{y * img.width + x} |> Int32.to_int; | ||
|
||
let a = pixel lsr 24 land 0xFF; | ||
let r = pixel lsr 16 land 0xFF; | ||
let g = pixel lsr 8 land 0xFF; | ||
let b = pixel land 0xFF; | ||
|
||
(r, g, b, a); | ||
}; | ||
|
||
let readRow = (img: Odiff.ImageIO.img(t), y): row => y; | ||
// row is always an int, so we can read pixel directly | ||
let readImgColor = (x, row: row, img: Odiff.ImageIO.img(t)) => | ||
readDirectPixel(~x, ~y=row, img); | ||
|
||
let setImgColor = (x, y, pixel, img: Odiff.ImageIO.img(t)) => { | ||
ReadPng.set_pixel_data(img.image.rowPointers, x, y, pixel); | ||
}; | ||
|
||
let loadImage = (filename): Odiff.ImageIO.img(t) => { | ||
let (width, height, rowbytes, rowPointers) = | ||
ReadPng.read_png_image(filename); | ||
|
||
let bigarray = | ||
ReadPng.row_pointers_to_bigarray(rowPointers, rowbytes, height, width); | ||
|
||
{ | ||
width, | ||
height, | ||
image: { | ||
bigarray, | ||
rowPointers, | ||
}, | ||
}; | ||
}; | ||
|
||
let saveImage = (img: Odiff.ImageIO.img(t), filename) => { | ||
ReadPng.write_png_file( | ||
img.image.rowPointers, | ||
img.width, | ||
img.height, | ||
filename, | ||
); | ||
}; | ||
|
||
let freeImage = (img: Odiff.ImageIO.img(t)) => { | ||
ReadPng.free_row_pointers(img.image.rowPointers, img.height); | ||
}; | ||
|
||
let makeSameAsLayout = (img: Odiff.ImageIO.img(t)) => { | ||
{ | ||
...img, | ||
image: { | ||
rowPointers: ReadPng.create_empty_img(img.height, img.width), | ||
bigarray: img.image.bigarray, | ||
}, | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.