Path: blob/master/src/java.desktop/share/native/libmlib_image/mlib_ImageConvCopyEdge_Bit.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_ImageConvCopyEdge_Bit - Copy src edges to dst edges29*30*31* SYNOPSIS32* mlib_status mlib_ImageConvCopyEdge_Bit(mlib_image *dst,33* const mlib_image *src,34* mlib_s32 dx_l,35* mlib_32 dx_r,36* mlib_s32 dy_t,37* mlib_32 dy_b,38* mlib_s32 cmask);39*40* ARGUMENT41* dst Pointer to an dst image.42* src Pointer to an src image.43* dx_l Number of columns on the left side of the44* image to be copyed.45* dx_r Number of columns on the right side of the46* image to be copyed.47* dy_t Number of rows on the top edge of the48* image to be copyed.49* dy_b Number of rows on the top edge of the50* image to be copyed.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* The src and the dst must be the MLIB_BIT type, same width, same height and have same number57* of channels (1). The unselected channels are not58* overwritten. If both src and dst have just one channel,59* cmask is ignored.60*61* DESCRIPTION62* Copy src edges to dst edges.63*64* The unselected channels are not overwritten.65* If src and dst have just one channel,66* cmask is ignored.67*/6869#include "mlib_image.h"70#include "mlib_ImageConvEdge.h"7172/***************************************************************/73mlib_status mlib_ImageConvCopyEdge_Bit(mlib_image *dst,74const mlib_image *src,75mlib_s32 dx_l,76mlib_s32 dx_r,77mlib_s32 dy_t,78mlib_s32 dy_b,79mlib_s32 cmask)80{81mlib_u8 *pdst = mlib_ImageGetData(dst), *pd;82mlib_u8 *psrc = mlib_ImageGetData(src), *ps;83mlib_s32 img_height = mlib_ImageGetHeight(dst);84mlib_s32 img_width = mlib_ImageGetWidth(dst);85mlib_s32 img_strided = mlib_ImageGetStride(dst);86mlib_s32 img_strides = mlib_ImageGetStride(src);87mlib_s32 bitoffd = mlib_ImageGetBitOffset(dst);88mlib_s32 bitoffs = mlib_ImageGetBitOffset(src);89mlib_s32 bitoff_end, test, shift1, shift2;90mlib_u32 s0, s1, tmp;91mlib_u8 mask, mask_end;92mlib_u8 tmp_start, tmp_end;93mlib_s32 i, j, amount;9495if (bitoffd == bitoffs) {96pd = pdst;97ps = psrc;9899if (dx_l > 0) {100if (bitoffd + dx_l <= 8) {101mask = (0xFF >> bitoffd) & (0xFF << ((8 - (bitoffd + dx_l)) & 7));102103for (i = dy_t; i < (img_height - dy_b); i++) {104pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (ps[i*img_strides] & mask);105}106107} else {108mask = (0xFF >> bitoffd);109110for (i = dy_t; i < (img_height - dy_b); i++) {111pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (ps[i*img_strides] & mask);112}113114amount = (bitoffd + dx_l + 7) >> 3;115mask = (0xFF << ((8 - (bitoffd + dx_l)) & 7));116117for (j = 1; j < amount - 1; j++) {118for (i = dy_t; i < (img_height - dy_b); i++) {119pd[i*img_strided + j] = ps[i*img_strides + j];120}121}122123for (i = dy_t; i < (img_height - dy_b); i++) {124pd[i*img_strided + amount - 1] = (pd[i*img_strided + amount - 1] & ~mask) |125(ps[i*img_strides + amount - 1] & mask);126}127}128}129130if (dx_r > 0) {131pd = pdst + (img_width + bitoffd - dx_r) / 8;132ps = psrc + (img_width + bitoffd - dx_r) / 8;133bitoffd = (img_width + bitoffd - dx_r) & 7;134135if (bitoffd + dx_r <= 8) {136mask = (0xFF >> bitoffd) & (0xFF << ((8 - (bitoffd + dx_r)) & 7));137138for (i = dy_t; i < (img_height - dy_b); i++) {139pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (ps[i*img_strides] & mask);140}141142} else {143mask = (0xFF >> bitoffd);144145for (i = dy_t; i < (img_height - dy_b); i++) {146pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (ps[i*img_strides] & mask);147}148149amount = (bitoffd + dx_r + 7) >> 3;150mask = (0xFF << ((8 - (bitoffd + dx_r)) & 7));151152for (j = 1; j < amount - 1; j++) {153for (i = dy_t; i < (img_height - dy_b); i++) {154pd[i*img_strided + j] = ps[i*img_strides + j];155}156}157158for (i = dy_t; i < (img_height - dy_b); i++) {159pd[i*img_strided + amount - 1] = (pd[i*img_strided + amount - 1] & ~mask) |160(ps[i*img_strides + amount - 1] & mask);161}162}163}164165bitoffd = mlib_ImageGetBitOffset(dst);166bitoff_end = (bitoffd + img_width) & 7;167amount = (bitoffd + img_width + 7) >> 3;168mask = (0xFF >> bitoffd);169mask_end = (0xFF << ((8 - bitoff_end) & 7));170171pd = pdst;172ps = psrc;173174for (i = 0; i < dy_t; i++) {175tmp_start = pd[i*img_strided];176tmp_end = pd[i*img_strided+amount-1];177for (j = 0; j < amount; j++) {178pd[i*img_strided + j] = ps[i*img_strides + j];179}180181pd[i*img_strided] = (tmp_start & (~mask)) | (pd[i*img_strided] & mask);182pd[i*img_strided+amount-1] = (tmp_end & (~mask_end)) |183(pd[i*img_strided+amount-1] & mask_end);184}185186pd = pdst + (img_height-1)*img_strided;187ps = psrc + (img_height-1)*img_strides;188189for (i = 0; i < dy_b; i++) {190tmp_start = pd[-i*img_strided];191tmp_end = pd[-i*img_strided+amount-1];192for (j = 0; j < amount; j++) {193pd[-i*img_strided + j] = ps[-i*img_strides + j];194}195196pd[-i*img_strided] = (tmp_start & (~mask)) | (pd[-i*img_strided] & mask);197pd[-i*img_strided+amount-1] = (tmp_end & (~mask_end)) |198(pd[-i*img_strided+amount-1] & mask_end);199}200201} else {202pd = pdst;203204if (bitoffs > bitoffd) {205ps = psrc;206shift2 = (8 - (bitoffs - bitoffd));207test = 0;208} else {209test = 1;210ps = psrc - 1;211shift2 = bitoffd - bitoffs;212}213214shift1 = 8 - shift2;215216if (dx_l > 0) {217if (bitoffd + dx_l <= 8) {218mask = (0xFF >> bitoffd) & (0xFF << ((8 - (bitoffd + dx_l)) & 7));219220for (i = dy_t; i < (img_height - dy_b); i++) {221s0 = ps[i*img_strides];222s1 = ps[i*img_strides+1];223tmp = (s0 << shift1) | (s1 >> shift2);224pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (tmp & mask);225}226227} else {228mask = (0xFF >> bitoffd);229230for (i = dy_t; i < (img_height - dy_b); i++) {231s0 = ps[i*img_strides];232s1 = ps[i*img_strides+1];233tmp = (s0 << shift1) | (s1 >> shift2);234pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (tmp & mask);235}236237amount = (bitoffd + dx_l + 7) >> 3;238mask = (0xFF << ((8 - (bitoffd + dx_l)) & 7));239240for (j = 1; j < amount - 1; j++) {241for (i = dy_t; i < (img_height - dy_b); i++) {242s0 = ps[i*img_strides+j];243s1 = ps[i*img_strides+j+1];244pd[i*img_strided + j] = (s0 << shift1) | (s1 >> shift2);245s0 = s1;246}247}248249for (i = dy_t; i < (img_height - dy_b); i++) {250s0 = ps[i*img_strides+amount-1];251s1 = ps[i*img_strides+amount];252tmp = (s0 << shift1) | (s1 >> shift2);253pd[i*img_strided + amount - 1] = (pd[i*img_strided + amount - 1] & ~mask) |254(tmp & mask);255}256}257}258259if (dx_r > 0) {260pd = pdst + (img_width + bitoffd - dx_r) / 8;261ps = psrc + (img_width + bitoffd - dx_r) / 8;262bitoffd = (img_width + bitoffd - dx_r) & 7;263ps -= test;264265if (bitoffd + dx_r <= 8) {266mask = (0xFF >> bitoffd) & (0xFF << ((8 - (bitoffd + dx_r)) & 7));267268for (i = dy_t; i < (img_height - dy_b); i++) {269s0 = ps[i*img_strides];270s1 = ps[i*img_strides+1];271tmp = (s0 << shift1) | (s1 >> shift2);272pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (tmp & mask);273}274275} else {276mask = (0xFF >> bitoffd);277278for (i = dy_t; i < (img_height - dy_b); i++) {279s0 = ps[i*img_strides];280s1 = ps[i*img_strides+1];281tmp = (s0 << shift1) | (s1 >> shift2);282pd[i*img_strided] = (pd[i*img_strided] & ~mask) | (tmp & mask);283}284285amount = (bitoffd + dx_r + 7) >> 3;286mask = (0xFF << ((8 - (bitoffd + dx_r)) & 7));287288for (j = 1; j < amount - 1; j++) {289for (i = dy_t; i < (img_height - dy_b); i++) {290s0 = ps[i*img_strides+j];291s1 = ps[i*img_strides+j+1];292pd[i*img_strided + j] = (s0 << shift1) | (s1 >> shift2);293}294}295296for (i = dy_t; i < (img_height - dy_b); i++) {297s0 = ps[i*img_strides+amount-1];298s1 = ps[i*img_strides+amount];299tmp = (s0 << shift1) | (s1 >> shift2);300pd[i*img_strided + amount - 1] = (pd[i*img_strided + amount - 1] & ~mask) |301(tmp & mask);302}303}304}305306bitoffd = mlib_ImageGetBitOffset(dst);307bitoff_end = (bitoffd + img_width) & 7;308amount = (bitoffd + img_width + 7) >> 3;309mask = (0xFF >> bitoffd);310mask_end = (0xFF << ((8 - bitoff_end) & 7));311312pd = pdst;313ps = psrc-test;314315for (i = 0; i < dy_t; i++) {316tmp_start = pd[i*img_strided];317tmp_end = pd[i*img_strided+amount-1];318s0 = ps[i*img_strides];319for (j = 0; j < amount; j++) {320s1 = ps[i*img_strides+j+1];321pd[i*img_strided + j] = (s0 << shift1) | (s1 >> shift2);322s0 = s1;323}324325pd[i*img_strided] = (tmp_start & (~mask)) | (pd[i*img_strided] & mask);326pd[i*img_strided+amount-1] = (tmp_end & (~mask_end)) |327(pd[i*img_strided+amount-1] & mask_end);328}329330pd = pdst + (img_height-1)*img_strided;331ps = psrc + (img_height-1)*img_strides - test;332333for (i = 0; i < dy_b; i++) {334tmp_start = pd[-i*img_strided];335tmp_end = pd[-i*img_strided+amount-1];336s0 = ps[-i*img_strides];337for (j = 0; j < amount; j++) {338s1 = ps[-i*img_strides+j+1];339pd[-i*img_strided + j] = (s0 << shift1) | (s1 >> shift2);340s0 = s1;341}342343pd[-i*img_strided] = (tmp_start & (~mask)) | (pd[-i*img_strided] & mask);344pd[-i*img_strided+amount-1] = (tmp_end & (~mask_end)) |345(pd[-i*img_strided+amount-1] & mask_end);346}347}348349return MLIB_SUCCESS;350}351352/***************************************************************/353354355