Path: blob/master/src/java.desktop/share/native/libmlib_image/mlib_ImageConvClearEdge_Bit.c
41149 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_ImageConvClearEdge_BIt - Set edge of an bit type image to a specific29* color.30*31* SYNOPSIS32* mlib_status mlib_ImageConvClearEdge_Bit(mlib_image *img,33* mlib_s32 dx_l,34* mlib_32 dx_r,35* mlib_s32 dy_t,36* mlib_32 dy_b,37* const mlib_s32 *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 channels of MLIB_BIT data type.57*58* DESCRIPTION59* Set edge of an image to a specific color.60* The unselected channels are not overwritten.61* If src and dst have just one channel,62* cmask is ignored.63*/6465#include "mlib_image.h"66#include "mlib_ImageConvEdge.h"6768/***************************************************************/69mlib_status mlib_ImageConvClearEdge_Bit(mlib_image *img,70mlib_s32 dx_l,71mlib_s32 dx_r,72mlib_s32 dy_t,73mlib_s32 dy_b,74const mlib_s32 *color,75mlib_s32 cmask)76{77mlib_u8 *pimg = mlib_ImageGetData(img), *pd;78mlib_s32 img_height = mlib_ImageGetHeight(img);79mlib_s32 img_width = mlib_ImageGetWidth(img);80mlib_s32 img_stride = mlib_ImageGetStride(img);81mlib_s32 bitoff = mlib_ImageGetBitOffset(img);82mlib_s32 bitoff_end;83mlib_u8 color_i, mask, mask_end, tmp_color;84mlib_u8 tmp_start, tmp_end;85mlib_s32 i, j, amount;8687if ((mlib_ImageGetType(img) != MLIB_BIT) || (mlib_ImageGetChannels(img) != 1))88return MLIB_FAILURE;8990color_i = (mlib_u8)(color[0] & 1);91color_i |= (color_i << 1);92color_i |= (color_i << 2);93color_i |= (color_i << 4);9495pd = pimg;9697if (dx_l > 0) {98if (bitoff + dx_l <= 8) {99mask = (0xFF >> bitoff) & (0xFF << ((8 - (bitoff + dx_l)) & 7));100tmp_color = color_i & mask;101mask = ~mask;102103for (i = dy_t; i < (img_height - dy_b); i++) {104pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;105}106107} else {108mask = (0xFF >> bitoff);109tmp_color = color_i & mask;110mask = ~mask;111112for (i = dy_t; i < (img_height - dy_b); i++) {113pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;114}115116amount = (bitoff + dx_l + 7) >> 3;117mask = (0xFF << ((8 - (bitoff + dx_l)) & 7));118tmp_color = color_i & mask;119mask = ~mask;120121for (j = 1; j < amount - 1; j++) {122for (i = dy_t; i < (img_height - dy_b); i++) {123pd[i*img_stride + j] = color_i;124}125}126127for (i = dy_t; i < (img_height - dy_b); i++) {128pd[i*img_stride + amount - 1] = (pd[i*img_stride + amount - 1] & mask) | tmp_color;129}130}131}132133if (dx_r > 0) {134pd = pimg + (img_width + bitoff - dx_r) / 8;135bitoff = (img_width + bitoff - dx_r) & 7;136137if (bitoff + dx_r <= 8) {138mask = (0xFF >> bitoff) & (0xFF << ((8 - (bitoff + dx_r)) & 7));139tmp_color = color_i & mask;140mask = ~mask;141142for (i = dy_t; i < (img_height - dy_b); i++) {143pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;144}145146} else {147mask = (0xFF >> bitoff);148tmp_color = color_i & mask;149mask = ~mask;150151for (i = dy_t; i < (img_height - dy_b); i++) {152pd[i*img_stride] = (pd[i*img_stride] & mask) | tmp_color;153}154155amount = (bitoff + dx_r + 7) >> 3;156mask = (0xFF << ((8 - (bitoff + dx_r)) & 7));157tmp_color = color_i & mask;158mask = ~mask;159160for (j = 1; j < amount - 1; j++) {161for (i = dy_t; i < (img_height - dy_b); i++) {162pd[i*img_stride + j] = color_i;163}164}165166for (i = dy_t; i < (img_height - dy_b); i++) {167pd[i*img_stride + amount - 1] = (pd[i*img_stride + amount - 1] & mask) | tmp_color;168}169}170}171172bitoff = mlib_ImageGetBitOffset(img);173bitoff_end = (bitoff + img_width) & 7;174amount = (bitoff + img_width + 7) >> 3;175mask = (0xFF >> bitoff);176mask_end = (0xFF << ((8 - bitoff_end) & 7));177178pd = pimg;179180for (i = 0; i < dy_t; i++) {181tmp_start = pd[i*img_stride];182tmp_end = pd[i*img_stride+amount-1];183for (j = 0; j < amount; j++) {184pd[i*img_stride + j] = color_i;185}186187pd[i*img_stride] = (tmp_start & (~mask)) | (pd[i*img_stride] & mask);188pd[i*img_stride+amount-1] = (tmp_end & (~mask_end)) |189(pd[i*img_stride+amount-1] & mask_end);190}191192pd = pimg + (img_height-1)*img_stride;193194for (i = 0; i < dy_b; i++) {195tmp_start = pd[-i*img_stride];196tmp_end = pd[-i*img_stride+amount-1];197for (j = 0; j < amount; j++) {198pd[-i*img_stride + j] = color_i;199}200201pd[-i*img_stride] = (tmp_start & (~mask)) | (pd[-i*img_stride] & mask);202pd[-i*img_stride+amount-1] = (tmp_end & (~mask_end)) |203(pd[-i*img_stride+amount-1] & mask_end);204}205206return MLIB_SUCCESS;207}208209/***************************************************************/210211212