1/* 2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 27/* 28 * FUNCTIONS 29 * mlib_c_ImageConvClearEdge - Set edge of an image to a specific 30 * color. (for float-point image) 31 * 32 * SYNOPSIS 33 * mlib_status mlib_c_ImageConvClearEdge_Fp(mlib_image *img, 34 * mlib_s32 dx_l, 35 * mlib_s32 dx_r, 36 * mlib_s32 dy_t, 37 * mlib_s32 dy_b, 38 * const mlib_d64 *color, 39 * mlib_s32 cmask) 40 * 41 * ARGUMENT 42 * img Pointer to an image. 43 * dx_l Number of columns on the left side of the 44 * image to be cleared. 45 * dx_r Number of columns on the right side of the 46 * image to be cleared. 47 * dy_t Number of rows on the top edge of the 48 * image to be cleared. 49 * dy_b Number of rows on the top edge of the 50 * image to be cleared. 51 * color Pointer to the color that the edges are set to. 52 * cmask Channel mask to indicate the channels to be convolved. 53 * Each bit of which represents a channel in the image. The 54 * channels corresponded to 1 bits are those to be processed. 55 * 56 * RESTRICTION 57 * img can have 1, 2, 3 or 4 channels of MLIB_FLOAT or MLIB_DOUBLE 58 * data type. 59 * 60 * DESCRIPTION 61 * Set edge of an image to a specific color. 62 * The unselected channels are not overwritten. 63 * If src and dst have just one channel, 64 * cmask is ignored. 65 */ 66 67#include "mlib_image.h" 68#include "mlib_ImageConvEdge.h" 69 70/***************************************************************/ 71#define EDGES(chan, type, mask) \ 72{ \ 73 type *pimg = (type *) mlib_ImageGetData(img); \ 74 type color_i; \ 75 mlib_s32 img_stride = mlib_ImageGetStride(img) / sizeof(type); \ 76 mlib_s32 i, j, l; \ 77 mlib_s32 testchan; \ 78 \ 79 testchan = 1; \ 80 for (l = chan - 1; l >= 0; l--) { \ 81 if ((mask & testchan) == 0) { \ 82 testchan <<= 1; \ 83 continue; \ 84 } \ 85 testchan <<= 1; \ 86 color_i = (type) color[l]; \ 87 for (j = 0; j < dx_l; j++) { \ 88 for (i = dy_t; i < (img_height - dy_b); i++) { \ 89 pimg[i * img_stride + l + j * chan] = color_i; \ 90 } \ 91 } \ 92 for (j = 0; j < dx_r; j++) { \ 93 for (i = dy_t; i < (img_height - dy_b); i++) { \ 94 pimg[i * img_stride + l + (img_width - 1 - j) * chan] = color_i; \ 95 } \ 96 } \ 97 for (i = 0; i < dy_t; i++) { \ 98 for (j = 0; j < img_width; j++) { \ 99 pimg[i * img_stride + l + j * chan] = color_i; \ 100 } \ 101 } \ 102 for (i = 0; i < dy_b; i++) { \ 103 for (j = 0; j < img_width; j++) { \ 104 pimg[(img_height - 1 - i) * img_stride + l + j * chan] = color_i; \ 105 } \ 106 } \ 107 } \ 108} 109 110/***************************************************************/ 111mlib_status mlib_ImageConvClearEdge_Fp(mlib_image *img, 112 mlib_s32 dx_l, 113 mlib_s32 dx_r, 114 mlib_s32 dy_t, 115 mlib_s32 dy_b, 116 const mlib_d64 *color, 117 mlib_s32 cmask) 118{ 119 mlib_s32 img_width = mlib_ImageGetWidth(img); 120 mlib_s32 img_height = mlib_ImageGetHeight(img); 121 mlib_s32 channel = mlib_ImageGetChannels(img); 122 123 if (dx_l + dx_r > img_width) { 124 dx_l = img_width; 125 dx_r = 0; 126 } 127 128 if (dy_t + dy_b > img_height) { 129 dy_t = img_height; 130 dy_b = 0; 131 } 132 133 if (channel == 1) cmask = 1; 134 135 switch (mlib_ImageGetType(img)) { 136 case MLIB_FLOAT: 137 EDGES(channel,mlib_f32, cmask); 138 break; 139 case MLIB_DOUBLE: 140 EDGES(channel,mlib_d64, cmask); 141 break; 142 default: 143 return MLIB_FAILURE; 144 } 145 146 return MLIB_SUCCESS; 147} 148 149/***************************************************************/ 150