コード例 #1
0
        public void TestInitialize()
        {
            mockImageProcessor    = new Mock <IImageProcessorWrapper>();
            imageProcessorWrapper = mockImageProcessor.Object;
            sut = new WaterMarker(imageProcessorWrapper);

            // Setup mocking here...
            mockImageProcessor
            .Setup(imgProc => imgProc.Load(It.IsAny <MemoryStream>()))
            .Returns(imageProcessorWrapper);
            mockImageProcessor
            .Setup(imgProc => imgProc.Watermark(It.IsAny <IWaterMark>()))
            .Returns(imageProcessorWrapper);
            mockImageProcessor
            .SetupGet(imgProc => imgProc.Image)
            .Returns(imageProcessorWrapper.Image);
        }
コード例 #2
0
        public async Task GetImagesAsync()
        {
            var imageList = new List <UploadedImage>();
            var token     = new BlobContinuationToken();
            var blobList  = await _uploadContainer.ListBlobsSegmentedAsync(ImagePrefix, true, BlobListingDetails.All, 100, token, null, null);

            foreach (var blob in blobList.Results)
            {
                CloudBlockBlob thing = (CloudBlockBlob)blob;
                string         name  = thing.Name;
                _logger.LogInformation($"Blob name is : {name}");
                Stream inputFile = await thing.OpenReadAsync();

                Stream outputFile = new MemoryStream();
                WaterMarker.WriteWatermark("i am so hungry", inputFile, outputFile);
                await AddImageAsync(outputFile, name);
                await DeleteImageAsync(name);
            }
        }
コード例 #3
0
 public static void Run([BlobTrigger("images/{name}")] Stream inputBlob,
                        [Blob("watermarked/{name}", FileAccess.Write)] Stream outputBlob,
                        string name,
                        ILogger log)
 {
     if (!outputBlob.CanWrite)
     {
         log.LogError($"{Constants.WatermarkedContainer} Blob has no Write access");
         return;
     }
     try
     {
         WaterMarker.Generate(inputBlob, outputBlob);
         log.LogInformation($"Image:{name}, {inputBlob.Length} bytes");
     }
     catch (Exception e)
     {
         log.LogError($"Watermaking failed {e.Message}");
     }
 }
コード例 #4
0
        // this is only needed for map testing
        // private byte[,] originalTestMap = null;

        public TerrainMap(Terrain[] terrains1D, int sceneBuildId)
        {
            _sceneBuildId = sceneBuildId;
            WaterMarker water = GameObject.FindObjectOfType <WaterMarker>();

            if (water != null)
            {
                WATER_HEIGHT = water.GetMaxChildHeight();
                Debug.Log($"Water found with height {WATER_HEIGHT}.");
            }
            else
            {
                WATER_HEIGHT = -1000;
                Debug.LogWarning(
                    "Could not find any water, is this really a fully dry map?");
            }

            // Find limits of the map
            MapMin = new Vector3(99999f, 0f, 99999f);
            MapMax = new Vector3(-99999f, 0f, -99999f);
            foreach (Terrain terrain in terrains1D)
            {
                if (terrain.gameObject.layer != 8)
                {
                    Debug.LogWarning($"The terrain at {terrain.gameObject} does not have " +
                                     $"the 'terrain' layer, instead it has layer {terrain.gameObject.layer}. " +
                                     $"This is very likely to make it impossible to buy units.");
                }
                Vector3 pos  = terrain.transform.position;
                Vector3 size = terrain.terrainData.size;
                MapMin.Set(Mathf.Min(MapMin.x, pos.x), 0.0f, Mathf.Min(MapMin.z, pos.z));
                MapMax.Set(Mathf.Max(MapMax.x, pos.x + size.x), 0.0f, Mathf.Max(MapMax.z, pos.z + size.x));
            }
            MapCenter = (MapMin + MapMax) / 2f;

            // Move terrains from 1D array to 2D array
            int sqrtLen = Mathf.RoundToInt(Mathf.Sqrt(terrains1D.Length));

            _terrains        = new Terrain[sqrtLen, sqrtLen];
            _terrainSpacingX = (MapMax.x - MapMin.x) / sqrtLen;
            _terrainSpacingZ = (MapMax.z - MapMin.z) / sqrtLen;
            for (int i = 0; i < sqrtLen; i++)
            {
                for (int j = 0; j < sqrtLen; j++)
                {
                    Vector3 corner = MapMin + new Vector3(_terrainSpacingX * i, 0f, _terrainSpacingZ * j);
                    foreach (Terrain terrain in terrains1D)
                    {
                        if (Mathf.Abs(terrain.transform.position.x - corner.x) < _terrainSpacingX / 2 &&
                            Mathf.Abs(terrain.transform.position.z - corner.z) < _terrainSpacingZ / 2)
                        {
                            _terrains[i, j] = terrain;
                        }
                    }
                }
            }

            _mapSize = (int)(Mathf.Max(MapMax.x - MapMin.x, MapMax.z - MapMin.z) / 2f / MAP_SPACING);

            _HEIGHT_MAP_PATH = GetTerrainMapCachePath();

            int mapLen = 2 * _mapSize + 2 * EXTENSION;

            _map        = new byte[mapLen, mapLen];
            _height_map = new float[mapLen, mapLen];

            _roads   = (ERModularRoad[])GameObject.FindObjectsOfType(typeof(ERModularRoad));
            _bridges = GameObject.FindGameObjectsWithTag("Bridge");

            // get our trees
            foreach (Terrain terrain in _terrains)
            {
                foreach (TreeInstance tree in terrain.terrainData.treeInstances)
                {
                    Vector3 treePosition = Vector3.Scale(tree.position, terrain.terrainData.size) + terrain.transform.position;
                    _treePositions.Add(treePosition);
                }
            }


            // get our bridge positions so we dont have to be in the main thread to access bridge info
            for (int i = 0; i < _bridges.Length; i++)
            {
                GameObject bridge = _bridges[i];
                _bridgePositions.Add(bridge.transform.position);
            }

            //_loader = new Loading("Terrain");

            // TODO need to also somehow verify the height map is valid??
            // not sure how to do this each time without reading the original data.

            if (!MapVersionCheck(_HEIGHT_MAP_PATH))
            {
                File.Delete(_HEIGHT_MAP_PATH);
            }

            if (!File.Exists(_HEIGHT_MAP_PATH))
            {
                // this cannot be in another thread because it uses the terrain and cannot cache the terrain because
                // it is just as slow, so no point in putting it in a worker. Nothing we can really do about this
                // unless one day we release every map with it's compressed data.
                //_loader.AddWorker(LoadWater, null, true, "Loading water");

                //LoadingScreen.SWorkers.Enqueue(new CoroutineWorker(LoadWaterRunner, "Loading water."));

                //AddCouroutine(LoadWaterRunner, "Load water");
                AddCouroutine(WriteHeightMap, "Writing Height Map data for the first time...");

                //AddMultithreadedRoutine(ExportFinishedMapRunner, "Creating Compressed Map File");
            }


            //_loader.AddWorker(null, LoadCompressedMapRunner, false, "Reading Compressed Map Data");
            AddMultithreadedRoutine(ReadHeightMapRunner, "Reading Compressed Height Map Data...");



            // Loading bridges from a separate thread throws an exception.
            // This is why we first cache the bridge positions outside the thread
            // before doing the below. same goes for roads and trees.
            AddMultithreadedRoutine(LoadTreesRunner, "Loading trees...");
            AddMultithreadedRoutine(LoadRoadsRunner, "Loading roads...");
            AddMultithreadedRoutine(LoadBridgesRunner, "Loading bridges...");


            // leave this commented out until we make a change and need to retest the map
            //_loader.AddWorker(MapTester);
        }