From ec6b39eb3ccd9319c23eedef18ccc1296b0b6413 Mon Sep 17 00:00:00 2001 From: moosecrab Date: Sun, 12 Nov 2023 06:30:46 -0800 Subject: [PATCH] Added support for gAMA chunk and white point calculation. --- pngchunk/pngchunk.vb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pngchunk/pngchunk.vb b/pngchunk/pngchunk.vb index 38f00bb..c458f05 100755 --- a/pngchunk/pngchunk.vb +++ b/pngchunk/pngchunk.vb @@ -280,13 +280,25 @@ Dim offset As Integer = 0 For Each pointname As String In {"white point", "red", "green ", "blue"} Dim xcounts, ycounts As UInteger + Dim extrainfo As String = "" xcounts = BigEndianUInt32(data, offset) ycounts = BigEndianUInt32(data, offset + 4) - Console.WriteLine("{0}: x = {1:g} y = {2:g}", pointname, xcounts / 100000.0, ycounts / 100000.0) + 'Calculate color temperature of white point + If pointname = "white point" Then + Dim n As Double = ((xcounts / 100000.0) - 0.332) / ((ycounts / 100000.0) - 0.1858) + Dim cctapprox As Double = (-449 * n ^ 3) + (3525 * n ^ 2) - (6823.3 * n) + 5520.33 + extrainfo = " (" & cctapprox.ToString("F0") & " K)" + End If + + Console.WriteLine("{0}: x = {1:g} y = {2:g}{3}", pointname, xcounts / 100000.0, ycounts / 100000.0, extrainfo) offset += 8 Next + + Case "gAMA" + Dim gammacounts As UInteger = BigEndianUInt32(data) + Console.WriteLine("gamma: 1/{0:g5}", 1 / (gammacounts / 100000.0)) End Select End Sub