From patchwork Sun Apr 12 20:46:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 18898 Delivered-To: andriy.gelman@gmail.com Received: by 2002:ad4:45d0:0:0:0:0:0 with SMTP id v16csp2046980qvt; Sun, 12 Apr 2020 13:47:18 -0700 (PDT) X-Google-Smtp-Source: APiQypJnpFSnmIJJFtC4CnkedjuLVv/CiGytutwpYtdrcylvYH/qhxnxmCU8Y6BdO8oSoUqau7j/ X-Received: by 2002:adf:ab12:: with SMTP id q18mr1167075wrc.225.1586724437985; Sun, 12 Apr 2020 13:47:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586724437; cv=none; d=google.com; s=arc-20160816; b=e5LAJEY+SVSpEcEyOCwM8Yyzn811/CgCN/anshbm4otIvB02hpJcmIgCXaL1naPjke BTjHKxFFRKqpgehAJYK0AbFHX01cscqVeAMrfD1NgwNaa0i4cQIcngagz1NbTgy8CqlF 6PpRSyfx/pAUxnpyogUppKyZTDePh1km5wfQuAXyMsWyYRebD7XCwhFfFzNMUIXlBg8V WImnhsC9dEJNv5PLOiFVYrgz/FfoT4tQsDeiWqb9ZZprTK79aM91eRYlz1tZ9+oXKHtl iCWSHS1UZoSQMHjFIhURIMioJ4uh6nguYzWdCWbS1mZ3VzSk2KXn21bylrGctCmJ8jgk QBgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:delivered-to; bh=fdoJLpudjyuWaAa0d4xhCp8eb8wyNCk0O+TGSKBG2Mk=; b=Hk2yK5WbboOnxaKCJajvJBkW0hDGYToS/Qk1hRqJ2aGBfewiNkBnzQp7ZMvduxM332 SMwEMdwKQ/ViBACiN8OHYcGuilcM6mVqls0OsXnQ6Xka9/M67jtRWl+lkqk62LxeBMMY 2BAZ/N0ByLGeNSlVFIRBNco8jRJYHeH02MRhqADK8tOx1kWo6eJdcUtx1o+RCC5o8uXO CFHm3lRa4BE/epbA6iVh+APm84zXFef1IKZm6iu7cfKt44RYO7Tlok5fRh4dO9tbwWUk yqsxcq7YTz7piKImVEF2JJfAOz/E2H4eeIuALyo3jBGTHPh4wxsvHtcjp6Fq7YcMtbz5 toHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=WKTu+Bo5; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b10si7210796wrp.352.2020.04.12.13.47.17; Sun, 12 Apr 2020 13:47: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=@gmail.com header.s=20161025 header.b=WKTu+Bo5; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0831868B876; Sun, 12 Apr 2020 23:47:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BCA9568B5D8 for ; Sun, 12 Apr 2020 23:47:05 +0300 (EEST) Received: by mail-io1-f68.google.com with SMTP id b12so7478135ion.8 for ; Sun, 12 Apr 2020 13:47:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=NAWTwqbKdBLeXC8+YSaq09vxjnFqVcJ5x4MUGVEjrXY=; b=WKTu+Bo5ybluK1YgRrUEzRgPAnfS5VydLwDNpVenhiqsRG9S7nFWBk0LuhE0ONJwmE 6z8GBHAqogdpE3/1g6Tyq6FPKpevAv7SxbET6s+qq7Qq1PZGDPP3DKhiDsPUkWQG4oIT Mtqukgd3BripcBbeQ6viqEmNMMtzF2bNBa941yfPNkX8tD9siwhy09sUpNuv2l421Tt0 x8k5y7fGul3AuRJ7RQbP2V9CoPtjuyLtczxEeVhkt+mEfoHpuFVrwdWmWOK4z2uqRVAL /+lMRRBB/vnrneIv/s0ZdHFXOOXZrXftBtyLXx6eMXqnOOn407ICJXGeo3cAWmuStPPI w6Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=NAWTwqbKdBLeXC8+YSaq09vxjnFqVcJ5x4MUGVEjrXY=; b=Lo1qd5ArI7iUHIZj3TJZLJ1wUaEZok3Gna45wSjQEAU5+CjlnuDg5j+pNKITGFcOJM +eKEmVBJ4Qo+j6lo42qccmIDwdRdZE3EjljXS9VQ1NpeCf6yZRXQSiLF6ePrFjiwqwMb Gpe03EA5KApuvXmiJTW46SmE3093D098UNBAubkr2iw+YcbKGGUihkR6HTWSisVMe+Ry Dzn1wlYEhEk9DFL8nrsZ2MsZadxxTk4Vn/ASQiSTOwYIXbR/2MnTn2dns8GEOUfOw7q7 QQ0MIuVELxf1IKlZrJKbHELKGMeleaAJXgLlc/sTBBarPMDojf8wNVXRVEg033DZ4xFK 8JPQ== X-Gm-Message-State: AGi0PuZxin1PYKQj7qxrUnD/HPpdY2crbEKwHxTP2souTYDfjEuWnH2R vg/6J+TL76SiZa7dBE5MElxYAFQXfO71mfHbUJxq9w== X-Received: by 2002:a02:455:: with SMTP id 82mr13232289jab.112.1586724424088; Sun, 12 Apr 2020 13:47:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Carl Eugen Hoyos Date: Sun, 12 Apr 2020 22:46:52 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH v2]lavf/gdv: Improve palette saturation 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KaTctv3H3r8k Content-Length: 4441 Am Do., 7. Sept. 2017 um 15:40 Uhr schrieb Ronald S. Bultje : > > Hi Carl, > > On Mon, Aug 28, 2017 at 10:49 AM, Carl Eugen Hoyos > wrote: > > > 2017-08-27 9:03 GMT+02:00 Paul B Mahol : > > > On 8/26/17, Carl Eugen Hoyos wrote: > > > > >> Attached patch slightly improves the saturation of the > > >> gdv palette. > > >> > > >> Please comment, Carl Eugen > > > > > > Does this match how it is displayed by original game? > > > > The original game was written for a graphic adapter that > > supports 6bit palette. FFmpeg only supports 8bit palette, > > > > OK, so that matches the current code: > > unsigned r = bytestream2_get_byte(gb); > unsigned g = bytestream2_get_byte(gb); > unsigned b = bytestream2_get_byte(gb); > gdv->pal[i] = 0xFFU << 24 | r << 18 | g << 10 | b << 2; > > This indeed suggests the byte only contains 6 lower bits, the upper 2 being > 0. It also indeed suggests that "white" (111111) would be converted to (in > bits) 11111100, not 11111111, which is indeed unsaturated. > > > > the patch makes the colour white (and all saturated colours) > > as similar to the intended output as possible and does not > > change black (and other colours with little intensity). > > > So let's say you have (in bits) 111111 or 000000 (white and black). > > unsigned r = bytestream2_get_byte(gb); > unsigned g = bytestream2_get_byte(gb); > unsigned b = bytestream2_get_byte(gb); > + r |= r >> 4; > + g |= g >> 4; > + b |= b >> 4; > > This converts that to 111111 and 000000. > > gdv->pal[i] = 0xFFU << 24 | r << 18 | g << 10 | b << 2; > > And it seems to me that the color is then _still_ 11111100, which is > unsaturated. Don't you want to do something like: > > #define convert6to8(x) ((x << 2) | ((x + 8) >> 4)) > > unsigned r = bytestream2_get_byte(gb); > unsigned g = bytestream2_get_byte(gb); > unsigned b = bytestream2_get_byte(gb); > + r = convert6to8(r); > + g = convert6to8(g); > + b = convert6to8(b); > gdv->pal[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b; > > Or am I misunderstanding? No, thank you for your review! New patch attached. Please comment, Carl Eugen From 3e456735e8dd268947a92574296a80a8a1e40750 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sun, 12 Apr 2020 22:46:08 +0200 Subject: [PATCH] lavf/gdv: Improve saturation of gdv palette. --- libavformat/gdv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/gdv.c b/libavformat/gdv.c index 2ecbb535e7..2d50530b83 100644 --- a/libavformat/gdv.c +++ b/libavformat/gdv.c @@ -143,7 +143,7 @@ static int gdv_read_header(AVFormatContext *ctx) unsigned r = avio_r8(pb); unsigned g = avio_r8(pb); unsigned b = avio_r8(pb); - gdv->pal[i] = 0xFFU << 24 | r << 18 | g << 10 | b << 2; + gdv->pal[i] = 0xFFU << 24 | r << 18 | r >> 4 << 16 | g << 10 | g >> 4 << 8 | b << 2 | b >> 4; } } -- 2.24.1