J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2000-2003 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * FUNCTION |
| 30 | * mlib_ImageCopy - Direct copy from one image to another. |
| 31 | * |
| 32 | * SYNOPSIS |
| 33 | * mlib_status mlib_ImageCopy(mlib_image *dst, |
| 34 | * mlib_image *src); |
| 35 | * |
| 36 | * ARGUMENT |
| 37 | * dst pointer to output or destination image |
| 38 | * src pointer to input or source image |
| 39 | * |
| 40 | * RESTRICTION |
| 41 | * src and dst must have the same size, type and number of channels. |
| 42 | * They can have 1, 2, 3 or 4 channels of MLIB_BIT, MLIB_BYTE, |
| 43 | * MLIB_SHORT, MLIB_INT, MLIB_FLOAT or MLIB_DOUBLE data type. |
| 44 | * |
| 45 | * DESCRIPTION |
| 46 | * Direct copy from one image to another. |
| 47 | */ |
| 48 | |
| 49 | #include <stdlib.h> |
| 50 | #include "mlib_image.h" |
| 51 | #include "mlib_ImageCheck.h" |
| 52 | |
| 53 | /***************************************************************/ |
| 54 | |
| 55 | extern void mlib_v_ImageCopy_blk(mlib_u8 *sa, mlib_u8 *da, mlib_s32 size); |
| 56 | extern void mlib_v_ImageCopy_a1(mlib_d64 *sp, mlib_d64 *dp, mlib_s32 size); |
| 57 | extern void mlib_ImageCopy_na(mlib_u8 *sa, mlib_u8 *da, mlib_s32 size); |
| 58 | extern void mlib_ImageCopy_bit_al(mlib_u8 *sa, mlib_u8 *da, |
| 59 | mlib_s32 size, mlib_s32 offset); |
| 60 | extern void mlib_ImageCopy_bit_na(mlib_u8 *sa, mlib_u8 *da, mlib_s32 size, |
| 61 | mlib_s32 s_offset, mlib_s32 d_offset); |
| 62 | |
| 63 | /***************************************************************/ |
| 64 | |
| 65 | #ifdef MLIB_TEST |
| 66 | |
| 67 | mlib_status mlib_v_ImageCopy(mlib_image *dst, mlib_image *src) |
| 68 | |
| 69 | #else |
| 70 | |
| 71 | mlib_status mlib_ImageCopy(mlib_image *dst, const mlib_image *src) |
| 72 | |
| 73 | #endif |
| 74 | { |
| 75 | mlib_u8 *sa; /* start point in source */ |
| 76 | mlib_u8 *da; /* start points in destination */ |
| 77 | mlib_s32 width; /* width in bytes of src and dst */ |
| 78 | mlib_s32 height; /* height in lines of src and dst */ |
| 79 | mlib_s32 s_offset; /* bit offset of src */ |
| 80 | mlib_s32 d_offset; /* bit offset of dst */ |
| 81 | mlib_s32 stride; /* stride in bytes in src*/ |
| 82 | mlib_s32 dstride; /* stride in bytes in dst */ |
| 83 | mlib_s32 j; /* indices for x, y */ |
| 84 | mlib_s32 size; |
| 85 | |
| 86 | MLIB_IMAGE_CHECK(src); |
| 87 | MLIB_IMAGE_CHECK(dst); |
| 88 | MLIB_IMAGE_TYPE_EQUAL(src, dst); |
| 89 | MLIB_IMAGE_CHAN_EQUAL(src, dst); |
| 90 | MLIB_IMAGE_SIZE_EQUAL(src, dst); |
| 91 | |
| 92 | width = mlib_ImageGetWidth(dst) * mlib_ImageGetChannels(dst); |
| 93 | height = mlib_ImageGetHeight(dst); |
| 94 | sa = (mlib_u8 *)mlib_ImageGetData(src); |
| 95 | da = (mlib_u8 *)mlib_ImageGetData(dst); |
| 96 | |
| 97 | switch (mlib_ImageGetType(dst)) { |
| 98 | case MLIB_BIT: |
| 99 | |
| 100 | if (!mlib_ImageIsNotOneDvector(src) && |
| 101 | !mlib_ImageIsNotOneDvector(dst)) { |
| 102 | size = height * (width >> 3); |
| 103 | if ((size & 0x3f) == 0 && |
| 104 | !mlib_ImageIsNotAligned64(src) && |
| 105 | !mlib_ImageIsNotAligned64(dst)) { |
| 106 | |
| 107 | mlib_v_ImageCopy_blk(sa, da, size); |
| 108 | return MLIB_SUCCESS; |
| 109 | } |
| 110 | if (((size & 7) == 0) && !mlib_ImageIsNotAligned8(src) && |
| 111 | !mlib_ImageIsNotAligned8(dst)) { |
| 112 | |
| 113 | size >>= 3; /* in octlet */ |
| 114 | mlib_v_ImageCopy_a1((mlib_d64 *)sa, (mlib_d64 *)da, size); |
| 115 | } |
| 116 | else { |
| 117 | |
| 118 | mlib_ImageCopy_na(sa, da, size); |
| 119 | } |
| 120 | } |
| 121 | else { |
| 122 | stride = mlib_ImageGetStride(src); /* in byte */ |
| 123 | dstride = mlib_ImageGetStride(dst); /* in byte */ |
| 124 | s_offset = mlib_ImageGetBitOffset(src); /* in bits */ |
| 125 | d_offset = mlib_ImageGetBitOffset(dst); /* in bits */ |
| 126 | |
| 127 | if (s_offset == d_offset) { |
| 128 | for (j = 0; j < height; j++) { |
| 129 | mlib_ImageCopy_bit_al(sa, da, width, s_offset); |
| 130 | sa += stride; |
| 131 | da += dstride; |
| 132 | } |
| 133 | } else { |
| 134 | for (j = 0; j < height; j++) { |
| 135 | mlib_ImageCopy_bit_na(sa, da, width, s_offset, d_offset); |
| 136 | sa += stride; |
| 137 | da += dstride; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | return MLIB_SUCCESS; |
| 142 | case MLIB_BYTE: |
| 143 | break; |
| 144 | case MLIB_SHORT: |
| 145 | width *= 2; |
| 146 | break; |
| 147 | case MLIB_INT: |
| 148 | case MLIB_FLOAT: |
| 149 | width *= 4; |
| 150 | break; |
| 151 | case MLIB_DOUBLE: |
| 152 | width *= 8; |
| 153 | break; |
| 154 | default: |
| 155 | return MLIB_FAILURE; |
| 156 | } |
| 157 | |
| 158 | if (!mlib_ImageIsNotOneDvector(src) && |
| 159 | !mlib_ImageIsNotOneDvector(dst)) { |
| 160 | size = height * width; |
| 161 | if ((size & 0x3f) == 0 && |
| 162 | !mlib_ImageIsNotAligned64(src) && |
| 163 | !mlib_ImageIsNotAligned64(dst)) { |
| 164 | |
| 165 | mlib_v_ImageCopy_blk(sa, da, size); |
| 166 | return MLIB_SUCCESS; |
| 167 | } |
| 168 | if (((size & 7) == 0) && !mlib_ImageIsNotAligned8(src) && |
| 169 | !mlib_ImageIsNotAligned8(dst)) { |
| 170 | |
| 171 | size >>= 3; /* in octlet */ |
| 172 | mlib_v_ImageCopy_a1((mlib_d64 *)sa, (mlib_d64 *)da, size); |
| 173 | } |
| 174 | else { |
| 175 | |
| 176 | mlib_ImageCopy_na(sa, da, size); |
| 177 | } |
| 178 | } |
| 179 | else { |
| 180 | stride = mlib_ImageGetStride(src); /* in byte */ |
| 181 | dstride = mlib_ImageGetStride(dst); /* in byte */ |
| 182 | |
| 183 | /* row loop */ |
| 184 | for (j = 0; j < height; j++) { |
| 185 | mlib_ImageCopy_na(sa, da, width); |
| 186 | sa += stride; |
| 187 | da += dstride; |
| 188 | } |
| 189 | } |
| 190 | return MLIB_SUCCESS; |
| 191 | } |
| 192 | |
| 193 | /***************************************************************/ |