From patchwork Tue Nov 21 03:48:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia Mirkin X-Patchwork-Id: 10067625 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9B01603FA for ; Tue, 21 Nov 2017 03:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC16822ADC for ; Tue, 21 Nov 2017 03:48:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDCE328C98; Tue, 21 Nov 2017 03:48:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2708F22ADC for ; Tue, 21 Nov 2017 03:48:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D52F89F5B; Tue, 21 Nov 2017 03:48:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x242.google.com (mail-qt0-x242.google.com [IPv6:2607:f8b0:400d:c0d::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id B5AA589F5B for ; Tue, 21 Nov 2017 03:48:15 +0000 (UTC) Received: by mail-qt0-x242.google.com with SMTP id q13so6031018qtb.5 for ; Mon, 20 Nov 2017 19:48:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=zVRGKfpxOV92DSrcQul6x1HhRZLc98F0ILjaRGgFG3A=; b=uIXJgehVfAk9WHiqPxHOpptXAcymg3EMDzkdwcCYoDdIvBxa9+fp3QcKmfdAX01X+i +sl6ehSgLeyKIdKPt1VmS8LmmX5khuclSAkSGlWAjEmlmJIfhB4umCnwn0ShBmarRE6N 2+oa77W2+phWEpLiuw7t4tma4gG0q34PIXbrEPHQrt01H2qY+Ea/lVIc58mo7csCMWyQ LBPd2pP1I0ffvrTCZNIkL1WaNYRCMz+c3w4Ih8pW+wQLvynV3uLLO8IX5pDdpnhm9U2M W3URM8HOfQcGh984vS1zRjhDf/KZXNFpmHb7vwmVmPRC5dqBS86+74nF+R6xBqWAk6gd jSGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=zVRGKfpxOV92DSrcQul6x1HhRZLc98F0ILjaRGgFG3A=; b=eKbcQclJ20SA25vszG3de8lPK23krzB0gPq2jH0z6Aer8v7fMV+v0Pz+JYry1DqHKo SkZdtr+f71iXev6iE/eLvoRCv42Oh/xIJNWGL94w8j0EKCLBPmAJR6VuLC9IwMf0PJBL uxMfKuIb5v6Gwn1WDMZYdF0eUgbi8x73d2SRNvPuu6N5gNhDiYNcX+rgpIeTlRRqy0i+ e/+87FjWIilCMehElEnGIr7cutShAswxPfkuFh/xVU3Cg7N1CuPhMhJgKFRSLRoJ0dBW E56xW7RwD33QcJ/qVpHn08/FYVwsE+DeseI5pMCl1Jd2bapf3y6O+HkFUi43lG6mnpQx q9qQ== X-Gm-Message-State: AJaThX70EURTOusM/ncJgw6OYUvG9vx5Pzqpx0/9+hodO0EtAvWh8/W/ Y9qffGg8v3mQzp3GzC82gSE9Pqmo X-Google-Smtp-Source: AGs4zMYvZOGf1AFuirdnPuW3ns6OtYlQ9tcTcyI6Y29YMuv5bh/KvestxiR5wUB9hHEE5FyQ+BwiPQ== X-Received: by 10.237.60.117 with SMTP id u50mr23441209qte.6.1511236094603; Mon, 20 Nov 2017 19:48:14 -0800 (PST) Received: from athos.fios-router.home (pool-100-2-1-206.nycmny.fios.verizon.net. [100.2.1.206]) by smtp.gmail.com with ESMTPSA id k10sm7947570qke.75.2017.11.20.19.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 19:48:13 -0800 (PST) From: Ilia Mirkin To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm v2] modetest: add C8 support to generate SMPTE pattern Date: Mon, 20 Nov 2017 22:48:08 -0500 Message-Id: <20171121034808.32246-1-imirkin@alum.mit.edu> X-Mailer: git-send-email 2.13.6 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Tested on nouveau with the CRTC only (no planes). Signed-off-by: Ilia Mirkin --- v1 -> v2: always set a flat gamma ramp for non-indexed modes tests/modetest/buffers.c | 2 ++ tests/modetest/modetest.c | 24 ++++++++++++++++ tests/util/format.c | 2 ++ tests/util/pattern.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ tests/util/pattern.h | 2 ++ 5 files changed, 103 insertions(+) diff --git a/tests/modetest/buffers.c b/tests/modetest/buffers.c index 4fd310b9..58f88e85 100644 --- a/tests/modetest/buffers.c +++ b/tests/modetest/buffers.c @@ -139,6 +139,7 @@ bo_create(int fd, unsigned int format, int ret; switch (format) { + case DRM_FORMAT_C8: case DRM_FORMAT_NV12: case DRM_FORMAT_NV21: case DRM_FORMAT_NV16: @@ -279,6 +280,7 @@ bo_create(int fd, unsigned int format, planes[2] = virtual + offsets[2]; break; + case DRM_FORMAT_C8: case DRM_FORMAT_ARGB4444: case DRM_FORMAT_XRGB4444: case DRM_FORMAT_ABGR4444: diff --git a/tests/modetest/modetest.c b/tests/modetest/modetest.c index 62d93327..6092244f 100644 --- a/tests/modetest/modetest.c +++ b/tests/modetest/modetest.c @@ -1228,6 +1228,30 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co fprintf(stderr, "failed to set mode: %s\n", strerror(errno)); return; } + + if (pipes[0].fourcc == DRM_FORMAT_C8) { + /* the pattern relies on colors being set properly */ + uint16_t r[256] = {0}, g[256] = {0}, b[256] = {0}; + + util_smpte_c8_gamma(256, r, g, b); + ret = drmModeCrtcSetGamma( + dev->fd, pipe->crtc->crtc->crtc_id, + 256, r, g, b); + if (ret) { + fprintf(stderr, "failed to set gamma: %s\n", strerror(errno)); + return; + } + } else { + /* gamma may be left over from a previous modeset */ + uint16_t r[256], g[256], b[256]; + + for (j = 0; j < 256; j++) + r[j] = g[j] = b[j] = j << 8; + /* errors are probably ok */ + drmModeCrtcSetGamma( + dev->fd, pipe->crtc->crtc->crtc_id, + 256, r, g, b); + } } } diff --git a/tests/util/format.c b/tests/util/format.c index 043cfe7f..3eefe224 100644 --- a/tests/util/format.c +++ b/tests/util/format.c @@ -43,6 +43,8 @@ .yuv = { (order), (xsub), (ysub), (chroma_stride) } static const struct util_format_info format_info[] = { + /* Indexed */ + { DRM_FORMAT_C8, "C8" }, /* YUV packed */ { DRM_FORMAT_UYVY, "UYVY", MAKE_YUV_INFO(YUV_YCbCr | YUV_CY, 2, 2, 2) }, { DRM_FORMAT_VYUY, "VYUY", MAKE_YUV_INFO(YUV_YCrCb | YUV_CY, 2, 2, 2) }, diff --git a/tests/util/pattern.c b/tests/util/pattern.c index 00b08a8c..41fb541b 100644 --- a/tests/util/pattern.c +++ b/tests/util/pattern.c @@ -461,6 +461,77 @@ static void fill_smpte_rgb32(const struct util_rgb_info *rgb, void *mem, } } +static void fill_smpte_c8(void *mem, unsigned int width, unsigned int height, + unsigned int stride) +{ + unsigned int x; + unsigned int y; + + for (y = 0; y < height * 6 / 9; ++y) { + for (x = 0; x < width; ++x) + ((uint8_t *)mem)[x] = x * 7 / width; + mem += stride; + } + + for (; y < height * 7 / 9; ++y) { + for (x = 0; x < width; ++x) + ((uint8_t *)mem)[x] = 7 + (x * 7 / width); + mem += stride; + } + + for (; y < height; ++y) { + for (x = 0; x < width * 5 / 7; ++x) + ((uint8_t *)mem)[x] = + 14 + (x * 4 / (width * 5 / 7)); + for (; x < width * 6 / 7; ++x) + ((uint8_t *)mem)[x] = + 14 + ((x - width * 5 / 7) * 3 + / (width / 7) + 4); + for (; x < width; ++x) + ((uint8_t *)mem)[x] = 14 + 7; + mem += stride; + } +} + +void util_smpte_c8_gamma(unsigned size, uint16_t *r, uint16_t *g, uint16_t *b) +{ + if (size < 7 + 7 + 8) { + printf("Error: gamma too small: %d < %d\n", size, 7 + 7 + 8); + return; + } +#define FILL_COLOR(idx, red, green, blue) \ + r[idx] = red << 8; \ + g[idx] = green << 8; \ + b[idx] = blue << 8 + + FILL_COLOR( 0, 192, 192, 192); /* grey */ + FILL_COLOR( 1, 192, 192, 0 ); /* yellow */ + FILL_COLOR( 2, 0, 192, 192); /* cyan */ + FILL_COLOR( 3, 0, 192, 0 ); /* green */ + FILL_COLOR( 4, 192, 0, 192); /* magenta */ + FILL_COLOR( 5, 192, 0, 0 ); /* red */ + FILL_COLOR( 6, 0, 0, 192); /* blue */ + + FILL_COLOR( 7, 0, 0, 192); /* blue */ + FILL_COLOR( 8, 19, 19, 19 ); /* black */ + FILL_COLOR( 9, 192, 0, 192); /* magenta */ + FILL_COLOR(10, 19, 19, 19 ); /* black */ + FILL_COLOR(11, 0, 192, 192); /* cyan */ + FILL_COLOR(12, 19, 19, 19 ); /* black */ + FILL_COLOR(13, 192, 192, 192); /* grey */ + + FILL_COLOR(14, 0, 33, 76); /* in-phase */ + FILL_COLOR(15, 255, 255, 255); /* super white */ + FILL_COLOR(16, 50, 0, 106); /* quadrature */ + FILL_COLOR(17, 19, 19, 19); /* black */ + FILL_COLOR(18, 9, 9, 9); /* 3.5% */ + FILL_COLOR(19, 19, 19, 19); /* 7.5% */ + FILL_COLOR(20, 29, 29, 29); /* 11.5% */ + FILL_COLOR(21, 19, 19, 19); /* black */ + +#undef FILL_COLOR +} + static void fill_smpte(const struct util_format_info *info, void *planes[3], unsigned int width, unsigned int height, unsigned int stride) @@ -468,6 +539,8 @@ static void fill_smpte(const struct util_format_info *info, void *planes[3], unsigned char *u, *v; switch (info->format) { + case DRM_FORMAT_C8: + return fill_smpte_c8(planes[0], width, height, stride); case DRM_FORMAT_UYVY: case DRM_FORMAT_VYUY: case DRM_FORMAT_YUYV: diff --git a/tests/util/pattern.h b/tests/util/pattern.h index d5c4260c..302d523e 100644 --- a/tests/util/pattern.h +++ b/tests/util/pattern.h @@ -36,4 +36,6 @@ void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern, void *planes[3], unsigned int width, unsigned int height, unsigned int stride); +void util_smpte_c8_gamma(unsigned size, uint16_t *r, uint16_t *g, uint16_t *b); + #endif /* UTIL_PATTERN_H */