private void SetValue(string propertyName, string value) { BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase; Type objectType = SummaryItem.GetType(); var propType = objectType.GetProperty(propertyName, bindingFlags); if (propType != null) { SummaryItem.SetPropertyValue(propertyName, value); } else { foreach (var prop in objectType.GetProperties().Where(pr => pr.PropertyType.IsClass && pr.PropertyType != typeof(string))) { propType = prop.PropertyType.GetProperty(propertyName, bindingFlags); if (propType != null) { Type propertyType = propType.PropertyType; Type propInfoType = propertyType; if (FilterUtil.IsNullableType(propertyType)) { propInfoType = propertyType.GetGenericArguments()[0]; } object target = prop.GetValue(SummaryItem); if (target == null) { target = Activator.CreateInstance(prop.PropertyType); prop.SetValue(SummaryItem, target); } propType.SetValue(target, System.Convert.ChangeType(value, propInfoType)); } } } }
private static async Task Test() { var account = GetStorageAccount(); var tableClient = account.CreateCloudTableClient(); var table = tableClient.GetTableReference(AzureConstants.TableNames.BuildResultDate); var query = new TableQuery <DynamicTableEntity>() .Where(FilterUtil.SinceDate(ColumnNames.PartitionKey, DateTimeOffset.UtcNow - TimeSpan.FromDays(2))) .Select(new[] { "JobName" }); var nameSet = new HashSet <string>(); var kindSet = new HashSet <string>(); foreach (var entity in table.ExecuteQuery(query)) { var name = entity["JobName"].StringValue; if (nameSet.Add(name)) { var id = JobId.ParseName(name); try { var client = CreateClient(id); var kind = await client.GetJobKindAsync(id); if (kindSet.Add(kind)) { Console.WriteLine(kind); } } catch { // Ignore } } } }
private void BtnUpdatePrice_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.textPriceA.Text) || string.IsNullOrWhiteSpace(this.textPriceB.Text) || string.IsNullOrWhiteSpace(this.textPriceC.Text)) { XtraMessageBox.Show("价格信息不完整!"); return; } if (!FilterUtil.isNumberic(this.textPriceA.Text) || !FilterUtil.isNumberic(this.textPriceB.Text) || !FilterUtil.isNumberic(this.textPriceC.Text)) { XtraMessageBox.Show("价格信息不正确!"); return; } SkillPriceVo vo = (SkillPriceVo)this.gridView3.GetRow(this.gridView3.FocusedRowHandle); vo.SkillName = this.textServerNP.Text; vo.PriceType = this.comboType.Text; vo.PriceA = Convert.ToDouble(this.textPriceA.Text); vo.PriceB = Convert.ToDouble(this.textPriceB.Text); vo.PriceC = Convert.ToDouble(this.textPriceC.Text); vo.Remark = this.textreamark.Text; if (UpdateDao.UpdateByID(vo) > 0) { XtraMessageBox.Show("更新价格成功!"); RefreshSkillPrice(this.textServerNP.Text); } }
private static async Task ViewNameMigration() { var account = GetStorageAccount(); var client = account.CreateCloudTableClient(); var viewNameTable = client.GetTableReference(AzureConstants.TableNames.ViewNameDate); var buildResultTable = client.GetTableReference(AzureConstants.TableNames.BuildResultDate); var startDate = DateTimeOffset.UtcNow - TimeSpan.FromDays(14); var query = new TableQuery <DynamicTableEntity>() .Where(FilterUtil.SinceDate(ColumnNames.PartitionKey, startDate)) .Select(new[] { "PartitionKey", nameof(BuildResultEntity.ViewName) }); var all = await AzureUtil.QueryAsync(buildResultTable, query); var set = new HashSet <Tuple <DateKey, string> >(); var list = new List <ViewNameEntity>(); foreach (var entity in all) { var dateKey = DateKey.Parse(entity.PartitionKey); var viewName = entity.Properties[nameof(BuildResultEntity.ViewName)].StringValue; var tuple = Tuple.Create(dateKey, viewName); if (set.Add(tuple)) { list.Add(new ViewNameEntity(dateKey, viewName)); } } await AzureUtil.InsertBatchUnordered(viewNameTable, list); }
private void BtnAddPrice_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.textPriceA.Text) || string.IsNullOrWhiteSpace(this.textPriceB.Text) || string.IsNullOrWhiteSpace(this.textPriceC.Text)) { XtraMessageBox.Show("价格信息不完整!"); return; } if (!FilterUtil.isNumberic(this.textPriceA.Text) || !FilterUtil.isNumberic(this.textPriceB.Text) || !FilterUtil.isNumberic(this.textPriceC.Text)) { XtraMessageBox.Show("价格信息不正确!"); return; } SkillPriceVo vo = new SkillPriceVo() { SkillName = this.textServerNP.Text, PriceType = this.comboType.Text, PriceA = Convert.ToDouble(this.textPriceA.Text), PriceB = Convert.ToDouble(this.textPriceB.Text), PriceC = Convert.ToDouble(this.textPriceC.Text), Remark = this.textreamark.Text, CompanyId = SystemConst.companyId }; if (SelectDao.IsExistSkillPrice(vo.SkillName, vo.PriceType)) { XtraMessageBox.Show("此价格已经存在!"); return; } if (InsertDao.InsertData(vo, typeof(SkillPriceVo)) > 0) { XtraMessageBox.Show("添加价格成功!"); RefreshSkillPrice(this.textServerNP.Text); } }
private static async Task Random() { /* * var boundBuildId = BoundBuildId.Parse("https://dotnet-ci.cloudapp.net/job/dotnet_corefx/job/master/job/fedora23_debug_tst/134/"); * var buildId = boundBuildId.BuildId; * var client = CreateClient(uri: boundBuildId.HostUri, auth: true); * var buildInfo = await client.GetBuildInfoAsync(buildId); * var buildResult = await client.GetBuildResultAsync(buildInfo); * var test = await client.GetFailedTestCasesAsync(buildId); * var prInfo = await client.GetPullRequestInfoAsync(buildId); */ var testboundBuildId = BoundBuildId.Parse("https://dotnet-ci.cloudapp.net/job/dotnet_coreclr/job/release_1.0.0/job/x64_release_rhel7.2_pri1_flow/30/"); var testbuildId = testboundBuildId.BuildId; var client = CreateClient(uri: testboundBuildId.HostUri, auth: true); var elapsedTimeObj = client.GetBuildInfo(testbuildId).Duration; Console.WriteLine($"\tET: {elapsedTimeObj.TotalMilliseconds}"); var account = GetStorageAccount(); var dateKey = new DateKey(DateTimeOffset.UtcNow - TimeSpan.FromDays(1)); var table = account.CreateCloudTableClient().GetTableReference(AzureConstants.TableNames.BuildResultDate); var query = new TableQuery <BuildResultEntity>() .Where(FilterUtil .Column(ColumnNames.PartitionKey, dateKey, ColumnOperator.GreaterThanOrEqual) .And(FilterUtil.Column("MachineName", "Azure0602081822"))); var all = await AzureUtil.QueryAsync(table, query); foreach (var entity in all) { var boundBuildId = new BoundBuildId(SharedConstants.DotnetJenkinsUri.Host, entity.BuildId); Console.WriteLine(boundBuildId.Uri); } }
private void BtnAddT_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.textPriceA.Text) || string.IsNullOrWhiteSpace(this.textPriceB.Text) || string.IsNullOrWhiteSpace(this.textPriceC.Text)) { XtraMessageBox.Show("价格信息不完整!"); return; } if (!FilterUtil.isNumberic(this.textPriceA.Text) || !FilterUtil.isNumberic(this.textPriceB.Text) || !FilterUtil.isNumberic(this.textPriceC.Text)) { XtraMessageBox.Show("价格信息不正确!"); return; } SkillCommisionVo vo = new SkillCommisionVo() { SkillName = this.textSkillName.Text, StaffLevel = this.comboLevel.Text, PriceA = Convert.ToDouble(this.textPriceAT.Text), PriceB = Convert.ToDouble(this.textPriceBT.Text), PriceC = Convert.ToDouble(this.textPriceCT.Text), Remark = this.textreamark.Text, CompanyId = SystemConst.companyId }; if (InsertDao.InsertData(vo, typeof(SkillCommisionVo)) > 0) { XtraMessageBox.Show("添加技师提成成功!"); RefreshSkillCommision(this.textSkillName.Text); } }
public async Task TaoFailure() { var buildId = new BuildId(4, JobId.ParseName("test")); _restClient.AddJson( buildId: buildId, buildResultJson: TestResources.Tao1BuildResult, buildInfoJson: TestResources.Tao1BuildInfo, failureInfoJson: TestResources.Tao1FailureInfo, testReportJson: TestResources.Tao1TestResult); var entity = await _populator.PopulateBuild(buildId); var filter = FilterUtil .Column(nameof(BuildFailureEntity.JobName), buildId.JobName) .Filter; var list = AzureUtil.Query <BuildFailureEntity>(_buildFailureExactTable, filter).ToList(); Assert.Equal(2, list.Count); foreach (var item in list) { Assert.Equal(BuildFailureKind.TestCase, item.BuildFailureKind); Assert.Equal(buildId, item.BuildId); } }
public IList <P> RunCluster() { // Skip points outside the grid, not visible to user then skip those IList <P> filtered = ClusterInfo.DoFilterData(this._jsonReceive.Zoomlevel) ? FilterUtil.FilterDataByViewport(this.points, Grid) : this.points; // Put points in buckets foreach (var p in filtered) { var idxy = GetPointMappedIds(p, Grid, DeltaX, DeltaY); var idx = idxy[0]; var idy = idxy[1]; // Bucket id var id = GetId(idx, idy); // Bucket exists, add point if (BucketsLookup.ContainsKey(id)) { BucketsLookup[id].Points.Add(p); } // New bucket, create and add point else { var bucket = new Bucket(idx, idy, id); bucket.Points.Add(p); BucketsLookup.Add(id, bucket); } } // Calculate centroid for all buckets SetCentroidForAllBuckets(BucketsLookup.Values); // Merge if gridpoint is to close if (GmcSettings.Get.DoMergeGridIfCentroidsAreCloseToEachOther) { MergeClustersGrid(); } if (GmcSettings.Get.DoUpdateAllCentroidsToNearestContainingPoint) { UpdateAllCentroidsToNearestContainingPoint(); } // Check again // Merge if gridpoint is to close if (GmcSettings.Get.DoMergeGridIfCentroidsAreCloseToEachOther && GmcSettings.Get.DoUpdateAllCentroidsToNearestContainingPoint) { MergeClustersGrid(); // And again set centroid to closest point in bucket UpdateAllCentroidsToNearestContainingPoint(); } return(GetClusterResult(Grid)); }
private bool CheckRoomId() { if (FilterUtil.isNumberic(this.textRoomId.Text)) { int roomId = Convert.ToInt32(this.textRoomId.Text); return(SelectDao.CheckRoomExist(roomId)); } return(false); }
private static async Task FixNulls(CloudStorageAccount storageAccount) { var table = storageAccount.CreateCloudTableClient().GetTableReference(AzureConstants.TableNames.RoachIssueTable); var filter = FilterUtil.PartitionKey(EntityKeyUtil.ToKey(SharedUtil.RepoId)); var list = await AzureUtil.QueryAsync <RoachIssueEntity>(table, filter); var bad = list.Where(x => x.Assignee == null).ToList(); await AzureUtil.DeleteBatchUnordered(table, bad); }
internal async Task <SendGridMessage> Clean(CancellationToken cancellationToken) { var limit = DateTimeOffset.UtcNow - TimeSpan.FromHours(12); var filter = FilterUtil.Column( nameof(UnprocessedBuildEntity.LastUpdate), limit, ColumnOperator.LessThanOrEqual); var query = new TableQuery <UnprocessedBuildEntity>().Where(filter); var list = await AzureUtil.QueryAsync(_unprocessedBuildTable, query, cancellationToken); if (list.Count == 0) { return(null); } var textBuilder = new StringBuilder(); var htmlBuilder = new StringBuilder(); foreach (var entity in list) { var boundBuildId = entity.BoundBuildId; var buildId = boundBuildId.BuildId; // GC Stress jobs can correctly execute for up to 3 days. This is a bit of an outlier but one we // need to handle; if (JobUtil.IsGCStressJob(buildId.JobId)) { var stressLimit = DateTimeOffset.UtcNow - TimeSpan.FromDays(3); if (entity.LastUpdate >= stressLimit) { continue; } } _logger.WriteLine($"Deleting stale data {boundBuildId.Uri}"); textBuilder.Append($"Deleting stale data: {boundBuildId.Uri}"); textBuilder.Append($"Eror: {entity.StatusText}"); htmlBuilder.Append($@"<div>"); htmlBuilder.Append($@"<div>Build <a href=""{boundBuildId.Uri}"">{buildId.JobName} {buildId.Number}</a></div>"); htmlBuilder.Append($@"<div>Error: {WebUtility.HtmlEncode(entity.StatusText)}</div>"); htmlBuilder.Append($@"</div>"); } await AzureUtil.DeleteBatchUnordered(_unprocessedBuildTable, list); return(new SendGridMessage() { Text = textBuilder.ToString(), Html = htmlBuilder.ToString() }); }
private T GetOrCreateEntity(CounterData counterData) { var key = CounterUtil.GetEntityKey(counterData); var filter = FilterUtil.Key(key).Filter; var query = new TableQuery <T>().Where(filter); var entity = _table.ExecuteQuery(query).FirstOrDefault(); if (entity != null) { return(entity); } return(_createFunc(counterData)); }
private void MenuSnipe_Click(object sender, RoutedEventArgs e) { var menuItem = (MenuItem)sender; //Get the ContextMenu to which the menuItem belongs var contextMenu = (ContextMenu)menuItem.Parent; //Find the placementTarget var item = (DataGrid)contextMenu.PlacementTarget; var selectItem = (PokemonDataViewModel)item.SelectedCells[0].Item; var filter = TinyIoCContainer.Current.Resolve <ISession>().LogicSettings.PokemonSnipeFilters.GetFilter <SnipeFilter>(selectItem.PokemonId); var setting = new FilterSetting(selectItem.PokemonId, filter, "SnipePokemonFilter", (id, f) => { var globalSettings = GlobalSettings.Load("", false); FilterUtil.UpdateFilterSetting <SnipeFilter>(globalSettings, globalSettings.SnipePokemonFilter, id, (SnipeFilter)f); }); setting.ShowDialog(); }
/// <summary> /// Processes the filters. /// </summary> /// <param name="internalItem">The internal item.</param> /// <param name="filter">The filter.</param> /// <returns>if true Filter passed successfully; otherwise, false</returns> private bool FilterPassed(InternalItem internalItem, Filter filter) { bool retVal = true; if (filter != null) { if (!FilterUtil.ProcessFilter(internalItem, filter, InDeserializationContext.InclusiveFilter, InDeserializationContext.TagHashCollection)) { retVal = false; if (InDeserializationContext.CollectFilteredItems) { outDeserializationContext.FilteredInternalItemList.Add(internalItem); } } } return(retVal); }
private void BtnQuery_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textEdit1.Text)) { return; } if (!FilterUtil.isNumberic(this.textEdit1.Text)) { XtraMessageBox.Show("请输入正确的金额!", "提示"); return; } double amount = Convert.ToDouble(this.textEdit1.Text); int companyId = SystemConst.companyId; if (ProcedureDao.MemberRechargeByID(this.mId, this.mName, companyId, amount) > 0) { XtraMessageBox.Show("充值成功!", "提示"); EventBus.PublishEvent("UpdateMemberInfoChanged", this, this.mId); this.Close(); } }
public ActionResult Index(string jobNamePattern, DateTime?fromDateTime, DateTime?toDateTime, string slavePattern) { if (fromDateTime == null) { fromDateTime = DateTime.UtcNow; } if (toDateTime == null) { toDateTime = DateTime.UtcNow; } if (jobNamePattern == null) { return(View(new List <Build>())); } var builds = CIFactory.GetCIApi().GetAllBuilds(); var buildsByName = FilterUtil.FilterByName(builds, jobNamePattern); var filteredBuilds = FilterUtil.FilterByDateTimeAndNode(buildsByName, fromDateTime, toDateTime, slavePattern); return(View(filteredBuilds)); }
public ChatAppController(DataAccessLayer.IProductManagement productDb) { _filter = new FilterUtil(productDb); _sendEmail = new SendEmail(); }
private static void DecodeIdat(PngImageHelper.PngParameters png) { int nbitDepth = png.bitDepth; if (nbitDepth == 16) { nbitDepth = 8; } int size = -1; png.bytesPerPixel = (png.bitDepth == 16) ? 2 : 1; switch (png.colorType) { case 0: { size = (nbitDepth * png.width + 7) / 8 * png.height; break; } case 2: { size = png.width * 3 * png.height; png.bytesPerPixel *= 3; break; } case 3: { if (png.interlaceMethod == 1) { size = (nbitDepth * png.width + 7) / 8 * png.height; } png.bytesPerPixel = 1; break; } case 4: { size = png.width * png.height; png.bytesPerPixel *= 2; break; } case 6: { size = png.width * 3 * png.height; png.bytesPerPixel *= 4; break; } } if (size >= 0) { png.imageData = new byte[size]; } if (png.palShades) { png.smask = new byte[png.width * png.height]; } else { if (png.genBWMask) { png.smask = new byte[(png.width + 7) / 8 * png.height]; } } MemoryStream bai = new MemoryStream(png.idat.ToArray()); png.dataStream = FilterUtil.GetInflaterInputStream(bai); if (png.interlaceMethod != 1) { DecodePass(0, 0, 1, 1, png.width, png.height, png); } else { DecodePass(0, 0, 8, 8, (png.width + 7) / 8, (png.height + 7) / 8, png); DecodePass(4, 0, 8, 8, (png.width + 3) / 8, (png.height + 7) / 8, png); DecodePass(0, 4, 4, 8, (png.width + 3) / 4, (png.height + 3) / 8, png); DecodePass(2, 0, 4, 4, (png.width + 1) / 4, (png.height + 3) / 4, png); DecodePass(0, 2, 2, 4, (png.width + 1) / 2, (png.height + 1) / 4, png); DecodePass(1, 0, 2, 2, png.width / 2, (png.height + 1) / 2, png); DecodePass(0, 1, 1, 2, png.width, png.height / 2, png); } }
/// <exception cref="System.IO.IOException"/> private static void ReadPng(Stream pngStream, PngImageHelper.PngParameters png) { for (int i = 0; i < PNGID.Length; i++) { if (PNGID[i] != pngStream.Read()) { throw new System.IO.IOException("file.is.not.a.valid.png"); } } byte[] buffer = new byte[TRANSFERSIZE]; while (true) { int len = GetInt(pngStream); String marker = GetString(pngStream); if (len < 0 || !CheckMarker(marker)) { throw new System.IO.IOException("corrupted.png.file"); } if (IDAT.Equals(marker)) { int size; while (len != 0) { size = pngStream.JRead(buffer, 0, Math.Min(len, TRANSFERSIZE)); if (size < 0) { return; } png.idat.Write(buffer, 0, size); len -= size; } } else { if (tRNS.Equals(marker)) { switch (png.colorType) { case 0: { if (len >= 2) { len -= 2; int gray = GetWord(pngStream); if (png.bitDepth == 16) { png.transRedGray = gray; } else { png.additional.Put("Mask", MessageFormatUtil.Format("[{0} {1}]", gray, gray)); } } break; } case 2: { if (len >= 6) { len -= 6; int red = GetWord(pngStream); int green = GetWord(pngStream); int blue = GetWord(pngStream); if (png.bitDepth == 16) { png.transRedGray = red; png.transGreen = green; png.transBlue = blue; } else { png.additional.Put("Mask", MessageFormatUtil.Format("[{0} {1} {2} {3} {4} {5}]", red, red, green, green, blue , blue)); } } break; } case 3: { if (len > 0) { png.trans = new byte[len]; for (int k = 0; k < len; ++k) { png.trans[k] = (byte)pngStream.Read(); } len = 0; } break; } } StreamUtil.Skip(pngStream, len); } else { if (IHDR.Equals(marker)) { png.width = GetInt(pngStream); png.height = GetInt(pngStream); png.bitDepth = pngStream.Read(); png.colorType = pngStream.Read(); png.compressionMethod = pngStream.Read(); png.filterMethod = pngStream.Read(); png.interlaceMethod = pngStream.Read(); } else { if (PLTE.Equals(marker)) { if (png.colorType == 3) { Object[] colorspace = new Object[4]; colorspace[0] = "/Indexed"; colorspace[1] = GetColorspace(png); colorspace[2] = len / 3 - 1; ByteBuffer colorTableBuf = new ByteBuffer(); while ((len--) > 0) { colorTableBuf.Append(pngStream.Read()); } png.colorTable = colorTableBuf.ToByteArray(); colorspace[3] = PdfEncodings.ConvertToString(png.colorTable, null); png.additional.Put("ColorSpace", colorspace); } else { StreamUtil.Skip(pngStream, len); } } else { if (pHYs.Equals(marker)) { int dx = GetInt(pngStream); int dy = GetInt(pngStream); int unit = pngStream.Read(); if (unit == 1) { png.dpiX = (int)(dx * 0.0254f + 0.5f); png.dpiY = (int)(dy * 0.0254f + 0.5f); } else { if (dy != 0) { png.XYRatio = (float)dx / (float)dy; } } } else { if (cHRM.Equals(marker)) { png.xW = GetInt(pngStream) / 100000f; png.yW = GetInt(pngStream) / 100000f; png.xR = GetInt(pngStream) / 100000f; png.yR = GetInt(pngStream) / 100000f; png.xG = GetInt(pngStream) / 100000f; png.yG = GetInt(pngStream) / 100000f; png.xB = GetInt(pngStream) / 100000f; png.yB = GetInt(pngStream) / 100000f; png.hasCHRM = !(Math.Abs(png.xW) < 0.0001f || Math.Abs(png.yW) < 0.0001f || Math.Abs(png.xR) < 0.0001f || Math.Abs(png.yR) < 0.0001f || Math.Abs(png.xG) < 0.0001f || Math.Abs(png.yG) < 0.0001f || Math.Abs(png .xB) < 0.0001f || Math.Abs(png.yB) < 0.0001f); } else { if (sRGB.Equals(marker)) { int ri = pngStream.Read(); png.intent = intents[ri]; png.gamma = 2.2f; png.xW = 0.3127f; png.yW = 0.329f; png.xR = 0.64f; png.yR = 0.33f; png.xG = 0.3f; png.yG = 0.6f; png.xB = 0.15f; png.yB = 0.06f; png.hasCHRM = true; } else { if (gAMA.Equals(marker)) { int gm = GetInt(pngStream); if (gm != 0) { png.gamma = 100000f / gm; if (!png.hasCHRM) { png.xW = 0.3127f; png.yW = 0.329f; png.xR = 0.64f; png.yR = 0.33f; png.xG = 0.3f; png.yG = 0.6f; png.xB = 0.15f; png.yB = 0.06f; png.hasCHRM = true; } } } else { if (iCCP.Equals(marker)) { do { --len; }while (pngStream.Read() != 0); pngStream.Read(); --len; byte[] icccom = new byte[len]; int p = 0; while (len > 0) { int r = pngStream.JRead(icccom, p, len); if (r < 0) { throw new System.IO.IOException("premature.end.of.file"); } p += r; len -= r; } byte[] iccp = FilterUtil.FlateDecode(icccom, true); icccom = null; try { png.iccProfile = IccProfile.GetInstance(iccp); } catch (Exception) { png.iccProfile = null; } } else { if (IEND.Equals(marker)) { break; } else { StreamUtil.Skip(pngStream, len); } } } } } } } } } } StreamUtil.Skip(pngStream, 4); } }
private static void ReadPng(Stream pngStream, PngImageHelper.PngParameters png) { for (int i = 0; i < PNGID.Length; i++) { if (PNGID[i] != pngStream.Read()) { throw new System.IO.IOException("file.is.not.a.valid.png"); } } byte[] buffer = new byte[TRANSFERSIZE]; while (true) { int len = GetInt(pngStream); String marker = GetString(pngStream); if (len < 0 || !CheckMarker(marker)) { throw new System.IO.IOException("corrupted.png.file"); } if (IDAT.Equals(marker)) { int size; while (len != 0) { size = pngStream.JRead(buffer, 0, Math.Min(len, TRANSFERSIZE)); if (size < 0) { return; } png.idat.Write(buffer, 0, size); len -= size; } } else { if (tRNS.Equals(marker)) { switch (png.image.GetColorType()) { case 0: { if (len >= 2) { len -= 2; int gray = GetWord(pngStream); if (png.bitDepth == 16) { png.transRedGray = gray; } else { png.additional.Put(PngImageHelperConstants.MASK, MessageFormatUtil.Format("[{0} {1}]", gray, gray)); } } break; } case 2: { if (len >= 6) { len -= 6; int red = GetWord(pngStream); int green = GetWord(pngStream); int blue = GetWord(pngStream); if (png.bitDepth == 16) { png.transRedGray = red; png.transGreen = green; png.transBlue = blue; } else { png.additional.Put(PngImageHelperConstants.MASK, MessageFormatUtil.Format("[{0} {1} {2} {3} {4} {5}]", red , red, green, green, blue, blue)); } } break; } case 3: { if (len > 0) { png.trans = new byte[len]; for (int k = 0; k < len; ++k) { png.trans[k] = (byte)pngStream.Read(); } len = 0; } break; } } StreamUtil.Skip(pngStream, len); } else { if (IHDR.Equals(marker)) { png.width = GetInt(pngStream); png.height = GetInt(pngStream); png.bitDepth = pngStream.Read(); png.image.SetColorType(pngStream.Read()); png.compressionMethod = pngStream.Read(); png.filterMethod = pngStream.Read(); png.interlaceMethod = pngStream.Read(); } else { if (PLTE.Equals(marker)) { if (png.image.IsIndexed()) { ByteBuffer colorTableBuf = new ByteBuffer(); while ((len--) > 0) { colorTableBuf.Append(pngStream.Read()); } png.image.SetColorPalette(colorTableBuf.ToByteArray()); } else { StreamUtil.Skip(pngStream, len); } } else { if (pHYs.Equals(marker)) { int dx = GetInt(pngStream); int dy = GetInt(pngStream); int unit = pngStream.Read(); if (unit == 1) { png.dpiX = (int)(dx * 0.0254f + 0.5f); png.dpiY = (int)(dy * 0.0254f + 0.5f); } else { if (dy != 0) { png.XYRatio = (float)dx / (float)dy; } } } else { if (cHRM.Equals(marker)) { PngChromaticities pngChromaticities = new PngChromaticities(GetInt(pngStream) / 100000f, GetInt(pngStream) / 100000f, GetInt(pngStream) / 100000f, GetInt(pngStream) / 100000f, GetInt(pngStream) / 100000f, GetInt (pngStream) / 100000f, GetInt(pngStream) / 100000f, GetInt(pngStream) / 100000f); if (!(Math.Abs(pngChromaticities.GetXW()) < 0.0001f || Math.Abs(pngChromaticities.GetYW()) < 0.0001f || Math .Abs(pngChromaticities.GetXR()) < 0.0001f || Math.Abs(pngChromaticities.GetYR()) < 0.0001f || Math.Abs (pngChromaticities.GetXG()) < 0.0001f || Math.Abs(pngChromaticities.GetYG()) < 0.0001f || Math.Abs(pngChromaticities .GetXB()) < 0.0001f || Math.Abs(pngChromaticities.GetYB()) < 0.0001f)) { png.image.SetPngChromaticities(pngChromaticities); } } else { if (sRGB.Equals(marker)) { int ri = pngStream.Read(); png.intent = intents[ri]; png.image.SetGamma(2.2f); PngChromaticities pngChromaticities = new PngChromaticities(0.3127f, 0.329f, 0.64f, 0.33f, 0.3f, 0.6f, 0.15f , 0.06f); png.image.SetPngChromaticities(pngChromaticities); } else { if (gAMA.Equals(marker)) { int gm = GetInt(pngStream); if (gm != 0) { png.image.SetGamma(100000f / gm); if (!png.image.IsHasCHRM()) { PngChromaticities pngChromaticities = new PngChromaticities(0.3127f, 0.329f, 0.64f, 0.33f, 0.3f, 0.6f, 0.15f , 0.06f); png.image.SetPngChromaticities(pngChromaticities); } } } else { if (iCCP.Equals(marker)) { do { --len; }while (pngStream.Read() != 0); pngStream.Read(); --len; byte[] icccom = new byte[len]; int p = 0; while (len > 0) { int r = pngStream.JRead(icccom, p, len); if (r < 0) { throw new System.IO.IOException("premature.end.of.file"); } p += r; len -= r; } byte[] iccp = FilterUtil.FlateDecode(icccom, true); icccom = null; try { png.iccProfile = IccProfile.GetInstance(iccp); } catch (Exception) { png.iccProfile = null; } } else { if (IEND.Equals(marker)) { break; } else { StreamUtil.Skip(pngStream, len); } } } } } } } } } } StreamUtil.Skip(pngStream, 4); } }
/// <summary> /// Read Through Cache /// </summary> /// <param name="getParams"></param> /// <returns></returns> private ClusterMarkersResponse GetMarkersHelper(GetMarkersParams getParams) { try { var neLat = getParams.NorthEastLatitude; var neLong = getParams.NorthEastLongitude; var swLat = getParams.SouthWestLatitude; var swLong = getParams.SouthWestLongitude; var zoomLevel = getParams.ZoomLevel; var filter = getParams.Filter ?? ""; // values are validated there var markersInput = new MarkersInput(neLat, neLong, swLat, swLong, zoomLevel, filter); var grid = GridCluster.GetBoundaryExtended(markersInput); var cacheKeyHelper = string.Format("{0}_{1}_{2}", markersInput.Zoomlevel, markersInput.FilterHashCode(), grid.GetHashCode()); var cacheKey = CacheKeys.GetMarkers(cacheKeyHelper.GetHashCode()); var response = new ClusterMarkersResponse(); markersInput.Viewport.ValidateLatLon(); // Validate google map viewport input (should be always valid) markersInput.Viewport.Normalize(); // Get all points from memory IList <MapPoint> points = _pointCollection.Get(getParams.PointType); // _pointsDatabase.GetPoints(); // Filter points points = FilterUtil.FilterByType( points, new FilterData { TypeFilterExclude = markersInput.TypeFilterExclude } ); // Create new instance for every ajax request with input all points and json data var clusterAlgo = new GridCluster(points, markersInput); var clusteringEnabled = markersInput.IsClusteringEnabled || GmcConfiguration.Get.AlwaysClusteringEnabledWhenZoomLevelLess > markersInput.Zoomlevel; // Clustering if (clusteringEnabled && markersInput.Zoomlevel < GmcConfiguration.Get.ZoomlevelClusterStop) { IList <MapPoint> markers = clusterAlgo.RunCluster(); response = new ClusterMarkersResponse { Markers = markers, Polylines = clusterAlgo.GetPolyLines() }; } else { // If we are here then there are no clustering // The number of items returned is restricted to avoid json data overflow IList <MapPoint> filteredDataset = FilterUtil.FilterDataByViewport(points, markersInput.Viewport); IList <MapPoint> filteredDatasetMaxPoints = filteredDataset.Take(GmcConfiguration.Get.MaxMarkersReturned).ToList(); response = new ClusterMarkersResponse { Markers = filteredDatasetMaxPoints, Polylines = clusterAlgo.GetPolyLines(), Mia = filteredDataset.Count - filteredDatasetMaxPoints.Count, }; } // if client ne and sw is inside a specific grid box then cache the grid box and the result // next time test if ne and sw is inside the grid box and return the cached result if (GmcConfiguration.Get.CacheServices) { _memCache.Set(cacheKey, response, TimeSpan.FromMinutes(10)); // cache data } return(response); } catch (Exception ex) { return(new ClusterMarkersResponse { OperationResult = "0", ErrorMessage = string.Format("MapService says: exception {0}", ex.Message) }); } }
/// <summary> /// Read Through Cache /// </summary> /// <param name="input"></param> /// <returns></returns> public JsonMarkersReply GetMarkersHelper(JsonGetMarkersInput input) { try { var nelat = Math.Round(input.nelat.ToDouble(), Numbers.Round); var nelon = Math.Round(input.nelon.ToDouble(), Numbers.Round); var swlat = Math.Round(input.swlat.ToDouble(), Numbers.Round); var swlon = Math.Round(input.swlon.ToDouble(), Numbers.Round); var zoomLevel = int.Parse(input.zoomLevel); var filter = input.filter ?? ""; // values are validated there var inputValidated = new JsonGetMarkersReceive(nelat, nelon, swlat, swlon, zoomLevel, filter); var grid = GridCluster.GetBoundaryExtended(inputValidated); var cacheKeyHelper = string.Format("{0}_{1}_{2}", inputValidated.Zoomlevel, inputValidated.FilterHashCode(), grid.GetHashCode()); var cacheKey = CacheKeys.GetMarkers(cacheKeyHelper.GetHashCode()); var reply = _memCache.Get <JsonMarkersReply>(cacheKey); if (reply != null) { // return cached data reply.Cache = true; return(reply); } inputValidated.Viewport.ValidateLatLon(); // Validate google map viewport input (should be always valid) inputValidated.Viewport.Normalize(); // Get all points from memory IList <P> points = _pointsDatabase.GetPoints(); #region fiter // Filter points points = FilterUtil.FilterByType( points, new FilterData { TypeFilterExclude = inputValidated.TypeFilterExclude } ); #endregion filter // Create new instance for every ajax request with input all points and json data ICluster clusterAlgo = new GridCluster(points, inputValidated); var clusteringEnabled = inputValidated.IsClusteringEnabled || GmcSettings.Get.AlwaysClusteringEnabledWhenZoomLevelLess > inputValidated.Zoomlevel; // Clustering if (clusteringEnabled && inputValidated.Zoomlevel < GmcSettings.Get.ZoomlevelClusterStop) { #region cluster IList <P> markers = clusterAlgo.RunCluster(); #endregion cluster reply = new JsonMarkersReply { Markers = markers, Polylines = clusterAlgo.GetPolyLines(), }; } else { // If we are here then there are no clustering // The number of items returned is restricted to avoid json data overflow IList <P> filteredDataset = FilterUtil.FilterDataByViewport(points, inputValidated.Viewport); IList <P> filteredDatasetMaxPoints = filteredDataset.Take(GmcSettings.Get.MaxMarkersReturned).ToList(); reply = new JsonMarkersReply { Markers = filteredDatasetMaxPoints, Polylines = clusterAlgo.GetPolyLines(), Mia = filteredDataset.Count - filteredDatasetMaxPoints.Count, }; } // if client ne and sw is inside a specific grid box then cache the grid box and the result // next time test if ne and sw is inside the grid box and return the cached result if (GmcSettings.Get.CacheServices) { _memCache.Set(reply, cacheKey, TimeSpan.FromMinutes(10)); // cache data } return(reply); } catch (Exception ex) { return(new JsonMarkersReply { Ok = "0", EMsg = string.Format("MapService says: exception {0}", ex.Message) }); } }
public static T GetFilter <T>(this Dictionary <PokemonId, T> source, PokemonId pid) where T : IPokemonFilter { return(FilterUtil.GetApplyFilter <T>(source, pid)); }
private static void ProcessTiffImageColor(TIFFDirectory dir, RandomAccessFileOrArray s, TiffImageHelper.TiffParameters tiff) { try { int compression = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_COMPRESSION); int predictor = 1; TIFFLZWDecoder lzwDecoder = null; switch (compression) { case TIFFConstants.COMPRESSION_NONE: case TIFFConstants.COMPRESSION_LZW: case TIFFConstants.COMPRESSION_PACKBITS: case TIFFConstants.COMPRESSION_DEFLATE: case TIFFConstants.COMPRESSION_ADOBE_DEFLATE: case TIFFConstants.COMPRESSION_OJPEG: case TIFFConstants.COMPRESSION_JPEG: { break; } default: { throw new iText.IO.IOException(iText.IO.IOException.Compression1IsNotSupported).SetMessageParams(compression ); } } int photometric = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_PHOTOMETRIC); switch (photometric) { case TIFFConstants.PHOTOMETRIC_MINISWHITE: case TIFFConstants.PHOTOMETRIC_MINISBLACK: case TIFFConstants.PHOTOMETRIC_RGB: case TIFFConstants.PHOTOMETRIC_SEPARATED: case TIFFConstants.PHOTOMETRIC_PALETTE: { break; } default: { if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG) { throw new iText.IO.IOException(iText.IO.IOException.Photometric1IsNotSupported).SetMessageParams(photometric ); } break; } } float rotation = 0; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_ORIENTATION)) { int rot = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_ORIENTATION); if (rot == TIFFConstants.ORIENTATION_BOTRIGHT || rot == TIFFConstants.ORIENTATION_BOTLEFT) { rotation = (float)Math.PI; } else { if (rot == TIFFConstants.ORIENTATION_LEFTTOP || rot == TIFFConstants.ORIENTATION_LEFTBOT) { rotation = (float)(Math.PI / 2.0); } else { if (rot == TIFFConstants.ORIENTATION_RIGHTTOP || rot == TIFFConstants.ORIENTATION_RIGHTBOT) { rotation = -(float)(Math.PI / 2.0); } } } } if (dir.IsTagPresent(TIFFConstants.TIFFTAG_PLANARCONFIG) && dir.GetFieldAsLong(TIFFConstants.TIFFTAG_PLANARCONFIG ) == TIFFConstants.PLANARCONFIG_SEPARATE) { throw new iText.IO.IOException(iText.IO.IOException.PlanarImagesAreNotSupported); } int extraSamples = 0; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_EXTRASAMPLES)) { extraSamples = 1; } int samplePerPixel = 1; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL)) { // 1,3,4 samplePerPixel = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_SAMPLESPERPIXEL); } int bitsPerSample = 1; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_BITSPERSAMPLE)) { bitsPerSample = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_BITSPERSAMPLE); } switch (bitsPerSample) { case 1: case 2: case 4: case 8: { break; } default: { throw new iText.IO.IOException(iText.IO.IOException.BitsPerSample1IsNotSupported).SetMessageParams(bitsPerSample ); } } int h = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_IMAGELENGTH); int w = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_IMAGEWIDTH); int dpiX; int dpiY; int resolutionUnit = TIFFConstants.RESUNIT_INCH; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_RESOLUTIONUNIT)) { resolutionUnit = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_RESOLUTIONUNIT); } dpiX = GetDpi(dir.GetField(TIFFConstants.TIFFTAG_XRESOLUTION), resolutionUnit); dpiY = GetDpi(dir.GetField(TIFFConstants.TIFFTAG_YRESOLUTION), resolutionUnit); int fillOrder = 1; TIFFField fillOrderField = dir.GetField(TIFFConstants.TIFFTAG_FILLORDER); if (fillOrderField != null) { fillOrder = fillOrderField.GetAsInt(0); } bool reverse = (fillOrder == TIFFConstants.FILLORDER_LSB2MSB); int rowsStrip = h; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_ROWSPERSTRIP)) { //another hack for broken tiffs rowsStrip = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_ROWSPERSTRIP); } if (rowsStrip <= 0 || rowsStrip > h) { rowsStrip = h; } long[] offset = GetArrayLongShort(dir, TIFFConstants.TIFFTAG_STRIPOFFSETS); long[] size = GetArrayLongShort(dir, TIFFConstants.TIFFTAG_STRIPBYTECOUNTS); if ((size == null || (size.Length == 1 && (size[0] == 0 || size[0] + offset[0] > s.Length()))) && h == rowsStrip ) { // some TIFF producers are really lousy, so... size = new long[] { s.Length() - (int)offset[0] }; } if (compression == TIFFConstants.COMPRESSION_LZW || compression == TIFFConstants.COMPRESSION_DEFLATE || compression == TIFFConstants.COMPRESSION_ADOBE_DEFLATE) { TIFFField predictorField = dir.GetField(TIFFConstants.TIFFTAG_PREDICTOR); if (predictorField != null) { predictor = predictorField.GetAsInt(0); if (predictor != 1 && predictor != 2) { throw new iText.IO.IOException(iText.IO.IOException.IllegalValueForPredictorInTiffFile); } if (predictor == 2 && bitsPerSample != 8) { throw new iText.IO.IOException(iText.IO.IOException._1BitSamplesAreNotSupportedForHorizontalDifferencingPredictor ).SetMessageParams(bitsPerSample); } } } if (compression == TIFFConstants.COMPRESSION_LZW) { lzwDecoder = new TIFFLZWDecoder(w, predictor, samplePerPixel); } int rowsLeft = h; ByteArrayOutputStream stream = null; ByteArrayOutputStream mstream = null; DeflaterOutputStream zip = null; DeflaterOutputStream mzip = null; if (extraSamples > 0) { mstream = new ByteArrayOutputStream(); mzip = new DeflaterOutputStream(mstream); } CCITTG4Encoder g4 = null; if (bitsPerSample == 1 && samplePerPixel == 1 && photometric != TIFFConstants.PHOTOMETRIC_PALETTE) { g4 = new CCITTG4Encoder(w); } else { stream = new ByteArrayOutputStream(); if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG) { zip = new DeflaterOutputStream(stream); } } if (compression == TIFFConstants.COMPRESSION_OJPEG) { // Assume that the TIFFTAG_JPEGIFBYTECOUNT tag is optional, since it's obsolete and // is often missing if ((!dir.IsTagPresent(TIFFConstants.TIFFTAG_JPEGIFOFFSET))) { throw new iText.IO.IOException(iText.IO.IOException.MissingTagsForOjpegCompression); } int jpegOffset = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_JPEGIFOFFSET); int jpegLength = (int)s.Length() - jpegOffset; if (dir.IsTagPresent(TIFFConstants.TIFFTAG_JPEGIFBYTECOUNT)) { jpegLength = (int)dir.GetFieldAsLong(TIFFConstants.TIFFTAG_JPEGIFBYTECOUNT) + (int)size[0]; } byte[] jpeg = new byte[Math.Min(jpegLength, (int)s.Length() - jpegOffset)]; int posFilePointer = (int)s.GetPosition(); posFilePointer += jpegOffset; s.Seek(posFilePointer); s.ReadFully(jpeg); tiff.image.data = jpeg; tiff.image.SetOriginalType(ImageType.JPEG); JpegImageHelper.ProcessImage(tiff.image); tiff.jpegProcessing = true; } else { if (compression == TIFFConstants.COMPRESSION_JPEG) { if (size.Length > 1) { throw new iText.IO.IOException(iText.IO.IOException.CompressionJpegIsOnlySupportedWithASingleStripThisImageHas1Strips ).SetMessageParams(size.Length); } byte[] jpeg = new byte[(int)size[0]]; s.Seek(offset[0]); s.ReadFully(jpeg); // if quantization and/or Huffman tables are stored separately in the tiff, // we need to add them to the jpeg data TIFFField jpegtables = dir.GetField(TIFFConstants.TIFFTAG_JPEGTABLES); if (jpegtables != null) { byte[] temp = jpegtables.GetAsBytes(); int tableoffset = 0; int tablelength = temp.Length; // remove FFD8 from start if (temp[0] == (byte)0xFF && temp[1] == (byte)0xD8) { tableoffset = 2; tablelength -= 2; } // remove FFD9 from end if (temp[temp.Length - 2] == (byte)0xFF && temp[temp.Length - 1] == (byte)0xD9) { tablelength -= 2; } byte[] tables = new byte[tablelength]; System.Array.Copy(temp, tableoffset, tables, 0, tablelength); // TODO insert after JFIF header, instead of at the start byte[] jpegwithtables = new byte[jpeg.Length + tables.Length]; System.Array.Copy(jpeg, 0, jpegwithtables, 0, 2); System.Array.Copy(tables, 0, jpegwithtables, 2, tables.Length); System.Array.Copy(jpeg, 2, jpegwithtables, tables.Length + 2, jpeg.Length - 2); jpeg = jpegwithtables; } tiff.image.data = jpeg; tiff.image.SetOriginalType(ImageType.JPEG); JpegImageHelper.ProcessImage(tiff.image); tiff.jpegProcessing = true; if (photometric == TIFFConstants.PHOTOMETRIC_RGB) { tiff.image.SetColorTransform(0); } } else { for (int k = 0; k < offset.Length; ++k) { byte[] im = new byte[(int)size[k]]; s.Seek(offset[k]); s.ReadFully(im); int height = Math.Min(rowsStrip, rowsLeft); byte[] outBuf = null; if (compression != TIFFConstants.COMPRESSION_NONE) { outBuf = new byte[(w * bitsPerSample * samplePerPixel + 7) / 8 * height]; } if (reverse) { TIFFFaxDecoder.ReverseBits(im); } switch (compression) { case TIFFConstants.COMPRESSION_DEFLATE: case TIFFConstants.COMPRESSION_ADOBE_DEFLATE: { FilterUtil.InflateData(im, outBuf); ApplyPredictor(outBuf, predictor, w, height, samplePerPixel); break; } case TIFFConstants.COMPRESSION_NONE: { outBuf = im; break; } case TIFFConstants.COMPRESSION_PACKBITS: { DecodePackbits(im, outBuf); break; } case TIFFConstants.COMPRESSION_LZW: { lzwDecoder.Decode(im, outBuf, height); break; } } if (bitsPerSample == 1 && samplePerPixel == 1 && photometric != TIFFConstants.PHOTOMETRIC_PALETTE) { g4.Fax4Encode(outBuf, height); } else { if (extraSamples > 0) { ProcessExtraSamples(zip, mzip, outBuf, samplePerPixel, bitsPerSample, w, height); } else { zip.Write(outBuf); } } rowsLeft -= rowsStrip; } if (bitsPerSample == 1 && samplePerPixel == 1 && photometric != TIFFConstants.PHOTOMETRIC_PALETTE) { RawImageHelper.UpdateRawImageParameters(tiff.image, w, h, false, RawImageData.CCITTG4, photometric == TIFFConstants .PHOTOMETRIC_MINISBLACK ? RawImageData.CCITT_BLACKIS1 : 0, g4.Close(), null); } else { zip.Close(); RawImageHelper.UpdateRawImageParameters(tiff.image, w, h, samplePerPixel - extraSamples, bitsPerSample, stream .ToArray()); tiff.image.SetDeflated(true); } } } tiff.image.SetDpi(dpiX, dpiY); if (compression != TIFFConstants.COMPRESSION_OJPEG && compression != TIFFConstants.COMPRESSION_JPEG) { if (dir.IsTagPresent(TIFFConstants.TIFFTAG_ICCPROFILE)) { try { TIFFField fd = dir.GetField(TIFFConstants.TIFFTAG_ICCPROFILE); IccProfile icc_prof = IccProfile.GetInstance(fd.GetAsBytes()); if (samplePerPixel - extraSamples == icc_prof.GetNumComponents()) { tiff.image.SetProfile(icc_prof); } } catch (Exception) { } } //empty if (dir.IsTagPresent(TIFFConstants.TIFFTAG_COLORMAP)) { TIFFField fd = dir.GetField(TIFFConstants.TIFFTAG_COLORMAP); char[] rgb = fd.GetAsChars(); byte[] palette = new byte[rgb.Length]; int gColor = rgb.Length / 3; int bColor = gColor * 2; for (int k = 0; k < gColor; ++k) { //there is no sense in >>> for unsigned char palette[k * 3] = (byte)(rgb[k] >> 8); palette[k * 3 + 1] = (byte)(rgb[k + gColor] >> 8); palette[k * 3 + 2] = (byte)(rgb[k + bColor] >> 8); } // Colormap components are supposed to go from 0 to 655535 but, // as usually, some tiff producers just put values from 0 to 255. // Let's check for these broken tiffs. bool colormapBroken = true; for (int k_1 = 0; k_1 < palette.Length; ++k_1) { if (palette[k_1] != 0) { colormapBroken = false; break; } } if (colormapBroken) { for (int k_2 = 0; k_2 < gColor; ++k_2) { palette[k_2 * 3] = (byte)rgb[k_2]; palette[k_2 * 3 + 1] = (byte)rgb[k_2 + gColor]; palette[k_2 * 3 + 2] = (byte)rgb[k_2 + bColor]; } } Object[] indexed = new Object[4]; indexed[0] = "Indexed"; indexed[1] = "DeviceRGB"; indexed[2] = gColor - 1; indexed[3] = PdfEncodings.ConvertToString(palette, null); tiff.additional = new Dictionary <String, Object>(); tiff.additional["ColorSpace"] = indexed; } } if (photometric == TIFFConstants.PHOTOMETRIC_MINISWHITE) { tiff.image.SetInverted(true); } if (rotation != 0) { tiff.image.SetRotation(rotation); } if (extraSamples > 0) { mzip.Close(); RawImageData mimg = (RawImageData)ImageDataFactory.CreateRawImage(null); RawImageHelper.UpdateRawImageParameters(mimg, w, h, 1, bitsPerSample, mstream.ToArray()); mimg.MakeMask(); mimg.SetDeflated(true); tiff.image.SetImageMask(mimg); } } catch (Exception) { throw new iText.IO.IOException(iText.IO.IOException.CannotGetTiffImageColor); } }