From patchwork Mon Jul 6 12:35:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lespiau, Damien" X-Patchwork-Id: 6723361 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1D6359F38C for ; Mon, 6 Jul 2015 12:36:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86E7620601 for ; Mon, 6 Jul 2015 12:36:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id A6BB6205F9 for ; Mon, 6 Jul 2015 12:36:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ACE316E879; Mon, 6 Jul 2015 05:36:00 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTP id AFB356E871 for ; Mon, 6 Jul 2015 05:35:52 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP; 06 Jul 2015 05:35:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,414,1432623600"; d="scan'208";a="741421011" Received: from magarwal-mobl.amr.corp.intel.com (HELO strange.amr.corp.intel.com) ([10.254.77.111]) by fmsmga001.fm.intel.com with ESMTP; 06 Jul 2015 05:35:51 -0700 From: Damien Lespiau To: intel-gfx@lists.freedesktop.org Date: Mon, 6 Jul 2015 13:35:34 +0100 Message-Id: <1436186144-19665-7-git-send-email-damien.lespiau@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1436186144-19665-1-git-send-email-damien.lespiau@intel.com> References: <1436186144-19665-1-git-send-email-damien.lespiau@intel.com> Subject: [Intel-gfx] [PATCH i-g-t 06/16] plot: Add a way to color plots X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It can look pretty and allows to differenciate between several plots drawn on the same canvas. Signed-off-by: Damien Lespiau --- lib/igt_plot.c | 24 ++++++++++++++++++++++++ lib/igt_plot.h | 3 +++ lib/tests/igt_plot.c | 1 + 3 files changed, 28 insertions(+) diff --git a/lib/igt_plot.c b/lib/igt_plot.c index f7187f6..3f3c2fe 100644 --- a/lib/igt_plot.c +++ b/lib/igt_plot.c @@ -231,6 +231,8 @@ static void igt_plot_ctx_init(igt_plot_ctx_t *ctx) memset(ctx, 0, sizeof(*ctx)); ctx->line_width = 1.5; + ctx->r = ctx->g = ctx->b = 0.0; + ctx->a = 1.0; } static void igt_plot_ctx_fini(igt_plot_ctx_t *ctx) @@ -287,6 +289,27 @@ void igt_plot_fini(igt_plot_t *plot) } /** + * igt_plot_set_color: + * @plot: An #igt_plot_t instance + * @r: Red component in the [0, 1] range + * @g: Green component in the [0, 1] range + * @b: Blue component in the [0, 1] range + * @a: Alpha component in the [0, 1] range + * + * Set the color to use when drawing plots. + */ +void igt_plot_set_color(igt_plot_t *plot, + double r, double g, double b, double a) +{ + igt_plot_ctx_t *ctx = plot->ctx; + + ctx->r = r; + ctx->g = g; + ctx->b = b; + ctx->a = a; +} + +/* * igt_plot_set_line_width: * @plot: An #igt_plot_t instance * @width: The new line width to use @@ -442,6 +465,7 @@ igt_plot_draw_one(igt_plot_t *plot, igt_plot_ctx_t *ctx, flush_t *flush) cairo_line_to(plot->cr, fit(x->values[i], area->x1, x_range, x_scale), fit(y->values[i], area->y2, y_range, -y_scale)); + cairo_set_source_rgba(plot->cr, ctx->r, ctx->g, ctx->b, ctx->a); cairo_set_line_cap(plot->cr, CAIRO_LINE_CAP_BUTT); cairo_set_line_width(plot->cr, ctx->line_width); cairo_stroke(plot->cr); diff --git a/lib/igt_plot.h b/lib/igt_plot.h index 82ad10a..2e00c60 100644 --- a/lib/igt_plot.h +++ b/lib/igt_plot.h @@ -76,6 +76,7 @@ typedef struct { igt_vector_t *x, *y; double x_range, y_range; double line_width; + double r, g, b, a; } igt_plot_ctx_t; /** @@ -115,6 +116,8 @@ typedef enum { void igt_plot_init(igt_plot_t *plot, unsigned int width, unsigned int height); void igt_plot_fini(igt_plot_t *plot); +void igt_plot_set_color(igt_plot_t *plot, + double r, double g, double b, double a); void igt_plot_set_line_width(igt_plot_t *plot, double width); void igt_plot_draw(igt_plot_t *plot, igt_vector_t *x, igt_vector_t *y); void igt_plot_write(igt_plot_t *plot, const char *filename); diff --git a/lib/tests/igt_plot.c b/lib/tests/igt_plot.c index be0e132..cb7f022 100644 --- a/lib/tests/igt_plot.c +++ b/lib/tests/igt_plot.c @@ -82,6 +82,7 @@ static void test_simple_plot(void) y->values[i] = sin(2 * M_PI * x->values[i]); igt_plot_init(&plot, 800, 600); + igt_plot_set_color(&plot, 0.0, 0.0, 1.0, 1.0); igt_plot_draw(&plot, x, y); igt_plot_write(&plot, "test_simple_plot.png");