4bf6192341ba4c63d7aa63adf86a5433ad294096615ec2aa91b4ae7f266fafa1fdf96c8e370e9c04ba52ad0fce8ddec8fa27371e3a8d40fb687c7ccd429a9b 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { getCharIndex } from './minimapCharSheet.js';
  6. import { toUint8 } from '../../../../base/common/uint.js';
  7. export class MinimapCharRenderer {
  8. constructor(charData, scale) {
  9. this.scale = scale;
  10. this._minimapCharRendererBrand = undefined;
  11. this.charDataNormal = MinimapCharRenderer.soften(charData, 12 / 15);
  12. this.charDataLight = MinimapCharRenderer.soften(charData, 50 / 60);
  13. }
  14. static soften(input, ratio) {
  15. const result = new Uint8ClampedArray(input.length);
  16. for (let i = 0, len = input.length; i < len; i++) {
  17. result[i] = toUint8(input[i] * ratio);
  18. }
  19. return result;
  20. }
  21. renderChar(target, dx, dy, chCode, color, foregroundAlpha, backgroundColor, backgroundAlpha, fontScale, useLighterFont, force1pxHeight) {
  22. const charWidth = 1 /* Constants.BASE_CHAR_WIDTH */ * this.scale;
  23. const charHeight = 2 /* Constants.BASE_CHAR_HEIGHT */ * this.scale;
  24. const renderHeight = (force1pxHeight ? 1 : charHeight);
  25. if (dx + charWidth > target.width || dy + renderHeight > target.height) {
  26. console.warn('bad render request outside image data');
  27. return;
  28. }
  29. const charData = useLighterFont ? this.charDataLight : this.charDataNormal;
  30. const charIndex = getCharIndex(chCode, fontScale);
  31. const destWidth = target.width * 4 /* Constants.RGBA_CHANNELS_CNT */;
  32. const backgroundR = backgroundColor.r;
  33. const backgroundG = backgroundColor.g;
  34. const backgroundB = backgroundColor.b;
  35. const deltaR = color.r - backgroundR;
  36. const deltaG = color.g - backgroundG;
  37. const deltaB = color.b - backgroundB;
  38. const destAlpha = Math.max(foregroundAlpha, backgroundAlpha);
  39. const dest = target.data;
  40. let sourceOffset = charIndex * charWidth * charHeight;
  41. let row = dy * destWidth + dx * 4 /* Constants.RGBA_CHANNELS_CNT */;
  42. for (let y = 0; y < renderHeight; y++) {
  43. let column = row;
  44. for (let x = 0; x < charWidth; x++) {
  45. const c = (charData[sourceOffset++] / 255) * (foregroundAlpha / 255);
  46. dest[column++] = backgroundR + deltaR * c;
  47. dest[column++] = backgroundG + deltaG * c;
  48. dest[column++] = backgroundB + deltaB * c;
  49. dest[column++] = destAlpha;
  50. }
  51. row += destWidth;
  52. }
  53. }
  54. blockRenderChar(target, dx, dy, color, foregroundAlpha, backgroundColor, backgroundAlpha, force1pxHeight) {
  55. const charWidth = 1 /* Constants.BASE_CHAR_WIDTH */ * this.scale;
  56. const charHeight = 2 /* Constants.BASE_CHAR_HEIGHT */ * this.scale;
  57. const renderHeight = (force1pxHeight ? 1 : charHeight);
  58. if (dx + charWidth > target.width || dy + renderHeight > target.height) {
  59. console.warn('bad render request outside image data');
  60. return;
  61. }
  62. const destWidth = target.width * 4 /* Constants.RGBA_CHANNELS_CNT */;
  63. const c = 0.5 * (foregroundAlpha / 255);
  64. const backgroundR = backgroundColor.r;
  65. const backgroundG = backgroundColor.g;
  66. const backgroundB = backgroundColor.b;
  67. const deltaR = color.r - backgroundR;
  68. const deltaG = color.g - backgroundG;
  69. const deltaB = color.b - backgroundB;
  70. const colorR = backgroundR + deltaR * c;
  71. const colorG = backgroundG + deltaG * c;
  72. const colorB = backgroundB + deltaB * c;
  73. const destAlpha = Math.max(foregroundAlpha, backgroundAlpha);
  74. const dest = target.data;
  75. let row = dy * destWidth + dx * 4 /* Constants.RGBA_CHANNELS_CNT */;
  76. for (let y = 0; y < renderHeight; y++) {
  77. let column = row;
  78. for (let x = 0; x < charWidth; x++) {
  79. dest[column++] = colorR;
  80. dest[column++] = colorG;
  81. dest[column++] = colorB;
  82. dest[column++] = destAlpha;
  83. }
  84. row += destWidth;
  85. }
  86. }
  87. }