Skip to content

Commit

Permalink
Fix uv height computation.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jan 24, 2024
1 parent b00087c commit 1ed0016
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
=====
- Fix note names (#18).
- Fix GC pace when allocating bigarrays with custom memory.
- Fix UV height calculation in `caml_yuv420_fill`.

0.8.4 (2023-07-01)
=====
Expand Down
7 changes: 5 additions & 2 deletions src/imageYUV420.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type t = {

let width img = img.width
let height img = img.height
let uv_height height = Data.round 2 ((height + 1) / 2)
let dimensions img = (width img, height img)
let y img = img.y
let y_stride img = img.y_stride
Expand All @@ -65,7 +66,9 @@ let ensure_alpha img =
Data.fill a 0xff;
img.alpha <- Some a)

external fill : t -> Pixel.yuv -> unit = "caml_yuv420_fill"
external fill : t -> Pixel.yuv -> int -> unit = "caml_yuv420_fill"

let fill img pix = fill img pix (uv_height img.height)

let fill_alpha img a =
if a = 0xff then img.alpha <- None
Expand Down Expand Up @@ -104,7 +107,7 @@ let create ?(blank = false) ?y_stride ?uv_stride width height =
let y_stride, uv_stride = default_stride width y_stride uv_stride in
let y = Data.aligned align (height * y_stride) in
let u, v =
let height = Data.round 2 ((height + 1) / 2) in
let height = uv_height height in
( Data.aligned align (height * uv_stride),
Data.aligned align (height * uv_stride) )
in
Expand Down
7 changes: 3 additions & 4 deletions src/image_yuv420.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define round(r, n) (((n + (r - 1)) / r) * r)

CAMLprim value caml_yuv420_fill(value img, value p) {
CAMLprim value caml_yuv420_fill(value img, value p, value uv_height) {
CAMLparam2(img, p);
int y = Int_val(Field(p, 0));
int u = Int_val(Field(p, 1));
Expand All @@ -28,8 +27,8 @@ CAMLprim value caml_yuv420_fill(value img, value p) {
int y_stride = YUV420_y_stride(img);
int uv_stride = YUV420_uv_stride(img);
memset(YUV420_y(img), y, height * y_stride);
memset(YUV420_u(img), u, round(2, height / 2) * uv_stride);
memset(YUV420_v(img), v, round(2, height / 2) * uv_stride);
memset(YUV420_u(img), u, Int_val(uv_height) * uv_stride);
memset(YUV420_v(img), v, Int_val(uv_height) * uv_stride);
CAMLreturn(Val_unit);
}

Expand Down

0 comments on commit 1ed0016

Please sign in to comment.