private void BtnCreate_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int y = 0; y < DestinationImage.PhysicalDimension.Height; y++)
            {
                for (int x = 0; x < DestinationImage.PhysicalDimension.Width; x++)
                {
                    var color = DestinationImage.GetPixel(x, y);

                    int b1, b2;

                    b1 = (color.R & 0xF8) | (color.G >> 5);
                    b2 = ((color.G & 0x1C) << 3) | (color.B >> 3);

                    stringBuilder.AppendLine($"0x{b2.ToString("X")},0x{b1.ToString("X")},");
                }
            }

            string header = $"const unsigned char myImage[{DestinationImage.PhysicalDimension.Height * DestinationImage.PhysicalDimension.Width * 2}] = {{";
            string code   = stringBuilder.ToString();

            code = code.Substring(0, code.Length - 3);
            string footer = "};";

            TxtCode.Text = $"{header}{Environment.NewLine}{code}{Environment.NewLine}{footer}";
        }
Beispiel #2
0
        public async Task <ActionResult> Index(Destination?destination, int count = 50)
        {
            if (destination.HasValue)
            {
                DestinationImageRepository imageRepository = await DestinationImageRepository.Create();

                DestinationImage destinationImage = imageRepository.Find(destination.Value);

                ViewBag.Title    = $"{destination} Schedule";
                ViewBag.ImageUrl = destinationImage?.ImageURL;

                string SAStoken = ConfigurationHelper.GetConfigValue("SAStoken");
                if ((ViewBag.ImageUrl) != null)
                {
                    ViewBag.ImageUrl += SAStoken;
                }
            }
            else
            {
                ViewBag.Title    = "All Schedules";
                ViewBag.ImageUrl = null;
            }

            ScheduleRepository scheduleRepository = new ScheduleRepository();

            IList <Schedule> schedules = await scheduleRepository.GetCategoryAsync(destination, count);

            return(View(schedules));
        }
Beispiel #3
0
        public async Task UpdateAsync(DestinationImage destinationImage)
        {
            Trace.TraceInformation($"Updating image: {destinationImage.Destination}");

            _db.Entry(destinationImage).State = EntityState.Modified;

            await _db.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task AddAsync(DestinationImage destinationImage)
        {
            Trace.TraceInformation($"Adding image: {destinationImage.Destination}");

            _db.DestinationImages.Add(destinationImage);

            await _db.SaveChangesAsync();
        }
Beispiel #5
0
        public async Task <DestinationImage> FindAsync(Guid id)
        {
            Trace.TraceInformation($"Finding image by id: {id}");

            DestinationImage image = await _db.DestinationImages.FindAsync(id);

            return(image);
        }
Beispiel #6
0
        private void GérerSouris()
        {
            Point positionSouris = GestionInput.GetPositionSouris();

            if (GestionInput.EstNouveauClicGauche())
            {
                if (DestinationImage.Contains(positionSouris))
                {
                    EstSélectionné /*EstActif*/ = true;
                    //Fond = FondActif;
                }
                else
                {
                    EstSélectionné = false;
                    //Fond = FondInactif; //propriété?
                }
            }
        }
Beispiel #7
0
        private async Task UpdateUrl(Destination destination, string url)
        {
            DestinationImageRepository imageRepository = await DestinationImageRepository.Create();

            DestinationImage destinationImage = imageRepository.Find(destination);

            if (destinationImage == null)
            {
                await imageRepository.AddAsync(new DestinationImage
                {
                    Id          = Guid.NewGuid(),
                    Destination = destination,
                    ImageURL    = url
                });
            }
            else
            {
                destinationImage.ImageURL = url;

                await imageRepository.UpdateAsync(destinationImage);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Renders the destination image using the contents of the source
        /// noise map and an optional background image.
        /// </summary>
        /// <remarks>
        /// The background image and the destination image can safely refer to
        /// the same image, although in this case, the destination image is
        /// irretrievably blended into the background image.
        /// </remarks>
        public void Render()
        {
            if (SourceNoiseMap == null ||
                DestinationImage == null ||
                SourceNoiseMap.Width <= 0 ||
                SourceNoiseMap.Height <= 0 ||
                gradient.PointCount < 2)
            {
                throw new InvalidOperationException("The renderer isn't propertly set up.");
            }

            var width  = SourceNoiseMap.Width;
            var height = SourceNoiseMap.Height;

            // If a background image was provided, make sure it is the same size the
            // source noise map.
            if (BackgroundImage != null)
            {
                if (BackgroundImage.Width != width ||
                    BackgroundImage.Height != height)
                {
                    throw new ArgumentException("The provided background image isn't the same size as the source NoiseMap.");
                }
            }

            // Create the destination image.  It is safe to reuse it if this is also the
            // background image.
            if (DestinationImage != BackgroundImage)
            {
                DestinationImage.SetSize(height, width);
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    float source = SourceNoiseMap[x, y];

                    // Get the color based on the value at the current point in the noise
                    // map.
                    Color destColor = gradient.GetColor(source);

                    // If lighting is enabled, calculate the light intensity based on the
                    // rate of change at the current point in the noise map.
                    double lightIntensity;;
                    if (EnableLight)
                    {
                        // Calculate the positions of the current point's four-neighbors.
                        int xLeftOffset, xRightOffset;
                        int yUpOffset, yDownOffset;
                        if (EnableWrap)
                        {
                            if (x == 0)
                            {
                                xLeftOffset  = width - 1;
                                xRightOffset = 1;
                            }
                            else if (x == width - 1)
                            {
                                xLeftOffset  = -1;
                                xRightOffset = -(width - 1);
                            }
                            else
                            {
                                xLeftOffset  = -1;
                                xRightOffset = 1;
                            }
                            if (y == 0)
                            {
                                yDownOffset = height - 1;
                                yUpOffset   = 1;
                            }
                            else if (y == height - 1)
                            {
                                yDownOffset = -1;
                                yUpOffset   = -(height - 1);
                            }
                            else
                            {
                                yDownOffset = -1;
                                yUpOffset   = 1;
                            }
                        }
                        else
                        {
                            if (x == 0)
                            {
                                xLeftOffset  = 0;
                                xRightOffset = 1;
                            }
                            else if (x == width - 1)
                            {
                                xLeftOffset  = -1;
                                xRightOffset = 0;
                            }
                            else
                            {
                                xLeftOffset  = -1;
                                xRightOffset = 1;
                            }
                            if (y == 0)
                            {
                                yDownOffset = 0;
                                yUpOffset   = 1;
                            }
                            else if (y == height - 1)
                            {
                                yDownOffset = -1;
                                yUpOffset   = 0;
                            }
                            else
                            {
                                yDownOffset = -1;
                                yUpOffset   = 1;
                            }
                        }

                        yDownOffset *= SourceNoiseMap.Width;
                        yUpOffset   *= SourceNoiseMap.Width;

                        // Get the noise value of the current point in the source noise map
                        // and the noise values of its four-neighbors.
                        var nc = (double)(SourceNoiseMap[x, y]);
                        var nl = (double)(SourceNoiseMap[x + xLeftOffset, y]);
                        var nr = (double)(SourceNoiseMap[x + xRightOffset, y]);
                        var nd = (double)(SourceNoiseMap[x, y + yDownOffset]);
                        var nu = (double)(SourceNoiseMap[x, y + yUpOffset]);

                        // Now we can calculate the lighting intensity.
                        lightIntensity  = CalcLightIntensity(nc, nl, nr, nd, nu);
                        lightIntensity *= LightBrightness;
                    }
                    else
                    {
                        // These values will apply no lighting to the destination image.
                        lightIntensity = 1.0;
                    }

                    // Get the current background color from the background image.
                    Color backgroundColor;
                    if (BackgroundImage != null)
                    {
                        backgroundColor = BackgroundImage[x, y];
                    }
                    else
                    {
                        backgroundColor = new Color(255, 255, 255, 255);
                    }

                    // Blend the destination color, background color, and the light
                    // intensity together, then update the destination image with that
                    // color.
                    DestinationImage[x, y] = CalcDestinationColor(destColor, backgroundColor, lightIntensity);
                }
            }
        }