• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            misschuer

            常用鏈接

            統(tǒng)計(jì)

            積分與排名

            百事通

            最新評(píng)論

            alchemy c 圖像的縮放 (三次卷積)

            在alchemy c中進(jìn)行圖片的縮放
            傳進(jìn)的是byteArray 傳出的也是byteArray 千萬不要在alchemy c 中對(duì)as的對(duì)象進(jìn)行函數(shù)調(diào)用 那樣速度很慢.... 達(dá)不到煉金術(shù)的效果... 
            好吧 代碼 自己看吧 還是比較簡單的
            alchemy c 代碼

            #include <iostream>
            #include <stdio.h>
            #include <stdlib.h>
            #include <string.h>
            #include <math.h>
            #include "AS3.h"
            typedef unsigned int uint;
            #define MAXV 4
            using namespace std;

            double SinXDivX(double x) {
                double a = -1;
                if (x < 0)
                    x = -x;
                double x2 = x * x;
                double x3 = x2 * x;
                if (x <= 1)
                    return (a + 2) * x3 - (a + 3) * x2 + 1;
                else if (x <= 2)
                    return a * x3 - 5 * a * x2 + 8 * a * x - 4 * a;
                return 0;
            }

            uint availablePixel(uint *src, int srcWidth, int srcHeight, int x, int y) {
                bool flag = true;
                if (x < 0) {
                    x = 0;
                    flag = false;
                } else if (x >= srcWidth) {
                    x = srcWidth - 1;
                    flag = false;
                }
                if (y < 0) {
                    y = 0;
                    flag = false;
                } else if (y >= srcHeight) {
                    y = srcHeight - 1;
                    flag = false;
                }
                int lenth = srcWidth * srcHeight;
                int in = x + y*srcWidth;
                uint ret = src[in];
                if (!flag)
                    ret = ret & 0x00ffffff;
                return ret;
            }

            uint border_color(double Color) {
                if (Color <= 0)
                    return uint(0);
                if (Color >= 255)
                    return uint(255);
                return uint(Color);
            }

            char *strreverse(char *a) {
                char r[10] = { 0 };
                int i, j;
                for (i = 0, j = strlen(a) - 1; a[i]; ++i, --j) {
                    r[j] = a[i];
                }
                return r;
            }

            char *toString(uint val) {
                char a[10] = { 0 };
                char ch[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
                        'C', 'D', 'E', 'F' };
                int i = 0, rt;
                if (val == 0)
                    a[0] = '0';
                while (val) {
                    rt = val % 16;
                    val >>= 4;
                    a[i++] = ch[rt];
                }
                return strreverse(a);
            }

            uint MatrixMutiple(double a[], uint b[][MAXV], double c[], int ii, int jj) {
                int i, j, k, z;
                double tp[MAXV], ret[MAXV], ttp[MAXV];
                memset(ret, 0.0, sizeof(ret));

                for (i = 0; i < MAXV; ++i) {
                    memset(tp, 0.0, sizeof(tp));
                    for (j = 0; j < MAXV; ++j) {
                        tp[0] += a[j] * (b[j][i] >> 24);
                        tp[1] += a[j] * ((b[j][i] & 0x00ffffff) >> 16);
                        tp[2] += a[j] * ((b[j][i] & 0x0000ffff) >> 8);
                        tp[3] += a[j] * (b[j][i] & 0x000000ff);
                    }
                    for (k = 0; k < MAXV; ++k) {
                        ret[k] += c[i] * tp[k];
                    }
                }

                uint af1 = border_color(ret[0] + 0.5) << 24;
                uint r1 = border_color(ret[1] + 0.5) << 16;
                uint g1 = border_color(ret[2] + 0.5) << 8;
                uint b1 = border_color(ret[3] + 0.5);

                return af1 + r1 + g1 + b1;
            }

            void echo(uint *val, int len) {
                int i = 0;
                for (i = 0; i < len; ++i) {
                    AS3_Trace(AS3_String(toString(val[i])));
                }
            }

            static AS3_Val biCubic(void* self, AS3_Val args) {
                AS3_Val srcByte, dstByte;
                int srcWidth, srcHeight, dstWidth, dstHeight;
                AS3_ArrayValue(args,
                        "AS3ValType, IntType, IntType, AS3ValType, IntType, IntType",
                        &srcByte, &srcWidth, &srcHeight, &dstByte, &dstWidth, &dstHeight);

                int srcLen = srcWidth * srcHeight;
                int dstLen = dstWidth * dstHeight;
                uint *src = new uint[srcLen];
                uint *dst = new uint[dstLen];

                AS3_SetS(srcByte, "position", AS3_Int(0));
                AS3_ByteArray_readBytes(src, srcByte, 4 * srcLen);
                double widthFactor = 1.0 * srcWidth / dstWidth;
                double heightFactor = 1.0 * srcHeight / dstHeight;

                int i, j, k, z, gf = 0;
                double tx, ty, u, v;
                int x, y;
                double A[MAXV], C[MAXV];
                uint B[MAXV][MAXV];
                for (i = 0; i < dstWidth; ++i) {
                    for (j = 0; j < dstHeight; ++j) {
                        tx = (i + 0.5) * widthFactor - 0.5;
                        ty = (j + 0.5) * heightFactor - 0.5;
                        if (tx < 0)
                            tx = -tx;
                        if (ty < 0)
                            ty = -ty;
                        x = floor(tx);
                        y = floor(ty);
                        u = tx - x;
                        v = ty - y;
                        for (k = 0; k < MAXV; ++k) {
                            A[k] = SinXDivX(u + 1.0 - k);
                            C[k] = SinXDivX(v + 1.0 - k);
                            for (z = 0; z < MAXV; ++z) {
                                B[k][z] = availablePixel(src, srcWidth, srcHeight,
                                        x + k - 1, y + z - 1);
                            }
                        }
                        dst[i+j*dstWidth] = MatrixMutiple(A, B, C, i, j);
                    }
                }
                //echo(dst, dstLen);

                AS3_SetS(dstByte, "position", AS3_Int(0));
                AS3_ByteArray_writeBytes(dstByte, dst, 4 * dstLen);
                return AS3_True();
            }

            int main() {
                AS3_Val biCubicMethod = AS3_Function(NULL, biCubic);
                AS3_Val lib = AS3_Object("biCubic:AS3ValType", biCubicMethod);
                AS3_Release(biCubicMethod);
                AS3_LibInit(lib);

                return 0;
            }


            as 代碼
            package {
            import cmodule.ImageScaling.CLibInit;
            import flash.display.Bitmap;
            import flash.display.BitmapData;
            import flash.display.Sprite;
            import flash.display.StageScaleMode;
            import flash.geom.Rectangle;
            import flash.utils.ByteArray;
            import flash.utils.Timer;
            [SWF(width="1000", height="600", backgroundColor="#000000", frameRate="24")]
            public class Main extends Sprite {
            [Embed(source='f_01.png')]
            public static const image:Class;
            public function Main() {
            this.stage.scaleMode = StageScaleMode.NO_SCALE;
            var bitmapdata:BitmapData = (new image() as Bitmap).bitmapData;
            var t1:Number = (new Date()).time;
            var bitmap:Bitmap = new Bitmap(Main.Cubic(bitmapdata, 256, 256));
            var t2:Number = (new Date()).time;
            trace((t2-t1)+"ms");
            this.addChild(bitmap);
            }
            public static function Cubic (bitmapData:BitmapData, scalingWidth:uint, scalingHeight:uint):BitmapData {
            var nbd:BitmapData = new BitmapData(scalingWidth, scalingHeight, true, 0xffffffff);
            var loader:cmodule.ImageScaling.CLibInit = new cmodule.ImageScaling.CLibInit();
            var lib:Object = loader.init();
            var byte:ByteArray = bitmapData.getPixels(new Rectangle(0, 0, bitmapData.width, bitmapData.height));
            var byte2:ByteArray = nbd.getPixels(new Rectangle(0, 0, scalingWidth, scalingHeight));
            lib.biCubic(byte, bitmapData.width, bitmapData.height, byte2, scalingWidth, scalingHeight);
            byte2.position = 0;
            nbd.setPixels(new Rectangle(0, 0, scalingWidth, scalingHeight), byte2);
            return nbd;
            }
            }
            }


            posted on 2012-08-10 10:11 此最相思 閱讀(1748) 評(píng)論(0)  編輯 收藏 引用 所屬分類: as

            亚洲?V乱码久久精品蜜桃| 久久人人爽爽爽人久久久| 精品久久久久久亚洲精品| 精品伊人久久大线蕉色首页| 99久久伊人精品综合观看| 日本免费一区二区久久人人澡 | 91久久精一区二区三区大全| 久久国产精品77777| 国产亚洲色婷婷久久99精品| 国内精品人妻无码久久久影院 | 久久ww精品w免费人成| 久久久久亚洲AV片无码下载蜜桃 | 久久久久女人精品毛片| 久久久久人妻精品一区| 亚洲乱亚洲乱淫久久| 国产69精品久久久久99| 久久午夜无码鲁丝片午夜精品| 久久人妻少妇嫩草AV无码蜜桃 | 亚洲综合久久综合激情久久| 久久久久人妻一区精品 | 国内精品人妻无码久久久影院| 久久国产精品久久| 色婷婷狠狠久久综合五月| 久久成人小视频| 亚洲AV日韩AV天堂久久| 91精品观看91久久久久久 | 久久久久亚洲av毛片大| 狠狠综合久久综合88亚洲| 亚洲国产成人久久精品影视| 久久中文字幕人妻丝袜| 99久久精品国内| 日韩亚洲国产综合久久久| 97久久超碰成人精品网站| 狠狠久久综合伊人不卡| 久久中文骚妇内射| 久久精品无码专区免费| 久久人人爽人人爽人人片av高请| 精品久久久久久99人妻| 久久99热只有频精品8| 超级碰碰碰碰97久久久久| 99久久国产综合精品五月天喷水|