示例#1
0
        public bool RawForeachV1(TOnRawForeachV1 OnRawForeachV1)
        {
            if (ver != 1 || OnRawForeachV1 == null)
            {
                return(false);
            }

            for (int i = 0; i < getSprNum(); ++i)
            {
                sprMsgV1 spr = getSprMsgV1(i);
                if (spr.pcxDataLen == 0)
                {
                    sprMsgV1 linkSpr = spr;
                    while (linkSpr.pcxDataLen == 0)
                    {
                        linkSpr = getSprMsgV1(linkSpr.linkIndex);
                    }

                    OnRawForeachV1(spr, linkSpr.group, linkSpr.index, null, null);
                }
                else
                {
                    byte[] pal;
                    byte[] colors = getSprDataV1(i, out pal, FI_FORMAT.FIF_UNKNOWN);
                    if (colors == null || colors.Length <= 0)
                    {
                        return(false);
                    }
                    OnRawForeachV1(spr, -1, -1, colors, pal);
                }
            }

            return(true);
        }
示例#2
0
        //SFFV1 获取指定图像信息
        public sprMsgV1 getSprMsgV1(int index)
        {
            int      offset = msgV1.sprOffset;
            sprMsgV1 spr    = new sprMsgV1();

            for (int i = 0; i < msgV1.sprNum; i++)
            {
                seek(offset);
                if (i == index)
                {
                    spr.offset     = br.ReadInt32();
                    spr.pcxDataLen = br.ReadInt32();
                    spr.x          = br.ReadInt16();
                    spr.y          = br.ReadInt16();
                    spr.group      = br.ReadUInt16();
                    spr.index      = br.ReadUInt16();
                    spr.linkIndex  = br.ReadUInt16();
                    spr.palType    = br.ReadByte();
                    offset         = spr.offset;
                }
                else
                {
                    offset = br.ReadInt32();
                }
            }
            return(spr);
        }
示例#3
0
        //SFFV1 从索引获取指定图像数据
        public byte[] getSprDataV1(int index, out byte[] pp, FI_FORMAT type)
        {
            int      offset = msgV1.sprOffset;
            sprMsgV1 spr    = new sprMsgV1();

            byte[] facePalData = new byte[0];
            byte[] palData     = new byte[0];
            byte[] sprData     = new byte[0];
            for (int i = 0; i < msgV1.sprNum; i++)
            {
                seek(offset);
                offset         = br.ReadInt32();
                spr.pcxDataLen = br.ReadInt32();
                spr.x          = br.ReadInt16();
                spr.y          = br.ReadInt16();
                spr.group      = br.ReadUInt16();
                spr.index      = br.ReadUInt16();
                spr.linkIndex  = br.ReadUInt16();
                spr.palType    = br.ReadByte();
                if (i == 0)
                {
                    //第一张图强制为独立色表
                    spr.palType = 0;
                }
                seek(13, SeekOrigin.Current);
                if ((spr.group == 0 && spr.index == 0 || spr.group == 9000 && spr.index == 0) && facePalData.Length != 0)
                {
                    //0,0和9000,0强制为独立色表,且使用第一张色表
                    palData = facePalData;
                }
                if (i == index)
                {
                    if (spr.pcxDataLen == 0)
                    {
                        //链接型图像
                        return(getSprDataV1(spr.linkIndex, out pp, type));
                    }

                    sprData = br.ReadBytes(spr.pcxDataLen);
                    if (type != FI_FORMAT.FIF_UNKNOWN)
                    {
                        IntPtr dib = FI.LoadFromMemory(sprData, FI_FORMAT.FIF_PCX);
                        if (spr.palType == 1)
                        {
                            RGBQUAD *pal = FI.GetPalette(dib);
                            for (int n = 0; n < 256; n++)
                            {
                                pal[n].Red   = palData[n * 3];
                                pal[n].Green = palData[n * 3 + 1];
                                pal[n].Blue  = palData[n * 3 + 2];
                            }
                        }
                        FI.SaveToMemory(dib, ref sprData, type);


                        //释放图像流
                        FI.Free(dib);
                    }

                    pp = palData;
                    return(sprData);
                }
                else
                {
                    if (spr.palType == 0)
                    {
                        //读取PCX尾部色表数据
                        seek(spr.pcxDataLen - 768, SeekOrigin.Current);
                        palData = br.ReadBytes(768);
                        if (i == 0)
                        {
                            //保留第一张图的色表
                            facePalData = palData;
                        }
                    }
                }
            }

            pp = null;
            return(null);
        }