Path: blob/master/src/java.desktop/share/native/libmlib_image/mlib_ImageConvClearEdge_Fp.c
41152 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/242526/*27* FUNCTIONS28* mlib_c_ImageConvClearEdge - Set edge of an image to a specific29* color. (for float-point image)30*31* SYNOPSIS32* mlib_status mlib_c_ImageConvClearEdge_Fp(mlib_image *img,33* mlib_s32 dx_l,34* mlib_s32 dx_r,35* mlib_s32 dy_t,36* mlib_s32 dy_b,37* const mlib_d64 *color,38* mlib_s32 cmask)39*40* ARGUMENT41* img Pointer to an image.42* dx_l Number of columns on the left side of the43* image to be cleared.44* dx_r Number of columns on the right side of the45* image to be cleared.46* dy_t Number of rows on the top edge of the47* image to be cleared.48* dy_b Number of rows on the top edge of the49* image to be cleared.50* color Pointer to the color that the edges are set to.51* cmask Channel mask to indicate the channels to be convolved.52* Each bit of which represents a channel in the image. The53* channels corresponded to 1 bits are those to be processed.54*55* RESTRICTION56* img can have 1, 2, 3 or 4 channels of MLIB_FLOAT or MLIB_DOUBLE57* data type.58*59* DESCRIPTION60* Set edge of an image to a specific color.61* The unselected channels are not overwritten.62* If src and dst have just one channel,63* cmask is ignored.64*/6566#include "mlib_image.h"67#include "mlib_ImageConvEdge.h"6869/***************************************************************/70#define EDGES(chan, type, mask) \71{ \72type *pimg = (type *) mlib_ImageGetData(img); \73type color_i; \74mlib_s32 img_stride = mlib_ImageGetStride(img) / sizeof(type); \75mlib_s32 i, j, l; \76mlib_s32 testchan; \77\78testchan = 1; \79for (l = chan - 1; l >= 0; l--) { \80if ((mask & testchan) == 0) { \81testchan <<= 1; \82continue; \83} \84testchan <<= 1; \85color_i = (type) color[l]; \86for (j = 0; j < dx_l; j++) { \87for (i = dy_t; i < (img_height - dy_b); i++) { \88pimg[i * img_stride + l + j * chan] = color_i; \89} \90} \91for (j = 0; j < dx_r; j++) { \92for (i = dy_t; i < (img_height - dy_b); i++) { \93pimg[i * img_stride + l + (img_width - 1 - j) * chan] = color_i; \94} \95} \96for (i = 0; i < dy_t; i++) { \97for (j = 0; j < img_width; j++) { \98pimg[i * img_stride + l + j * chan] = color_i; \99} \100} \101for (i = 0; i < dy_b; i++) { \102for (j = 0; j < img_width; j++) { \103pimg[(img_height - 1 - i) * img_stride + l + j * chan] = color_i; \104} \105} \106} \107}108109/***************************************************************/110mlib_status mlib_ImageConvClearEdge_Fp(mlib_image *img,111mlib_s32 dx_l,112mlib_s32 dx_r,113mlib_s32 dy_t,114mlib_s32 dy_b,115const mlib_d64 *color,116mlib_s32 cmask)117{118mlib_s32 img_width = mlib_ImageGetWidth(img);119mlib_s32 img_height = mlib_ImageGetHeight(img);120mlib_s32 channel = mlib_ImageGetChannels(img);121122if (dx_l + dx_r > img_width) {123dx_l = img_width;124dx_r = 0;125}126127if (dy_t + dy_b > img_height) {128dy_t = img_height;129dy_b = 0;130}131132if (channel == 1) cmask = 1;133134switch (mlib_ImageGetType(img)) {135case MLIB_FLOAT:136EDGES(channel,mlib_f32, cmask);137break;138case MLIB_DOUBLE:139EDGES(channel,mlib_d64, cmask);140break;141default:142return MLIB_FAILURE;143}144145return MLIB_SUCCESS;146}147148/***************************************************************/149150151