internal static IEnumerable<SelectListItem> GetPageSizes(Int32[] pageSizes = null, Int32? currentSize = null)
 {
     if (pageSizes == null)
         pageSizes = TableModel.DefaultPageSizes;
     if (currentSize.HasValue && !pageSizes.Contains(currentSize.Value))
         pageSizes = pageSizes.Union(new[] { currentSize.Value }).OrderBy(p => p).ToArray();
     return pageSizes.Select(i => new SelectListItem { Text = i.ToString(), Value = i.ToString(), Selected = i == TableModel.DefaultPageSize });
 }
Example #2
0
            public void TargetProjectionsOfElementsAreReturnedWhenSourceIsEmpty()
            {
                var source = new Int32[0];
                var expected = new Boolean[0];
                var result = source.Select(i => i == 0);

                Assert.That(result, Is.EqualTo(expected));
            }
 /// <summary>
 /// g = c * log (1 + f)
 /// </summary>
 /// <param name="pixels"></param>
 /// <param name="c">constant</param>
 /// <returns></returns>
 public static Int32[] LogarithmicCorrection(Int32[] pixels, byte c)
 {
     return pixels.Select(pixel => Pixel.SetBrightness(pixel, Pixel.GetValidByte(c * Math.Log(1 + Pixel.GetBrightness(pixel))))).ToArray();
 }
 /// <summary>
 /// g = c + f
 /// </summary>
 /// <param name="pixels"></param>
 /// <param name="c">constant</param>
 /// <returns></returns>
 public static Int32[] ChangeBrightness(Int32[] pixels, byte c)
 {
     return pixels.Select(pixel => Pixel.SetBrightness(pixel, Pixel.GetValidByte(c + Pixel.GetBrightness(pixel)))).ToArray();
 }
Example #5
0
 public void SetIndices(MLOD mlod, MLOD.Mesh mesh, MLOD.GeometryState geometryState, Int32[] indices)
 {
     SetIndices(mlod, mesh.IndexBufferIndex, mesh.PrimitiveType, geometryState.StartIndex, geometryState.PrimitiveCount,
         indices.Select(x => x + geometryState.MinVertexIndex).ToArray());
     geometryState.PrimitiveCount = indices.Length / IndexCountFromPrimitiveType(mesh.PrimitiveType);
 }
 public List<TaskDetail> GetDataBySite(Int64 TaskHeaderID, String TaskSite, Int32[] TaskStatus)
 {
     String Query = "SELECT * FROM TaskDetail WHERE TaskHeaderID = @TaskHeaderID AND TaskSite = @TaskSite AND TaskStatus IN ({0})";
     Query = String.Format(Query, String.Join(",", TaskStatus.Select(x => x.ToString()).ToArray()));
     SqlCeDataManager oDm = new SqlCeDataManager(ConnectionString, Query, true);
     oDm.AddIntegerBigPara("TaskHeaderID", TaskHeaderID);
     oDm.AddVarcharPara("TaskSite", 4000, TaskSite);
     return DataParser.ToList<TaskDetail>(oDm.GetTable());
 }
 public List<TaskDetail> GetDataByStatus(Int64 TaskHeaderID, Int32[] TaskStatus)
 {
     String Query = "SELECT * FROM TaskDetail WHERE TaskHeaderID = " + TaskHeaderID.ToString()
         + " AND TaskStatus IN (" + string.Join(",", TaskStatus.Select(x => x.ToString())) + ")";
     SqlCeDataManager oDm = new SqlCeDataManager(ConnectionString, Query, true);
     return DataParser.ToList<TaskDetail>(oDm.GetTable());
 }
Example #8
0
        private void save_button_Click(object sender, EventArgs e)
        {
            Int32[] new_ingredients;
            new_ingredients = new Int32[10];

            // get information about the selected ingredient and calibration for each pump
            var combo_boxes = settingsPanel.Controls
                           .OfType<ComboBox>()
                           .Where(txt => txt.Name.ToLower().StartsWith("seting"));

            int pump = 0;
            foreach (ComboBox txt in combo_boxes)
            {
                new_ingredients[pump] = txt.SelectedIndex;
                pump++;
            }

            var calib_textboxes = settingsPanel.Controls
                           .OfType<TextBox>()
                           .Where(txt => txt.Name.ToLower().StartsWith("calib"));

            pump = 0;
            Int16[] calib_value;
            calib_value = new Int16[10];
            foreach (TextBox txt in calib_textboxes)
            {
                calib_value[pump] = Convert.ToInt16(txt.Text);
                pump++;
            }

            // start assuming we don't have a duplicate
            bool duplicate = false;

            for (int i = 0; i < 10; i++)
            {
                for (int j = i + 1; j < 10; j++)
                {
                    if ((new_ingredients[i] == new_ingredients[j]) && (new_ingredients[i] != 0))
                        // verify all the ingredients for duplicates
                        duplicate = true;
                }

            }

            // give error if duplicates
            if (!duplicate)
            {
                try
                {
                    System.IO.File.WriteAllLines(@"available_ing.txt", new_ingredients.Select(x => x.ToString()).ToArray());
                    System.IO.File.AppendAllLines(@"available_ing.txt", calib_value.Select(x => x.ToString()).ToArray());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                // Reload
                LoadAll(this, EventArgs.Empty);
                // close seetings panel
                settingsPanel.Visible = false;
            }
            else
            {
                MessageBox.Show("Duplicates were found. \nPlease make sure that you don't have the same ingredient in two slots");
            }
        }
        //Input image and returns a color quantized image (Hardcoded to 31 color - HSB Algorithm!)
        //31 color to allow for a transparent BG color
        private Image GetQuantizedImage(Image image)
        {
            // checks whether a source image is valid
            if (image == null)
            {
                const String message = "Cannot quantize a null image.";
                throw new ArgumentNullException(message);
            }

            // locks the source image data
            Bitmap bitmap = (Bitmap)image;
            Rectangle bounds = Rectangle.FromLTRB(0, 0, bitmap.Width, bitmap.Height);
            BitmapData sourceData = bitmap.LockBits(bounds, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            // prepares time statistics variables
            TimeSpan duration = new TimeSpan(0);
            DateTime before;

            try
            {
                // initalizes the pixel read buffer
                Int32[] sourceBuffer = new Int32[image.Width];

                // sets the offset to the first pixel in the image
                Int64 sourceOffset = sourceData.Scan0.ToInt64();

                for (Int32 row = 0; row < image.Height; row++)
                {
                    // copies the whole row of pixels to the buffer
                    Marshal.Copy(new IntPtr(sourceOffset), sourceBuffer, 0, image.Width);

                    // scans all the colors in the buffer
                    foreach (Color color in sourceBuffer.Select(argb => Color.FromArgb(argb)))
                    {
                        before = DateTime.Now;

                        //Ideas to do the transparent color:
                        // make a mask
                        // AND the bytes
                        if(color != System.Drawing.Color.FromArgb(255,255,0,255))
                              //   .the_quantizerthe_quantizer.AddColor(color);

                        duration += DateTime.Now - before;
                    }

                    // increases a source offset by a row
                    sourceOffset += sourceData.Stride;
                }

                // editTargetInfo.Text = string.Format("Quantized: {0} colors (duration {1})", 256, duration); // TODO
            }
            catch
            {
                bitmap.UnlockBits(sourceData);
                throw;
            }

            Bitmap result = new Bitmap(image.Width, image.Height, PixelFormat.Format8bppIndexed);

            // calculates the palette
            try
            {
                before = DateTime.Now;
                Int32 colorCount = 31; //GetColorCount();
             //   List<Color> palette = the_quantizer.GetPalette(colorCount);

                // sets our newly calculated palette to the target image
                ColorPalette imagePalette = result.Palette;
                duration += DateTime.Now - before;

                imagePalette.Entries[0] = System.Drawing.Color.FromArgb(255, 255, 0, 255);

            /*    for (Int32 index = 1; index-1 < palette.Count; index++)
                {
                   imagePalette.Entries[index] = palette[index-1];
                }
                */
                result.Palette = imagePalette;

            }
            catch (Exception)
            {
                bitmap.UnlockBits(sourceData);
                throw;
            }

            // locks the target image data
            BitmapData targetData = result.LockBits(bounds, ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            try
            {
                // initializes read/write buffers
                Byte[] targetBuffer = new Byte[result.Width];
                Int32[] sourceBuffer = new Int32[image.Width];

                // sets the offsets on the beginning of both source and target image
                Int64 sourceOffset = sourceData.Scan0.ToInt64();
                Int64 targetOffset = targetData.Scan0.ToInt64();

                for (Int32 row = 0; row < image.Height; row++)
                {
                    // reads the pixel row from the source image
                    Marshal.Copy(new IntPtr(sourceOffset), sourceBuffer, 0, image.Width);

                    // goes thru all the pixels, reads the color on the source image, and writes calculated palette index on the target
                    for (Int32 index = 0; index < image.Width; index++)
                    {

                       Color color = Color.FromArgb(sourceBuffer[index]);
                        //Color color = Color.FromArgb(255, 189, 112, 89);

                      if (color == System.Drawing.Color.FromArgb(255, 255, 0, 255))
                           targetBuffer[index] = 0;
                       //else
                        //  targetBuffer[index] = (Byte)(the_quantizer.GetPaletteIndex(color)+1);

                        before = DateTime.Now;
                        duration += DateTime.Now - before;
                    }

                    // writes the pixel row to the target image
                    Marshal.Copy(targetBuffer, 0, new IntPtr(targetOffset), result.Width);

                    // increases the offsets (on both images) by a row
                    sourceOffset += sourceData.Stride;
                    targetOffset += targetData.Stride;
                }
            }
            finally
            {
                // releases the locks on both images
                bitmap.UnlockBits(sourceData);
                result.UnlockBits(targetData);
            }

            // spits some duration statistics (those actually slow the processing quite a bit, turn them off to make it quicker)
            // editSourceInfo.Text = string.Format("Original: {0} colors ({1} x {2})", activeQuantizer.GetColorCount(), image.Width, image.Height);

            // returns the quantized image
            return result;
        }