Leptonica 1.68
C Image Processing Library

paintcmap.c

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 /*
00017  *  paintcmap.c
00018  *
00019  *      These in-place functions paint onto colormap images.
00020  *
00021  *      Repaint selected pixels in region
00022  *           l_int32     pixSetSelectCmap()
00023  *
00024  *      Repaint non-white pixels in region
00025  *           l_int32     pixColorGrayCmap()
00026  *           l_int32     addColorizedGrayToCmap()
00027  *
00028  *      Repaint selected pixels through mask
00029  *           l_int32     pixSetSelectMaskedCmap()
00030  *
00031  *      Repaint all pixels through mask
00032  *           l_int32     pixSetMaskedCmap()
00033  *
00034  *
00035  *  The 'set select' functions condition the setting on a specific
00036  *  pixel value (i.e., index into the colormap) of the underyling
00037  *  Pix that is being modified.  The same conditioning is used in
00038  *  pixBlendCmap().
00039  *
00040  *  The pixColorGrayCmap() function sets all truly gray (r = g = b) pixels,
00041  *  with the exception of either black or white pixels, to a new color.
00042  *
00043  *  The pixSetSelectMaskedCmap() function conditions pixel painting
00044  *  on both a specific pixel value and location within the fg mask.
00045  *  By contrast, pixSetMaskedCmap() sets all pixels under the
00046  *  mask foreground, without considering the initial pixel values.
00047  */
00048 
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <string.h>
00052 #include "allheaders.h"
00053 
00054 
00055 /*-------------------------------------------------------------*
00056  *               Repaint selected pixels in region             *
00057  *-------------------------------------------------------------*/
00058 /*!
00059  *  pixSetSelectCmap()
00060  *
00061  *      Input:  pixs (1, 2, 4 or 8 bpp, with colormap)
00062  *              box (<optional> region to set color; can be NULL)
00063  *              sindex (colormap index of pixels to be changed)
00064  *              rval, gval, bval (new color to paint)
00065  *      Return: 0 if OK, 1 on error
00066  *
00067  *  Note:
00068  *      (1) This is an in-place operation.
00069  *      (2) It sets all pixels in region that have the color specified
00070  *          by the colormap index 'sindex' to the new color.
00071  *      (3) sindex must be in the existing colormap; otherwise an
00072  *          error is returned.
00073  *      (4) If the new color exists in the colormap, it is used;
00074  *          otherwise, it is added to the colormap.  If it cannot be
00075  *          added because the colormap is full, an error is returned.
00076  *      (5) If box is NULL, applies function to the entire image; otherwise,
00077  *          clips the operation to the intersection of the box and pix.
00078  *      (6) An example of use would be to set to a specific color all
00079  *          the light (background) pixels within a certain region of
00080  *          a 3-level 2 bpp image, while leaving light pixels outside
00081  *          this region unchanged.
00082  */
00083 l_int32
00084 pixSetSelectCmap(PIX     *pixs,
00085                  BOX     *box,
00086                  l_int32  sindex,
00087                  l_int32  rval,
00088                  l_int32  gval,
00089                  l_int32  bval)
00090 {
00091 l_int32    i, j, w, h, d, n, x1, y1, x2, y2, bw, bh, val, wpls;
00092 l_int32    index;  /* of new color to be set */
00093 l_uint32  *lines, *datas;
00094 PIXCMAP   *cmap;
00095 
00096     PROCNAME("pixSetSelectCmap");
00097 
00098     if (!pixs)
00099         return ERROR_INT("pixs not defined", procName, 1);
00100     if ((cmap = pixGetColormap(pixs)) == NULL)
00101         return ERROR_INT("no colormap", procName, 1);
00102     d = pixGetDepth(pixs);
00103     if (d != 1 && d != 2 && d != 4 && d != 8)
00104         return ERROR_INT("depth not in {1,2,4,8}", procName, 1);
00105 
00106         /* Add new color if necessary; get index of this color in cmap */
00107     n = pixcmapGetCount(cmap);
00108     if (sindex >= n)
00109         return ERROR_INT("sindex too large; no cmap entry", procName, 1);
00110     if (pixcmapGetIndex(cmap, rval, gval, bval, &index)) { /* not found */
00111         if (pixcmapAddColor(cmap, rval, gval, bval))
00112             return ERROR_INT("error adding cmap entry", procName, 1);
00113         else
00114             index = n;  /* we've added one color */
00115     }
00116 
00117         /* Determine the region of substitution */
00118     pixGetDimensions(pixs, &w, &h, NULL);
00119     if (!box) {
00120         x1 = y1 = 0;
00121         x2 = w;
00122         y2 = h;
00123     }
00124     else {
00125         boxGetGeometry(box, &x1, &y1, &bw, &bh);
00126         x2 = x1 + bw - 1;
00127         y2 = y1 + bh - 1;
00128     }
00129 
00130         /* Replace pixel value sindex by index in the region */
00131     datas = pixGetData(pixs);
00132     wpls = pixGetWpl(pixs);
00133     for (i = y1; i <= y2; i++) {
00134         if (i < 0 || i >= h)  /* clip */
00135             continue;
00136         lines = datas + i * wpls;
00137         for (j = x1; j <= x2; j++) {
00138             if (j < 0 || j >= w)  /* clip */
00139                 continue;
00140             switch (d) {
00141             case 1:
00142                 val = GET_DATA_BIT(lines, j);
00143                 if (val == sindex) {
00144                     if (index == 0)
00145                         CLEAR_DATA_BIT(lines, j);
00146                     else
00147                         SET_DATA_BIT(lines, j);
00148                 }
00149                 break;
00150             case 2:
00151                 val = GET_DATA_DIBIT(lines, j);
00152                 if (val == sindex)
00153                     SET_DATA_DIBIT(lines, j, index);
00154                 break;
00155             case 4:
00156                 val = GET_DATA_QBIT(lines, j);
00157                 if (val == sindex)
00158                     SET_DATA_QBIT(lines, j, index);
00159                 break;
00160             case 8:
00161                 val = GET_DATA_BYTE(lines, j);
00162                 if (val == sindex)
00163                     SET_DATA_BYTE(lines, j, index);
00164                 break;
00165             default:
00166                 return ERROR_INT("depth not in {1,2,4,8}", procName, 1);
00167             }
00168         }
00169     }
00170 
00171     return 0;
00172 }
00173 
00174 
00175 /*-------------------------------------------------------------*
00176  *                  Repaint gray pixels in region              *
00177  *-------------------------------------------------------------*/
00178 /*!
00179  *  pixColorGrayCmap()
00180  *
00181  *      Input:  pixs (2, 4 or 8 bpp, with colormap)
00182  *              box (<optional> region to set color; can be NULL)
00183  *              type (L_PAINT_LIGHT, L_PAINT_DARK)
00184  *              rval, gval, bval (target color)
00185  *      Return: 0 if OK, 1 on error
00186  *
00187  *  Notes:
00188  *      (1) This is an in-place operation.
00189  *      (2) If type == L_PAINT_LIGHT, it colorizes non-black pixels,
00190  *          preserving antialiasing.
00191  *          If type == L_PAINT_DARK, it colorizes non-white pixels,
00192  *          preserving antialiasing.
00193  *      (3) If box is NULL, applies function to the entire image; otherwise,
00194  *          clips the operation to the intersection of the box and pix.
00195  *      (4) This can also be called through pixColorGray().
00196  *      (5) This increases the colormap size by the number of
00197  *          different gray (non-black or non-white) colors in the
00198  *          input colormap.  If there is not enough room in the colormap
00199  *          for this expansion, it returns 1 (error), and the caller
00200  *          should check the return value.  If an error is returned
00201  *          and the cmap is only 2 or 4 bpp, the pix can be converted
00202  *          to 8 bpp and this function will succeed if run again on
00203  *          a larger colormap.
00204  *      (6) Using the darkness of each original pixel in the rect,
00205  *          it generates a new color (based on the input rgb values).
00206  *          If type == L_PAINT_LIGHT, the new color is a (generally)
00207  *          darken-to-black version of the  input rgb color, where the
00208  *          amount of darkening increases with the darkness of the
00209  *          original pixel color.
00210  *          If type == L_PAINT_DARK, the new color is a (generally)
00211  *          faded-to-white version of the  input rgb color, where the
00212  *          amount of fading increases with the brightness of the
00213  *          original pixel color.
00214  */
00215 l_int32
00216 pixColorGrayCmap(PIX     *pixs,
00217                  BOX     *box,
00218                  l_int32  type,
00219                  l_int32  rval,
00220                  l_int32  gval,
00221                  l_int32  bval)
00222 {
00223 l_int32    i, j, w, h, d, x1, y1, x2, y2, bw, bh, wpl;
00224 l_int32    val, nval;
00225 l_int32   *map;
00226 l_uint32  *line, *data;
00227 NUMA      *na;
00228 PIX       *pixt;
00229 PIXCMAP   *cmap, *cmapc;
00230 
00231     PROCNAME("pixColorGrayCmap");
00232 
00233     if (!pixs)
00234         return ERROR_INT("pixs not defined", procName, 1);
00235     if ((cmap = pixGetColormap(pixs)) == NULL)
00236         return ERROR_INT("no colormap", procName, 1);
00237     d = pixGetDepth(pixs);
00238     if (d != 2 && d != 4 && d != 8)
00239         return ERROR_INT("depth not in {2, 4, 8}", procName, 1);
00240     if (type != L_PAINT_DARK && type != L_PAINT_LIGHT)
00241         return ERROR_INT("invalid type", procName, 1);
00242 
00243         /* If 2 bpp or 4 bpp, see if the new colors will fit into
00244          * the existing colormap.  If not, convert in-place to 8 bpp. */
00245     if (d == 2 || d == 4) {
00246         cmapc = pixcmapCopy(cmap);  /* experiment with a copy */
00247         if (addColorizedGrayToCmap(cmapc, type, rval, gval, bval, NULL)) {
00248             pixt = pixConvertTo8(pixs, 1);
00249             pixTransferAllData(pixs, &pixt, 0, 0);
00250         }
00251         pixcmapDestroy(&cmapc);
00252     }
00253 
00254         /* Find gray colors, add the corresponding new colors,
00255          * and set up a mapping table from gray to new.
00256          * That table has the value 256 for all colors that are
00257          * not to be mapped. */
00258     cmap = pixGetColormap(pixs);
00259     if (addColorizedGrayToCmap(cmap, type, rval, gval, bval, &na)) {
00260         numaDestroy(&na);
00261         return ERROR_INT("no room; cmap full", procName, 1);
00262     }
00263     map = numaGetIArray(na);
00264     
00265         /* Determine the region of substitution */
00266     pixGetDimensions(pixs, &w, &h, &d);  /* d may be different */
00267     data = pixGetData(pixs);
00268     wpl = pixGetWpl(pixs);
00269     if (!box) {
00270         x1 = y1 = 0;
00271         x2 = w;
00272         y2 = h;
00273     }
00274     else {
00275         boxGetGeometry(box, &x1, &y1, &bw, &bh);
00276         x2 = x1 + bw - 1;
00277         y2 = y1 + bh - 1;
00278     }
00279 
00280         /* Remap gray pixels in the region */
00281     for (i = y1; i <= y2; i++) {
00282         if (i < 0 || i >= h)  /* clip */
00283             continue;
00284         line = data + i * wpl;
00285         for (j = x1; j <= x2; j++) {
00286             if (j < 0 || j >= w)  /* clip */
00287                 continue;
00288             switch (d)
00289             {
00290             case 2:
00291                 val = GET_DATA_DIBIT(line, j);
00292                 nval = map[val];
00293                 if (nval != 256)
00294                     SET_DATA_DIBIT(line, j, nval);
00295                 break;
00296             case 4:
00297                 val = GET_DATA_QBIT(line, j);
00298                 nval = map[val];
00299                 if (nval != 256)
00300                     SET_DATA_QBIT(line, j, nval);
00301                 break;
00302             case 8:
00303                 val = GET_DATA_BYTE(line, j);
00304                 nval = map[val];
00305                 if (nval != 256)
00306                     SET_DATA_BYTE(line, j, nval);
00307                 break;
00308             }
00309         }
00310     }
00311 
00312     FREE(map);
00313     numaDestroy(&na);
00314     return 0;
00315 }
00316 
00317 
00318 /*!
00319  *  addColorizedGrayToCmap()
00320  *
00321  *      Input:  cmap (from 2 or 4 bpp pix)
00322  *              type (L_PAINT_LIGHT, L_PAINT_DARK)
00323  *              rval, gval, bval (target color)
00324  *              &na (<optional return> table for mapping new cmap entries)
00325  *      Return: 0 if OK; 1 on error; 2 if new colors will not fit in cmap.
00326  *
00327  *  Notes:
00328  *      (1) If type == L_PAINT_LIGHT, it colorizes non-black pixels,
00329  *          preserving antialiasing.
00330  *          If type == L_PAINT_DARK, it colorizes non-white pixels,
00331  *          preserving antialiasing.
00332  *      (2) This increases the colormap size by the number of
00333  *          different gray (non-black or non-white) colors in the
00334  *          input colormap.  If there is not enough room in the colormap
00335  *          for this expansion, it returns 1 (treated as a warning);
00336  *          the caller should check the return value.
00337  *      (3) This can be used to determine if the new colors will fit in
00338  *          the cmap, using null for &na.  Returns 0 if they fit; 2 if
00339  *          they don't fit.
00340  *      (4) The mapping table contains, for each gray color found, the
00341  *          index of the corresponding colorized pixel.  Non-gray
00342  *          pixels are assigned the invalid index 256.
00343  *      (5) See pixColorGrayCmap() for usage.
00344  */
00345 l_int32
00346 addColorizedGrayToCmap(PIXCMAP  *cmap,
00347                        l_int32   type,
00348                        l_int32   rval,
00349                        l_int32   gval,
00350                        l_int32   bval,
00351                        NUMA    **pna)
00352 {
00353 l_int32  i, n, erval, egval, ebval, nrval, ngval, nbval, newindex;
00354 NUMA    *na;
00355 
00356     PROCNAME("addColorizedGrayToCmap");
00357 
00358     if (pna) *pna = NULL;
00359     if (!cmap)
00360         return ERROR_INT("cmap not defined", procName, 1);
00361     if (type != L_PAINT_DARK && type != L_PAINT_LIGHT)
00362         return ERROR_INT("invalid type", procName, 1);
00363 
00364     n = pixcmapGetCount(cmap);
00365     na = numaCreate(n);
00366     for (i = 0; i < n; i++) {
00367         pixcmapGetColor(cmap, i, &erval, &egval, &ebval);
00368         if (type == L_PAINT_LIGHT) {
00369             if (erval == egval && erval == ebval && erval != 0) {
00370                 nrval = (l_int32)(rval * (l_float32)erval / 255.);
00371                 ngval = (l_int32)(gval * (l_float32)egval / 255.);
00372                 nbval = (l_int32)(bval * (l_float32)ebval / 255.);
00373                 if (pixcmapAddNewColor(cmap, nrval, ngval, nbval, &newindex)) {
00374                     numaDestroy(&na);
00375                     L_WARNING("no room; colormap full;", procName);
00376                     return 2;
00377                 }
00378                 numaAddNumber(na, newindex);
00379             }
00380             else
00381                 numaAddNumber(na, 256);  /* invalid number; not gray */
00382         }
00383         else {  /* L_PAINT_DARK */
00384             if (erval == egval && erval == ebval && erval != 255) {
00385                 nrval = rval +
00386                         (l_int32)((255. - rval) * (l_float32)erval / 255.);
00387                 ngval = gval +
00388                         (l_int32)((255. - gval) * (l_float32)egval / 255.);
00389                 nbval = bval +
00390                         (l_int32)((255. - bval) * (l_float32)ebval / 255.);
00391                 if (pixcmapAddNewColor(cmap, nrval, ngval, nbval, &newindex)) {
00392                     numaDestroy(&na);
00393                     L_WARNING("no room; colormap full;", procName);
00394                     return 2;
00395                 }
00396                 numaAddNumber(na, newindex);
00397             }
00398             else
00399                 numaAddNumber(na, 256);  /* invalid number; not gray */
00400         }
00401     }
00402 
00403     if (pna)
00404         *pna = na;
00405     else
00406         numaDestroy(&na);
00407     return 0;
00408 }
00409 
00410 
00411 /*-------------------------------------------------------------*
00412  *             Repaint selected pixels through mask            *
00413  *-------------------------------------------------------------*/
00414 /*!
00415  *  pixSetSelectMaskedCmap()
00416  *
00417  *      Input:  pixs (2, 4 or 8 bpp, with colormap)
00418  *              pixm (<optional> 1 bpp mask; no-op if NULL)
00419  *              x, y (UL corner of mask relative to pixs)
00420  *              sindex (colormap index of pixels in pixs to be changed)
00421  *              rval, gval, bval (new color to substitute)
00422  *      Return: 0 if OK, 1 on error
00423  *
00424  *  Note:
00425  *      (1) This is an in-place operation.
00426  *      (2) This paints through the fg of pixm and replaces all pixels
00427  *          in pixs that have a particular value (sindex) with the new color.
00428  *      (3) If pixm == NULL, a warning is given.
00429  *      (4) sindex must be in the existing colormap; otherwise an
00430  *          error is returned.
00431  *      (5) If the new color exists in the colormap, it is used;
00432  *          otherwise, it is added to the colormap.  If the colormap
00433  *          is full, an error is returned.
00434  */
00435 l_int32
00436 pixSetSelectMaskedCmap(PIX     *pixs,
00437                        PIX     *pixm,
00438                        l_int32  x,
00439                        l_int32  y,
00440                        l_int32  sindex,
00441                        l_int32  rval,
00442                        l_int32  gval,
00443                        l_int32  bval)
00444 {
00445 l_int32    i, j, w, h, d, n, wm, hm, wpls, wplm, val;
00446 l_int32    index;  /* of new color to be set */
00447 l_uint32  *lines, *linem, *datas, *datam;
00448 PIXCMAP   *cmap;
00449 
00450     PROCNAME("pixSetSelectMaskedCmap");
00451 
00452     if (!pixs)
00453         return ERROR_INT("pixs not defined", procName, 1);
00454     if ((cmap = pixGetColormap(pixs)) == NULL)
00455         return ERROR_INT("no colormap", procName, 1);
00456     if (!pixm) {
00457         L_WARNING("no mask; nothing to do", procName);
00458         return 0;
00459     }
00460 
00461     d = pixGetDepth(pixs);
00462     if (d != 2 && d != 4 && d != 8)
00463         return ERROR_INT("depth not in {2, 4, 8}", procName, 1);
00464 
00465         /* add new color if necessary; get index of this color in cmap */
00466     n = pixcmapGetCount(cmap);
00467     if (sindex >= n)
00468         return ERROR_INT("sindex too large; no cmap entry", procName, 1);
00469     if (pixcmapGetIndex(cmap, rval, gval, bval, &index)) { /* not found */
00470         if (pixcmapAddColor(cmap, rval, gval, bval))
00471             return ERROR_INT("error adding cmap entry", procName, 1);
00472         else
00473             index = n;  /* we've added one color */
00474     }
00475 
00476         /* replace pixel value sindex by index when fg pixel in pixmc
00477          * overlays it */
00478     w = pixGetWidth(pixs);
00479     h = pixGetHeight(pixs);
00480     datas = pixGetData(pixs);
00481     wpls = pixGetWpl(pixs);
00482     wm = pixGetWidth(pixm);
00483     hm = pixGetHeight(pixm);
00484     datam = pixGetData(pixm);
00485     wplm = pixGetWpl(pixm);
00486     for (i = 0; i < hm; i++) {
00487         if (i + y < 0 || i + y >= h) continue;
00488         lines = datas + (y + i) * wpls;
00489         linem = datam + i * wplm;
00490         for (j = 0; j < wm; j++) {
00491             if (j + x < 0  || j + x >= w) continue;
00492             if (GET_DATA_BIT(linem, j)) {
00493                 switch (d) {
00494                 case 1:
00495                     val = GET_DATA_BIT(lines, x + j);
00496                     if (val == sindex) {
00497                         if (index == 0)
00498                             CLEAR_DATA_BIT(lines, x + j);
00499                         else
00500                             SET_DATA_BIT(lines, x + j);
00501                     }
00502                     break;
00503                 case 2:
00504                     val = GET_DATA_DIBIT(lines, x + j);
00505                     if (val == sindex)
00506                         SET_DATA_DIBIT(lines, x + j, index);
00507                     break;
00508                 case 4:
00509                     val = GET_DATA_QBIT(lines, x + j);
00510                     if (val == sindex)
00511                         SET_DATA_QBIT(lines, x + j, index);
00512                     break;
00513                 case 8:
00514                     val = GET_DATA_BYTE(lines, x + j);
00515                     if (val == sindex)
00516                         SET_DATA_BYTE(lines, x + j, index);
00517                     break;
00518                 default:
00519                     return ERROR_INT("depth not in {1,2,4,8}", procName, 1);
00520                 }
00521             }
00522         }
00523     }
00524 
00525     return 0;
00526 }
00527 
00528 
00529 /*-------------------------------------------------------------*
00530  *               Repaint all pixels through mask               *
00531  *-------------------------------------------------------------*/
00532 /*!
00533  *  pixSetMaskedCmap()
00534  *
00535  *      Input:  pixs (2, 4 or 8 bpp, colormapped)
00536  *              pixm (<optional> 1 bpp mask; no-op if NULL)
00537  *              x, y (origin of pixm relative to pixs; can be negative)
00538  *              rval, gval, bval (new color to set at each masked pixel)
00539  *      Return: 0 if OK; 1 on error
00540  *
00541  *  Notes:
00542  *      (1) This is an in-place operation.
00543  *      (2) It paints a single color through the mask (as a stencil).
00544  *      (3) The mask origin is placed at (x,y) on pixs, and the
00545  *          operation is clipped to the intersection of the mask and pixs.
00546  *      (4) If pixm == NULL, a warning is given.
00547  *      (5) Typically, pixm is a small binary mask located somewhere
00548  *          on the larger pixs.
00549  *      (6) If the color is in the colormap, it is used.  Otherwise,
00550  *          it is added if possible; an error is returned if the
00551  *          colormap is already full.
00552  */
00553 l_int32
00554 pixSetMaskedCmap(PIX      *pixs,
00555                  PIX      *pixm,
00556                  l_int32   x,
00557                  l_int32   y,
00558                  l_int32   rval,
00559                  l_int32   gval,
00560                  l_int32   bval)
00561 {
00562 l_int32    w, h, d, wpl, wm, hm, wplm;
00563 l_int32    i, j, index;
00564 l_uint32  *data, *datam, *line, *linem;
00565 PIXCMAP   *cmap;
00566 
00567     PROCNAME("pixSetMaskedCmap");
00568 
00569     if (!pixs)
00570         return ERROR_INT("pixs not defined", procName, 1);
00571     if ((cmap = pixGetColormap(pixs)) == NULL)
00572         return ERROR_INT("no colormap in pixs", procName, 1);
00573     if (!pixm) {
00574         L_WARNING("no mask; nothing to do", procName);
00575         return 0;
00576     }
00577     d = pixGetDepth(pixs);
00578     if (d != 2 && d != 4 && d != 8)
00579         return ERROR_INT("depth not in {2,4,8}", procName, 1);
00580     if (pixGetDepth(pixm) != 1)
00581         return ERROR_INT("pixm not 1 bpp", procName, 1);
00582 
00583         /* Add new color if necessary; store in 'index' */
00584     if (pixcmapGetIndex(cmap, rval, gval, bval, &index)) {  /* not found */
00585         if (pixcmapAddColor(cmap, rval, gval, bval))
00586             return ERROR_INT("no room in cmap", procName, 1);
00587         index = pixcmapGetCount(cmap) - 1;
00588     }
00589 
00590     pixGetDimensions(pixs, &w, &h, NULL);
00591     wpl = pixGetWpl(pixs);
00592     data = pixGetData(pixs);
00593     pixGetDimensions(pixm, &wm, &hm, NULL);
00594     wplm = pixGetWpl(pixm);
00595     datam = pixGetData(pixm);
00596     for (i = 0; i < hm; i++) {
00597         if (i + y < 0 || i + y >= h) continue;
00598         line = data + (i + y) * wpl;
00599         linem = datam + i * wplm;
00600         for (j = 0; j < wm; j++) {
00601             if (j + x < 0  || j + x >= w) continue;
00602             if (GET_DATA_BIT(linem, j)) {  /* paint color */
00603                 switch (d) 
00604                 {
00605                 case 2:
00606                     SET_DATA_DIBIT(line, j + x, index);
00607                     break;
00608                 case 4:
00609                     SET_DATA_QBIT(line, j + x, index);
00610                     break;
00611                 case 8:
00612                     SET_DATA_BYTE(line, j + x, index);
00613                     break;
00614                 default:
00615                     return ERROR_INT("depth not in {2,4,8}", procName, 1);
00616                 }
00617             }
00618         }
00619     }
00620 
00621     return 0;
00622 }
00623 
00624 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines