void FFont::LoadTranslations() { unsigned int count = LastChar - FirstChar + 1; uint32_t usedcolors[256] = {}; uint8_t identity[256]; TArray<double> Luminosity; for (unsigned int i = 0; i < count; i++) { if (Chars[i].TranslatedPic) { FFontChar1 *pic = static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetImage()); if (pic) { pic->SetSourceRemap(nullptr); // Force the FFontChar1 to return the same pixels as the base texture RecordTextureColors(pic, usedcolors); } } } ActiveColors = SimpleTranslation (usedcolors, PatchRemap, identity, Luminosity); for (unsigned int i = 0; i < count; i++) { if(Chars[i].TranslatedPic) static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap); } BuildTranslations (Luminosity.Data(), identity, &TranslationParms[TranslationType][0], ActiveColors, nullptr); }
void FFont::SetDefaultTranslation(uint32_t *othercolors) { uint32_t mycolors[256] = {}; RecordAllTextureColors(mycolors); uint8_t mytranslation[256], othertranslation[256], myreverse[256], otherreverse[256]; TArray<double> myluminosity, otherluminosity; SimpleTranslation(mycolors, mytranslation, myreverse, myluminosity); SimpleTranslation(othercolors, othertranslation, otherreverse, otherluminosity); FRemapTable remap(ActiveColors); remap.Remap[0] = 0; remap.Palette[0] = 0; for (unsigned l = 1; l < myluminosity.Size(); l++) { for (unsigned o = 1; o < otherluminosity.Size()-1; o++) // luminosity[0] is for the transparent color { if (myluminosity[l] >= otherluminosity[o] && myluminosity[l] <= otherluminosity[o+1]) { PalEntry color1 = GPalette.BaseColors[otherreverse[o]]; PalEntry color2 = GPalette.BaseColors[otherreverse[o+1]]; double weight = 0; if (otherluminosity[o] != otherluminosity[o + 1]) { weight = (myluminosity[l] - otherluminosity[o]) / (otherluminosity[o + 1] - otherluminosity[o]); } int r = int(color1.r + weight * (color2.r - color1.r)); int g = int(color1.g + weight * (color2.g - color1.g)); int b = int(color1.b + weight * (color2.b - color1.b)); r = clamp(r, 0, 255); g = clamp(g, 0, 255); b = clamp(b, 0, 255); remap.Remap[l] = ColorMatcher.Pick(r, g, b); remap.Palette[l] = PalEntry(255, r, g, b); break; } } } Ranges[CR_UNTRANSLATED] = remap; forceremap = true; }
FFont::FFont (const char *name, const char *nametemplate, int first, int count, int start) { int i, lump; char buffer[12]; int *charlumps; BYTE usedcolors[256], identity[256]; double *luminosity; int maxyoffs; bool doomtemplate = gameinfo.gametype == GAME_Doom ? strncmp (nametemplate, "STCFN", 5) == 0 : false; Chars = new CharData[count]; charlumps = new int[count]; PatchRemap = new BYTE[256]; Ranges = NULL; FirstChar = first; LastChar = first + count - 1; FontHeight = 0; GlobalKerning = false; memset (usedcolors, 0, 256); Name = copystring (name); Next = FirstFont; FirstFont = this; maxyoffs = 0; for (i = 0; i < count; i++) { sprintf (buffer, nametemplate, i + start); lump = Wads.CheckNumForName (buffer, ns_graphics); if (doomtemplate && lump >= 0 && i + start == 121) { // HACKHACK: Don't load STCFN121 in doom(2), because // it's not really a lower-case 'y' but an upper-case 'I'. // Because a lot of wads with their own font seem to foolishly // copy STCFN121 and make it an 'I' themselves, wads must // provide STCFN120 (x) and STCFN122 (z) for STCFN121 to load. if (Wads.CheckNumForName ("STCFN120", ns_graphics) == -1 || Wads.CheckNumForName ("STCFN122", ns_graphics) == -1) { lump = -1; } } charlumps[i] = lump; if (lump >= 0) { FTexture *pic = TexMan[TexMan.AddPatch (buffer)]; int height = pic->GetScaledHeight(); int yoffs = pic->GetScaledTopOffset(); if (yoffs > maxyoffs) { maxyoffs = yoffs; } height += abs (yoffs); if (height > FontHeight) { FontHeight = height; } RecordTextureColors (pic, usedcolors); } } ActiveColors = SimpleTranslation (usedcolors, PatchRemap, identity, &luminosity); for (i = 0; i < count; i++) { if (charlumps[i] >= 0) { Chars[i].Pic = new FFontChar1 (charlumps[i], PatchRemap); } else { Chars[i].Pic = NULL; } } if ('N'-first>=0 && 'N'-first<count && Chars['N' - first].Pic) { SpaceWidth = (Chars['N' - first].Pic->GetScaledWidth() + 1) / 2; } else { SpaceWidth = 4; } BuildTranslations (luminosity, identity, &TranslationParms[0][0]); delete[] luminosity; delete[] charlumps; }