Lines Matching +full:offset +full:- +full:y
1 // SPDX-License-Identifier: GPL-2.0+
15 * packed_pixels_offset() - Get the offset of the block containing the pixel at coordinates x/y
19 * @y: The y coordinate of the wanted pixel in the buffer
21 * @offset: The returned offset inside the buffer of the block
23 * @rem_y: The returned Y coordinate of the requested pixel in the block
26 * pixels are not individually addressable. This function return 3 values: the offset of the
28 * For example, if the format is DRM_FORMAT_R1 and the requested coordinate is 13,5, the offset
34 static void packed_pixels_offset(const struct vkms_frame_info *frame_info, int x, int y,
35 int plane_index, int *offset, int *rem_x, int *rem_y)
37 struct drm_framebuffer *fb = frame_info->fb;
38 const struct drm_format_info *format = frame_info->fb->format;
39 /* Directly using x and y to multiply pitches and format->ccp is not sufficient because
42 * Dividing x and y by the block size allows to extract the correct offset of the block
47 int block_y = y / drm_format_info_block_height(format, plane_index);
48 int block_pitch = fb->pitches[plane_index] * drm_format_info_block_height(format,
51 *rem_y = y % drm_format_info_block_height(format, plane_index);
52 *offset = fb->offsets[plane_index] +
54 block_x * format->char_per_block[plane_index];
58 * packed_pixels_addr() - Get the pointer to the block containing the pixel at the given
63 * @y: The y (height) coordinate inside the plane
67 * @rem_y: The returned Y coordinate of the requested pixel in the block
75 int x, int y, int plane_index, u8 **addr, int *rem_x,
78 int offset;
80 packed_pixels_offset(frame_info, x, y, plane_index, &offset, rem_x, rem_y);
81 *addr = (u8 *)frame_info->map[0].vaddr + offset;
85 * get_block_step_bytes() - Common helper to compute the correct step value between each pixel block
102 return fb->format->char_per_block[plane_index];
104 return -fb->format->char_per_block[plane_index];
106 return (int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format,
109 return -(int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format,
117 * packed_pixels_addr_1x1() - Get the pointer to the block containing the pixel at the given
122 * @y: The y (height) coordinate inside the plane
129 int x, int y, int plane_index, u8 **addr)
131 int offset, rem_x, rem_y;
133 WARN_ONCE(drm_format_info_block_width(frame_info->fb->format,
136 WARN_ONCE(drm_format_info_block_height(frame_info->fb->format,
140 packed_pixels_offset(frame_info, x, y, plane_index, &offset, &rem_x,
142 *addr = (u8 *)frame_info->map[0].vaddr + offset;
146 * get_subsampling() - Get the subsampling divisor value on a specific direction
157 return format->vsub;
160 return format->hsub;
167 * get_subsampling_offset() - An offset for keeping the chroma siting consistent regardless of
170 * @direction: direction of the reading to properly compute this offset
172 * @y_start: y coordinate of the starting point of the readed line
178 return -y_start - 1;
182 return -x_start - 1;
202 * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get
262 VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_2,
269 fp_y = drm_int2fixp(((int)y - matrix->y_offset) * 257);
270 fp_channel_1 = drm_int2fixp(((int)channel_1 - 128) * 257);
271 fp_channel_2 = drm_int2fixp(((int)channel_2 - 128) * 257);
273 fp_r = drm_fixp_mul(matrix->matrix[0][0], fp_y) +
274 drm_fixp_mul(matrix->matrix[0][1], fp_channel_1) +
275 drm_fixp_mul(matrix->matrix[0][2], fp_channel_2);
276 fp_g = drm_fixp_mul(matrix->matrix[1][0], fp_y) +
277 drm_fixp_mul(matrix->matrix[1][1], fp_channel_1) +
278 drm_fixp_mul(matrix->matrix[1][2], fp_channel_2);
279 fp_b = drm_fixp_mul(matrix->matrix[2][0], fp_y) +
280 drm_fixp_mul(matrix->matrix[2][1], fp_channel_1) +
281 drm_fixp_mul(matrix->matrix[2][2], fp_channel_2);
305 * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33b3a3@riseup.net/
313 int bits_per_pixel = drm_format_info_bpp(plane->frame_info->fb->format, 0);
317 WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, 0) != 1,
320 packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &rem_x, &rem_y);
321 int bit_offset = (8 - bits_per_pixel) - rem_x * bits_per_pixel;
322 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
323 int mask = (0x1 << bits_per_pixel) - 1;
331 restart_bit_offset = 8 - bits_per_pixel;
332 step_bit_offset = -bits_per_pixel;
387 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
389 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
405 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
407 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
424 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
426 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
443 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
445 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
463 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
465 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
482 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
484 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
501 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
503 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
516 * stored in the same plane (often called semi-planar formats). It will
520 * - Apply the correct color range and encoding
521 * - Convert YUV and YVU with the same function (a column swap is needed when setting up
522 * plane->conversion_matrix)
531 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0,
533 packed_pixels_addr_1x1(plane->frame_info,
534 x_start / plane->frame_info->fb->format->hsub,
535 y_start / plane->frame_info->fb->format->vsub, 1,
537 int step_y = get_block_step_bytes(plane->frame_info->fb, direction, 0);
538 int step_uv = get_block_step_bytes(plane->frame_info->fb, direction, 1);
539 int subsampling = get_subsampling(plane->frame_info->fb->format, direction);
541 const struct conversion_matrix *conversion_matrix = &plane->conversion_matrix;
559 * - Apply the correct color range and encoding
560 * - Convert YUV and YVU with the same function (a column swap is needed when setting up
561 * plane->conversion_matrix)
571 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0,
573 packed_pixels_addr_1x1(plane->frame_info,
574 x_start / plane->frame_info->fb->format->hsub,
575 y_start / plane->frame_info->fb->format->vsub, 1,
577 packed_pixels_addr_1x1(plane->frame_info,
578 x_start / plane->frame_info->fb->format->hsub,
579 y_start / plane->frame_info->fb->format->vsub, 2,
581 int step_y = get_block_step_bytes(plane->frame_info->fb, direction, 0);
582 int step_channel_1 = get_block_step_bytes(plane->frame_info->fb, direction, 1);
583 int step_channel_2 = get_block_step_bytes(plane->frame_info->fb, direction, 2);
584 int subsampling = get_subsampling(plane->frame_info->fb->format, direction);
586 const struct conversion_matrix *conversion_matrix = &plane->conversion_matrix;
611 * in little-endian. In the case of the ARGB8888 the memory is
619 out_pixel[3] = DIV_ROUND_CLOSEST(in_pixel->a, 257);
620 out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257);
621 out_pixel[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257);
622 out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257);
628 out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257);
629 out_pixel[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257);
630 out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257);
635 out_pixel[3] = DIV_ROUND_CLOSEST(in_pixel->a, 257);
636 out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->b, 257);
637 out_pixel[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257);
638 out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->r, 257);
645 pixel[3] = cpu_to_le16(in_pixel->a);
646 pixel[2] = cpu_to_le16(in_pixel->r);
647 pixel[1] = cpu_to_le16(in_pixel->g);
648 pixel[0] = cpu_to_le16(in_pixel->b);
656 pixel[2] = cpu_to_le16(in_pixel->r);
657 pixel[1] = cpu_to_le16(in_pixel->g);
658 pixel[0] = cpu_to_le16(in_pixel->b);
668 s64 fp_r = drm_int2fixp(in_pixel->r);
669 s64 fp_g = drm_int2fixp(in_pixel->g);
670 s64 fp_b = drm_int2fixp(in_pixel->b);
680 * vkms_writeback_row() - Generic loop for all supported writeback format. It is executed just
685 * @y: Row to write in the writeback buffer
688 const struct line_buffer *src_buffer, int y)
690 struct vkms_frame_info *frame_info = &wb->wb_frame_info;
691 int x_dst = frame_info->dst.x1;
695 packed_pixels_addr(frame_info, x_dst, y, 0, &dst_pixels, &rem_x, &rem_y);
696 struct pixel_argb_u16 *in_pixels = src_buffer->pixels;
697 int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), src_buffer->n_pixels);
699 for (size_t x = 0; x < x_limit; x++, dst_pixels += frame_info->fb->format->cpp[0])
700 wb->pixel_write(dst_pixels, &in_pixels[x]);
704 * get_pixel_read_line_function() - Retrieve the correct read_line function for a specific
751 * - Be listed in vkms_formats in vkms_plane.c
752 * - Have a pixel_read callback defined here
767 * numpy.around(colour.matrix_YCbCr(K=colour.WEIGHTS_YCBCR["ITU-R BT.601"],
783 { 4294967296, -1478054095, -3067191994 },
790 * numpy.around(colour.matrix_YCbCr(K=colour.WEIGHTS_YCBCR["ITU-R BT.601"],
797 { 5020601039, -1689204679, -3505362278 },
804 * numpy.around(colour.matrix_YCbCr(K=colour.WEIGHTS_YCBCR["ITU-R BT.709"],
811 { 4294967296, -804551626, -2010578443 },
818 * numpy.around(colour.matrix_YCbCr(K=colour.WEIGHTS_YCBCR["ITU-R BT.709"],
825 { 5020601039, -919487572, -2297803934 },
832 * numpy.around(colour.matrix_YCbCr(K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"],
839 { 4294967296, -706750298, -2453942994 },
846 * numpy.around(colour.matrix_YCbCr(K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"],
853 { 5020601039, -807714626, -2804506279 },
860 * swap_uv_columns() - Swap u and v column of a given matrix
866 swap(matrix->matrix[0][2], matrix->matrix[0][1]);
867 swap(matrix->matrix[1][2], matrix->matrix[1][1]);
868 swap(matrix->matrix[2][2], matrix->matrix[2][1]);
872 * get_conversion_matrix_to_argb_u16() - Retrieve the correct yuv to rgb conversion matrix for a
938 * get_pixel_write_function() - Retrieve the correct write_pixel function for a specific format.
963 * - Be listed in vkms_wb_formats in vkms_writeback.c
964 * - Have a pixel_write callback defined here