freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][ftinspect-grayscale] 2 commits: [ftinspec


From: Charlie Jiang (@cqjjjzr)
Subject: [Git][freetype/freetype-demos][ftinspect-grayscale] 2 commits: [ftinspect] Fix uninitialized memory issue and reference misuse.
Date: Tue, 07 Mar 2023 05:23:41 +0000

Charlie Jiang pushed to branch ftinspect-grayscale at FreeType / FreeType Demo Programs

Commits:

  • b33c0ecf
    by Charlie Jiang at 2023-03-03T09:52:15+01:00
    [ftinspect] Fix uninitialized memory issue and reference misuse.
    
    Fixes issue #23.
    
    * src/ftinspect/engine/rendering.cpp (RenderingEngine::convertBitmapTo8Bpp):
    Properly initialize `FT_Bitmap` since it is a value type.
    (RenderingEngine::convertBitmapToQImage): Fix the accidental overwriting of
    the source bitmap when converting the bitmap format (only happens for
    `FT_PIXEL_MODE_GRAY2` and `FT_PIXEL_MODE_GRAY4`) due to a misuse of a C++
    reference.
    
    * src/ftinspect/glyphcomponents/glyphcontinuous.cpp
    (GlyphContinuous::drawCacheGlyph): Fix a crash when the `QImage` was failed
    to produce.
    
  • 027f08ee
    by Charlie Jiang at 2023-03-07T13:22:37+08:00
    * src/ftinspect/engine/rendering.cpp: Support gray level scaling.
    
    See 746d5be5: Convert to 256 grays.
    

2 changed files:

Changes:

  • src/ftinspect/engine/rendering.cpp
    ... ... @@ -136,14 +136,33 @@ RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src,
    136 136
     FT_Bitmap
    
    137 137
     RenderingEngine::convertBitmapTo8Bpp(FT_Bitmap* bitmap)
    
    138 138
     {
    
    139
    -  FT_Bitmap out;
    
    140
    -  out.buffer = NULL;
    
    139
    +  FT_Bitmap out = {};
    
    141 140
       // This will create a new bitmap object.
    
    142 141
       auto error = FT_Bitmap_Convert(engine_->ftLibrary(), bitmap, &out, 1);
    
    143 142
       if (error)
    
    144 143
       {
    
    145 144
         // XXX handling?
    
    146 145
       }
    
    146
    +
    
    147
    +  if (out.num_grays == 256)
    
    148
    +    return out;
    
    149
    +
    
    150
    +  // Scale gray values, too.
    
    151
    +  auto buf = reinterpret_cast<uint32_t*>(out.buffer);
    
    152
    +  uint32_t scale = 255U / (out.num_grays - 1);
    
    153
    +
    
    154
    +  // Four bytes at a time.
    
    155
    +  unsigned i = 0;
    
    156
    +  unsigned size = std::abs(out.pitch) * out.rows;
    
    157
    +  for (; i <= size - 4; i += 4, buf++)
    
    158
    +    *buf *= scale;
    
    159
    +
    
    160
    +  // The remaining bytes.
    
    161
    +  for (; i < size; i++ )
    
    162
    +    out.buffer[i] *= scale;
    
    163
    +
    
    164
    +  out.num_grays = 256;
    
    165
    +
    
    147 166
       return out;
    
    148 167
     }
    
    149 168
     
    
    ... ... @@ -167,7 +186,7 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
    167 186
     {
    
    168 187
       QImage* result = NULL;
    
    169 188
     
    
    170
    -  auto& bmap = *src;
    
    189
    +  auto bmap = *src;
    
    171 190
       bool ownBitmap = false; // If true, we need to clean up `bmap`.
    
    172 191
     
    
    173 192
       int width = INT_MAX;
    

  • src/ftinspect/glyphcomponents/glyphcontinuous.cpp
    ... ... @@ -552,6 +552,8 @@ GlyphContinuous::drawCacheGlyph(QPainter* painter,
    552 552
                                     const GlyphCacheEntry& entry,
    
    553 553
                                     bool colorInverted)
    
    554 554
     {
    
    555
    +  if (!entry.image)
    
    556
    +    return;
    
    555 557
       // From `ftview.c:557`.
    
    556 558
       // Well, metrics are also part of the cache...
    
    557 559
       int width = entry.advance.x ? entry.advance.x >> 16
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]