示例#1
0
            public ColInfoEx(ModelLoadContext ctx)
            {
                Contracts.AssertValue(ctx);

                // *** Binary format ***
                // byte: colors
                // int: widht
                // int: height
                // Float: offset
                // Float: scale
                // byte: separateChannels
                Colors = (ColorBits)ctx.Reader.ReadByte();
                Contracts.CheckDecode(Colors != 0);
                Contracts.CheckDecode((Colors & ColorBits.All) == Colors);

                // Count the planes.
                int planes = (int)Colors;

                planes = (planes & 0x05) + ((planes >> 1) & 0x05);
                planes = (planes & 0x03) + ((planes >> 2) & 0x03);
                Planes = (byte)planes;
                Contracts.Assert(0 < Planes & Planes <= 4);

                Width = ctx.Reader.ReadInt32();
                Contracts.CheckDecode(Width > 0);
                Height = ctx.Reader.ReadInt32();
                Contracts.CheckDecode(Height > 0);
                Offset = ctx.Reader.ReadFloat();
                Contracts.CheckDecode(FloatUtils.IsFinite(Offset));
                Scale = ctx.Reader.ReadFloat();
                Contracts.CheckDecode(FloatUtils.IsFiniteNonZero(Scale));
                Interleave = ctx.Reader.ReadBoolByte();
            }
示例#2
0
            public void Save(ModelSaveContext ctx)
            {
                Contracts.AssertValue(ctx);

#if DEBUG
                // This code is used in deserialization - assert that it matches what we computed above.
                int planes = (int)Colors;
                planes = (planes & 0x05) + ((planes >> 1) & 0x05);
                planes = (planes & 0x03) + ((planes >> 2) & 0x03);
                Contracts.Assert(planes == Planes);
#endif

                // *** Binary format ***
                // byte: colors
                // byte: convert
                // Float: offset
                // Float: scale
                // byte: separateChannels
                Contracts.Assert(Colors != 0);
                Contracts.Assert((Colors & ColorBits.All) == Colors);
                ctx.Writer.Write((byte)Colors);
                ctx.Writer.Write(Width);
                ctx.Writer.Write(Height);
                Contracts.Assert(FloatUtils.IsFinite(Offset));
                ctx.Writer.Write(Offset);
                Contracts.Assert(FloatUtils.IsFiniteNonZero(Scale));
                ctx.Writer.Write(Scale);
                ctx.Writer.WriteBoolByte(Interleave);
            }
示例#3
0
            public ColInfoEx(Column item, Arguments args)
            {
                if (item.ContainsAlpha ?? args.ContainsAlpha)
                {
                    Colors |= ColorBits.Alpha; Planes++;
                }
                if (item.ContainsRed ?? args.ContainsRed)
                {
                    Colors |= ColorBits.Red; Planes++;
                }
                if (item.ContainsGreen ?? args.ContainsGreen)
                {
                    Colors |= ColorBits.Green; Planes++;
                }
                if (item.ContainsBlue ?? args.ContainsBlue)
                {
                    Colors |= ColorBits.Blue; Planes++;
                }
                Contracts.CheckUserArg(Planes > 0, nameof(item.ContainsRed), "Need to use at least one color plane");

                Interleave = item.InterleaveArgb ?? args.InterleaveArgb;

                Width  = item.ImageWidth ?? args.ImageWidth;
                Height = item.ImageHeight ?? args.ImageHeight;
                Offset = item.Offset ?? args.Offset ?? 0;
                Scale  = item.Scale ?? args.Scale ?? 1;
                Contracts.CheckUserArg(FloatUtils.IsFinite(Offset), nameof(item.Offset));
                Contracts.CheckUserArg(FloatUtils.IsFiniteNonZero(Scale), nameof(item.Scale));
            }
示例#4
0
            internal ColumnInfo(string input, string output, ModelLoadContext ctx)
            {
                Contracts.AssertNonEmpty(input);
                Contracts.AssertNonEmpty(output);
                Contracts.AssertValue(ctx);

                Input  = input;
                Output = output;

                // *** Binary format ***
                // byte: colors
                // byte: convert
                // Float: offset
                // Float: scale
                // byte: separateChannels
                Colors = (ColorBits)ctx.Reader.ReadByte();
                Contracts.CheckDecode(Colors != 0);
                Contracts.CheckDecode((Colors & ColorBits.All) == Colors);

                // Count the planes.
                int planes = (int)Colors;

                planes = (planes & 0x05) + ((planes >> 1) & 0x05);
                planes = (planes & 0x03) + ((planes >> 2) & 0x03);
                Planes = (byte)planes;
                Contracts.Assert(0 < Planes & Planes <= 4);

                Convert = ctx.Reader.ReadBoolByte();
                Offset  = ctx.Reader.ReadFloat();
                Contracts.CheckDecode(FloatUtils.IsFinite(Offset));
                Scale = ctx.Reader.ReadFloat();
                Contracts.CheckDecode(FloatUtils.IsFiniteNonZero(Scale));
                Contracts.CheckDecode(Convert || Offset == 0 && Scale == 1);
                Interleave = ctx.Reader.ReadBoolByte();
            }
示例#5
0
            /// <summary>
            /// Describes how the transformer handles one input-output column pair.
            /// </summary>
            /// <param name="name">Name of the column resulting from the transformation of <paramref name="inputColumnName"/>.</param>
            /// <param name="inputColumnName">Name of column to transform. If set to <see langword="null"/>, the value of the <paramref name="name"/> will be used as source.</param>
            /// <param name="colors">What colors to extract.</param>
            /// <param name="interleave"></param>
            /// <param name="scale">Scale color pixel value by this amount.</param>
            /// <param name="offset">Offset color pixel value by this amount.</param>
            /// <param name="asFloat">Output array as float array. If false, output as byte array.</param>

            public ColumnInfo(string name, string inputColumnName = null,
                              ColorBits colors = Defaults.Colors,
                              bool interleave  = Defaults.Interleave,
                              float scale      = Defaults.Scale,
                              float offset     = Defaults.Offset,
                              bool asFloat     = Defaults.Convert)
            {
                Contracts.CheckNonWhiteSpace(name, nameof(name));

                Name            = name;
                InputColumnName = inputColumnName ?? name;
                Colors          = colors;

                if ((Colors & ColorBits.Alpha) == ColorBits.Alpha)
                {
                    Planes++;
                }
                if ((Colors & ColorBits.Red) == ColorBits.Red)
                {
                    Planes++;
                }
                if ((Colors & ColorBits.Green) == ColorBits.Green)
                {
                    Planes++;
                }
                if ((Colors & ColorBits.Blue) == ColorBits.Blue)
                {
                    Planes++;
                }
                Contracts.CheckParam(Planes > 0, nameof(colors), "Need to use at least one color plane");

                Interleave = interleave;

                AsFloat = asFloat;
                if (!AsFloat)
                {
                    Offset = Defaults.Offset;
                    Scale  = Defaults.Scale;
                }
                else
                {
                    Offset = offset;
                    Scale  = scale;
                }
                Contracts.CheckParam(FloatUtils.IsFinite(Offset), nameof(offset));
                Contracts.CheckParam(FloatUtils.IsFiniteNonZero(Scale), nameof(scale));
            }
示例#6
0
            private ColumnInfo(string input, string output, ColorBits colors, bool interleave, bool convert, float scale, float offset)
            {
                Contracts.CheckNonEmpty(input, nameof(input));
                Contracts.CheckNonEmpty(output, nameof(output));

                Input  = input;
                Output = output;
                Colors = colors;

                if ((Colors & ColorBits.Alpha) == ColorBits.Alpha)
                {
                    Planes++;
                }
                if ((Colors & ColorBits.Red) == ColorBits.Red)
                {
                    Planes++;
                }
                if ((Colors & ColorBits.Green) == ColorBits.Green)
                {
                    Planes++;
                }
                if ((Colors & ColorBits.Blue) == ColorBits.Blue)
                {
                    Planes++;
                }
                Contracts.CheckParam(Planes > 0, nameof(colors), "Need to use at least one color plane");

                Interleave = interleave;

                Convert = convert;
                if (!Convert)
                {
                    Offset = 0;
                    Scale  = 1;
                }
                else
                {
                    Offset = offset;
                    Scale  = scale;
                    Contracts.CheckParam(FloatUtils.IsFinite(Offset), nameof(offset));
                    Contracts.CheckParam(FloatUtils.IsFiniteNonZero(Scale), nameof(scale));
                }
            }
示例#7
0
            internal ColumnInfo(Column item, Arguments args)
            {
                Contracts.CheckValue(item, nameof(item));
                Contracts.CheckValue(args, nameof(args));

                Input  = item.Source ?? item.Name;
                Output = item.Name;

                if (item.UseAlpha ?? args.UseAlpha)
                {
                    Colors |= ColorBits.Alpha; Planes++;
                }
                if (item.UseRed ?? args.UseRed)
                {
                    Colors |= ColorBits.Red; Planes++;
                }
                if (item.UseGreen ?? args.UseGreen)
                {
                    Colors |= ColorBits.Green; Planes++;
                }
                if (item.UseBlue ?? args.UseBlue)
                {
                    Colors |= ColorBits.Blue; Planes++;
                }
                Contracts.CheckUserArg(Planes > 0, nameof(item.UseRed), "Need to use at least one color plane");

                Interleave = item.InterleaveArgb ?? args.InterleaveArgb;

                Convert = item.Convert ?? args.Convert;
                if (!Convert)
                {
                    Offset = 0;
                    Scale  = 1;
                }
                else
                {
                    Offset = item.Offset ?? args.Offset ?? 0;
                    Scale  = item.Scale ?? args.Scale ?? 1;
                    Contracts.CheckUserArg(FloatUtils.IsFinite(Offset), nameof(item.Offset));
                    Contracts.CheckUserArg(FloatUtils.IsFiniteNonZero(Scale), nameof(item.Scale));
                }
            }