Texture2D MakeIndexTexture16(ColorMap map, Color32[] srcPixels, int width, int height)
    {
        var dstWidth = (width + 1) / 2;         // 切り上げで幅半分にする
        var texture  = new Texture2D(dstWidth, height, TextureFormat.Alpha8, false);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < dstWidth; x++)             // 2画素づつ処理。書き込み側の幅でループ
            {
                var color0 = srcPixels[(y * width) + (x * 2)];
                int index0 = map.Find(color0);
                int index1 = 0;
                if (((x * 2) + 1) < width)                 // 2画素目が含まれている時だけ
                {
                    var color1 = srcPixels[(y * width) + ((x * 2) + 1)];
                    index1 = map.Find(color1);
                }
                Debug.Assert((index0 < 16) || (index1 < 16));
                var composedIndex = (index0 << 4) | index1;
                var indexAsColor  = new Color(0f, 0f, 0f, (float)composedIndex / 255f);
                texture.SetPixel(x, y, indexAsColor);
            }
        }
        return(texture);
    }
    Texture2D MakeIndexTexture256(ColorMap map, Color32[] srcPixels, int width, int height)
    {
        var texture = new Texture2D(width, height, TextureFormat.RGBA32, false);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                var color = srcPixels[(y * width) + x];
                int index = map.Find(color);
                Debug.Assert(index < 256);
                var encoded      = ((float)index) / 255f;
                var indexAsColor = new Color(0f, 0f, 0f, encoded);
                texture.SetPixel(x, y, indexAsColor);
            }
        }
        return(texture);
    }
    Texture2D MakeTableTexture(ColorMap map, int colorCount)
    {
        var texture = new Texture2D(colorCount, 1, TextureFormat.RGBA32, false);
        // 配列化してテクスチャに書き込み
        var colors = new Color32[colorCount];

        foreach (var color in map.keyList)
        {
            var index = map.Find(color);
            Debug.Assert(index < colorCount);
            colors[index] = color;
        }
        // 確認のために残りは紫で埋める
        var magenta = new Color32(255, 0, 255, 255);

        for (int i = map.keyList.Count; i < colorCount; i++)
        {
            colors[i] = magenta;
        }
        texture.SetPixels32(colors);
        return(texture);
    }