⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pfrsbit.c

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  pfrsbit.c                                                              *//*                                                                         *//*    FreeType PFR bitmap loader (body).                                   *//*                                                                         *//*  Copyright 2002, 2003 by                                                *//*  David Turner, Robert Wilhelm, and Werner Lemberg.                      *//*                                                                         *//*  This file is part of the FreeType project, and may only be used,       *//*  modified, and distributed under the terms of the FreeType project      *//*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     *//*  this file you indicate that you have read the license and              *//*  understand and accept it fully.                                        *//*                                                                         *//***************************************************************************/#include "pfrsbit.h"#include "pfrload.h"#include FT_INTERNAL_DEBUG_H#include FT_INTERNAL_STREAM_H#include "pfrerror.h"#undef  FT_COMPONENT#define FT_COMPONENT  trace_pfr  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                      PFR BIT WRITER                           *****/  /*****                                                               *****/  /*************************************************************************/  /*************************************************************************/  typedef struct  PFR_BitWriter_  {    FT_Byte*  line;      /* current line start                    */    FT_Int    pitch;     /* line size in bytes                    */    FT_Int    width;     /* width in pixels/bits                  */    FT_Int    rows;      /* number of remaining rows to scan      */    FT_Int    total;     /* total number of bits to draw          */  } PFR_BitWriterRec, *PFR_BitWriter;  static void  pfr_bitwriter_init( PFR_BitWriter  writer,                      FT_Bitmap*     target,                      FT_Bool        decreasing )  {    writer->line   = target->buffer;    writer->pitch  = target->pitch;    writer->width  = target->width;    writer->rows   = target->rows;    writer->total  = writer->width * writer->rows;    if ( !decreasing )    {      writer->line += writer->pitch * ( target->rows-1 );      writer->pitch = -writer->pitch;    }  }  static void  pfr_bitwriter_decode_bytes( PFR_BitWriter  writer,                              FT_Byte*       p,                              FT_Byte*       limit )  {    FT_Int    n, reload;    FT_Int    left = writer->width;    FT_Byte*  cur  = writer->line;    FT_UInt   mask = 0x80;    FT_UInt   val  = 0;    FT_UInt   c    = 0;    n = (FT_Int)( limit - p ) * 8;    if ( n > writer->total )      n = writer->total;    reload = n & 7;    for ( ; n > 0; n-- )    {      if ( ( n & 7 ) == reload )        val = *p++;      if ( val & 0x80 )        c |= mask;      val  <<= 1;      mask >>= 1;      if ( --left <= 0 )      {        cur[0] = (FT_Byte)c;        left   = writer->width;        mask   = 0x80;        writer->line += writer->pitch;        cur           = writer->line;        c             = 0;      }      else if ( mask == 0 )      {        cur[0] = (FT_Byte)c;        mask   = 0x80;        c      = 0;        cur ++;      }    }    if ( mask != 0x80 )      cur[0] = (FT_Byte)c;  }  static void  pfr_bitwriter_decode_rle1( PFR_BitWriter  writer,                             FT_Byte*       p,                             FT_Byte*       limit )  {    FT_Int    n, phase, count, counts[2], reload;    FT_Int    left = writer->width;    FT_Byte*  cur  = writer->line;    FT_UInt   mask = 0x80;    FT_UInt   c    = 0;    n = writer->total;    phase     = 1;    counts[0] = 0;    counts[1] = 0;    count     = 0;    reload    = 1;    for ( ; n > 0; n-- )    {      if ( reload )      {        do        {          if ( phase )          {            FT_Int  v;            if ( p >= limit )              break;            v         = *p++;            counts[0] = v >> 4;            counts[1] = v & 15;            phase     = 0;            count     = counts[0];          }          else          {            phase = 1;            count = counts[1];          }        } while ( count == 0 );      }      if ( phase )        c |= mask;      mask >>= 1;      if ( --left <= 0 )      {        cur[0] = (FT_Byte) c;        left   = writer->width;        mask   = 0x80;        writer->line += writer->pitch;        cur           = writer->line;        c             = 0;      }      else if ( mask == 0 )      {        cur[0] = (FT_Byte)c;        mask   = 0x80;        c      = 0;        cur ++;      }      reload = ( --count <= 0 );    }    if ( mask != 0x80 )      cur[0] = (FT_Byte) c;  }  static void  pfr_bitwriter_decode_rle2( PFR_BitWriter  writer,                             FT_Byte*       p,                             FT_Byte*       limit )  {    FT_Int    n, phase, count, reload;    FT_Int    left = writer->width;    FT_Byte*  cur  = writer->line;    FT_UInt   mask = 0x80;    FT_UInt   c    = 0;    n = writer->total;    phase  = 1;    count  = 0;    reload = 1;    for ( ; n > 0; n-- )    {      if ( reload )      {        do        {          if ( p >= limit )            break;          count = *p++;          phase = phase ^ 1;        } while ( count == 0 );      }      if ( phase )        c |= mask;      mask >>= 1;      if ( --left <= 0 )      {        cur[0] = (FT_Byte) c;        c      = 0;        mask   = 0x80;        left   = writer->width;        writer->line += writer->pitch;        cur           = writer->line;      }      else if ( mask == 0 )      {        cur[0] = (FT_Byte)c;        c      = 0;        mask   = 0x80;        cur ++;      }      reload = ( --count <= 0 );    }    if ( mask != 0x80 )      cur[0] = (FT_Byte) c;  }  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                  BITMAP DATA DECODING                         *****/  /*****                                                               *****/  /*************************************************************************/  /*************************************************************************/  static void  pfr_lookup_bitmap_data( FT_Byte*   base,                          FT_Byte*   limit,                          FT_UInt    count,                          FT_UInt    flags,                          FT_UInt    char_code,                          FT_ULong*  found_offset,                          FT_ULong*  found_size )  {    FT_UInt   left, right, char_len;    FT_Bool   two = FT_BOOL( flags & 1 );    FT_Byte*  buff;    char_len = 4;    if ( two )       char_len += 1;    if ( flags & 2 ) char_len += 1;    if ( flags & 4 ) char_len += 1;    left  = 0;    right = count;    while ( left < right )    {      FT_UInt  middle, code;      middle = ( left + right ) >> 1;      buff   = base + middle * char_len;      /* check that we are not outside of the table -- */      /* this is possible with broken fonts...         */      if ( buff + char_len > limit )        goto Fail;      if ( two )        code = PFR_NEXT_USHORT( buff );      else        code = PFR_NEXT_BYTE( buff );      if ( code == char_code )        goto Found_It;      if ( code < char_code )        left = middle;      else        right = middle;    }  Fail:    /* Not found */    *found_size   = 0;    *found_offset = 0;    return;  Found_It:    if ( flags & 2 )      *found_size = PFR_NEXT_USHORT( buff );    else      *found_size = PFR_NEXT_BYTE( buff );    if ( flags & 4 )      *found_offset = PFR_NEXT_ULONG( buff );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -