2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[メモ] sRGB から リニアRGBに変換

2
Last updated at Posted at 2019-04-08
  • C#

式に問題があったので修正しました

- return Math.Pow((c_srgb + a / 1 + a ), 2.4 );
+ return Math.Pow(((c_srgb + a) / (1 + a) ), 2.4 );

using System;
using System.Collections.Generic;
using System.Linq;


public class App {
    
    public static void Main(string[] args) {
        int[] rgb = { 1, 1, 1};
        double[] linearrgb = Array.ConvertAll(rgb,LinerRgb);
        Array.ForEach(linearrgb, Console.WriteLine);
    }
    
    private static double LinerRgb(int c) {
        double c_srgb = (double)c / 255;
        double a = 0.055;
        
        if ( c_srgb <= 0.04045 ) return  c_srgb / 12.92;
        return Math.Pow(((c_srgb + a) / (1 + a) ), 2.4 );
    }
}
  • python
def linearrgbg(c):
	c_srgb = c / 255
	a = 0.0555
	
	if c_srgb <= 0.4045:
		return c_srgb / 12.92
	return math.pow(((c_srgb + a) / (1 + a) ), 2.4 )
	
if __name__ == '__main__':
	rgb = [1,1,1]
	linearrgbg = list(map(linearrgbg, rgb))
	print(linearrgbg)

参考: sRGB - Wikipedia

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?