GetRawTextureData() private method

private GetRawTextureData ( ) : byte[]
return byte[]
コード例 #1
0
 static public int GetRawTextureData(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Texture2D self = (UnityEngine.Texture2D)checkSelf(l);
         var ret = self.GetRawTextureData();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
コード例 #2
0
        public void EqualSource()
        {
            Assert.AreEqual(texture.Cube, false);
            Assert.AreEqual(texture.Format, (Schema.TextureFormat)originTexture.format);
            Assert.AreEqual(texture.MipmapCount, originTexture.mipmapCount);
            Assert.AreEqual(texture.AlphaIsTransparency, originTexture.alphaIsTransparency);
            Assert.AreEqual(texture.Width, originTexture.width);
            Assert.AreEqual(texture.Height, originTexture.height);
            Assert.AreEqual(texture.Depth, 1);
            Assert.AreEqual(texture.AnisoLevel, originTexture.anisoLevel);
            Assert.AreEqual(texture.FilterMode, (Schema.FilterMode)originTexture.filterMode);
            Assert.AreEqual(texture.MipMapBias, originTexture.mipMapBias);
            Assert.AreEqual(texture.WrapMode, (Schema.TextureWrapMode)originTexture.wrapMode);

            byte[] originRawData = originTexture.GetRawTextureData();

            ArraySegment <byte> arrayRawData = texture.GetRawDataBytes().GetValueOrDefault();

            byte[] rawData = new byte[arrayRawData.Count];
            Array.Copy(arrayRawData.Array, arrayRawData.Offset, rawData, 0, arrayRawData.Count);

            Assert.AreEqual(originRawData.Length, texture.RawDataLength);
            Assert.AreEqual(originRawData.Length, arrayRawData.Count);

            for (int i = 0; i < originRawData.Length; i++)
            {
                Assert.AreEqual(originRawData[i], rawData[i]);
            }
        }
コード例 #3
0
        public static ByteBuffer Save(UnityEngine.Texture2D texture)
        {
            FlatBufferBuilder builder = new FlatBufferBuilder(InitBufferSize);

            VectorOffset voRawData = Schema.Texture.CreateRawDataVector(builder, texture.GetRawTextureData());

            Schema.Texture.StartTexture(builder);

            Schema.Texture.AddCube(builder, false);

            Schema.Texture.AddFormat(builder, (Schema.TextureFormat)texture.format);
            Schema.Texture.AddMipmapCount(builder, texture.mipmapCount);
            Schema.Texture.AddAlphaIsTransparency(builder, texture.alphaIsTransparency);

            Schema.Texture.AddWidth(builder, texture.width);
            Schema.Texture.AddHeight(builder, texture.height);
            Schema.Texture.AddDepth(builder, 1);
            Schema.Texture.AddAnisoLevel(builder, texture.anisoLevel);
            Schema.Texture.AddFilterMode(builder, (Schema.FilterMode)texture.filterMode);
            Schema.Texture.AddMipMapBias(builder, texture.mipMapBias);
            Schema.Texture.AddWrapMode(builder, (Schema.TextureWrapMode)texture.wrapMode);

            Schema.Texture.AddRawData(builder, voRawData);

            builder.Finish(Schema.Texture.EndTexture(builder).Value);

            return(builder.DataBuffer);
        }
コード例 #4
0
    public static void Create(Texture2D texture)
    {
        var map = texture.GetRawTextureData();
        if (texture.name == "hoge")
        {
            var alpha = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
            var j = 0;
            var png = new byte[map.Length];
            for(var i = 0; i < map.Length; i += 4)
            {
                png[i]   = 0;
                png[i+1] = 0;
                png[i+2] = 0;
                png[i+3] = map[i];

                if (j == texture.width)
                {
                    j = -1;
                }
                j ++;
            }
            Debug.Log(alpha.width + ", " + alpha.height);
            Debug.Log(map.Length + " - " + png.Length);
            alpha.LoadRawTextureData(png);
            alpha.Apply();
            var pngData = alpha.EncodeToPNG();
            string filePath = EditorUtility.SaveFilePanel("Save Texture", "", "alphaMap.png", "png");
            if (filePath.Length > 0) {
                // pngファイル保存.
                File.WriteAllBytes(filePath, pngData);
            }
        }

        using (Stream stream = File.OpenWrite("Assets/Resources/AlphaMap/" + texture.name + ".bytes")) {
            using (var writer = new BinaryWriter(stream)) {
                writer.Write((uint)texture.width);
                writer.Write((uint)texture.height);
                for (var i = 0; i < map.Length; i += 4 * 8)
                {
                    int j = i + 4, k = i + 8, l = i + 12, m = i + 16, n = i + 20, o = i + 24, p = i + 28;
                    byte b = (byte)(
                        128 * Bit(map, p)+
                        64  * Bit(map, o)+
                        32  * Bit(map, n)+
                        16  * Bit(map, m)+
                        8   * Bit(map, l)+
                        4   * Bit(map, k)+
                        2   * Bit(map, j)+
                        1   * Bit(map, i));
                    writer.Write(b);
                }
            }
        }
    }
コード例 #5
0
 static public int GetRawTextureData(IntPtr l)
 {
     try {
         UnityEngine.Texture2D self = (UnityEngine.Texture2D)checkSelf(l);
         var ret = self.GetRawTextureData();
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
コード例 #6
0
    // вызывается из потока событий unity
    static private PacketDepthReady depth(PacketHeader packet)
    {
        if (activecamera != "")
        {
            int w = 1280;
            int h = 720;

            UnityEngine.GameObject obj    = cameras[idnames[activecamera]];
            UnityEngine.Camera     camera = obj.GetComponent <UnityEngine.Camera>();

            UnityEngine.Texture2D map = new UnityEngine.Texture2D(w, h, UnityEngine.TextureFormat.RGB24, false);

            UnityEngine.RenderTexture texture = new UnityEngine.RenderTexture(w, h, 0);
            UnityEngine.RenderTexture.active     = texture;
            camera.targetTexture                 = texture;
            obj.GetComponent <camera>().IsdDepth = true;
            camera.Render();
            obj.GetComponent <camera>().IsdDepth = false;

            map.ReadPixels(new UnityEngine.Rect(0, 0, w, h), 0, 0);
            map.Apply();

            byte[] raw    = map.GetRawTextureData();
            byte[] floats = new byte[h * w * 4];

            for (int y = 0; y < h; y++)
            {
                int y_ = h - y - 1;
                for (int x = 0; x < w; x++)
                {
                    float depth =
                        raw[(y_ * w + x) * 3 + 0] / 255.0f +
                        raw[(y_ * w + x) * 3 + 1] / 65025.0f +
                        raw[(y_ * w + x) * 3 + 2] / 16581375.0f;
                    depth = (depth == 0.0f || depth == 1.0f) ? 0.0f : camera.nearClipPlane + (camera.farClipPlane - camera.nearClipPlane) * depth;
                    byte[] eb = BitConverter.GetBytes(depth);
                    floats[(y * w + x) * 4 + 0] = BitConverter.IsLittleEndian ? eb[3] : eb[0];
                    floats[(y * w + x) * 4 + 1] = BitConverter.IsLittleEndian ? eb[2] : eb[1];
                    floats[(y * w + x) * 4 + 2] = BitConverter.IsLittleEndian ? eb[1] : eb[2];
                    floats[(y * w + x) * 4 + 3] = BitConverter.IsLittleEndian ? eb[0] : eb[3];
                }
            }

            camera.targetTexture             = null;
            UnityEngine.RenderTexture.active = null;
            UnityEngine.Object.Destroy(map);

            return(new PacketDepthReady(1, Convert.ToBase64String(floats)));
        }

        return(new PacketDepthReady(0, ""));
    }
コード例 #7
0
		public vectorx.ColorStorage GetBitmapDataFromFile(string file)
		{
			Debug.Log ("Loading bitmap: " + file);

			var asset = Resources.Load (file) as TextAsset;
			var texture = new Texture2D (2, 2);
			texture.LoadImage (asset.bytes);
			var bytes = texture.GetRawTextureData ();
			var stream = new System.IO.MemoryStream(bytes);
			var data = types.Data.fromMemoryStream (stream,  bytes.Length);

			return new vectorx.ColorStorage (texture.width, texture.height, data);
		}
コード例 #8
0
 static int QPYX_GetRawTextureData_YXQP(IntPtr L_YXQP)
 {
     try
     {
         ToLua.CheckArgsCount(L_YXQP, 1);
         UnityEngine.Texture2D QPYX_obj_YXQP = (UnityEngine.Texture2D)ToLua.CheckObject(L_YXQP, 1, typeof(UnityEngine.Texture2D));
         byte[] QPYX_o_YXQP = QPYX_obj_YXQP.GetRawTextureData();
         ToLua.Push(L_YXQP, QPYX_o_YXQP);
         return(1);
     }
     catch (Exception e_YXQP)                {
         return(LuaDLL.toluaL_exception(L_YXQP, e_YXQP));
     }
 }
コード例 #9
0
 static int GetRawTextureData(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.Texture2D obj = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
         byte[] o = obj.GetRawTextureData();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #10
0
 public static int GetRawTextureData_wrap(long L)
 {
     try
     {
         long nThisPtr             = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.Texture2D obj = get_obj(nThisPtr);
         byte[] ret     = obj.GetRawTextureData();
         long   ret_ptr = FCLibHelper.fc_get_return_ptr(L);
         FCCustomParam.ReturnArray(ret, ret_ptr);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
コード例 #11
0
    static int GetRawTextureData(IntPtr L)
    {
#if UNITY_EDITOR
        ToluaProfiler.AddCallRecord("UnityEngine.Texture2D.GetRawTextureData");
#endif
        try
        {
            ToLua.CheckArgsCount(L, 1);
            UnityEngine.Texture2D obj = (UnityEngine.Texture2D)ToLua.CheckObject(L, 1, typeof(UnityEngine.Texture2D));
            byte[] o = obj.GetRawTextureData();
            ToLua.Push(L, o);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
コード例 #12
0
        public static Texture2D Instantiate <T>(Texture2D original) where T : Texture2D
        {
            Texture2D tex = new Texture2D(original.GetRawTextureData());

            return(tex);
        }