Beispiel #1
0
        static public void Mux(string[] fileNames, string outFile, int countPerLine)
        {
            List <Bmp> bmps  = new List <Bmp>();
            var        lines = (fileNames.Length + countPerLine - 1) / countPerLine;
            var        index = 0;

            for (var y = 0; y < lines; ++y)
            {
                for (var x = 0; x < countPerLine; ++x)
                {
                    bmps.Add(Bmp.FromFile(fileNames[index]));
                    index++;
                }
            }
            bool           palettable = IsPalettable(bmps);
            List <RGBQUAD> colors     = null;

            if (palettable)
            {
                // パレット統合
                colors = CombinePalettes(bmps);
                if (colors.Count > 256)
                {
                    palettable = false;
                }
            }
            if (palettable)
            {
                ushort biBitCount = 8;
                if (colors.Count <= 2)
                {
                    biBitCount = 1;
                }
                if (colors.Count <= 16)
                {
                    biBitCount = 4;
                }
                else
                {
                    biBitCount = 8;
                }
                Bmp bmp = new Bmp();
                bmp.bmih = bmps[0].bmih;
                var width  = bmps[0].bmih.biWidth;
                var height = Math.Abs(bmps[0].bmih.biHeight);
                bmp.bmih.biWidth    = width * countPerLine;
                bmp.bmih.biHeight   = height * lines;
                bmp.bmih.biBitCount = biBitCount;
                if (bmp.bmih.biClrUsed == 0)
                {
                    bmp.colorTable = new RGBQUAD[1 << biBitCount];
                }
                else
                {
                    bmp.bmih.biClrUsed = (uint)(colors.Count);
                    bmp.colorTable     = new RGBQUAD[bmp.bmih.biClrUsed];
                }
                for (int i = 0; i < colors.Count; ++i)
                {
                    bmp.colorTable[i] = colors[i];
                }

                int lineStride = bmp.GetLineStride();
                bmp.imageData = new byte[Math.Abs(lineStride * bmp.bmih.biHeight)];
                index         = 0;
                for (var y = 0; y < lines; ++y)
                {
                    for (var x = 0; x < countPerLine; ++x)
                    {
                        bmp.Paste(x * width, y * height, bmps[index]);
                        index++;
                    }
                }
                bmp.ToFile(outFile);
            }
            else
            {
                throw new NotImplementedException();
            }
        }