public unsafe void PopulateCharColorData(CharInfo ci, IFontProvider font) { ColorF charRGB = ColorF.Init; for (int ty = 0; ty < LumaTiles.Height; ++ty) { for (int tx = 0; tx < LumaTiles.Width; ++tx) { Size tileSize; Point tilePos; GetTileInfo(font.CharSizeNoPadding, LumaTiles, tx, ty, out tilePos, out tileSize); // process this single tile of this char. // grab all pixels for this tile and calculate Y component for each ColorF tileRGB = font.GetRegionColor(ci.srcIndex, tilePos, tileSize, LumaTiles, tx, ty); charRGB = charRGB.Add(tileRGB); LCCColorDenorm tileLAB = Colorspace.RGBToLCC(tileRGB); ci.actualValues.DenormalizedValues[GetValueLIndex(tx, ty)] = (float)tileLAB.L; ci.actualValues.NormalizedValues[GetValueLIndex(tx, ty)] = (float)Colorspace.NormalizeL(ci.actualValues.DenormalizedValues[GetValueLIndex(tx, ty)]); } } if (UseChroma) { charRGB = charRGB.Div(Utils.Product(LumaTiles)); LCCColorDenorm charLAB = Colorspace.RGBToLCC(charRGB); ci.actualValues.DenormalizedValues[GetValueC1Index()] = (float)charLAB.C1; ci.actualValues.DenormalizedValues[GetValueC2Index()] = (float)charLAB.C2; ci.actualValues.NormalizedValues[GetValueC1Index()] = (float)Colorspace.NormalizeC1(ci.actualValues.DenormalizedValues[GetValueC1Index()]); ci.actualValues.NormalizedValues[GetValueC2Index()] = (float)Colorspace.NormalizeC2(ci.actualValues.DenormalizedValues[GetValueC2Index()]); } }
public LCCColorNorm RGBToNormalizedLCC(ColorF c) { LCCColorDenorm d = Colorspace.RGBToLCC(c); LCCColorNorm ret; ret.L = Colorspace.NormalizeL(d.L); ret.C1 = Colorspace.NormalizeC1(d.C1); ret.C2 = Colorspace.NormalizeC2(d.C2); return(ret); }
public unsafe void PopulateCharColorData(CharInfo ci, IFontProvider font) { ColorF charRGB = ColorF.Init; ColorF[] lumaRGB = new ColorF[LumaComponentCount]; int[] pixelCounts = new int[LumaComponentCount]; for (int i = 0; i < LumaComponentCount; ++i) { lumaRGB[i] = ColorF.Init; pixelCounts[i] = 0; } for (int py = 0; py < font.CharSizeNoPadding.Height; ++py) { for (int px = 0; px < font.CharSizeNoPadding.Width; ++px) { ColorF pc = font.GetPixel(ci.srcIndex, px, py); charRGB = charRGB.Add(pc); int lumaIdx = Tessellator.GetLumaTileIndexOfPixelPosInCell(px, py, font.CharSizeNoPadding); lumaRGB[lumaIdx] = lumaRGB[lumaIdx].Add(pc); pixelCounts[lumaIdx]++; } } for (int i = 0; i < LumaComponentCount; ++i) { var pc = pixelCounts[i]; var lc = lumaRGB[i]; if (pixelCounts[i] < 1) { throw new Exception("!!!!!! Your fonts are just too small; i can't sample them properly."); } lc = lc.Div(pc); LCCColorDenorm lccc = Colorspace.RGBToLCC(lc); ci.actualValues.DenormalizedValues[i] = (float)lccc.L; ci.actualValues.NormalizedValues[i] = (float)Colorspace.NormalizeL(ci.actualValues.DenormalizedValues[i]); } if (UseChroma) { charRGB = charRGB.Div(Utils.Product(font.CharSizeNoPadding)); LCCColorDenorm charLAB = Colorspace.RGBToLCC(charRGB); ci.actualValues.DenormalizedValues[GetValueC1Index()] = (float)charLAB.C1; ci.actualValues.DenormalizedValues[GetValueC2Index()] = (float)charLAB.C2; ci.actualValues.NormalizedValues[GetValueC1Index()] = (float)Colorspace.NormalizeC1(ci.actualValues.DenormalizedValues[GetValueC1Index()]); ci.actualValues.NormalizedValues[GetValueC2Index()] = (float)Colorspace.NormalizeC2(ci.actualValues.DenormalizedValues[GetValueC2Index()]); } }
public static ValueSet GetValueSetForSinglePixel(this ILCCColorSpace cs, ColorF color, bool useChroma) { // a value set normally consists of multiple luma & chroma components for a char (for example 5 luma + 2 chroma) // for this we just have the normal default 3-component. all our colorspaces are LCC (luma chroma chroma). LCCColorDenorm denorm = cs.RGBToLCC(color); ValueSet src = new ValueSet(); float[] normArray = new float[] { (float)cs.NormalizeL(denorm.L), (float)cs.NormalizeC1(denorm.C1), (float)cs.NormalizeC2(denorm.C2), }; ValueSet.Init(ref src, useChroma ? 3 : 1, 0, normArray); src.DenormalizedValues[0] = (float)denorm.L; src.DenormalizedValues[1] = (float)denorm.C1; src.DenormalizedValues[2] = (float)denorm.C2; return(src); }
public int GetMapIndexOfRegion(Bitmap img, int x, int y, Size sz) { ColorF rgb = ColorF.Init; LCCColorDenorm lab = LCCColorDenorm.Init; LCCColorNorm norm = LCCColorNorm.Init; float[] vals = new float[DimensionCount]; ColorF charRGB = ColorF.Init; for (int ty = LumaTiles.Height - 1; ty >= 0; --ty) { for (int tx = LumaTiles.Width - 1; tx >= 0; --tx) { Point tilePos = GetTileOrigin(sz, LumaTiles, tx, ty); // YES this just gets 1 pixel per char-sized area. rgb = ColorF.From(img.GetPixel(x + tilePos.X, y + tilePos.Y)); lab = Colorspace.RGBToLCC(rgb); norm = RGBToNormalizedLCC(rgb); vals[GetValueLIndex(tx, ty)] = (float)norm.L; charRGB = charRGB.Add(rgb); } } if (UseChroma) { int numTiles = Utils.Product(LumaTiles); charRGB = charRGB.Div(numTiles); norm = RGBToNormalizedLCC(charRGB); vals[GetValueC1Index()] = (float)norm.C1; vals[GetValueC2Index()] = (float)norm.C2; } int ID = NormalizedValueSetToMapID(vals); return(ID); }