forge
Explore
Log in

Don't you dare go Hollow

S2: picture.rs plane fills read rows straight from the mapped plane through one plane_row helper; the row_buf copy is gone

Browse files at this commit

a78494532a2f35549588ab2f37da76da5281d037Ahmet Kaan GümüşParent: 8c693a2
crates/ec-hw/src/picture.rsmodified+13 -25
@@ -258,20 +258,16 @@ pub(crate) fn fill_i420_16(
258 let bytes = if bit_depth == 8 { 1 } else { 2 };258 let bytes = if bit_depth == 8 { 1 } else { 2 };
259 check_plane("luma", y_plane.len(), y_pitch, h, w * bytes)?;259 check_plane("luma", y_plane.len(), y_pitch, h, w * bytes)?;
260 check_plane("chroma", uv_plane.len(), uv_pitch, ch, cw * 2 * bytes)?;260 check_plane("chroma", uv_plane.len(), uv_pitch, ch, cw * 2 * bytes)?;
261- let mut row_buf = vec![0u8; uv_pitch.max(y_pitch).max(w * 2)];
262 match bit_depth {261 match bit_depth {
263 8 => {262 8 => {
264 for row in 0..h {263 for row in 0..h {
265- let src = row * y_pitch;264+ let line = plane_row(y_plane, y_pitch, row, w);
266- row_buf[..w].copy_from_slice(&y_plane[src..src + w]);265+ for (dst, &sample) in out.y[row * w..(row + 1) * w].iter_mut().zip(line) {
267- for (dst, &sample) in out.y[row * w..(row + 1) * w].iter_mut().zip(&row_buf[..w]) {
268 *dst = u16::from(sample) << 2;266 *dst = u16::from(sample) << 2;
269 }267 }
270 }268 }
271 for row in 0..ch {269 for row in 0..ch {
272- let src = row * uv_pitch;270+ let line = plane_row(uv_plane, uv_pitch, row, cw * 2);
273- let line = &mut row_buf[..cw * 2];
274- line.copy_from_slice(&uv_plane[src..src + cw * 2]);
275 for col in 0..cw {271 for col in 0..cw {
276 out.u[row * cw + col] = u16::from(line[col * 2]) << 2;272 out.u[row * cw + col] = u16::from(line[col * 2]) << 2;
277 out.v[row * cw + col] = u16::from(line[col * 2 + 1]) << 2;273 out.v[row * cw + col] = u16::from(line[col * 2 + 1]) << 2;
@@ -282,18 +278,14 @@ pub(crate) fn fill_i420_16(
282 // P010 is 16-bit little endian with the sample in the top ten278 // P010 is 16-bit little endian with the sample in the top ten
283 // bits; the low six are zero padding.279 // bits; the low six are zero padding.
284 for row in 0..h {280 for row in 0..h {
285- let src = row * y_pitch;281+ let line = plane_row(y_plane, y_pitch, row, w * 2);
286- let line = &mut row_buf[..w * 2];
287- line.copy_from_slice(&y_plane[src..src + w * 2]);
288 for col in 0..w {282 for col in 0..w {
289 out.y[row * w + col] =283 out.y[row * w + col] =
290 u16::from_le_bytes([line[col * 2], line[col * 2 + 1]]) >> 6;284 u16::from_le_bytes([line[col * 2], line[col * 2 + 1]]) >> 6;
291 }285 }
292 }286 }
293 for row in 0..ch {287 for row in 0..ch {
294- let src = row * uv_pitch;288+ let line = plane_row(uv_plane, uv_pitch, row, cw * 4);
295- let line = &mut row_buf[..cw * 4];
296- line.copy_from_slice(&uv_plane[src..src + cw * 4]);
297 for col in 0..cw {289 for col in 0..cw {
298 out.u[row * cw + col] =290 out.u[row * cw + col] =
299 u16::from_le_bytes([line[col * 4], line[col * 4 + 1]]) >> 6;291 u16::from_le_bytes([line[col * 4], line[col * 4 + 1]]) >> 6;
@@ -347,17 +339,13 @@ pub(crate) fn fill_i420(
347 let bytes = if bit_depth == 8 { 1 } else { 2 };339 let bytes = if bit_depth == 8 { 1 } else { 2 };
348 check_plane("luma", y_plane.len(), y_pitch, h, w * bytes)?;340 check_plane("luma", y_plane.len(), y_pitch, h, w * bytes)?;
349 check_plane("chroma", uv_plane.len(), uv_pitch, ch, cw * 2 * bytes)?;341 check_plane("chroma", uv_plane.len(), uv_pitch, ch, cw * 2 * bytes)?;
350- let mut row_buf = vec![0u8; uv_pitch.max(y_pitch).max(w * 2)];
351 match bit_depth {342 match bit_depth {
352 8 => {343 8 => {
353 for row in 0..h {344 for row in 0..h {
354- let src = row * y_pitch;345+ out.y[row * w..(row + 1) * w].copy_from_slice(plane_row(y_plane, y_pitch, row, w));
355- out.y[row * w..(row + 1) * w].copy_from_slice(&y_plane[src..src + w]);
356 }346 }
357 for row in 0..ch {347 for row in 0..ch {
358- let src = row * uv_pitch;348+ let line = plane_row(uv_plane, uv_pitch, row, cw * 2);
359- let line = &mut row_buf[..cw * 2];
360- line.copy_from_slice(&uv_plane[src..src + cw * 2]);
361 for col in 0..cw {349 for col in 0..cw {
362 out.u[row * cw + col] = line[col * 2];350 out.u[row * cw + col] = line[col * 2];
363 out.v[row * cw + col] = line[col * 2 + 1];351 out.v[row * cw + col] = line[col * 2 + 1];
@@ -368,17 +356,13 @@ pub(crate) fn fill_i420(
368 // P010 keeps the sample in the *high* bits of each u16, so the356 // P010 keeps the sample in the *high* bits of each u16, so the
369 // 8-bit value is the high byte — a shift by 8, not by 2.357 // 8-bit value is the high byte — a shift by 8, not by 2.
370 for row in 0..h {358 for row in 0..h {
371- let src = row * y_pitch;359+ let line = plane_row(y_plane, y_pitch, row, w * 2);
372- let line = &mut row_buf[..w * 2];
373- line.copy_from_slice(&y_plane[src..src + w * 2]);
374 for col in 0..w {360 for col in 0..w {
375 out.y[row * w + col] = line[col * 2 + 1];361 out.y[row * w + col] = line[col * 2 + 1];
376 }362 }
377 }363 }
378 for row in 0..ch {364 for row in 0..ch {
379- let src = row * uv_pitch;365+ let line = plane_row(uv_plane, uv_pitch, row, cw * 4);
380- let line = &mut row_buf[..cw * 4];
381- line.copy_from_slice(&uv_plane[src..src + cw * 4]);
382 for col in 0..cw {366 for col in 0..cw {
383 out.u[row * cw + col] = line[col * 4 + 1];367 out.u[row * cw + col] = line[col * 4 + 1];
384 out.v[row * cw + col] = line[col * 4 + 3];368 out.v[row * cw + col] = line[col * 4 + 3];
@@ -389,6 +373,10 @@ pub(crate) fn fill_i420(
389 Ok(())373 Ok(())
390 }374 }
391 375
376+fn plane_row(plane: &[u8], pitch: usize, row: usize, len: usize) -> &[u8] {
377+ &plane[row * pitch..row * pitch + len]
378+}
379+
392 /// Check that `rows` rows of `row_bytes` bytes at `pitch` fit in a plane of380 /// Check that `rows` rows of `row_bytes` bytes at `pitch` fit in a plane of
393 /// `len` bytes. A lost or half-initialised GPU context can hand back a short381 /// `len` bytes. A lost or half-initialised GPU context can hand back a short
394 /// or odd mapping; this turns what would be a slice panic into an error.382 /// or odd mapping; this turns what would be a slice panic into an error.