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

📄 imgs.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}/********************************************************************** * bias_sub_image * * Add a constant to a portion of an image. **********************************************************************/DLLSYM void bias_sub_image(                //bias rectangle                           IMAGE *source,  //source image                           INT32 xstart,   //start coords                           INT32 ystart,                           INT32 xext,     //extent to copy                           INT32 yext,                           UINT8 bias      //number to add                          ) {  IMAGELINE copyline;            //copy of line  UINT8 *copy;                   //source pointer  INT32 pixel;                   //pixel index  INT32 y;                       //line index  UINT8 bytespp;                 //bytes per pixel  if (xstart < 0 || ystart < 0)    return;  if (xext <= 0)    xext = source->get_xsize (); //default to all  if (xext > source->get_xsize () - xstart)                                 //clip to smallest    xext = source->get_xsize () - xstart;  if (yext <= 0)    yext = source->get_ysize (); //default to all  if (yext > source->get_ysize () - ystart)                                 //clip to smallest    yext = source->get_ysize () - ystart;  if (xext <= 0 || yext <= 0)    return;                      //nothing to do  bytespp = source->get_bpp () == 24 ? 3 : 1;  for (y = 0; y < yext; y++) {    source->check_legal_access (xstart, ystart + y, xext);    source->fast_get_line (xstart, ystart + y, xext, &copyline);    for (pixel = xext * bytespp, copy = copyline.pixels; pixel > 0;      pixel--, copy++)    *copy += bias;               //add bias    source->fast_put_line (xstart, ystart + y, xext, &copyline);  }}/********************************************************************** * starbase_to_normal * * Copy a portion of one image to a portion of another image. * This function maps the colour tables used on the screen to * greyscale values in the way "normally" expected. **********************************************************************/DLLSYM void starbase_to_normal(                     //copy rectangle                               IMAGE *source,       //source image                               INT32 xstart,        //start coords                               INT32 ystart,                               INT32 xext,          //extent to copy                               INT32 yext,                               IMAGE *dest,         //destination image                               INT32 xdest,         //destination coords                               INT32 ydest,                               BOOL8 preserve_grey  //shift to new bpp                              ) {  IMAGELINE copyline;            //copy of line  UINT8 *copy;                   //source pointer  INT8 shift4;                   //shift factor  INT8 shift6;                   //shift factor  INT8 colour_shift;             //shift of colours  UINT8 white_level;             //dest white value  INT32 pixel;                   //pixel index  INT32 y;                       //line index  INT32 yoffset;                 //current adjusted offset  INT8 srcppb;                   //pixels per byte  if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)    return;  if (xext <= 0)    xext = source->get_xsize (); //default to all  if (xext > source->get_xsize () - xstart)                                 //clip to smallest    xext = source->get_xsize () - xstart;  if (xext > dest->get_xsize () - xdest)    xext = dest->get_xsize () - xdest;  if (yext <= 0)    yext = source->get_ysize (); //default to all  if (yext > source->get_ysize () - ystart)                                 //clip to smallest    yext = source->get_ysize () - ystart;  if (yext > dest->get_ysize () - ydest)    yext = dest->get_ysize () - ydest;  if (xext <= 0 || yext <= 0)    return;                      //nothing to do                                 //pixels per byte  srcppb = 8 / source->get_bpp ();  shift4 = 4 - dest->get_bpp (); //for different bpps  shift6 = 6 - dest->get_bpp ();                                 //for grey preserve  colour_shift = 8 - dest->get_bpp ();  white_level = dest->get_white_level ();  for (y = 0; y < yext; y++) {    if (ystart >= ydest)      yoffset = y;               //top down    else      yoffset = yext - y - 1;    //bottom up    source->check_legal_access (xstart, ystart + yoffset, xext);    dest->check_legal_access (xdest, ydest + yoffset, xext);    source->get_line (xstart, ystart + yoffset, xext, &copyline, 0);    for (pixel = 0, copy = copyline.pixels; pixel < xext; pixel++) {      if (*copy < FIXED_COLOURS && preserve_grey)        *copy = grey_scales[*copy] >> colour_shift;      else if (*copy < FIXED_COLOURS) {        if (*copy == BLACK_PIX)          *copy = white_level;   //black->white        else          *copy = 0;             //others->black      }      else if (*copy >= MIN_4BIT && *copy < MAX_4BIT) {        if (shift4 < 0)          *copy = (*copy - MIN_4BIT) << (-shift4);        else          *copy = (*copy - MIN_4BIT) >> shift4;      }      else if (*copy >= MIN_6BIT && *copy < MAX_6BIT) {        if (shift6 < 0)          *copy = (*copy - MIN_6BIT) << (-shift6);        else          *copy = (*copy - MIN_6BIT) >> shift6;      }      else {        *copy = white_level;     //white the rest      }      copy++;    }    dest->put_line (xdest, ydest + yoffset, xext, &copyline, 0);  }}/********************************************************************** * fast_get_line * * Get a line of image into the supplied image line buffer. * The image is converted to 8bpp by simple assignment. * If the image is aleady 8 or 6bpp, no copy is done and a pointer * to the correct image section is put in the line buffer. **********************************************************************/void IMAGE::fast_get_line(                    //get image line                          INT32 x,            //coord to start at                          INT32 y,            //line to get                          INT32 width,        //no of pixels to get                          IMAGELINE *linebuf  //line to copy to                         ) {  if (width > 0 && bpp > 4) {    check_legal_access(x, y, width);                                  //get pointer only    linebuf->pixels = image + xdim * (ymax - 1 - y) + x * bytespp;  }  else                                 //just copy it    this->get_line (x, y, width, linebuf, 0);  linebuf->bpp = bpp;}/********************************************************************** * get_line * * Get a line of image into the supplied image line buffer. * The image is converted to 8bpp by simple assignment. **********************************************************************/void IMAGE::get_line(                     //get image line                     INT32 x,             //coord to start at                     INT32 y,             //line to get                     INT32 width,         //no of pixels to get                     IMAGELINE *linebuf,  //line to copy to                     INT32 margins        //size of margins                    ) {  UINT8 *src;                    //source pointer  UINT8 *dest;                   //destination pointer  UINT8 *unpacksrc;              //unpacking pointer  INT8 bit;                      //bit index  INT8 pixperbyte;               //pixels per byte  UINT8 white;                   //white colour  INT32 pixel;                   //pixel index                                 //test coords  this->check_legal_access (x, y, width);  if (width > xsize - x)    width = xsize - x;           //clip to image  width *= bytespp;  linebuf->init (width + margins * bytespp * 2);  linebuf->bpp = bpp;                                 //start of line  src = image + xdim * (ymax - 1 - y);  dest = linebuf->line;          //destination line  linebuf->pixels = dest;  white = (1 << bpp) - 1;        //max value of pixel  for (pixel = margins * bytespp; pixel > 0; pixel--) {    *dest++ = white;             //margins are white  }  if (width > 0) {    if (bpp > 4) {      src += x;                  //offset                                 //easy way      memmove (dest, src, (unsigned) width);    }    else if (bpp == 4) {      src += x / 2;              //offset on line      if (x & 1) {                                 //get coded nibble        *dest++ = bpp4table[*src++][1];        width--;      }      while (width >= 2) {                                 //get coded bits        unpacksrc = bpp4table[*src++];        *dest++ = *unpacksrc++;        *dest++ = *unpacksrc++;  //copy nibbles        width -= 2;      }      if (width) {                                 //get coded nibble        *dest++ = bpp4table[*src++][0];      }    }    else if (bpp == 2) {      pixperbyte = 4;      src += x / 4;              //offset on line      bit = (INT8) (x % 4);      //offset in byte      width += bit;      while (width > 0) {        //until all done        if (width < pixperbyte)                                 //less on last byte          pixperbyte = (INT8) width;                                 //get coded bits        unpacksrc = &bpp2table[*src++][bit];        for (; bit < pixperbyte; bit++)          *dest++ = *unpacksrc++;//copy bytes        width -= pixperbyte;        bit = 0;      }    }    else {      pixperbyte = 8;      src += x / 8;              //offset on line      bit = (INT8) (x % 8);      //offset in byte      width += bit;      while (width > 0) {        //until all done        if (width < pixperbyte)                                 //less on last byte          pixperbyte = (INT8) width;                                 //get coded bits        unpacksrc = &bpp1table[*src++][bit];        for (; bit < pixperbyte; bit++)          *dest++ = *unpacksrc++;//copy bytes        width -= pixperbyte;        bit = 0;      }    }  }  for (pixel = margins * bytespp; pixel > 0; pixel--) {    *dest++ = white;             //margins are white  }}/********************************************************************** * get_column * * Get a column of image into the supplied image line buffer. * The image is converted to 8bpp by simple assignment. **********************************************************************/void IMAGE::get_column(                     //get image column                       INT32 x,             //coord to start at                       INT32 y,             //line to get                       INT32 height,        //no of pixels to get                       IMAGELINE *linebuf,  //line to copy to                       INT32 margins        //size of margins                      ) {  UINT8 *src;                    //source pointer  UINT8 *dest;                   //destination pointer  INT8 bit;                      //bit index  INT8 pixperbyte;               //pixels per byte  UINT8 white;                   //white colour  INT32 pixel;                   //pixel index                                 //test coords  this->check_legal_access (x, y, 1);                                 //test coords  this->check_legal_access (x, y + height - 1, 1);  if (height > ysize - y)    height = ysize - y;          //clip to image  linebuf->init (height * bytespp + margins * bytespp * 2);                                 //start of line  src = image + xdim * (ymax - 1 - y);  dest = linebuf->line;          //destination line  linebuf->pixels = dest;  white = (1 << bpp) - 1;        //max value of pixel  for (pixel = margins * bytespp; pixel > 0; pixel--) {    *dest++ = white;             //margins are white  }  if (height > 0) {    if (bpp == 24) {      src += x * bytespp;        //offset      for (; height > 0; --height) {        *dest++ = *src;          //copy bytes        *dest++ = *(src + 1);        *dest++ = *(src + 2);        src -= xdim;      }    }    else if (bpp > 4) {      src += x;      for (; height > 0; --height) {        *dest++ = *src;          //copy bytes        src -= xdim;      }    }    else if (bpp == 4) {      src += x / 2;              //offset on line      if (x & 1) {        for (; height > 0; --height) {                                 //get coded nibble          *dest++ = bpp4table[*src][1];          src -= xdim;        }      }      else {        for (; height > 0; --height) {                                 //get coded nibble          *dest++ = bpp4table[*src][0];          src -= xdim;        }      }    }    else if (bpp == 2) {      pixperbyte = 4;      src += x / 4;              //offset on line      bit = (INT8) (x % 4);      //offset in byte      for (; height > 0; --height) {                                 //get coded bits        *dest++ = bpp2table[*src][bit];        src -= xdim;      }    }    else {      pixperbyte = 8;      src += x / 8;              //offset on line      bit = (INT8) (x % 8);      //offset in byte      for (; height > 0; --height) {                                 //get coded bits        *dest++ = bpp1table[*src][bit];        src -= xdim;      }    }  }  for (pixel = margins * bytespp; pixel > 0; pixel--) {    *dest++ = white;             //margins are white  }}/********************************************************************** * fast_put_line * * Put a line buffer back into the image. * If the line buffer merely points back into the image, nothing is done. * Otherwise, put_line is used to copy the line back. **********************************************************************/void IMAGE::fast_put_line(                    //put image line                          INT32 x,            //coord to start at                          INT32 y,            //line to get                          INT32 width,        //no of pixels to put                          IMAGELINE *linebuf  //line to copy to                         ) {  if (width > 0 && (bpp <= 4 || linebuf->pixels == linebuf->line))                                 //just copy it    put_line (x, y, width, linebuf, 0);}/********************************************************************** * put_line * * Put the supplied line buffer into the image. * The image is converted from 8bpp by simple assignment. **********************************************************************/void IMAGE::put_line(                     //put image line                     INT32 x,             //coord to start at                     INT32 y,             //line to get                     INT32 width,         //no of pixels to get                     IMAGELINE *linebuf,  //line to copy to

⌨️ 快捷键说明

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