示例#1
0
文件: UnitGrid.cs 项目: rxpii/sv
    // posHex - the queried position
    // distinguishPlayers - retreive groups of the specified player
    // playerQueried - the id of the specified player
    // ignoreOwnGroup - ignore the group the position's unit is in
    // invertPlayerSelection - retreive groups not of the specified player
    public List <UnitGroup> GetPosNeighborGroups(VectorHex posHex, bool distinguishPlayers = false, int playerQueried = 0, bool ignoreOwnGroup = true, bool invertPlayerSelection = false)
    {
        List <ResUnit>   neighbors      = GetNeighbors(posHex);
        List <UnitGroup> neighborGroups = new List <UnitGroup>();
        ResUnit          unitAtPos      = GetAt(posHex);

        foreach (ResUnit neighbor in neighbors)
        {
            // reference comparison
            if (!neighborGroups.Contains(neighbor.group))
            {
                if (ignoreOwnGroup &&
                    unitAtPos != null &&
                    neighbor.group == unitAtPos.group)
                {
                    continue;
                }

                if (distinguishPlayers)
                {
                    bool unitIsPlayers = invertPlayerSelection ^ (neighbor.owner.playerID == playerQueried);
                    if (!unitIsPlayers)
                    {
                        continue;
                    }
                }
                neighborGroups.Add(neighbor.group);
            }
        }

        return(neighborGroups);
    }
示例#2
0
    // destroys the players units that do not survive the enemy groups
    // does not affect the units not controlled by the given player
    private void TerritoryUpdateGroup(PlayerController player)
    {
        // loop through all groups
        for (int i = allGroups.Count - 1; i >= 0; i--)
        {
            UnitGroup group = allGroups[i];

            // check if they are owned by the player
            if (group.owner.Equals(player))
            {
                // reevaluate for new dead units if a unit in the group was previously removed
                bool unitRemoved = false;
                do
                {
                    unitRemoved = false;
                    for (int j = group.units.Count - 1; j >= 0; j--)
                    {
                        ResUnit unit         = group.units[j];
                        bool    unitSurvived = EndureUnit(unit);
                        if (!unitSurvived)
                        {
                            RemoveUnit(unit);
                            unitRemoved = true;
                        }
                    }
                } while (unitRemoved && !group.empty);

                // remove the group if all units within it are dead
                if (group.empty)
                {
                    allGroups.Remove(group);
                }
            }
        }
    }
示例#3
0
文件: UnitGrid.cs 项目: rxpii/sv
    public ResUnit RemoveAt(VectorHex posHex)
    {
        VectorHex offsetPos = OffsetForGrid(posHex);
        ResUnit   removed   = grid[offsetPos.q, offsetPos.r];

        grid[offsetPos.q, offsetPos.r] = null;
        return(removed);
    }
示例#4
0
    private void RemoveUnit(ResUnit removedUnit)
    {
        allUnits.Remove(removedUnit);
        grid.RemoveUnit(removedUnit);
        UnitGroup removedUnitGroup = removedUnit.group;

        removedUnit.group.RemoveUnit(removedUnit);
        removedUnit.tile.RemoveUnit();
        Destroy(removedUnit.gameObject);
    }
示例#5
0
文件: UnitGroup.cs 项目: rxpii/sv
    // Call before actually setting the changedUnit's new att
    public void ChangeUnitAtt(ResUnit changedUnit, Vector3 newAtt)
    {
        groupHarvest -= changedUnit.attHarvest;
        groupDefense -= changedUnit.attDefense;
        groupOffense -= changedUnit.attOffense;

        groupHarvest += (int)newAtt.x;
        groupDefense += (int)newAtt.y;
        groupOffense += (int)newAtt.z;
    }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buffer">字节数组</param>
        /// <param name="width">图像的宽</param>
        /// <param name="height">图像的高</param>
        /// <param name="filePath"></param>
        /// <param name="rowsPerStrip">图像的实际高度</param>
        /// <param name="xResolution">x分辨率</param>
        /// <param name="yResolution">y分辨率</param>
        /// <param name="resUnit">分辨率单位,默认选inch</param>
        /// <param name="planarConfig">数据平面存储方式</param>
        /// <param name="bytePerSample">单个像素是多少位</param>
        /// <param name="photometric">图像模式</param>
        /// <param name="compression">压缩方式</param>
        /// <param name="samplePerPixel">一个像素几个采样</param>
        /// <param name="orientation">方向</param>
        /// <param name="fillOrder">大小端</param>
        public static void CreateGrayScaleTiff(byte[] buffer, int width, int height, string filePath, int rowsPerStrip,
                                               int xResolution, int yResolution, ResUnit resUnit = ResUnit.INCH,
                                               PlanarConfig planarConfig = PlanarConfig.CONTIG,
                                               int bytePerSample         = 16, Photometric photometric = Photometric.MINISBLACK,
                                               Compression compression   = Compression.NONE,
                                               int samplePerPixel        = 1, Orientation orientation = Orientation.TOPLEFT,
                                               FillOrder fillOrder       = FillOrder.MSB2LSB)
        {
            var info = CreateDoubleByteTiffInfo(buffer, null, width, height, filePath, height, width, height);

            Create16BitGrayScaleTiff(info);
        }
示例#7
0
    // endures the unit through onslaught of enemies. Returns true upon survival, otherwise false.
    private bool EndureUnit(ResUnit enduree)
    {
        // select all groups that are not under control of the enduree's owner
        List <UnitGroup> neighborGroups = grid.GetPosNeighborGroups(enduree.posHex, distinguishPlayers: true, playerQueried: enduree.owner.playerID, ignoreOwnGroup: true, invertPlayerSelection: true);
        int sumOff = 0;

        foreach (UnitGroup neighborGroup in neighborGroups)
        {
            sumOff += neighborGroup.groupOffense;
        }

        return(sumOff <= enduree.group.groupDefense);
    }
示例#8
0
    protected ResUnit GetUnit(string unitName, string inputUser)
    {
        if (string.IsNullOrEmpty(unitName))
        {
            return(null);
        }
        ResUnit resUnit = ResUnit.GetByUnitName(unitName);

        if (resUnit == null)
        {
            resUnit = ResUnit.Create(System.Guid.NewGuid().ToString(), System.DateTime.Now.ToString("yyyyMMddHHmmsss"), unitName, inputUser, new System.DateTime?(System.DateTime.Now));
            ResUnit.Add(resUnit);
        }
        return(resUnit);
    }
示例#9
0
        public ResolutionInfo(ImageResource imgRes)
            : base(imgRes)
        {
            BinaryReverseReader reader = imgRes.DataReader;

              this.m_hRes = reader.ReadInt16();
              this.m_hResUnit = (ResUnit)reader.ReadInt32();
              this.m_widthUnit = (Unit)reader.ReadInt16();

              this.m_vRes = reader.ReadInt16();
              this.m_vResUnit = (ResUnit)reader.ReadInt32();
              this.m_heightUnit = (Unit)reader.ReadInt16();

              reader.Close();
        }
示例#10
0
        public ResolutionInfo(ImageResource imgRes)
            : base(imgRes)
        {
            var reader = imgRes.DataReader;

            m_hRes      = reader.ReadInt16();
            m_hResUnit  = (ResUnit)reader.ReadInt32();
            m_widthUnit = (Unit)reader.ReadInt16();

            m_vRes       = reader.ReadInt16();
            m_vResUnit   = (ResUnit)reader.ReadInt32();
            m_heightUnit = (Unit)reader.ReadInt16();

            reader.Close();
        }
示例#11
0
    public void CreateUnitMultiple(Vector3 attributes, List <TileBehavior> spawnTiles, PlayerController owner)
    {
        foreach (TileBehavior spawnTile in spawnTiles)
        {
            ResUnit newUnit = CreateUnitSingle(attributes, spawnTile, owner);
        }
        foreach (PlayerController player in PlayerInteractionManager.Instance.players)
        {
            if (!player.Equals(owner))
            {
                TerritoryUpdateGroup(player);
            }
        }

        TerritoryUpdateGroup(owner);

        UIManager.Instance.UpdateModeUI(bypassPreviousCheck: true);
    }
示例#12
0
    public ResUnit SpawnUnit(Vector3 attributes, PlayerController owner)
    {
        if (unit != null)
        {
            unit.SetAttributes(attributes);
        }
        else
        {
            GameObject newUnit = Instantiate(pf_ResUnit, transform.parent.transform);
            newUnit.transform.localPosition = new Vector3(0f, 0.5f, 0f);
            ResUnit ru = newUnit.GetComponent <ResUnit>();
            ru.Initialize(attributes, this, owner);
            unit  = ru;
            empty = false;
        }

        return(unit);
    }
示例#13
0
    public ResUnit CreateUnitSingle(Vector3 attributes, TileBehavior spawnTile, PlayerController owner)
    {
        // remove old tile
        if (!spawnTile.empty)
        {
            /*if (allUnits.Contains(spawnTile.unit)) {
             *  RemoveUnit(spawnTile.unit);
             * }*/
            if (!spawnTile.unit.owner.Equals(owner))
            {
                return(null);
            }
            spawnTile.unit.group.ChangeUnitAtt(spawnTile.unit, attributes);
            spawnTile.unit.SetAttributes(attributes);
            return(spawnTile.unit);
        }
        ResUnit newUnit = spawnTile.SpawnUnit(attributes, owner);

        IntegrateUnit(newUnit);
        return(newUnit);
    }
示例#14
0
        public TiffDirectory()
        {
            td_subfiletype  = 0;
            td_compression  = 0;
            td_photometric  = 0;
            td_planarconfig = 0;

            td_fillorder            = FillOrder.MSB2LSB;
            td_bitspersample        = 1;
            td_threshholding        = Threshold.BILEVEL;
            td_orientation          = Orientation.TOPLEFT;
            td_samplesperpixel      = 1;
            td_rowsperstrip         = -1;
            td_tiledepth            = 1;
            td_stripbytecountsorted = true; // Our own arrays always sorted.
            td_resolutionunit       = ResUnit.INCH;
            td_sampleformat         = SampleFormat.UINT;
            td_imagedepth           = 1;
            td_ycbcrsubsampling[0]  = 2;
            td_ycbcrsubsampling[1]  = 2;
            td_ycbcrpositioning     = YCbCrPosition.CENTERED;
        }
示例#15
0
        /// <summary>
        /// Write byte images, support single channel 8 bit grayscale image and 24 bit RGB image
        /// </summary>
        /// <param name="data"></param>
        /// <param name="width">Number of pixels in one row</param>
        /// <param name="samplesPerPixel">1 for grayscale image, 3 for RGB image</param>
        /// <param name="photo">
        ///     <see cref="Photometric.MINISBLACK"/> or <see cref="Photometric.MINISWHITE"/> for grayscale image
        ///     <see cref="Photometric.RGB"/> for RGB image
        /// </param>
        /// <param name="path"></param>
        /// <param name="xRes"></param>
        /// <param name="yRes"></param>
        /// <param name="resUnit"></param>
        public static void SaveTiff(byte[] data, int width, int samplesPerPixel, string path, Photometric photo = Photometric.MINISBLACK,
                                    float xRes = 100, float yRes = 100, ResUnit resUnit = ResUnit.CENTIMETER)
        {
            var optimalSizePerStrip       = 8000.0;
            var optimalRowsPerStripDouble = optimalSizePerStrip / sizeof(byte) / width / samplesPerPixel;
            var optimalRowsPerStrip       = optimalRowsPerStripDouble < 1 ? 1 : (int)optimalRowsPerStripDouble;
            var height = data.Length / width / samplesPerPixel;

            using (var output = Tiff.Open(path, "w"))
            {
                output.SetField(TiffTag.IMAGEWIDTH, width);
                output.SetField(TiffTag.IMAGELENGTH, height);
                output.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                output.SetField(TiffTag.BITSPERSAMPLE, 8);
                output.SetField(TiffTag.ROWSPERSTRIP, optimalRowsPerStrip);
                output.SetField(TiffTag.PHOTOMETRIC, (int)photo);
                output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
                output.SetField(TiffTag.RESOLUTIONUNIT, resUnit);
                output.SetField(TiffTag.XRESOLUTION, xRes);
                output.SetField(TiffTag.YRESOLUTION, yRes);

                var stripCount = Math.Ceiling((float)height / optimalRowsPerStrip);

                var stripSize = optimalRowsPerStrip * width * samplesPerPixel;
                for (int stripIndex = 0; stripIndex < stripCount; stripIndex++)
                {
                    var start        = stripIndex * stripSize;
                    var bytesToWrite = (stripIndex == stripCount - 1) && (height % optimalRowsPerStrip != 0)
                        ? (height * width * samplesPerPixel - start)
                        : stripSize;
                    output.WriteEncodedStrip(stripIndex, data, start, bytesToWrite);
                }

                output.Close();
            }
        }
示例#16
0
    // places new unit within nearby group if one exists, aggregating multiple should it bridge different groups.
    private void IntegrateUnit(ResUnit unit)
    {
        Debug.Log("INTEGRATING");
        VectorHex posHex = unit.posHex;

        Debug.Log("ID: " + unit.owner.playerID);
        List <UnitGroup> neighborGroups = grid.GetPosNeighborGroups(posHex, distinguishPlayers: true, playerQueried: unit.owner.playerID, ignoreOwnGroup: true, invertPlayerSelection: false);

        // if there are no neighbors
        if (neighborGroups.Count < 1)
        {
            UnitGroup newGroup = new UnitGroup(unit.owner);
            newGroup.AddUnit(unit);
            allGroups.Add(newGroup);
        }
        else if (neighborGroups.Count > 1)
        {
            UnitGroup superGroup = neighborGroups[0];
            for (int i = 1; i < neighborGroups.Count; i++)
            {
                superGroup.AddUnits(neighborGroups[i].units);
                if (allGroups.Contains(neighborGroups[i]))
                {
                    allGroups.Remove(neighborGroups[i]);
                }
            }
            superGroup.AddUnit(unit);
        }
        else
        {
            neighborGroups[0].AddUnit(unit);
        }

        grid.PlaceUnit(unit);
        allUnits.Add(unit);
    }
示例#17
0
        public static void SaveTiff(float[] data, int width, string path, float xRes = 100,
                                    float yRes = 100, ResUnit resUnit = ResUnit.CENTIMETER, Photometric photometric = Photometric.MINISBLACK)
        {
            var samplesPerPixel = 1;
            var perfectDivided  = data.Length % (samplesPerPixel * width) == 0;

            if (!perfectDivided)
            {
                throw new InvalidOperationException(
                          $"Data length({data.Length}) is incompatible with current samplesPerPixel({samplesPerPixel}) and width({width})");
            }

            var byteArray = new byte[data.Length * 4];

            Buffer.BlockCopy(data, 0, byteArray, 0, byteArray.Length);

            // Calcualte suitable ROWSPERSTRIP
            var optimalSizePerStrip       = 8000.0;
            var optimalRowsPerStripDouble = optimalSizePerStrip / sizeof(float) / width / samplesPerPixel;
            var optimalRowsPerStrip       = optimalRowsPerStripDouble < 1 ? 1 : (int)optimalRowsPerStripDouble;
            var height = data.Length / samplesPerPixel / width;

            using (Tiff image = Tiff.Open(path, "w"))
            {
                if (image == null)
                {
                    throw new InvalidOperationException($"Can not open image: {path}");
                }

                // We need to set some values for basic tags before we can add any data
                image.SetField(TiffTag.SAMPLEFORMAT, SampleFormat.IEEEFP);
                image.SetField(TiffTag.IMAGEWIDTH, width);
                image.SetField(TiffTag.IMAGELENGTH, height);
                image.SetField(TiffTag.BITSPERSAMPLE, sizeof(float) * 8);
                image.SetField(TiffTag.SAMPLESPERPIXEL, samplesPerPixel);
                image.SetField(TiffTag.ROWSPERSTRIP, optimalRowsPerStrip);
                image.SetField(TiffTag.PHOTOMETRIC, photometric);
                image.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
                image.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);

                image.SetField(TiffTag.XRESOLUTION, xRes);
                image.SetField(TiffTag.YRESOLUTION, yRes);
                image.SetField(TiffTag.RESOLUTIONUNIT, resUnit);

                var maxStrip         = Math.Ceiling((float)height / optimalRowsPerStrip);
                var byteCountEachRow = width * samplesPerPixel * sizeof(float);
                for (int stripIndex = 0; stripIndex < maxStrip; stripIndex++)
                {
                    // Write the information to the file
                    var currentStripLength = (stripIndex == maxStrip - 1) && (height % optimalRowsPerStrip != 0)
                        ? height % optimalRowsPerStrip
                        : optimalRowsPerStrip;
                    var offset = stripIndex * byteCountEachRow * optimalRowsPerStrip;

                    var ret = image.WriteEncodedStrip(stripIndex, byteArray, offset,
                                                      currentStripLength * byteCountEachRow);
                    if (ret == -1)
                    {
                        throw new InvalidOperationException("Error when writing the image");
                    }
                }

                // file will be auto-closed during disposal
                // but you can close image yourself
                image.Close();
            }
        }
示例#18
0
文件: UnitGroup.cs 项目: rxpii/sv
 public void RemoveUnit(ResUnit removedUnit)
 {
     units.Remove(removedUnit);
     RemoveUnitAtt(removedUnit);
     removedUnit.UnsubscribeFromGroup();
 }
示例#19
0
文件: UnitGroup.cs 项目: rxpii/sv
 private void AddUnitAtt(ResUnit newUnit)
 {
     groupHarvest += newUnit.attHarvest;
     groupDefense += newUnit.attDefense;
     groupOffense += newUnit.attOffense;
 }
        /// <summary>
        /// Sets the value(s) of a tag in a TIFF file/stream open for writing.
        /// </summary>
        /// <param name="tif">An instance of the <see cref="Tiff"/> class.</param>
        /// <param name="tag">The tag.</param>
        /// <param name="value">The tag value(s).</param>
        /// <returns>
        /// <c>true</c> if tag value(s) were set successfully; otherwise, <c>false</c>.
        /// </returns>
        /// <seealso cref="Tiff.SetField"/>
        public virtual bool SetField(Tiff tif, TiffTag tag, FieldValue[] value)
        {
            const string module = "vsetfield";

            TiffDirectory td     = tif.m_dir;
            bool          status = true;
            int           v32    = 0;
            int           v      = 0;

            bool end        = false;
            bool badvalue   = false;
            bool badvalue32 = false;

            switch (tag)
            {
            case TiffTag.SUBFILETYPE:
                td.td_subfiletype = (FileType)value[0].ToByte();
                break;

            case TiffTag.IMAGEWIDTH:
                td.td_imagewidth = value[0].ToInt();
                break;

            case TiffTag.IMAGELENGTH:
                td.td_imagelength = value[0].ToInt();
                break;

            case TiffTag.BITSPERSAMPLE:
                td.td_bitspersample = value[0].ToShort();
                // If the data require post-decoding processing to byte-swap samples, set it
                // up here. Note that since tags are required to be ordered, compression code
                // can override this behavior in the setup method if it wants to roll the post
                // decoding work in with its normal work.
                if ((tif.m_flags & TiffFlags.SWAB) == TiffFlags.SWAB)
                {
                    switch (td.td_bitspersample)
                    {
                    case 16:
                        tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab16Bit;
                        break;

                    case 24:
                        tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab24Bit;
                        break;

                    case 32:
                        tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab32Bit;
                        break;

                    case 64:
                        tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab64Bit;
                        break;

                    case 128:
                        // two 64's
                        tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab64Bit;
                        break;
                    }
                }
                break;

            case TiffTag.COMPRESSION:
                v = value[0].ToInt() & 0xffff;
                Compression comp = (Compression)v;
                // If we're changing the compression scheme, then notify the previous module
                // so that it can cleanup any state it's setup.
                if (tif.fieldSet(FieldBit.Compression))
                {
                    if (td.td_compression == comp)
                    {
                        break;
                    }

                    tif.m_currentCodec.Cleanup();
                    tif.m_flags &= ~TiffFlags.CODERSETUP;
                }
                // Setup new compression scheme.
                status = tif.setCompressionScheme(comp);
                if (status)
                {
                    td.td_compression = comp;
                }
                else
                {
                    status = false;
                }
                break;

            case TiffTag.PHOTOMETRIC:
                td.td_photometric = (Photometric)value[0].ToInt();
                break;

            case TiffTag.THRESHHOLDING:
                td.td_threshholding = (Threshold)value[0].ToByte();
                break;

            case TiffTag.FILLORDER:
                v = value[0].ToInt();
                FillOrder fo = (FillOrder)v;
                if (fo != FillOrder.LSB2MSB && fo != FillOrder.MSB2LSB)
                {
                    badvalue = true;
                    break;
                }

                td.td_fillorder = fo;
                break;

            case TiffTag.ORIENTATION:
                v = value[0].ToInt();
                Orientation or = (Orientation)v;
                if (or < Orientation.TOPLEFT || Orientation.LEFTBOT < or)
                {
                    badvalue = true;
                    break;
                }
                else
                {
                    td.td_orientation = or;
                }
                break;

            case TiffTag.SAMPLESPERPIXEL:
                // XXX should cross check - e.g. if pallette, then 1
                v = value[0].ToInt();
                if (v == 0)
                {
                    badvalue = true;
                    break;
                }

                td.td_samplesperpixel = (short)v;
                break;

            case TiffTag.ROWSPERSTRIP:
                v32 = value[0].ToInt();
                if (v32 == 0)
                {
                    badvalue32 = true;
                    break;
                }

                td.td_rowsperstrip = v32;
                if (!tif.fieldSet(FieldBit.TileDimensions))
                {
                    td.td_tilelength = v32;
                    td.td_tilewidth  = td.td_imagewidth;
                }
                break;

            case TiffTag.MINSAMPLEVALUE:
                td.td_minsamplevalue = value[0].ToUShort();
                break;

            case TiffTag.MAXSAMPLEVALUE:
                td.td_maxsamplevalue = value[0].ToUShort();
                break;

            case TiffTag.SMINSAMPLEVALUE:
                td.td_sminsamplevalue = value[0].ToDouble();
                break;

            case TiffTag.SMAXSAMPLEVALUE:
                td.td_smaxsamplevalue = value[0].ToDouble();
                break;

            case TiffTag.XRESOLUTION:
                td.td_xresolution = value[0].ToFloat();
                break;

            case TiffTag.YRESOLUTION:
                td.td_yresolution = value[0].ToFloat();
                break;

            case TiffTag.PLANARCONFIG:
                v = value[0].ToInt();
                PlanarConfig pc = (PlanarConfig)v;
                if (pc != PlanarConfig.CONTIG && pc != PlanarConfig.SEPARATE)
                {
                    badvalue = true;
                    break;
                }
                td.td_planarconfig = pc;
                break;

            case TiffTag.XPOSITION:
                td.td_xposition = value[0].ToFloat();
                break;

            case TiffTag.YPOSITION:
                td.td_yposition = value[0].ToFloat();
                break;

            case TiffTag.RESOLUTIONUNIT:
                v = value[0].ToInt();
                ResUnit ru = (ResUnit)v;
                if (ru < ResUnit.NONE || ResUnit.CENTIMETER < ru)
                {
                    badvalue = true;
                    break;
                }

                td.td_resolutionunit = ru;
                break;

            case TiffTag.PAGENUMBER:
                td.td_pagenumber[0] = value[0].ToShort();
                td.td_pagenumber[1] = value[1].ToShort();
                break;

            case TiffTag.HALFTONEHINTS:
                td.td_halftonehints[0] = value[0].ToShort();
                td.td_halftonehints[1] = value[1].ToShort();
                break;

            case TiffTag.COLORMAP:
                v32 = 1 << td.td_bitspersample;
                Tiff.setShortArray(out td.td_colormap[0], value[0].ToShortArray(), v32);
                Tiff.setShortArray(out td.td_colormap[1], value[1].ToShortArray(), v32);
                Tiff.setShortArray(out td.td_colormap[2], value[2].ToShortArray(), v32);
                break;

            case TiffTag.EXTRASAMPLES:
                if (!setExtraSamples(td, ref v, value))
                {
                    badvalue = true;
                    break;
                }

                break;

            case TiffTag.MATTEING:
                if (value[0].ToShort() != 0)
                {
                    td.td_extrasamples = 1;
                }
                else
                {
                    td.td_extrasamples = 0;
                }

                if (td.td_extrasamples != 0)
                {
                    td.td_sampleinfo    = new ExtraSample[1];
                    td.td_sampleinfo[0] = ExtraSample.ASSOCALPHA;
                }
                break;

            case TiffTag.TILEWIDTH:
                v32 = value[0].ToInt();
                if ((v32 % 16) != 0)
                {
                    if (tif.m_mode != Tiff.O_RDONLY)
                    {
                        badvalue32 = true;
                        break;
                    }

                    Tiff.WarningExt(tif, tif.m_clientdata, tif.m_name,
                                    "Nonstandard tile width {0}, convert file", v32);
                }
                td.td_tilewidth = v32;
                tif.m_flags    |= TiffFlags.ISTILED;
                break;

            case TiffTag.TILELENGTH:
                v32 = value[0].ToInt();
                if ((v32 % 16) != 0)
                {
                    if (tif.m_mode != Tiff.O_RDONLY)
                    {
                        badvalue32 = true;
                        break;
                    }

                    Tiff.WarningExt(tif, tif.m_clientdata, tif.m_name,
                                    "Nonstandard tile length {0}, convert file", v32);
                }
                td.td_tilelength = v32;
                tif.m_flags     |= TiffFlags.ISTILED;
                break;

            case TiffTag.TILEDEPTH:
                v32 = value[0].ToInt();
                if (v32 == 0)
                {
                    badvalue32 = true;
                    break;
                }

                td.td_tiledepth = v32;
                break;

            case TiffTag.DATATYPE:
                v = value[0].ToInt();
                SampleFormat sf = SampleFormat.VOID;
                switch (v)
                {
                case DATATYPE_VOID:
                    sf = SampleFormat.VOID;
                    break;

                case DATATYPE_INT:
                    sf = SampleFormat.INT;
                    break;

                case DATATYPE_UINT:
                    sf = SampleFormat.UINT;
                    break;

                case DATATYPE_IEEEFP:
                    sf = SampleFormat.IEEEFP;
                    break;

                default:
                    badvalue = true;
                    break;
                }

                if (!badvalue)
                {
                    td.td_sampleformat = sf;
                }

                break;

            case TiffTag.SAMPLEFORMAT:
                v  = value[0].ToInt();
                sf = (SampleFormat)v;
                if (sf < SampleFormat.UINT || SampleFormat.COMPLEXIEEEFP < sf)
                {
                    badvalue = true;
                    break;
                }

                td.td_sampleformat = sf;

                // Try to fix up the SWAB function for complex data.
                if (td.td_sampleformat == SampleFormat.COMPLEXINT &&
                    td.td_bitspersample == 32 && tif.m_postDecodeMethod == Tiff.PostDecodeMethodType.pdmSwab32Bit)
                {
                    tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab16Bit;
                }
                else if ((td.td_sampleformat == SampleFormat.COMPLEXINT ||
                          td.td_sampleformat == SampleFormat.COMPLEXIEEEFP) &&
                         td.td_bitspersample == 64 && tif.m_postDecodeMethod == Tiff.PostDecodeMethodType.pdmSwab64Bit)
                {
                    tif.m_postDecodeMethod = Tiff.PostDecodeMethodType.pdmSwab32Bit;
                }
                break;

            case TiffTag.IMAGEDEPTH:
                td.td_imagedepth = value[0].ToInt();
                break;

            case TiffTag.SUBIFD:
                if ((tif.m_flags & TiffFlags.INSUBIFD) != TiffFlags.INSUBIFD)
                {
                    td.td_nsubifd = value[0].ToInt();
                    Tiff.setLong8Array(out td.td_subifd, value[1].TolongArray(), td.td_nsubifd);
                }
                else
                {
                    Tiff.ErrorExt(tif, tif.m_clientdata, module,
                                  "{0}: Sorry, cannot nest SubIFDs", tif.m_name);
                    status = false;
                }
                break;

            case TiffTag.YCBCRPOSITIONING:
                td.td_ycbcrpositioning = (YCbCrPosition)value[0].ToShort();
                break;

            case TiffTag.YCBCRSUBSAMPLING:
                td.td_ycbcrsubsampling[0] = value[0].ToShort();
                td.td_ycbcrsubsampling[1] = value[1].ToShort();
                break;

            case TiffTag.TRANSFERFUNCTION:
                v = ((td.td_samplesperpixel - td.td_extrasamples) > 1 ? 3 : 1);
                for (int i = 0; i < v; i++)
                {
                    Tiff.setShortArray(out td.td_transferfunction[i], value[0].ToShortArray(), 1 << td.td_bitspersample);
                }
                break;

            case TiffTag.REFERENCEBLACKWHITE:
                // XXX should check for null range
                Tiff.setFloatArray(out td.td_refblackwhite, value[0].ToFloatArray(), 6);
                break;

            case TiffTag.INKNAMES:
                v = value[0].ToInt();
                string s = value[1].ToString();
                v      = checkInkNamesString(tif, v, s);
                status = v > 0;
                if (v > 0)
                {
                    setNString(out td.td_inknames, s, v);
                    td.td_inknameslen = v;
                }
                break;

            default:
                // This can happen if multiple images are open with
                // different codecs which have private tags. The global tag
                // information table may then have tags that are valid for
                // one file but not the other. If the client tries to set a
                // tag that is not valid for the image's codec then we'll
                // arrive here. This happens, for example, when tiffcp is
                // used to convert between compression schemes and
                // codec-specific tags are blindly copied.
                TiffFieldInfo fip = tif.FindFieldInfo(tag, TiffType.ANY);
                if (fip == null || fip.Bit != FieldBit.Custom)
                {
                    Tiff.ErrorExt(tif, tif.m_clientdata, module,
                                  "{0}: Invalid {1}tag \"{2}\" (not supported by codec)",
                                  tif.m_name, Tiff.isPseudoTag(tag) ? "pseudo-" : string.Empty,
                                  fip != null ? fip.Name : "Unknown");
                    status = false;
                    break;
                }

                // Find the existing entry for this custom value.
                int tvIndex = -1;
                for (int iCustom = 0; iCustom < td.td_customValueCount; iCustom++)
                {
                    if (td.td_customValues[iCustom].info.Tag == tag)
                    {
                        tvIndex = iCustom;
                        td.td_customValues[iCustom].value = null;
                        break;
                    }
                }

                // Grow the custom list if the entry was not found.
                if (tvIndex == -1)
                {
                    td.td_customValueCount++;
                    TiffTagValue[] new_customValues = Tiff.Realloc(
                        td.td_customValues, td.td_customValueCount - 1, td.td_customValueCount);
                    td.td_customValues = new_customValues;

                    tvIndex = td.td_customValueCount - 1;
                    td.td_customValues[tvIndex].info  = fip;
                    td.td_customValues[tvIndex].value = null;
                    td.td_customValues[tvIndex].count = 0;
                }

                // Set custom value ... save a copy of the custom tag value.
                int tv_size = Tiff.dataSize(fip.Type);
                if (tv_size == 0)
                {
                    status = false;
                    Tiff.ErrorExt(tif, tif.m_clientdata, module,
                                  "{0}: Bad field type {1} for \"{2}\"",
                                  tif.m_name, fip.Type, fip.Name);
                    end = true;
                    break;
                }

                int paramIndex = 0;
                if (fip.PassCount)
                {
                    if (fip.WriteCount == TiffFieldInfo.Variable2)
                    {
                        td.td_customValues[tvIndex].count = value[paramIndex++].ToInt();
                    }
                    else
                    {
                        td.td_customValues[tvIndex].count = value[paramIndex++].ToInt();
                    }
                }
                else if (fip.WriteCount == TiffFieldInfo.Variable ||
                         fip.WriteCount == TiffFieldInfo.Variable2)
                {
                    td.td_customValues[tvIndex].count = 1;
                }
                else if (fip.WriteCount == TiffFieldInfo.Spp)
                {
                    td.td_customValues[tvIndex].count = td.td_samplesperpixel;
                }
                else
                {
                    td.td_customValues[tvIndex].count = fip.WriteCount;
                }

                if (fip.Type == TiffType.ASCII)
                {
                    string ascii;
                    Tiff.setString(out ascii, value[paramIndex++].ToString());
                    td.td_customValues[tvIndex].value = Tiff.Latin1Encoding.GetBytes(ascii);
                }
                else
                {
                    td.td_customValues[tvIndex].value = new byte[tv_size * td.td_customValues[tvIndex].count];
                    if ((fip.PassCount ||
                         fip.WriteCount == TiffFieldInfo.Variable ||
                         fip.WriteCount == TiffFieldInfo.Variable2 ||
                         fip.WriteCount == TiffFieldInfo.Spp ||
                         td.td_customValues[tvIndex].count > 1) &&
                        fip.Tag != TiffTag.PAGENUMBER &&
                        fip.Tag != TiffTag.HALFTONEHINTS &&
                        fip.Tag != TiffTag.YCBCRSUBSAMPLING &&
                        fip.Tag != TiffTag.DOTRANGE)
                    {
                        byte[] apBytes = value[paramIndex++].GetBytes();
                        Buffer.BlockCopy(apBytes, 0, td.td_customValues[tvIndex].value, 0, Math.Min(apBytes.Length, td.td_customValues[tvIndex].value.Length));
                    }
                    else
                    {
                        // XXX: The following loop required to handle
                        // PAGENUMBER, HALFTONEHINTS,
                        // YCBCRSUBSAMPLING and DOTRANGE tags.
                        // These tags are actually arrays and should be
                        // passed as arrays to SetField() function, but
                        // actually passed as a list of separate values.
                        // This behavior must be changed in the future!

                        // Upd: This loop also processes some EXIF tags with
                        // UNDEFINED type (like EXIF_FILESOURCE or EXIF_SCENETYPE)
                        // In this case input value is string-based, so
                        // in TiffType.UNDEFINED case we use FieldValue.GetBytes()[0]
                        // construction instead of direct call of FieldValue.ToByte() method.
                        byte[] val    = td.td_customValues[tvIndex].value;
                        int    valPos = 0;
                        for (int i = 0; i < td.td_customValues[tvIndex].count; i++, valPos += tv_size)
                        {
                            switch (fip.Type)
                            {
                            case TiffType.BYTE:
                            case TiffType.UNDEFINED:
                                val[valPos] = value[paramIndex + i].GetBytes()[0];
                                break;

                            case TiffType.SBYTE:
                                val[valPos] = value[paramIndex + i].ToByte();
                                break;

                            case TiffType.SHORT:
                                Buffer.BlockCopy(BitConverter.GetBytes(value[paramIndex + i].ToShort()), 0, val, valPos, tv_size);
                                break;

                            case TiffType.SSHORT:
                                Buffer.BlockCopy(BitConverter.GetBytes(value[paramIndex + i].ToShort()), 0, val, valPos, tv_size);
                                break;

                            case TiffType.LONG:
                            case TiffType.IFD:
                                Buffer.BlockCopy(BitConverter.GetBytes(value[paramIndex + i].ToInt()), 0, val, valPos, tv_size);
                                break;

                            case TiffType.SLONG:
                                Buffer.BlockCopy(BitConverter.GetBytes(value[paramIndex + i].ToInt()), 0, val, valPos, tv_size);
                                break;

                            case TiffType.RATIONAL:
                            case TiffType.SRATIONAL:
                            case TiffType.FLOAT:
                                Buffer.BlockCopy(BitConverter.GetBytes(value[paramIndex + i].ToFloat()), 0, val, valPos, tv_size);
                                break;

                            case TiffType.DOUBLE:
                                Buffer.BlockCopy(BitConverter.GetBytes(value[paramIndex + i].ToDouble()), 0, val, valPos, tv_size);
                                break;

                            default:
                                Array.Clear(val, valPos, tv_size);
                                status = false;
                                break;
                            }
                        }
                    }
                }
                break;
            }

            if (!end && !badvalue && !badvalue32)
            {
                if (status)
                {
                    tif.setFieldBit(tif.FieldWithTag(tag).Bit);
                    tif.m_flags |= TiffFlags.DIRTYDIRECT;
                }
            }

            if (badvalue)
            {
                Tiff.ErrorExt(tif, tif.m_clientdata, module,
                              "{0}: Bad value {1} for \"{2}\" tag",
                              tif.m_name, v, tif.FieldWithTag(tag).Name);
                return(false);
            }

            if (badvalue32)
            {
                Tiff.ErrorExt(tif, tif.m_clientdata, module,
                              "{0}: Bad value {1} for \"{2}\" tag",
                              tif.m_name, v32, tif.FieldWithTag(tag).Name);
                return(false);
            }

            return(status);
        }
示例#21
0
文件: UnitGroup.cs 项目: rxpii/sv
 private void RemoveUnitAtt(ResUnit removedUnit)
 {
     groupHarvest -= removedUnit.attHarvest;
     groupDefense -= removedUnit.attDefense;
     groupOffense -= removedUnit.attOffense;
 }
示例#22
0
        public TiffDirectory()
        {
            td_subfiletype = 0;
            td_compression = 0;
            td_photometric = 0;
            td_planarconfig = 0;

            td_fillorder = FillOrder.MSB2LSB;
            td_bitspersample = 1;
            td_threshholding = Threshold.BILEVEL;
            td_orientation = Orientation.TOPLEFT;
            td_samplesperpixel = 1;
            td_rowsperstrip = -1;
            td_tiledepth = 1;
            td_stripbytecountsorted = true; // Our own arrays always sorted.
            td_resolutionunit = ResUnit.INCH;
            td_sampleformat = SampleFormat.UINT;
            td_imagedepth = 1;
            td_ycbcrsubsampling[0] = 2;
            td_ycbcrsubsampling[1] = 2;
            td_ycbcrpositioning = YCbCrPosition.CENTERED;
        }
示例#23
0
文件: T2P.cs 项目: dronab/libtiff.net
        /*
        This function sets the input directory to the directory of a given
        page and determines information about the image.  It checks
        the image characteristics to determine if it is possible to convert
        the image data into a page of PDF output, setting values of the T2P
        struct for this page.  It determines what color space is used in
        the output PDF to represent the image.

        It determines if the image can be converted as raw data without
        requiring transcoding of the image data.
        */
        private void read_tiff_data(Tiff input)
        {
            m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_ENCODE;
            m_pdf_sample = t2p_sample_t.T2P_SAMPLE_NOTHING;
            m_pdf_switchdecode = m_pdf_colorspace_invert;

            input.SetDirectory(m_tiff_pages[m_pdf_page].page_directory);

            FieldValue[] result = input.GetField(TiffTag.IMAGEWIDTH);
            m_tiff_width = result[0].ToInt();
            if (m_tiff_width == 0)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, "No support for {0} with zero width", input.FileName());
                m_error = true;
                return;
            }

            result = input.GetField(TiffTag.IMAGELENGTH);
            m_tiff_length = result[0].ToInt();
            if (m_tiff_length == 0)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with zero length", input.FileName());
                m_error = true;
                return;
            }

            result = input.GetField(TiffTag.COMPRESSION);
            if (result == null)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with no compression tag", input.FileName());
                m_error = true;
                return;
            }
            else
                m_tiff_compression = (Compression)result[0].ToInt();

            if (!input.IsCodecConfigured(m_tiff_compression))
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with compression type {1}:  not configured", 
                    input.FileName(), m_tiff_compression);
                m_error = true;
                return;

            }

            result = input.GetFieldDefaulted(TiffTag.BITSPERSAMPLE);
            m_tiff_bitspersample = result[0].ToShort();

            switch (m_tiff_bitspersample)
            {
                case 1:
                case 2:
                case 4:
                case 8:
                    break;
                case 0:
                    Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                        "Image {0} has 0 bits per sample, assuming 1", input.FileName());
                    m_tiff_bitspersample = 1;
                    break;
                default:
                    Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                        "No support for {0} with {1} bits per sample",
                        input.FileName(), m_tiff_bitspersample);
                    m_error = true;
                    return;
            }

            result = input.GetFieldDefaulted(TiffTag.SAMPLESPERPIXEL);
            m_tiff_samplesperpixel = result[0].ToShort();
            if (m_tiff_samplesperpixel > 4)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with {1} samples per pixel", input.FileName(), m_tiff_samplesperpixel);
                m_error = true;
                return;
            }

            if (m_tiff_samplesperpixel == 0)
            {
                Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "Image {0} has 0 samples per pixel, assuming 1", input.FileName());
                m_tiff_samplesperpixel = 1;
            }

            result = input.GetField(TiffTag.SAMPLEFORMAT);
            if (result != null)
            {
                SampleFormat f = (SampleFormat)result[0].ToByte();
                switch (f)
                {
                    case 0:
                    case SampleFormat.UINT:
                    case SampleFormat.VOID:
                        break;

                    default:
                        Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                            "No support for {0} with sample format {1}", input.FileName(), f);
                        m_error = true;
                        return;
                }
            }

            result = input.GetFieldDefaulted(TiffTag.FILLORDER);
            m_tiff_fillorder = (FillOrder)result[0].ToByte();

            result = input.GetField(TiffTag.PHOTOMETRIC);
            if (result == null)
            {
                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                    "No support for {0} with no photometric interpretation tag", input.FileName());
                m_error = true;
                return;
            }
            else
                m_tiff_photometric = (Photometric)result[0].ToInt();

            short[] r;
            short[] g;
            short[] b;
            short[] a;
            bool photometric_palette;
            bool photometric_palette_cmyk;

            switch (m_tiff_photometric)
            {
                case Photometric.MINISWHITE:
                case Photometric.MINISBLACK:
                    if (m_tiff_bitspersample == 1)
                    {
                        m_pdf_colorspace = t2p_cs_t.T2P_CS_BILEVEL;
                        if (m_tiff_photometric == Photometric.MINISWHITE)
                            m_pdf_switchdecode ^= true;
                    }
                    else
                    {
                        m_pdf_colorspace = t2p_cs_t.T2P_CS_GRAY;
                        if (m_tiff_photometric == Photometric.MINISWHITE)
                            m_pdf_switchdecode ^= true;
                    }
                    break;
               
                case Photometric.RGB:
                case Photometric.PALETTE:
                    photometric_palette = (m_tiff_photometric == Photometric.PALETTE);
                    if (!photometric_palette)
                    {
                        m_pdf_colorspace = t2p_cs_t.T2P_CS_RGB;
                        if (m_tiff_samplesperpixel == 3)
                            break;

                        result = input.GetField(TiffTag.INDEXED);
                        if (result != null)
                        {
                            if (result[0].ToInt() == 1)
                                photometric_palette = true;
                        }
                    }

                    if (!photometric_palette)
                    {
                        if (m_tiff_samplesperpixel > 3)
                        {
                            if (m_tiff_samplesperpixel == 4)
                            {
                                m_pdf_colorspace = t2p_cs_t.T2P_CS_RGB;

                                result = input.GetField(TiffTag.EXTRASAMPLES);
                                if (result != null && result[0].ToInt() == 1)
                                {
                                    byte[] xuint16p = result[1].ToByteArray();
                                    if ((ExtraSample)xuint16p[0] == ExtraSample.ASSOCALPHA)
                                    {
                                        m_pdf_sample = t2p_sample_t.T2P_SAMPLE_RGBAA_TO_RGB;
                                        break;
                                    }

                                    if ((ExtraSample)xuint16p[0] == ExtraSample.UNASSALPHA)
                                    {
                                        m_pdf_sample = t2p_sample_t.T2P_SAMPLE_RGBA_TO_RGB;
                                        break;
                                    }
                                    
                                    Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                        "RGB image {0} has 4 samples per pixel, assuming RGBA", input.FileName());
                                    break;
                                }

                                m_pdf_colorspace = t2p_cs_t.T2P_CS_CMYK;
                                m_pdf_switchdecode ^= true;
                                Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                                    "RGB image {0} has 4 samples per pixel, assuming inverse CMYK", input.FileName());
                                break;
                            }
                            else
                            {
                                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                    "No support for RGB image {0} with {1} samples per pixel", 
                                    input.FileName(), m_tiff_samplesperpixel);
                                m_error = true;
                                break;
                            }
                        }
                        else
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                "No support for RGB image {0} with {1} samples per pixel",
                                input.FileName(), m_tiff_samplesperpixel);
                            m_error = true;
                            break;
                        }
                    }

                    if (photometric_palette)
                    {
                        if (m_tiff_samplesperpixel != 1)
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                "No support for palletized image {0} with not one sample per pixel",
                                input.FileName());
                            m_error = true;
                            return;
                        }

                        m_pdf_colorspace = (t2p_cs_t)(t2p_cs_t.T2P_CS_RGB | t2p_cs_t.T2P_CS_PALETTE);
                        m_pdf_palettesize = 0x0001 << m_tiff_bitspersample;

                        result = input.GetField(TiffTag.COLORMAP);
                        if (result == null)
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE, 
                                "Palletized image {0} has no color map", input.FileName());
                            m_error = true;
                            return;
                        }
                        else
                        {
                            r = result[0].ToShortArray();
                            g = result[1].ToShortArray();
                            b = result[2].ToShortArray();
                        }

                        m_pdf_palette = new byte [m_pdf_palettesize * 3];
                        for (int i = 0; i < m_pdf_palettesize; i++)
                        {
                            m_pdf_palette[i * 3] = (byte)(r[i] >> 8);
                            m_pdf_palette[i * 3 + 1] = (byte)(g[i] >> 8);
                            m_pdf_palette[i * 3 + 2] = (byte)(b[i] >> 8);
                        }

                        m_pdf_palettesize *= 3;
                    }
                    break;

                case Photometric.SEPARATED:
                    photometric_palette_cmyk = false;
                    result = input.GetField(TiffTag.INDEXED);
                    if (result != null)
                    {
                        if (result[0].ToInt() == 1)
                            photometric_palette_cmyk = true;
                    }

                    if (!photometric_palette_cmyk)
                    {
                        result = input.GetField(TiffTag.INKSET);
                        if (result != null)
                        {
                            if ((InkSet)result[0].ToByte() != InkSet.CMYK)
                            {
                                Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                    "No support for {0} because its inkset is not CMYK", input.FileName());
                                m_error = true;
                                return;
                            }
                        }
                        
                        if (m_tiff_samplesperpixel == 4)
                        {
                            m_pdf_colorspace = t2p_cs_t.T2P_CS_CMYK;
                        }
                        else
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                "No support for {0} because it has {1} samples per pixel",
                                input.FileName(), m_tiff_samplesperpixel);
                            m_error = true;
                            return;
                        }
                    }
                    else
                    {
                        if (m_tiff_samplesperpixel != 1)
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                "No support for palletized CMYK image {0} with not one sample per pixel",
                                input.FileName());
                            m_error = true;
                            return;
                        }
                        
                        m_pdf_colorspace = (t2p_cs_t)(t2p_cs_t.T2P_CS_CMYK | t2p_cs_t.T2P_CS_PALETTE);
                        m_pdf_palettesize = 0x0001 << m_tiff_bitspersample;
                        
                        result = input.GetField(TiffTag.COLORMAP);
                        if (result == null)
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                "Palletized image {0} has no color map", input.FileName());
                            m_error = true;
                            return;
                        }
                        else
                        {
                            r = result[0].ToShortArray();
                            g = result[1].ToShortArray();
                            b = result[2].ToShortArray();
                            a = result[3].ToShortArray();
                        }
                        
                        m_pdf_palette = new byte [m_pdf_palettesize * 4];
                        for (int i = 0; i < m_pdf_palettesize; i++)
                        {
                            m_pdf_palette[i * 4] = (byte)(r[i] >> 8);
                            m_pdf_palette[i * 4 + 1] = (byte)(g[i] >> 8);
                            m_pdf_palette[i * 4 + 2] = (byte)(b[i] >> 8);
                            m_pdf_palette[i * 4 + 3] = (byte)(a[i] >> 8);
                        }

                        m_pdf_palettesize *= 4;
                    }
                    break;
                
                case Photometric.YCBCR:
                    m_pdf_colorspace = t2p_cs_t.T2P_CS_RGB;
                    if (m_tiff_samplesperpixel == 1)
                    {
                        m_pdf_colorspace = t2p_cs_t.T2P_CS_GRAY;
                        m_tiff_photometric = Photometric.MINISBLACK;
                        break;
                    }

                    m_pdf_sample = t2p_sample_t.T2P_SAMPLE_YCBCR_TO_RGB;
                    if (m_pdf_defaultcompression == t2p_compress_t.T2P_COMPRESS_JPEG)
                        m_pdf_sample = t2p_sample_t.T2P_SAMPLE_NOTHING;

                    break;

                case Photometric.CIELAB:
                    m_pdf_labrange[0] = -127;
                    m_pdf_labrange[1] = 127;
                    m_pdf_labrange[2] = -127;
                    m_pdf_labrange[3] = 127;
                    m_pdf_sample = t2p_sample_t.T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED;
                    m_pdf_colorspace = t2p_cs_t.T2P_CS_LAB;
                    break;

                case Photometric.ICCLAB:
                    m_pdf_labrange[0] = 0;
                    m_pdf_labrange[1] = 255;
                    m_pdf_labrange[2] = 0;
                    m_pdf_labrange[3] = 255;
                    m_pdf_colorspace = t2p_cs_t.T2P_CS_LAB;
                    break;

                case Photometric.ITULAB:
                    m_pdf_labrange[0] = -85;
                    m_pdf_labrange[1] = 85;
                    m_pdf_labrange[2] = -75;
                    m_pdf_labrange[3] = 124;
                    m_pdf_sample = t2p_sample_t.T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED;
                    m_pdf_colorspace = t2p_cs_t.T2P_CS_LAB;
                    break;

                case Photometric.LOGL:
                case Photometric.LOGLUV:
                    Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                        "No support for {0} with photometric interpretation LogL/LogLuv", input.FileName());
                    m_error = true;
                    return;
                default:
                    Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                        "No support for {0} with photometric interpretation {1}",
                        input.FileName(), m_tiff_photometric);
                    m_error = true;
                    return;
            }

            result = input.GetField(TiffTag.PLANARCONFIG);
            if (result != null)
            {
                m_tiff_planar = (PlanarConfig)result[0].ToShort();
                switch (m_tiff_planar)
                {
                    case 0:
                        Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
                            "Image {0} has planar configuration 0, assuming 1", input.FileName());
                        m_tiff_planar = PlanarConfig.CONTIG;
                        break;

                    case PlanarConfig.CONTIG:
                        break;
                    
                    case PlanarConfig.SEPARATE:
                        m_pdf_sample = t2p_sample_t.T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG;
                        if (m_tiff_bitspersample != 8)
                        {
                            Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                                "No support for {0} with separated planar configuration and {1} bits per sample",
                                input.FileName(), m_tiff_bitspersample);
                            m_error = true;
                            return;
                        }
                        break;
                    
                    default:
                        Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                            "No support for {0} with planar configuration {1}",
                            input.FileName(), m_tiff_planar);
                        m_error = true;
                        return;
                }
            }

            result = input.GetFieldDefaulted(TiffTag.ORIENTATION);
            m_tiff_orientation = (Orientation)result[0].ToByte();

            if (m_tiff_orientation > Orientation.LEFTBOT)
            {
                Tiff.Warning(Tiff2PdfConstants.TIFF2PDF_MODULE,
                    "Image {0} has orientation {1}, assuming 0", 
                    input.FileName(), m_tiff_orientation);
                m_tiff_orientation = 0;
            }

            result = input.GetField(TiffTag.XRESOLUTION);
            if (result == null)
                m_tiff_xres = 0.0f;
            else
                m_tiff_xres = result[0].ToFloat();

            result = input.GetField(TiffTag.YRESOLUTION);
            if (result == null)
                m_tiff_yres = 0.0f;
            else
                m_tiff_yres = result[0].ToFloat();

            result = input.GetFieldDefaulted(TiffTag.RESOLUTIONUNIT);
            m_tiff_resunit = (ResUnit)result[0].ToByte();
            if (m_tiff_resunit == ResUnit.CENTIMETER)
            {
                m_tiff_xres *= 2.54F;
                m_tiff_yres *= 2.54F;
            }
            else if (m_tiff_resunit != ResUnit.INCH && m_pdf_centimeters)
            {
                m_tiff_xres *= 2.54F;
                m_tiff_yres *= 2.54F;
            }

            compose_pdf_page();

            m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_ENCODE;
            if (!m_pdf_nopassthrough)
            {
                if (m_tiff_compression == Compression.CCITTFAX4)
                {
                    if (input.IsTiled() || (input.NumberOfStrips() == 1))
                    {
                        m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_RAW;
                        m_pdf_compression = t2p_compress_t.T2P_COMPRESS_G4;
                    }
                }

                if (m_tiff_compression == Compression.ADOBE_DEFLATE || m_tiff_compression == Compression.DEFLATE)
                {
                    if (input.IsTiled() || (input.NumberOfStrips() == 1))
                    {
                        m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_RAW;
                        m_pdf_compression = t2p_compress_t.T2P_COMPRESS_ZIP;
                    }
                }

                if (m_tiff_compression == Compression.JPEG)
                {
                    m_pdf_transcode = t2p_transcode_t.T2P_TRANSCODE_RAW;
                    m_pdf_compression = t2p_compress_t.T2P_COMPRESS_JPEG;
                }
            }

            if (m_pdf_transcode != t2p_transcode_t.T2P_TRANSCODE_RAW)
                m_pdf_compression = m_pdf_defaultcompression;

            if (m_pdf_defaultcompression == t2p_compress_t.T2P_COMPRESS_JPEG)
            {
                if ((m_pdf_colorspace & t2p_cs_t.T2P_CS_PALETTE) != 0)
                {
                    m_pdf_sample = (t2p_sample_t)(m_pdf_sample | t2p_sample_t.T2P_SAMPLE_REALIZE_PALETTE);
                    m_pdf_colorspace = (t2p_cs_t)(m_pdf_colorspace ^ t2p_cs_t.T2P_CS_PALETTE);
                    m_tiff_pages[m_pdf_page].page_extra--;
                }
            }

            if (m_tiff_compression == Compression.JPEG)
            {
                if (m_tiff_planar == PlanarConfig.SEPARATE)
                {
                    Tiff.Error(Tiff2PdfConstants.TIFF2PDF_MODULE,
                        "No support for {0} with JPEG compression and separated planar configuration",
                        input.FileName());
                    m_error = true;
                    return;
                }
            }

            if ((m_pdf_sample & t2p_sample_t.T2P_SAMPLE_REALIZE_PALETTE) != 0)
            {
                if ((m_pdf_colorspace & t2p_cs_t.T2P_CS_CMYK) != 0)
                {
                    m_tiff_samplesperpixel = 4;
                    m_tiff_photometric = Photometric.SEPARATED;
                }
                else
                {
                    m_tiff_samplesperpixel = 3;
                    m_tiff_photometric = Photometric.RGB;
                }
            }

            result = input.GetField(TiffTag.TRANSFERFUNCTION);
            if (result != null)
            {
                m_tiff_transferfunction[0] = result[0].GetBytes();
                m_tiff_transferfunction[1] = result[1].GetBytes();
                m_tiff_transferfunction[2] = result[2].GetBytes();

                if (m_tiff_transferfunction[1] != m_tiff_transferfunction[0])
                    m_tiff_transferfunctioncount = 3;
                else
                    m_tiff_transferfunctioncount = 1;
            }
            else
            {
                m_tiff_transferfunctioncount = 0;
            }

            result = input.GetField(TiffTag.WHITEPOINT);
            if (result != null)
            {
                float[] xfloatp = result[0].ToFloatArray();
                m_tiff_whitechromaticities[0] = xfloatp[0];
                m_tiff_whitechromaticities[1] = xfloatp[1];
                
                if ((m_pdf_colorspace & t2p_cs_t.T2P_CS_GRAY) != 0)
                    m_pdf_colorspace = (t2p_cs_t)(m_pdf_colorspace | t2p_cs_t.T2P_CS_CALGRAY);

                if ((m_pdf_colorspace & t2p_cs_t.T2P_CS_RGB) != 0)
                    m_pdf_colorspace = (t2p_cs_t)(m_pdf_colorspace | t2p_cs_t.T2P_CS_CALRGB);
            }
            
            result = input.GetField(TiffTag.PRIMARYCHROMATICITIES);
            if (result != null)
            {
                float[] xfloatp = result[0].ToFloatArray();
                m_tiff_primarychromaticities[0] = xfloatp[0];
                m_tiff_primarychromaticities[1] = xfloatp[1];
                m_tiff_primarychromaticities[2] = xfloatp[2];
                m_tiff_primarychromaticities[3] = xfloatp[3];
                m_tiff_primarychromaticities[4] = xfloatp[4];
                m_tiff_primarychromaticities[5] = xfloatp[5];

                if ((m_pdf_colorspace & t2p_cs_t.T2P_CS_RGB) != 0)
                    m_pdf_colorspace = (t2p_cs_t)(m_pdf_colorspace | t2p_cs_t.T2P_CS_CALRGB);
            }

            if ((m_pdf_colorspace & t2p_cs_t.T2P_CS_LAB) != 0)
            {
                result = input.GetField(TiffTag.WHITEPOINT);
                if (result != null)
                {
                    float[] xfloatp = result[0].ToFloatArray();
                    m_tiff_whitechromaticities[0] = xfloatp[0];
                    m_tiff_whitechromaticities[1] = xfloatp[1];
                }
                else
                {
                    m_tiff_whitechromaticities[0] = 0.3457F; /* 0.3127F; */
                    m_tiff_whitechromaticities[1] = 0.3585F; /* 0.3290F; */
                }
            }

            result = input.GetField(TiffTag.ICCPROFILE);
            if (result != null)
            {
                m_tiff_iccprofilelength = result[0].ToInt();
                m_tiff_iccprofile = result[1].ToByteArray();
                m_pdf_colorspace = (t2p_cs_t)(m_pdf_colorspace | t2p_cs_t.T2P_CS_ICCBASED);
            }
            else
            {
                m_tiff_iccprofilelength = 0;
                m_tiff_iccprofile = null;
            }

            if (m_tiff_bitspersample == 1 && m_tiff_samplesperpixel == 1)
                m_pdf_compression = t2p_compress_t.T2P_COMPRESS_G4;
        }
示例#24
0
 private void ChangeGroup(ResUnit changingUnit, UnitGroup newGroup)
 {
     changingUnit.group.RemoveUnit(changingUnit);
     newGroup.AddUnit(changingUnit);
 }
示例#25
0
    protected void ImportResource(DataTable dtExcelInfo, System.Collections.Generic.Dictionary <string, int> dicRes)
    {
        System.Collections.Generic.List <string> priceTypeCodes = ResPriceType.GetPriceTypeCodes();
        string text = PageHelper.QueryUser(this, base.UserCode);
        int    num  = 0;

        for (int i = 0; i < dtExcelInfo.Rows.Count; i++)
        {
            DataRow dataRow = dtExcelInfo.Rows[i];
            string  text2   = dataRow[dicRes["ResourceCode"]].ToString();
            bool    flag    = this.IsExistResourceCode(text2);
            if (flag)
            {
                Label  expr_57 = this.lblErrorMsg;
                string text3   = expr_57.Text;
                expr_57.Text = string.Concat(new string[]
                {
                    text3,
                    "<div align='left' style=' margin-top:3px; padding-left:15px;  border-bottom-style:solid; border-bottom-color:#cccccc; border-bottom-width:1px;  background-color:white; line-height:28px; height:28px; text-align:left;'>在您的Excel中:",
                    dtExcelInfo.Columns[dicRes["ResourceCode"]].ColumnName,
                    "<span style='color:green;'>",
                    text2,
                    "</span>,此编码已经存在导入失败!</div>"
                });
            }
            else
            {
                string text4 = dtExcelInfo.Rows[i][dicRes["ResourceName"]].ToString();
                if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text4))
                {
                    string  brand   = dicRes.Keys.Any((string a) => a == "Brand") ? dataRow[dicRes["Brand"]].ToString() : string.Empty;
                    string  text5   = dicRes.Keys.Any((string a) => a == "TaxRate") ? dataRow[dicRes["TaxRate"]].ToString() : string.Empty;
                    decimal?taxRate = null;
                    decimal value;
                    if (!string.IsNullOrEmpty(text5) && decimal.TryParse(text5, out value))
                    {
                        taxRate = new decimal?(value);
                    }
                    string specification  = dicRes.Keys.Any((string a) => a == "Specification") ? dataRow[dicRes["Specification"]].ToString() : string.Empty;
                    string technicalParam = dicRes.Keys.Any((string a) => a == "TechnicalParameter") ? dataRow[dicRes["TechnicalParameter"]].ToString() : string.Empty;
                    string text6          = dicRes.Keys.Any((string a) => a == "Unit") ? dataRow[dicRes["Unit"]].ToString() : string.Empty;
                    if (string.IsNullOrEmpty(text6))
                    {
                        text6 = "xx";
                    }
                    string attributeName    = dicRes.Keys.Any((string a) => a == "Attribute") ? dataRow[dicRes["Attribute"]].ToString() : string.Empty;
                    string series           = dicRes.Keys.Any((string a) => a == "Series") ? dataRow[dicRes["Series"]].ToString() : string.Empty;
                    string supplierName     = dicRes.Keys.Any((string a) => a == "SupplierId") ? dataRow[dicRes["SupplierId"]].ToString() : string.Empty;
                    int?   supplierIdByName = cn.justwin.Domain.Resource.GetSupplierIdByName(supplierName);
                    string modelNumber      = dicRes.Keys.Any((string a) => a == "ModelNumber") ? dataRow[dicRes["ModelNumber"]].ToString() : string.Empty;
                    if (!dicRes.Keys.Any((string a) => a == "Note"))
                    {
                        string arg_400_0 = string.Empty;
                    }
                    else
                    {
                        dataRow[dicRes["Note"]].ToString();
                    }
                    System.Collections.Generic.Dictionary <ResPriceType, decimal?> dictionary = new System.Collections.Generic.Dictionary <ResPriceType, decimal?>();
                    foreach (string key in dicRes.Keys)
                    {
                        bool flag2 = priceTypeCodes.Any((string a) => a == key);
                        if (flag2)
                        {
                            string  s = dataRow[dicRes[key]].ToString();
                            decimal value2;
                            decimal.TryParse(s, out value2);
                            dictionary.Add(ResPriceType.GetByTypeCode(key), new decimal?(value2));
                        }
                    }
                    ResType                    byId            = ResType.GetById(base.Request["parentId"]);
                    ResUnit                    unit            = this.GetUnit(text6, text);
                    ResTypeAttribute           byAttributeName = ResTypeAttribute.GetByAttributeName(attributeName);
                    cn.justwin.Domain.Resource resource        = cn.justwin.Domain.Resource.Create(System.Guid.NewGuid().ToString(), byId, text2, text4, brand, taxRate, specification, modelNumber, technicalParam, unit, byAttributeName, series, dictionary, text, new System.DateTime?(System.DateTime.Now), supplierIdByName);
                    cn.justwin.Domain.Resource.Add(resource);
                    num++;
                }
            }
        }
        if (num == 0)
        {
            base.RegisterScript("alert('系统提示:\\n数据导入失败!');setTem('2');");
            return;
        }
        if (num == dtExcelInfo.Rows.Count)
        {
            base.RegisterScript("alert('系统提示:\\n数据导入成功!');setTem('2');closePage();");
            return;
        }
        base.RegisterScript("alert('系统提示:\\n数据导入成功!');setTem('2');");
    }
示例#26
0
 private static DoubleByteTiffInfo CreateDoubleByteTiffInfo(byte[] buffer, List <ushort[]> ushortBuffer, int width,
                                                            int height, string filePath,
                                                            int rowsPerStrip,
                                                            int xResolution, int yResolution, ResUnit resUnit = ResUnit.INCH,
                                                            PlanarConfig planarConfig = PlanarConfig.CONTIG,
                                                            int bytePerSample         = 16, Photometric photometric = Photometric.MINISBLACK,
                                                            Compression compression   = Compression.NONE,
                                                            int samplePerPixel        = 1, Orientation orientation = Orientation.TOPLEFT,
                                                            FillOrder fillOrder       = FillOrder.MSB2LSB)
 {
     return(new DoubleByteTiffInfo()
     {
         FilePath = filePath,
         Buffer = buffer,
         UshortBuffer = ushortBuffer,
         Width = width,
         Height = height,
         RowsPerStrip = rowsPerStrip,
         XResolution = xResolution,
         YResolution = yResolution,
         ResolutionUnit = resUnit,
         PlanarConfig = planarConfig,
         BitsPerSample = bytePerSample,
         Photometric = photometric,
         Compression = compression,
         SamplesPerPixel = samplePerPixel,
         Orientation = orientation,
         FillOrder = fillOrder
     });
 }
示例#27
0
文件: UnitGrid.cs 项目: rxpii/sv
 public void RemoveUnit(ResUnit unit)
 {
     RemoveAt(unit.posHex);
 }
示例#28
0
文件: UnitGrid.cs 项目: rxpii/sv
    public void PlaceUnit(ResUnit unit)
    {
        VectorHex offsetPos = OffsetForGrid(unit.posHex);

        grid[offsetPos.q, offsetPos.r] = unit;
    }
示例#29
0
文件: UIManager.cs 项目: rxpii/sv
    public void UpdateModeUI(bool bypassPreviousCheck = false)
    {
        if (currentMode == previousMode && !bypassPreviousCheck)
        {
            return;
        }

        previousMode = currentMode;

        DisableLabels();

        switch (currentMode)
        {
        case (int)Mode.AllAtt:
            Debug.Log("COUNT: " + UnitManager.Instance.allUnits.Count);
            for (int i = 0; i < UnitManager.Instance.allUnits.Count; i++)
            {
                ResUnit unit = UnitManager.Instance.allUnits[i];
                Debug.Log("UNIT LABEL: " + i + " " + unit);
                labelPool[i].transform.position = new Vector3(unit.transform.position.x, 1.5f, unit.transform.position.z);
                labelPool[i].GetComponentInChildren <Image>().color = new Color(0f, 0f, 0f, 0.5f);
                labelPool[i].GetComponentInChildren <Text>().text   = unit.attHarvest + " | " + unit.attDefense + " | " + unit.attOffense;
                labelPool[i].SetActive(true);
            }
            break;

        case (int)Mode.InfoHarv:
            for (int i = 0; i < UnitManager.Instance.allGroups.Count; i++)
            {
                UnitGroup group  = UnitManager.Instance.allGroups[i];
                Vector3   center = Vector3.zero;
                foreach (ResUnit unit in group.units)
                {
                    center += unit.gameObject.transform.position;
                }
                center /= group.units.Count;

                center.y = 1.5f;
                labelPool[i].transform.position = center;
                labelPool[i].GetComponentInChildren <Image>().color = Color.green;
                labelPool[i].GetComponentInChildren <Text>().text   = group.groupHarvest.ToString();
                labelPool[i].SetActive(true);
            }
            break;

        case (int)Mode.InfoDef:
            for (int i = 0; i < UnitManager.Instance.allGroups.Count; i++)
            {
                UnitGroup group  = UnitManager.Instance.allGroups[i];
                Vector3   center = Vector3.zero;
                foreach (ResUnit unit in group.units)
                {
                    center += unit.gameObject.transform.position;
                }
                center /= group.units.Count;

                center.y = 1.5f;
                labelPool[i].transform.position = center;
                labelPool[i].GetComponentInChildren <Image>().color = Color.blue;
                labelPool[i].GetComponentInChildren <Text>().text   = group.groupDefense.ToString();
                labelPool[i].SetActive(true);
            }
            break;

        case (int)Mode.InfoOff:
            for (int i = 0; i < UnitManager.Instance.allGroups.Count; i++)
            {
                UnitGroup group  = UnitManager.Instance.allGroups[i];
                Vector3   center = Vector3.zero;
                foreach (ResUnit unit in group.units)
                {
                    center += unit.gameObject.transform.position;
                }
                center /= group.units.Count;

                center.y = 1.5f;
                labelPool[i].transform.position = center;
                labelPool[i].GetComponentInChildren <Image>().color = Color.red;
                labelPool[i].GetComponentInChildren <Text>().text   = group.groupOffense.ToString();
                labelPool[i].SetActive(true);
            }
            break;

        default:
            break;
        }
    }
示例#30
0
文件: UnitGroup.cs 项目: rxpii/sv
 // add new unit to the group
 public void AddUnit(ResUnit newUnit)
 {
     units.Add(newUnit);
     AddUnitAtt(newUnit);
     newUnit.SubscribeToGroup(this);
 }