#include "img.h"
#include "varable.h"
Go to the source code of this file.
DLLSYM void bias_sub_image | ( | IMAGE * | source, | |
INT32 | xstart, | |||
INT32 | ystart, | |||
INT32 | xext, | |||
INT32 | yext, | |||
UINT8 | bias | |||
) |
Add a constant/bias to a portion of an image.
Definition at line 805 of file imgs.cpp.
References IMAGE::check_legal_access(), IMAGE::fast_get_line(), IMAGE::fast_put_line(), IMAGE::get_bpp(), IMAGE::get_xsize(), IMAGE::get_ysize(), and IMAGELINE::pixels.
00812 { 00813 IMAGELINE copyline; //copy of line 00814 UINT8 *copy; //source pointer 00815 INT32 pixel; //pixel index 00816 INT32 y; //line index 00817 UINT8 bytespp; //bytes per pixel 00818 00819 if (xstart < 0 || ystart < 0) 00820 return; 00821 if (xext <= 0) 00822 xext = source->get_xsize (); //default to all 00823 if (xext > source->get_xsize () - xstart) 00824 //clip to smallest 00825 xext = source->get_xsize () - xstart; 00826 if (yext <= 0) 00827 yext = source->get_ysize (); //default to all 00828 if (yext > source->get_ysize () - ystart) 00829 //clip to smallest 00830 yext = source->get_ysize () - ystart; 00831 if (xext <= 0 || yext <= 0) 00832 return; //nothing to do 00833 00834 bytespp = source->get_bpp () == 24 ? 3 : 1; 00835 for (y = 0; y < yext; y++) { 00836 source->check_legal_access (xstart, ystart + y, xext); 00837 source->fast_get_line (xstart, ystart + y, xext, ©line); 00838 for (pixel = xext * bytespp, copy = copyline.pixels; pixel > 0; 00839 pixel--, copy++) 00840 *copy += bias; //add bias 00841 00842 source->fast_put_line (xstart, ystart + y, xext, ©line); 00843 } 00844 }
Check that the supplied image sizes are legal.
Definition at line 219 of file imgs.cpp.
References BADBPP, BADIMAGESIZE, COMPUTE_IMAGE_XDIM, ERRCODE::error(), and LOG.
Referenced by IMAGE::capture(), IMAGE::create(), and main().
00223 { 00224 if (x <= 0 || y <= 0) { 00225 BADIMAGESIZE.error ("check_legal_image_size", LOG, "(%d,%d)", x, y); 00226 return -1; //failed 00227 } 00228 if (bits_per_pixel != 1 && bits_per_pixel != 2 00229 && bits_per_pixel != 4 && bits_per_pixel != 5 00230 && bits_per_pixel != 6 && bits_per_pixel != 8 && bits_per_pixel != 24) { 00231 BADBPP.error ("check_legal_image_size", LOG, "%d", bits_per_pixel); 00232 return -1; 00233 } 00234 //bytes per line 00235 return COMPUTE_IMAGE_XDIM (x, bits_per_pixel); 00236 }
DLLSYM void copy_sub_image | ( | IMAGE * | source, | |
INT32 | xstart, | |||
INT32 | ystart, | |||
INT32 | xext, | |||
INT32 | yext, | |||
IMAGE * | dest, | |||
INT32 | xdest, | |||
INT32 | ydest, | |||
BOOL8 | adjust_grey | |||
) |
Copy a portion of one image to a portion of another image.
If the bpps are different, the position of the most significant bit is preserved.
Definition at line 245 of file imgs.cpp.
References IMAGE::bpp, IMAGE::bps, IMAGE::check_legal_access(), COMPUTE_IMAGE_XDIM, IMAGE::fast_get_line(), IMAGE::get_line(), IMAGE::image, IMAGELINE::pixels, IMAGE::put_line(), IMAGE::xdim, IMAGE::xsize, IMAGE::ymax, and IMAGE::ysize.
Referenced by TessBaseAPI::CopyBinaryRect(), def_show_sub_image(), and scale_image_cop_out().
00255 { 00256 IMAGELINE copyline; //copy of line 00257 UINT8 *copy; //source pointer 00258 INT8 shift; //shift factor 00259 INT32 pixel; //pixel index 00260 INT32 y; //line index 00261 INT32 yoffset; //current adjusted offset 00262 INT32 bytesize; //no of bytes to copy 00263 INT32 srcppb; //pixels per byte 00264 BOOL8 aligned; 00265 00266 if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0) 00267 return; 00268 if (xext <= 0) 00269 xext = source->xsize; //default to all 00270 if (xext > source->xsize - xstart) 00271 //clip to smallest 00272 xext = source->xsize - xstart; 00273 if (xext > dest->xsize - xdest) 00274 xext = dest->xsize - xdest; 00275 if (yext <= 0) 00276 yext = source->ysize; //default to all 00277 if (yext > source->ysize - ystart) 00278 //clip to smallest 00279 yext = source->ysize - ystart; 00280 if (yext > dest->ysize - ydest) 00281 yext = dest->ysize - ydest; 00282 if (xext <= 0 || yext <= 0) 00283 return; //nothing to do 00284 00285 srcppb = 8 / source->bpp; //pixels per byte 00286 if (source->bpp == dest->bpp || !adjust_grey) 00287 shift = 0; //no adjustment 00288 else { 00289 shift = source->bps - dest->bps; 00290 if (shift < 0) 00291 shift = -shift; //keep positive 00292 } 00293 aligned = source->bpp == dest->bpp; 00294 if (aligned && srcppb != 0) { 00295 aligned = xstart % srcppb == 0 00296 && xdest % srcppb == 0 00297 && (xext % srcppb == 0 || xdest + xext == dest->xsize); 00298 } 00299 for (y = 0; y < yext; y++) { 00300 if (ystart >= ydest) 00301 yoffset = y; //top down 00302 else 00303 yoffset = yext - y - 1; //bottom up 00304 source->check_legal_access (xstart, ystart + yoffset, xext); 00305 dest->check_legal_access (xdest, ydest + yoffset, xext); 00306 if (aligned) { 00307 bytesize = COMPUTE_IMAGE_XDIM (xext, source->bpp); 00308 //get bytes per line 00309 if (srcppb == 0) 00310 //do cheap move 00311 memmove (dest->image + (dest->ymax - 1 - ydest - yoffset) 00312 * dest->xdim + xdest * 3, source->image 00313 + (source->ymax - 1 - ystart - yoffset) 00314 * source->xdim + xstart * 3, (unsigned) bytesize); 00315 else 00316 //do cheap move 00317 memmove (dest->image 00318 + (dest->ymax - 1 - ydest - yoffset) 00319 * dest->xdim + xdest / srcppb, source->image 00320 + (source->ymax - 1 - ystart - yoffset) 00321 * source->xdim + xstart / srcppb, (unsigned) bytesize); 00322 } 00323 else { 00324 if (shift == 0) { 00325 source->fast_get_line (xstart, ystart + yoffset, xext, 00326 ©line); 00327 } 00328 else if (source->bpp < dest->bpp) { 00329 source->get_line (xstart, ystart + yoffset, xext, ©line, 0); 00330 if (source->bpp <= shift 00331 && (source->bpp == 1 || source->bpp == 4)) { 00332 if (source->bpp == 1) { 00333 for (pixel = 0, copy = copyline.pixels; pixel < xext; 00334 pixel++, copy++) 00335 if (*copy) 00336 *copy = 0xff; 00337 } 00338 else { 00339 for (pixel = 0, copy = copyline.pixels; pixel < xext; 00340 pixel++, copy++) 00341 //scale up 00342 *copy = (*copy << shift) | *copy; 00343 } 00344 } 00345 else { 00346 for (pixel = 0, copy = copyline.pixels; pixel < xext; 00347 pixel++) 00348 *copy++ <<= shift; //scale up 00349 } 00350 } 00351 else { 00352 source->get_line (xstart, ystart + yoffset, xext, ©line, 0); 00353 if (source->bpp == 24) { 00354 for (pixel = 0, copy = copyline.pixels + 1; pixel < xext; 00355 pixel++) { 00356 *copy >>= shift; 00357 copy += 3; 00358 } 00359 } 00360 else { 00361 for (pixel = 0, copy = copyline.pixels; pixel < xext; 00362 pixel++) 00363 *copy++ >>= shift; //scale down 00364 } 00365 } 00366 dest->put_line (xdest, ydest + yoffset, xext, ©line, 0); 00367 } 00368 } 00369 }
DLLSYM void enlarge_sub_image | ( | IMAGE * | source, | |
INT32 | xstart, | |||
INT32 | ystart, | |||
IMAGE * | dest, | |||
INT32 | xdest, | |||
INT32 | ydest, | |||
INT32 | xext, | |||
INT32 | yext, | |||
INT32 | scale, | |||
BOOL8 | adjust_grey | |||
) |
Enlarge rectangle
Enlarge a portion of one image to a portion of another image. If the bpps are different, the position of the most significant bit is preserved.
Definition at line 379 of file imgs.cpp.
References IMAGE::bpp, IMAGELINE::bpp, IMAGE::bps, IMAGE::bytespp, IMAGE::check_legal_access(), IMAGE::fast_get_line(), IMAGELINE::init(), IMAGELINE::pixels, IMAGE::put_line(), IMAGE::xsize, and IMAGE::ysize.
Referenced by scale_image_cop_out().
00390 { 00391 INT8 shift; //shift factor 00392 UINT8 pixel; //current pixel 00393 INT32 srcext; //source extent 00394 INT32 xoffset; //column index 00395 INT32 yoffset; //line index 00396 INT32 xindex, yindex; //index in super pixel 00397 INT32 startxindex; //initial x index 00398 INT32 xscale; //x scale factor 00399 UINT8 *src; //source pixels 00400 UINT8 *destpix; //dest pixels 00401 IMAGELINE copyline; //copy of line 00402 IMAGELINE bigline; //expanded line 00403 00404 if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0) 00405 return; 00406 00407 if (xext <= 0) 00408 xext = dest->xsize; //default to all 00409 if (xext > source->xsize * scale - xstart) 00410 //clip to smallest 00411 xext = source->xsize * scale - xstart; 00412 if (xext > dest->xsize - xdest) 00413 xext = dest->xsize - xdest; 00414 if (yext <= 0) 00415 yext = dest->ysize; //default to all 00416 if (yext > source->ysize * scale - ystart) 00417 yext = source->ysize * scale - ystart; 00418 if (yext > dest->ysize - ydest) 00419 yext = dest->ysize - ydest; 00420 if (xext <= 0 || yext <= 0) 00421 return; //nothing to do 00422 00423 xindex = xstart % scale; //offset in super pixel 00424 startxindex = xindex; 00425 yindex = ystart % scale; 00426 //no of source pixels 00427 srcext = (xext + xindex + scale - 1) / scale; 00428 xstart /= scale; //actual start 00429 ystart /= scale; 00430 if (adjust_grey) { 00431 shift = dest->bps - source->bps; 00432 } 00433 else 00434 shift = 0; //no adjustment 00435 bigline.init (xext * 3); 00436 bigline.bpp = dest->bpp == 24 ? source->bpp : dest->bpp; 00437 00438 for (yoffset = 0; yoffset < yext; ystart++) { 00439 source->check_legal_access (xstart, ystart, srcext); 00440 dest->check_legal_access (xdest, ydest + yoffset, xext); 00441 source->fast_get_line (xstart, ystart, srcext, ©line); 00442 src = copyline.pixels; 00443 destpix = bigline.pixels; 00444 xscale = scale; //enlargement factor 00445 if (source->bpp == 24 && dest->bpp == 24) { 00446 for (xoffset = 0, xindex = startxindex; xoffset < xext; 00447 src += source->bytespp) { 00448 xoffset += xscale - xindex; 00449 if (xoffset > xext) 00450 xscale -= xoffset - xext; 00451 for (; xindex < xscale; xindex++) { 00452 *destpix++ = *src; 00453 *destpix++ = *(src + 1); 00454 *destpix++ = *(src + 2); 00455 } 00456 xindex = 0; 00457 } 00458 } 00459 else { 00460 if (source->bpp == 24) 00461 src++; 00462 for (xoffset = 0, xindex = startxindex; xoffset < xext; 00463 src += source->bytespp) { 00464 xoffset += xscale - xindex; 00465 if (xoffset > xext) 00466 //clip to dest limit 00467 xscale -= xoffset - xext; 00468 if (shift == 0) 00469 pixel = *src; 00470 else if (shift > 0) 00471 pixel = *src << shift; 00472 else 00473 pixel = *src >> (-shift); 00474 for (; xindex < xscale; xindex++) 00475 *destpix++ = pixel; //duplicate pixel 00476 xindex = 0; 00477 } 00478 } 00479 for (; yoffset < yext && yindex < scale; yindex++, yoffset++) { 00480 dest->put_line (xdest, ydest + yoffset, xext, &bigline, 0); 00481 } 00482 yindex = 0; 00483 } 00484 }
DLLSYM void fast_reduce_sub_image | ( | IMAGE * | source, | |
INT32 | xstart, | |||
INT32 | ystart, | |||
INT32 | xext, | |||
INT32 | yext, | |||
IMAGE * | dest, | |||
INT32 | xdest, | |||
INT32 | ydest, | |||
INT32 | scale, | |||
BOOL8 | adjust_grey | |||
) |
Reduce a portion of one image to a portion of another image.
If the bpps are different, the position of the most significant bit is preserved.
This is a fast but dirty version, which simply sub-samples. It does not smooth as it reduces.
Definition at line 496 of file imgs.cpp.
References IMAGELINE::bpp, IMAGE::bpp, IMAGE::bps, IMAGE::bytespp, IMAGE::check_legal_access(), IMAGE::fast_get_line(), IMAGELINE::init(), IMAGELINE::pixels, IMAGE::put_line(), IMAGE::xsize, and IMAGE::ysize.
00507 { 00508 INT8 shift; //shift factor 00509 INT32 xfactor; //run on x coord 00510 INT32 divisor; //total cell area 00511 INT32 xindex, yindex; //into averaging square 00512 INT32 xcoord; //current x coord 00513 INT32 destext; //destination size 00514 INT32 yoffset; //current adjusted offset 00515 UINT8 *pixel; //ptr to source pixels 00516 INT32 *sums; //ptr to sums array 00517 IMAGELINE copyline; //copy of line 00518 INT32 *linesums; //averaging sums 00519 00520 if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0) 00521 return; 00522 if (xext <= 0) 00523 xext = source->xsize; //default to all 00524 if (xext > source->xsize - xstart) 00525 //clip to smallest 00526 xext = source->xsize - xstart; 00527 if (xext > (dest->xsize - xdest) * scale) 00528 xext = (dest->xsize - xdest) * scale; 00529 if (yext <= 0) 00530 yext = source->ysize; //default to all 00531 if (yext > source->ysize - ystart) 00532 //clip to smallest 00533 yext = source->ysize - ystart; 00534 if (yext > (dest->ysize - ydest) * scale) 00535 yext = (dest->ysize - ydest) * scale; 00536 if (xext <= 0 || yext <= 0) 00537 return; //nothing to do 00538 00539 xfactor = xext % scale; //left overs 00540 if (xfactor == 0) 00541 xfactor = scale; 00542 //destination pixels 00543 destext = (xext + scale - 1) / scale; 00544 if (adjust_grey) 00545 //shift factor 00546 shift = dest->bps - source->bps; 00547 else 00548 shift = 0; //no adjustment 00549 linesums = new INT32[destext * source->bytespp]; 00550 00551 for (yoffset = 0; yoffset < yext; ydest++) { 00552 source->check_legal_access (xstart, ystart + yoffset, xext); 00553 dest->check_legal_access (xdest, ydest, destext); 00554 for (xindex = destext * source->bytespp - 1; xindex >= 0; xindex--) 00555 linesums[xindex] = 0; //zero sums 00556 for (yindex = 0; yindex < scale 00557 && ystart + yoffset < source->ysize; yindex += 3) { 00558 source->fast_get_line (xstart, ystart + yoffset, xext, ©line); 00559 pixel = copyline.pixels; //start of line 00560 if (source->bpp == 24) { 00561 for (xcoord = 1, sums = linesums; xcoord < destext; 00562 xcoord++, sums += 3) { 00563 for (xindex = 0; xindex < scale; xindex += 2) { 00564 *sums += *pixel++; 00565 *(sums + 1) += *pixel++; 00566 *(sums + 2) += *pixel++; 00567 pixel += 3; 00568 } 00569 if (scale & 1) 00570 pixel -= 3; //correct position 00571 } 00572 for (xindex = 0; xindex < xfactor; xindex += 2) { 00573 *sums += *pixel++; 00574 *(sums + 1) += *pixel++; 00575 *(sums + 2) += *pixel++; 00576 pixel += 3; 00577 } 00578 } 00579 else { 00580 for (xcoord = 1, sums = linesums; xcoord < destext; 00581 xcoord++, sums++) { 00582 for (xindex = 0; xindex < scale; xindex += 2) { 00583 *sums += *pixel; 00584 pixel += 2; 00585 } 00586 if (scale & 1) 00587 pixel--; //correct position 00588 } 00589 for (xindex = 0; xindex < xfactor; xindex += 2) { 00590 *sums += *pixel; 00591 pixel += 2; 00592 } 00593 } 00594 yoffset += 3; //every 3 lines 00595 } 00596 if (yindex > scale) 00597 yoffset -= yindex - scale; //back on right scale 00598 copyline.init (); //set pixels back to array 00599 copyline.bpp = source->bpp; 00600 pixel = copyline.pixels; 00601 //pixels in block 00602 divisor = ((yindex + 2) / 3) * ((scale + 1) / 2); 00603 if (shift <= 0) { 00604 divisor <<= (-shift); //do greyscale correction 00605 for (sums = linesums, xindex = (destext - 1) * source->bytespp; 00606 xindex > 0; xindex--) 00607 //turn to destination value 00608 *pixel++ = (UINT8) (*sums++ / divisor); 00609 for (xindex = source->bytespp; xindex > 0; xindex--) 00610 *pixel++ = *sums++ 00611 / (((yindex + 2) / 3) * ((xfactor + 1) / 2) << (-shift)); 00612 //lastone different 00613 } 00614 else { 00615 for (sums = linesums, xindex = (destext - 1) * source->bytespp; 00616 xindex > 0; xindex--) 00617 *pixel++ = (UINT8) ((*sums++ << shift) / divisor); 00618 //destination value 00619 for (xindex = source->bytespp; xindex > 0; xindex--) 00620 //last one different 00621 *pixel++ = (*(sums++) << shift) / 00622 (((yindex + 2) / 3) * ((xfactor + 1) / 2)); 00623 } 00624 //put in destination 00625 dest->put_line (xdest, ydest, destext, ©line, 0); 00626 } 00627 delete linesums; 00628 }
DLLSYM void invert_image | ( | IMAGE * | image | ) |
Invert the given image (the slow way.)
Definition at line 773 of file imgs.cpp.
References IMAGE::fast_get_line(), IMAGE::fast_put_line(), IMAGE::get_bpp(), IMAGE::get_xsize(), IMAGE::get_ysize(), and IMAGELINE::pixels.
Referenced by clip_sample(), and edges_and_textord().
00775 { 00776 UINT8 mask; //bit mask 00777 UINT8 bytespp; //bytes per pixel 00778 INT32 xsize, ysize; /*size of image */ 00779 INT32 xindex, yindex; /*index into image */ 00780 UINT8 *pixel; /*current pixel */ 00781 IMAGELINE line; /*line of image */ 00782 00783 bytespp = image->get_bpp () == 24 ? 3 : 1; 00784 xsize = image->get_xsize (); /*find sizes */ 00785 ysize = image->get_ysize (); 00786 //pixel mask 00787 mask = (1 << image->get_bpp ()) - 1; 00788 /*do each line */ 00789 for (yindex = ysize - 1; yindex >= 0; yindex--) { 00790 image->fast_get_line (0, yindex, xsize, &line); 00791 for (pixel = line.pixels, xindex = xsize * bytespp; xindex > 0; 00792 xindex--) { 00793 *pixel = (*pixel) ^ mask; //invert image only 00794 ++pixel; 00795 } 00796 /*put it back */ 00797 image->fast_put_line (0, yindex, xsize, &line); 00798 } 00799 }
DLLSYM void reduce_sub_image | ( | IMAGE * | source, | |
INT32 | xstart, | |||
INT32 | ystart, | |||
INT32 | xext, | |||
INT32 | yext, | |||
IMAGE * | dest, | |||
INT32 | xdest, | |||
INT32 | ydest, | |||
INT32 | scale, | |||
BOOL8 | adjust_grey | |||
) |
Reduce a portion of one image to a portion of another image.
If the bpps are different, the position of the most significant bit is preserved.
Definition at line 637 of file imgs.cpp.
References IMAGE::bpp, IMAGE::bps, IMAGE::bytespp, IMAGE::check_legal_access(), IMAGE::fast_get_line(), IMAGELINE::init(), IMAGELINE::pixels, IMAGE::put_line(), IMAGELINE::set_bpp(), tprintf(), IMAGE::xsize, and IMAGE::ysize.
Referenced by scale_image_cop_out().
00648 { 00649 INT8 shift; //shift factor 00650 INT32 xfactor; //run on x coord 00651 INT32 divisor; //total cell area 00652 INT32 div2; //total cell area divided by 2 00653 INT32 xindex, yindex; //into averaging square 00654 INT32 xcoord; //current x coord 00655 INT32 destext; //destination size 00656 INT32 yoffset; //current adjusted offset 00657 UINT8 *pixel; //ptr to source pixels 00658 INT32 *sums; //ptr to sums array 00659 IMAGELINE copyline; //copy of line 00660 INT32 *linesums; //averaging sums 00661 00662 if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0) 00663 return; 00664 if (xext <= 0) 00665 xext = source->xsize; //default to all 00666 if (xext > source->xsize - xstart) 00667 //clip to smallest 00668 xext = source->xsize - xstart; 00669 if (xext > (dest->xsize - xdest) * scale) 00670 xext = (dest->xsize - xdest) * scale; 00671 if (yext <= 0) 00672 yext = source->ysize; //default to all 00673 if (yext > source->ysize - ystart) 00674 //clip to smallest 00675 yext = source->ysize - ystart; 00676 if (yext > (dest->ysize - ydest) * scale) 00677 yext = (dest->ysize - ydest) * scale; 00678 if (xext <= 0 || yext <= 0) 00679 return; //nothing to do 00680 00681 xfactor = xext % scale; //left overs 00682 if (xfactor == 0) 00683 xfactor = scale; 00684 //destination pixels 00685 destext = (xext + scale - 1) / scale; 00686 if (adjust_grey) 00687 //shift factor 00688 shift = dest->bps - source->bps; 00689 else 00690 shift = 0; //no adjustment 00691 linesums = new INT32[destext * source->bytespp]; 00692 00693 for (yoffset = 0; yoffset < yext; ydest++) { 00694 source->check_legal_access (xstart, ystart + yoffset, xext); 00695 dest->check_legal_access (xdest, ydest, destext); 00696 for (xindex = 0; xindex < (destext) * source->bytespp; xindex++) 00697 linesums[xindex] = 0; //zero sums 00698 for (yindex = 0; yindex < scale && ystart + yoffset < source->ysize; 00699 yindex++) { 00700 source->fast_get_line (xstart, ystart + yoffset, xext, ©line); 00701 pixel = copyline.pixels; //start of line 00702 if (source->bpp == 24) { 00703 for (xcoord = 1, sums = linesums; xcoord < destext; 00704 xcoord++, sums += 3) { 00705 for (xindex = 0; xindex < scale; xindex++) { 00706 *sums += *pixel++; 00707 *(sums + 1) += *pixel++; 00708 *(sums + 2) += *pixel++; 00709 } 00710 } 00711 for (xindex = 0; xindex < xfactor; xindex++) { 00712 *sums += *pixel++; 00713 *(sums + 1) += *pixel++; 00714 *(sums + 2) += *pixel++; 00715 } 00716 } 00717 else { 00718 for (xcoord = 1, sums = linesums; xcoord < destext; 00719 xcoord++, sums++) { 00720 for (xindex = 0; xindex < scale; xindex++) 00721 *sums += *pixel++; 00722 } 00723 for (xindex = 0; xindex < xfactor; xindex++) 00724 *sums += *pixel++; 00725 } 00726 yoffset++; //next line 00727 } 00728 copyline.init (); //set pixels back to array 00729 copyline.set_bpp (source->bpp); 00730 pixel = copyline.pixels; 00731 divisor = yindex * scale; 00732 if (divisor == 0) { 00733 tprintf 00734 ("Impossible:divisor=0!, yindex=%d, scale=%d, yoffset=%d,yext=%d\n", 00735 yindex, scale, yoffset, yext); 00736 break; 00737 } 00738 if (shift <= 0) { 00739 divisor <<= (-shift); //do greyscale correction 00740 div2 = divisor / 2; 00741 for (sums = linesums, xindex = (destext - 1) * source->bytespp; 00742 xindex > 0; xindex--) 00743 *pixel++ = (UINT8) ((div2 + *sums++) / divisor); 00744 //turn to destination value 00745 div2 = (yindex * xfactor << (-shift)) / 2; 00746 for (xindex = source->bytespp; xindex > 0; xindex--) 00747 *pixel++ = 00748 (UINT8) ((div2 + *sums++) / (yindex * xfactor << (-shift))); 00749 //lastone different 00750 } 00751 else { 00752 div2 = divisor / 2; 00753 for (sums = linesums, xindex = (destext - 1) * source->bytespp; 00754 xindex > 0; xindex--) 00755 *pixel++ = (UINT8) ((div2 + (*sums++ << shift)) / divisor); 00756 //destination value 00757 div2 = (yindex * xfactor) / 2; 00758 for (xindex = source->bytespp; xindex > 0; xindex--) 00759 *pixel++ = 00760 (UINT8) ((div2 + (*sums++ << shift)) / (yindex * xfactor)); 00761 //last one different 00762 } 00763 //put in destination 00764 dest->put_line (xdest, ydest, destext, ©line, 0); 00765 } 00766 delete linesums; 00767 }
DLLSYM void starbase_to_normal | ( | IMAGE * | source, | |
INT32 | xstart, | |||
INT32 | ystart, | |||
INT32 | xext, | |||
INT32 | yext, | |||
IMAGE * | dest, | |||
INT32 | xdest, | |||
INT32 | ydest, | |||
BOOL8 | preserve_grey | |||
) |
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.
Definition at line 853 of file imgs.cpp.
References BLACK_PIX, IMAGE::check_legal_access(), FIXED_COLOURS, IMAGE::get_bpp(), IMAGE::get_line(), IMAGE::get_white_level(), IMAGE::get_xsize(), IMAGE::get_ysize(), grey_scales, MAX_4BIT, MAX_6BIT, MIN_4BIT, MIN_6BIT, IMAGELINE::pixels, and IMAGE::put_line().
00863 { 00864 IMAGELINE copyline; //copy of line 00865 UINT8 *copy; //source pointer 00866 INT8 shift4; //shift factor 00867 INT8 shift6; //shift factor 00868 INT8 colour_shift; //shift of colours 00869 UINT8 white_level; //dest white value 00870 INT32 pixel; //pixel index 00871 INT32 y; //line index 00872 INT32 yoffset; //current adjusted offset 00873 INT8 srcppb; //pixels per byte 00874 00875 if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0) 00876 return; 00877 if (xext <= 0) 00878 xext = source->get_xsize (); //default to all 00879 if (xext > source->get_xsize () - xstart) 00880 //clip to smallest 00881 xext = source->get_xsize () - xstart; 00882 if (xext > dest->get_xsize () - xdest) 00883 xext = dest->get_xsize () - xdest; 00884 if (yext <= 0) 00885 yext = source->get_ysize (); //default to all 00886 if (yext > source->get_ysize () - ystart) 00887 //clip to smallest 00888 yext = source->get_ysize () - ystart; 00889 if (yext > dest->get_ysize () - ydest) 00890 yext = dest->get_ysize () - ydest; 00891 if (xext <= 0 || yext <= 0) 00892 return; //nothing to do 00893 00894 //pixels per byte 00895 srcppb = 8 / source->get_bpp (); 00896 shift4 = 4 - dest->get_bpp (); //for different bpps 00897 shift6 = 6 - dest->get_bpp (); 00898 //for grey preserve 00899 colour_shift = 8 - dest->get_bpp (); 00900 white_level = dest->get_white_level (); 00901 for (y = 0; y < yext; y++) { 00902 if (ystart >= ydest) 00903 yoffset = y; //top down 00904 else 00905 yoffset = yext - y - 1; //bottom up 00906 source->check_legal_access (xstart, ystart + yoffset, xext); 00907 dest->check_legal_access (xdest, ydest + yoffset, xext); 00908 source->get_line (xstart, ystart + yoffset, xext, ©line, 0); 00909 for (pixel = 0, copy = copyline.pixels; pixel < xext; pixel++) { 00910 if (*copy < FIXED_COLOURS && preserve_grey) 00911 *copy = grey_scales[*copy] >> colour_shift; 00912 else if (*copy < FIXED_COLOURS) { 00913 if (*copy == BLACK_PIX) 00914 *copy = white_level; //black->white 00915 else 00916 *copy = 0; //others->black 00917 } 00918 else if (*copy >= MIN_4BIT && *copy < MAX_4BIT) { 00919 if (shift4 < 0) 00920 *copy = (*copy - MIN_4BIT) << (-shift4); 00921 else 00922 *copy = (*copy - MIN_4BIT) >> shift4; 00923 } 00924 else if (*copy >= MIN_6BIT && *copy < MAX_6BIT) { 00925 if (shift6 < 0) 00926 *copy = (*copy - MIN_6BIT) << (-shift6); 00927 else 00928 *copy = (*copy - MIN_6BIT) >> shift6; 00929 } 00930 else { 00931 *copy = white_level; //white the rest 00932 } 00933 copy++; 00934 } 00935 dest->put_line (xdest, ydest + yoffset, xext, ©line, 0); 00936 } 00937 }