00001 /* 00002 * PNG image format 00003 * Copyright (c) 2008 Loren Merrit <lorenm@u.washington.edu> 00004 * 00005 * This file is part of FFmpeg. 00006 * 00007 * FFmpeg is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * FFmpeg is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with FFmpeg; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include "libavutil/common.h" 00023 #include "png.h" 00024 #include "pngdsp.h" 00025 00026 // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size 00027 #define pb_7f (~0UL/255 * 0x7f) 00028 #define pb_80 (~0UL/255 * 0x80) 00029 00030 static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) 00031 { 00032 long i; 00033 for (i = 0; i <= w - sizeof(long); i += sizeof(long)) { 00034 long a = *(long *)(src1 + i); 00035 long b = *(long *)(src2 + i); 00036 *(long *)(dst + i) = ((a & pb_7f) + (b & pb_7f)) ^ ((a ^ b) & pb_80); 00037 } 00038 for (; i < w; i++) 00039 dst[i] = src1[i] + src2[i]; 00040 } 00041 00042 void ff_pngdsp_init(PNGDSPContext *dsp) 00043 { 00044 dsp->add_bytes_l2 = add_bytes_l2_c; 00045 dsp->add_paeth_prediction = ff_add_png_paeth_prediction; 00046 00047 if (HAVE_MMX) ff_pngdsp_init_x86(dsp); 00048 }