From patchwork Mon Oct 2 17:24:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Roche X-Patchwork-Id: 5384 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.61.8 with SMTP id n8csp1752451jan; Mon, 2 Oct 2017 10:25:17 -0700 (PDT) X-Received: by 10.223.195.110 with SMTP id e43mr13623642wrg.189.1506965117328; Mon, 02 Oct 2017 10:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506965117; cv=none; d=google.com; s=arc-20160816; b=IraZ75JamaOwG6aQN62X7PZw9GOIR6FilNxg4ZvB0YdUymegHeuJlyY/McIiNIundf Ma0COu5kzWsQgaNIBqsOGba5UOrhvkSfk3QBAR5OJT+Xpmpn82FNQsH82/Fwa8tb/Y13 76vDrfWB6hgU47tvJ+skflkATe25nHPqTxsvDDuof/Q5FgKZcRkALCQz32/rc1hkadRq XCWj2NKBz7H+dHp9PTzgzNz+0d1JI70yCr0rRhVyD8q3ZMJmwr2EGKTUdwYh988tEMba Mw1AwwudiQ8YMph5wmOTAOOYog4JOQjieCvdrUN9KN3DEIm4J2i80Wjc3KjCM1z0uFDO PXwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=0zRG0UpWUxo0C5xmAUvK8LyS8sEhwyqDWJ9NaV1jih4=; b=JgLPgqOx5MBRcX9BntaUEAl8l3guFPbHHeG6H221ioGm4JDyGq6+C+GCbvflvhTKWp FqEl1p7UFvCJCW2TxLLLytdDAvxnyrVy6zPFHMGf3MIle7/G4NoG8bNutHHh08GTV91M GXkfLROnmpJ3QQA52LbyC76aJN+onpCOXQ4o8zDJ5ZZ5JnmAkvgkmwapxdhJh8wxRru7 L1GsHPMweH09zfzE9SvCxEYm+KtHoqkFpSvVbqG9sewgk+TmoOzdY2Z/e3zPORs8KKg9 BMvgCfAz0X4LluiqPlpsY4NTPYqFJHsppek8BGY815R9EzWegpaxXq/8orun7sM5hBCL eglQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@giphy.com header.s=google header.b=qnyGVW77; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e22si5816168wre.203.2017.10.02.10.25.16; Mon, 02 Oct 2017 10:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@giphy.com header.s=google header.b=qnyGVW77; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B159F689EEF; Mon, 2 Oct 2017 20:24:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f175.google.com (mail-qk0-f175.google.com [209.85.220.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A1943689EC6 for ; Mon, 2 Oct 2017 20:24:47 +0300 (EEST) Received: by mail-qk0-f175.google.com with SMTP id c67so5305972qkg.2 for ; Mon, 02 Oct 2017 10:25:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=giphy.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Bu8L4NcjnwLND90VJgJrnkciaH3clVrFv6VeONtd5YI=; b=qnyGVW77p8AZ2CRg+T7TschXxS3Q4XwXAjQd7U3G/WI51XeMj+F/dxWBINgeyPrY+E AgQCKlh7O0lAQUpj5pQt+Egt+R78QXutP0BVGUS7AfLTcW/rwWrOmRZyPuQNF/F6xpPL zhg4+p2o5sfG57IsZnh/GeQShGM8Af+pznbpU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Bu8L4NcjnwLND90VJgJrnkciaH3clVrFv6VeONtd5YI=; b=SQlRFUGdPWRgB3mN1hxyiMlW7ViZoihgQft7NojmSRq+CN+v6c8Pcq+CuRp1pMmkPd L7lln0z5298RPyKIr4pDbPUlnAtTMfM7mOImQUiGgeo28obeyJPrIL9AxK4vIPBhMpEs ZNv7/t31AINw5Qqczap9BJth19LYY2nq1sY/F7hpyMbIBozddgDEOY/zo8m5McZZ687F 3PrGUIlcGrAuSTBt2BMbWYHhGgRZKYfiHmXihbLekL87AAyKGhjUL/Doyk4ldOHjz6hx Ss45d4DtAg4A3eYGeV0W7QfvD9wmAhVjeXIco+jgwUgYD50/l1oUW+bM1BWvJ5Lq8j4A YOvQ== X-Gm-Message-State: AMCzsaWir1g3CbE+i3hDOTV3S3K/wzavK+ojmP/+74q9Ns37yN07v3OA 5qwxQA4VFHX4tylg5c06Fyx26cpAcPA= X-Google-Smtp-Source: AOwi7QD6ZORnnwtJnhDPFy8N6UQzzEybAcSJSqEG+SPqXe1sD9wzS+YE9+JYKcWpT5GgxEVmQ786kg== X-Received: by 10.55.195.145 with SMTP id r17mr14626989qkl.120.1506965100826; Mon, 02 Oct 2017 10:25:00 -0700 (PDT) Received: from localhost.localdomain ([208.184.100.82]) by smtp.gmail.com with ESMTPSA id p25sm7339001qte.28.2017.10.02.10.25.00 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 02 Oct 2017 10:25:00 -0700 (PDT) From: Bjorn Roche To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2017 13:24:34 -0400 Message-Id: <20171002172439.65628-3-bjorn@giphy.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171002172439.65628-1-bjorn@giphy.com> References: <20171002172439.65628-1-bjorn@giphy.com> Subject: [FFmpeg-devel] [PATCH 2/7] Fix for dithering. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Bjorn Roche MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Bjorn Roche --- libavfilter/vf_paletteuse.c | 52 ++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c index e62503c8ea..abee1b3735 100644 --- a/libavfilter/vf_paletteuse.c +++ b/libavfilter/vf_paletteuse.c @@ -158,12 +158,13 @@ static int query_formats(AVFilterContext *ctx) static av_always_inline int dither_color(uint32_t px, int er, int eg, int eb, int scale, int shift) { - return av_clip_uint8((px >> 16 & 0xff) + ((er * scale) / (1<> 16 & 0xff) + ((er * scale) / (1<> 8 & 0xff) + ((eg * scale) / (1<> 8 & 0xff, palette[i] & 0xff, }; - const int d = diffAlpha(palargb, rgb); + const int d = diff(palargb, rgb); if (d < min_dist) { pal_id = i; min_dist = d; @@ -211,7 +203,7 @@ static av_always_inline uint8_t colormap_nearest_bruteforce(const uint32_t *pale } /* Recursive form, simpler but a bit slower. Kept for reference. */ -/* may not work with transparency */ +/* has not been updated for transparency */ struct nearest_color { int node_pos; int dist_sqd; @@ -224,10 +216,10 @@ static void colormap_nearest_node(const struct color_node *map, { printf( "colormap_nearest_node\n" ); const struct color_node *kd = map + node_pos; - const int s = kd->split; //FIXME: spliut is one more than it was before + const int s = kd->split; int dx, nearer_kd_id, further_kd_id; const uint8_t *current = kd->val; - const int current_to_target = diffAlpha(target, current); + const int current_to_target = diff(target, current); if (current_to_target < nearest->dist_sqd) { nearest->node_pos = node_pos; @@ -272,7 +264,7 @@ static av_always_inline uint8_t colormap_nearest_iterative(const struct color_no const struct color_node *kd = &root[cur_color_id]; const uint8_t *current = kd->val; - const int current_to_target = diffAlpha(target, current); + const int current_to_target = diff(target, current); printf( "%d-%d-%d-%d, %d, %d-%d-%d-%d\n", target[0], target[1], target[2], target[3], current_to_target, current[0], current[1], current[2], current[3] ); @@ -360,7 +352,7 @@ static av_always_inline int color_get(struct cache_node *cache, uint32_t argb, const enum color_search_method search_method) { printf("color_get\n"); - //int i; + int i; const uint8_t argb_elts[] = {a, r, g, b}; const uint8_t rhash = r & ((1<nb_entries; i++) { - // e = &node->entries[i]; - // if (e->color == rgb) - // return e->pal_entry; - // } + for (i = 0; i < node->nb_entries; i++) { + e = &node->entries[i]; + if (e->color == argb) + return e->pal_entry; + } e = av_dynarray2_add((void**)&node->entries, &node->nb_entries, sizeof(*node->entries), NULL); if (!e) return AVERROR(ENOMEM); e->color = argb; - // FIXME + e->pal_entry = COLORMAP_NEAREST(search_method, palette, map, argb_elts); return e->pal_entry; } @@ -438,13 +429,6 @@ static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFram for (x = x_start; x < w; x++) { int er, eg, eb; - // const uint8_t asss = src[x] >> 24 & 0xff; - // const uint8_t rsss = src[x] >> 16 & 0xff; - // const uint8_t gsss = src[x] >> 8 & 0xff; - // const uint8_t bsss = src[x] & 0xff; - - //printf( "converted %d: %d %d %d %d\n", src[x], asss, rsss, gsss, bsss ); - if (dither == DITHERING_BAYER) { printf( "bayer\n" ); const int d = s->ordered_dither[(y & 7)<<3 | (x & 7)]; @@ -623,8 +607,8 @@ static int debug_accuracy(const struct color_node *node, const uint32_t *palette const uint32_t c2 = palette[r2]; const uint8_t palrgb1[] = { c1>>16 & 0xff, c1>> 8 & 0xff, c1 & 0xff }; const uint8_t palrgb2[] = { c2>>16 & 0xff, c2>> 8 & 0xff, c2 & 0xff }; - const int d1 = diffAlpha(palrgb1, rgb); - const int d2 = diffAlpha(palrgb2, rgb); + const int d1 = diff(palrgb1, rgb); + const int d2 = diff(palrgb2, rgb); if (d1 != d2) { av_log(NULL, AV_LOG_ERROR, "/!\\ %02X%02X%02X: %d ! %d (%06"PRIX32" ! %06"PRIX32") / dist: %d ! %d\n", @@ -838,7 +822,7 @@ static void debug_mean_error(PaletteUseContext *s, const AVFrame *in1, const uint32_t c2 = palette[src2[x]]; const uint8_t rgb1[] = {c1 >> 16 & 0xff, c1 >> 8 & 0xff, c1 & 0xff}; const uint8_t rgb2[] = {c2 >> 16 & 0xff, c2 >> 8 & 0xff, c2 & 0xff}; - mean_err += diffAlpha(rgb1, rgb2); + mean_err += diff(rgb1, rgb2); } src1 += src1_linesize; src2 += src2_linesize;