Lines Matching +full:pixel +full:- +full:format
1 // SPDX-License-Identifier: GPL-2.0+
13 * packed_pixels_offset() - Get the offset of the block containing the pixel at coordinates x/y
16 * @x: The x coordinate of the wanted pixel in the buffer
17 * @y: The y coordinate of the wanted pixel in the buffer
20 * @rem_x: The returned X coordinate of the requested pixel in the block
21 * @rem_y: The returned Y coordinate of the requested pixel in the block
23 * As some pixel formats store multiple pixels in a block (DRM_FORMAT_R* for example), some
25 * whole block, and the coordinate of the requested pixel inside this block.
26 * For example, if the format is DRM_FORMAT_R1 and the requested coordinate is 13,5, the offset
30 * With this function, the caller just have to extract the correct pixel from the block.
35 struct drm_framebuffer *fb = frame_info->fb;
36 const struct drm_format_info *format = frame_info->fb->format;
37 /* Directly using x and y to multiply pitches and format->ccp is not sufficient because
41 * containing the pixel.
44 int block_x = x / drm_format_info_block_width(format, plane_index);
45 int block_y = y / drm_format_info_block_height(format, plane_index);
46 int block_pitch = fb->pitches[plane_index] * drm_format_info_block_height(format,
48 *rem_x = x % drm_format_info_block_width(format, plane_index);
49 *rem_y = y % drm_format_info_block_height(format, plane_index);
50 *offset = fb->offsets[plane_index] +
52 block_x * format->char_per_block[plane_index];
56 * packed_pixels_addr() - Get the pointer to the block containing the pixel at the given
64 * @rem_x: The returned X coordinate of the requested pixel in the block
65 * @rem_y: The returned Y coordinate of the requested pixel in the block
68 * of the block containing this pixel and the pixel position inside this block.
79 *addr = (u8 *)frame_info->map[0].vaddr + offset;
83 * get_block_step_bytes() - Common helper to compute the correct step value between each pixel block
100 return fb->format->char_per_block[plane_index];
102 return -fb->format->char_per_block[plane_index];
104 return (int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format,
107 return -(int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format,
115 * packed_pixels_addr_1x1() - Get the pointer to the block containing the pixel at the given
124 * This function can only be used with format where block_h == block_w == 1.
131 WARN_ONCE(drm_format_info_block_width(frame_info->fb->format,
134 WARN_ONCE(drm_format_info_block_height(frame_info->fb->format,
140 *addr = (u8 *)frame_info->map[0].vaddr + offset;
144 * The following functions take pixel data (a, r, g, b, pixel, ...) and convert them to
147 * They are used in the `read_line`s functions to avoid duplicate work for some pixel formats.
155 * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get
156 * the best color value in a pixel format with more possibilities.
185 static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
192 u16 rgb_565 = le16_to_cpu(*pixel);
206 * The following functions are read_line function for each pixel format supported by VKMS.
209 * is stored in @out_pixel and in the format ARGB16161616.
211 * These functions are very repetitive, but the innermost pixel loops must be kept inside these
215 * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33b3a3@riseup.net/
225 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
227 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
244 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
246 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
263 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
265 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
283 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
285 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
302 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
304 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
321 packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
323 int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
335 * The following functions take one &struct pixel_argb_u16 and convert it to a specific format.
338 * They are used in vkms_writeback_row() to convert and store a pixel from the src_buffer to
344 * This sequence below is important because the format's byte order is
345 * in little-endian. In the case of the ARGB8888 the memory is
353 out_pixel[3] = DIV_ROUND_CLOSEST(in_pixel->a, 257);
354 out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257);
355 out_pixel[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257);
356 out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257);
362 out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257);
363 out_pixel[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257);
364 out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257);
369 out_pixel[3] = DIV_ROUND_CLOSEST(in_pixel->a, 257);
370 out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->b, 257);
371 out_pixel[1] = DIV_ROUND_CLOSEST(in_pixel->g, 257);
372 out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->r, 257);
377 __le16 *pixel = (__le16 *)out_pixel;
379 pixel[3] = cpu_to_le16(in_pixel->a);
380 pixel[2] = cpu_to_le16(in_pixel->r);
381 pixel[1] = cpu_to_le16(in_pixel->g);
382 pixel[0] = cpu_to_le16(in_pixel->b);
387 __le16 *pixel = (__le16 *)out_pixel;
389 pixel[3] = cpu_to_le16(0xffff);
390 pixel[2] = cpu_to_le16(in_pixel->r);
391 pixel[1] = cpu_to_le16(in_pixel->g);
392 pixel[0] = cpu_to_le16(in_pixel->b);
397 __le16 *pixel = (__le16 *)out_pixel;
402 s64 fp_r = drm_int2fixp(in_pixel->r);
403 s64 fp_g = drm_int2fixp(in_pixel->g);
404 s64 fp_b = drm_int2fixp(in_pixel->b);
410 *pixel = cpu_to_le16(r << 11 | g << 5 | b);
414 * vkms_writeback_row() - Generic loop for all supported writeback format. It is executed just
424 struct vkms_frame_info *frame_info = &wb->wb_frame_info;
425 int x_dst = frame_info->dst.x1;
430 struct pixel_argb_u16 *in_pixels = src_buffer->pixels;
431 int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), src_buffer->n_pixels);
433 for (size_t x = 0; x < x_limit; x++, dst_pixels += frame_info->fb->format->cpp[0])
434 wb->pixel_write(dst_pixels, &in_pixels[x]);
438 * get_pixel_read_line_function() - Retrieve the correct read_line function for a specific
439 * format. The returned pointer is NULL for unsupported pixel formats. The caller must ensure that
442 * @format: DRM_FORMAT_* value for which to obtain a conversion function (see [drm_fourcc.h])
444 pixel_read_line_t get_pixel_read_line_function(u32 format)
446 switch (format) {
462 * format must:
463 * - Be listed in vkms_formats in vkms_plane.c
464 * - Have a pixel_read callback defined here
466 pr_err("Pixel format %p4cc is not supported by VKMS planes. This is a kernel bug, atomic check must forbid this configuration.\n",
467 &format);
473 * get_pixel_write_function() - Retrieve the correct write_pixel function for a specific format.
474 * The returned pointer is NULL for unsupported pixel formats. The caller must ensure that the
477 * @format: DRM_FORMAT_* value for which to obtain a conversion function (see [drm_fourcc.h])
479 pixel_write_t get_pixel_write_function(u32 format)
481 switch (format) {
497 * format must:
498 * - Be listed in vkms_wb_formats in vkms_writeback.c
499 * - Have a pixel_write callback defined here
501 pr_err("Pixel format %p4cc is not supported by VKMS writeback. This is a kernel bug, atomic check must forbid this configuration.\n",
502 &format);