JFLib

img_core/ops.rs#

Source: lib/img_core/ops.rs

ops -- whole-image operations on 32-bit surfaces (PARGB / ARGB / XRGB)  [src/img/imgops.s]

  flip_h(sf)                                   mirror left <-> right (in place)  [img_flip_h]
  flip_v(sf)                                   mirror top <-> bottom (in place)  [img_flip_v]
  rotate180(sf)                                (in place)                     [img_rotate180]
  rotate90(src, dir) -> Result<Surface, i32>   h x w; dir >= 0 clockwise, < 0 counter-
                                               clockwise                      [img_rotate90]
  crop(src, x, y, w, h) -> Result<Surface>     w x h; parts outside src transparent [img_crop]
  resize_canvas(src, w, h, fill) -> Result<>   w x h filled with fill (premultiplied like
                                               Dc::clear), src copied to its top-left
                                                                         [img_resize_canvas]
  blit_copy(dst, src, x, y)                    copy src to (x, y), no blending, clipped to
                                               dst only (not to a draw context's clip)
                                                                             [gfx_blit_copy]
  scale(src, w, h, bilinear) -> Result<>       16.16 fixed-point nearest / bilinear (7-bit
                                               fractions), edges clamped        [img_scale]
  skew(src, kx, ky, fill) -> Result<>          x' = x + kx y / 1000, y' = y + ky x / 1000,
                                               nearest, forward mapped; dst grows to fit
                                                                                 [img_skew]
  Band, Band::whole(sf), bands(sf, k)          disjoint row ranges of a surface, so worker
                                               threads can write different rows at once
                                               (the bands of rstest's rt_bands)

Results keep the source format; the Err value is ERR_FAIL (-1, the assembly's -1) when a
surface size is out of range or its memory is not there.  Rows are 4 bytes per pixel (blit_copy, scale, skew and the
flips copy whole pixels).
  • struct Band<'a> rows y0 .. y1 (exclusive) of a surface of w x h pixels: px holds them from row y0 on, row y at (y - y0) * stride. What one worker of a parallel loop may write.
    • px: &'a mut [u8]
    • w: i32
    • h: i32
    • fmt: u8
    • stride: usize
    • y0: i32
    • y1: i32

impl<'a> Band<'a>

  • fn whole(sf: &'a mut Surface) -> Band<'a> every row of sf

  • fn row(&mut self, y: i32) -> &mut [u8] row y (y0 <= y < y1) from its first pixel to the end of the band

  • fn bands(sf: &mut Surface, k: usize) -> Vec<Band<'_>> k bands of rows i * h / k .. (i + 1) * h / k (k < 1: one band)

  • fn flip_h(sf: &mut Surface) mirror left <-> right [img_flip_h]

  • fn flip_v(sf: &mut Surface) mirror top <-> bottom [img_flip_v]

  • fn rotate180(sf: &mut Surface) [img_rotate180]

  • fn rotate90(src: &Surface, dir: i32) -> Result<Surface, i32> a new h x w surface: clockwise dst(H-1-y, x) = src(x, y) (dir >= 0), counter-clockwise dst(y, W-1-x) = src(x, y) [img_rotate90]

  • fn blit_copy(dst: &mut Surface, src: &Surface, x: i32, y: i32) copy src to (x, y) of dst without blending, clipped to dst [gfx_blit_copy]

  • fn crop(src: &Surface, x: i32, y: i32, w: i32, h: i32) -> Result<Surface, i32> the w x h part of src at (x, y); outside parts transparent [img_crop]

  • fn resize_canvas(src: &Surface, w: i32, h: i32, fill: u32) -> Result<Surface, i32> w x h filled with fill, src copied to the top-left corner [img_resize_canvas]

  • fn scale(src: &Surface, w: i32, h: i32, bilinear: bool) -> Result<Surface, i32> w x h nearest / bilinear copy (16.16 steps, pixel centres) [img_scale]

  • fn skew(src: &Surface, kx: i32, ky: i32, fill: u32) -> Result<Surface, i32> shear by kx, ky in 1/1000 (nearest, every source pixel mapped forward); the dst grows by |kx h / 1000| x |ky w / 1000| and is filled with fill first [img_skew]

  • fn bpp(fmt: u8) -> usize bytes per pixel of a format (A8: 1, else 4)

Source: docs/API.md in the JFLib repository.