예제 #1
0
        public override void VisitInstanceFunctionCallSyntax(InstanceFunctionCallSyntax syntax)
        {
            FunctionFlags currentFlags = allowedFlags;

            this.Visit(syntax.BaseExpression);
            this.Visit(syntax.Dot);
            this.Visit(syntax.Name);
            this.Visit(syntax.OpenParen);
            allowedFlags = allowedFlags.HasDecoratorFlag() ? FunctionFlags.Default : allowedFlags;
            this.VisitNodes(syntax.Arguments);
            this.Visit(syntax.CloseParen);
            allowedFlags = currentFlags;

            if (!syntax.Name.IsValid)
            {
                // the parser produced an instance function calls with an invalid name
                // all instance function calls must be bound to a symbol, so let's
                // bind to a symbol without any errors (there's already a parse error)
                this.bindings.Add(syntax, new ErrorSymbol());
                return;
            }

            if (bindings.TryGetValue(syntax.BaseExpression, out var baseSymbol) && baseSymbol is NamespaceSymbol namespaceSymbol)
            {
                var functionSymbol = allowedFlags.HasDecoratorFlag()
                                     // Decorator functions are only valid when HasDecoratorFlag() is true which means
                                     // the instance function call is the top level expression of a DecoratorSyntax node.
                    ? namespaceSymbol.Type.MethodResolver.TryGetSymbol(syntax.Name) ?? namespaceSymbol.Type.DecoratorResolver.TryGetSymbol(syntax.Name)
                    : namespaceSymbol.Type.MethodResolver.TryGetSymbol(syntax.Name);

                var foundSymbol = SymbolValidator.ResolveNamespaceQualifiedFunction(allowedFlags, functionSymbol, syntax.Name, namespaceSymbol);

                this.bindings.Add(syntax, foundSymbol);
            }
        }
예제 #2
0
        /// <summary>
        /// Decompress a JPEG image to an RGB or grayscale image.
        /// </summary>
        /// <returns>A byte buffer containing the decompressed image.</returns>
        /// <param name="jpegBuf">A buffer containing the JPEG image to decompress.</param>
        /// <param name="pixelFormat">Desired pixel format of the destination image.</param>
        /// <param name="bottomUp">If true, then the uncompressed result should be stored in bottom-up (Windows, OpenGL) order, not top-down (X11) order.</param>
        public byte[] Decompress(byte[] jpegBuf, PixelFormat pixelFormat = PixelFormat.RGB, bool bottomUp = false)
        {
            if (jpegBuf == null)
            {
                throw new ArgumentNullException(nameof(jpegBuf));
            }

            ChrominanceSubsampling subsamp;
            Colorspace             colorspace;
            int width, height;

            DecompressHeader(jpegBuf, out width, out height, out subsamp, out colorspace);

            int pitch = pixelFormat.GetPixelSize() * width;

            byte[] dstBuf = new byte[pitch * height];

            FunctionFlags flags = FunctionFlags.NoRealloc;

            if (bottomUp)
            {
                flags |= FunctionFlags.BottomUp;
            }

            Library.tjDecompress2(_handle, jpegBuf, dstBuf, width, pitch, height, pixelFormat, flags);

            return(dstBuf);
        }
예제 #3
0
        /// <summary>
        /// Decompress a JPEG image to a YUV planar image.  This function performs JPEG
        /// decompression but leaves out the color conversion step, so a planar YUV
        /// image is generated instead of an RGB image.
        /// </summary>
        /// <returns>A byte buffer containing the decompressed image in planar YUV format.</returns>
        /// <param name="jpegBuf">A buffer containing the JPEG image to decompress.</param>
        /// <param name="pad">
        /// The width of each line in each plane of the YUV image will be padded to the nearest multiple of this number
        /// of bytes (must be a power of 2.) To generate images suitable for X Video, this should be set to 4.
        /// </param>
        /// <param name="bottomUp">If true, then the uncompressed result should be stored in bottom-up (Windows, OpenGL) order, not top-down (X11) order.</param>
        /// <remarks>
        /// Note that, if the width or height of the image is not an even multiple of
        /// the MCU block size (see <see cref="ChrominanceSubsamplingExtensions.GetMCUWidth"/>
        /// and <see cref="ChrominanceSubsamplingExtensions.GetMCUHeight"/>), then an
        /// intermediate buffer copy will be performed within TurboJPEG.
        /// </remarks>
        public byte[] DecompressToYUV(byte[] jpegBuf, int pad = 4, bool bottomUp = false)
        {
            if (jpegBuf == null)
            {
                throw new ArgumentNullException(nameof(jpegBuf));
            }

            ChrominanceSubsampling subsamp;
            Colorspace             colorspace;
            int width, height;

            DecompressHeader(jpegBuf, out width, out height, out subsamp, out colorspace);

            FunctionFlags flags = FunctionFlags.NoRealloc;

            if (bottomUp)
            {
                flags |= FunctionFlags.BottomUp;
            }

            uint outputSize = Library.tjBufSizeYUV2(width, pad, height, subsamp);

            byte[] output = new byte[outputSize];

            Library.tjDecompressToYUV2(_handle, jpegBuf, output, width, pad, height, flags);

            return(output);
        }
예제 #4
0
 public FunctionData(
     string name,
     string group,
     string description,
     IClientData clientData,
     string typeName,
     int arguments,
     TypeList types,
     FunctionFlags flags,
     IPlugin plugin,
     long token
     )
 {
     this.kind        = IdentifierKind.FunctionData;
     this.id          = AttributeOps.GetObjectId(this);
     this.name        = name;
     this.group       = group;
     this.description = description;
     this.clientData  = clientData;
     this.typeName    = typeName;
     this.arguments   = arguments;
     this.types       = types;
     this.flags       = flags;
     this.plugin      = plugin;
     this.token       = token;
 }
예제 #5
0
 public static Symbol ResolveNamespaceQualifiedFunction(FunctionFlags allowedFlags, Symbol?foundSymbol, IdentifierSyntax identifierSyntax, NamespaceSymbol namespaceSymbol)
 => ResolveSymbolInternal(
     allowedFlags,
     foundSymbol,
     identifierSyntax,
     getNameSuggestions: () => namespaceSymbol.Type.MethodResolver.GetKnownFunctions().Keys,
     getMissingNameError: (builder, suggestedName) => suggestedName switch {
     null => builder.FunctionDoesNotExistInNamespace(namespaceSymbol, identifierSyntax.IdentifierName),
 public FunctionBindingInfo(string name, int paramCount, NodeEvaluate evaluate, AstNode targetNode, FunctionFlags flags)
 {
     Name       = name;
     Evaluate   = evaluate;
     ParamCount = paramCount;
     LocalCount = ParamCount; //by default
     TargetNode = targetNode;
     Flags      = flags;
 }
예제 #7
0
 public override void VisitMissingDeclarationSyntax(MissingDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ParameterDecorator |
                    FunctionFlags.VariableDecorator |
                    FunctionFlags.ResourceDecorator |
                    FunctionFlags.ModuleDecorator |
                    FunctionFlags.OutputDecorator;
     base.VisitMissingDeclarationSyntax(syntax);
     allowedFlags = FunctionFlags.Default;
 }
예제 #8
0
 public static void Serialize(this SerializingContainer2 sc, ref FunctionFlags flags)
 {
     if (sc.IsLoading)
     {
         flags = (FunctionFlags)sc.ms.ReadUInt32();
     }
     else
     {
         sc.ms.Writer.WriteUInt32((uint)flags);
     }
 }
예제 #9
0
 public override void VisitImportDeclarationSyntax(ImportDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ImportDecorator;
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.Visit(syntax.ProviderName);
     this.Visit(syntax.AsKeyword);
     this.Visit(syntax.AliasName);
     this.Visit(syntax.Config);
     allowedFlags = FunctionFlags.Default;
 }
예제 #10
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ParameterDecorator;
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.Visit(syntax.Name);
     this.Visit(syntax.Type);
     allowedFlags = FunctionFlags.ParamDefaultsOnly;
     this.Visit(syntax.Modifier);
     allowedFlags = FunctionFlags.Default;
 }
예제 #11
0
 public override void VisitVariableDeclarationSyntax(VariableDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.VariableDecorator;
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.Visit(syntax.Name);
     this.Visit(syntax.Assignment);
     allowedFlags = FunctionFlags.RequiresInlining;
     this.Visit(syntax.Value);
     allowedFlags = FunctionFlags.Default;
 }
예제 #12
0
 public override void VisitModuleDeclarationSyntax(ModuleDeclarationSyntax syntax)
 {
     this.Visit(syntax.Keyword);
     this.Visit(syntax.Name);
     this.Visit(syntax.Path);
     this.Visit(syntax.Assignment);
     allowedFlags = FunctionFlags.Default;
     this.Visit(syntax.IfCondition);
     allowedFlags = FunctionFlags.RequiresInlining;
     this.Visit(syntax.Body);
     allowedFlags = FunctionFlags.Default;
 }
예제 #13
0
        public DecoratorBuilder WithFlags(FunctionFlags flags)
        {
            if (!Enum.IsDefined(typeof(FunctionFlags), flags))
            {
                // VisitMissingDeclarationSyntax in the TypeAssignmentVisitor uses the flags to determine the error message in cases of dangling decorators
                throw new ArgumentException($"The specified flags value is not explicitly defined in the {nameof(FunctionFlags)} enumeration. Define the combination and update usages to ensure the combination is handled correctly.");
            }

            this.functionOverloadBuilder.WithFlags(flags);

            return(this);
        }
예제 #14
0
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode ToList(
            FunctionFlags hasFlags,
            FunctionFlags notHasFlags,
            bool hasAll,
            bool notHasAll,
            string pattern,
            bool noCase,
            ref StringList list,
            ref Result error
            )
        {
            StringList inputList;

            //
            // NOTE: If no flags were supplied, we do not bother filtering on
            //       them.
            //
            if ((hasFlags == FunctionFlags.None) &&
                (notHasFlags == FunctionFlags.None))
            {
                inputList = new StringList(this.Keys);
            }
            else
            {
                inputList = new StringList();

                foreach (KeyValuePair <string, _Wrappers.Function> pair in this)
                {
                    if (pair.Value != null)
                    {
                        if (((hasFlags == FunctionFlags.None) ||
                             FlagOps.HasFlags(pair.Value.Flags,
                                              hasFlags, hasAll)) &&
                            ((notHasFlags == FunctionFlags.None) ||
                             !FlagOps.HasFlags(pair.Value.Flags,
                                               notHasFlags, notHasAll)))
                        {
                            inputList.Add(pair.Key);
                        }
                    }
                }
            }

            if (list == null)
            {
                list = new StringList();
            }

            return(GenericOps <string> .FilterList(
                       inputList, list, Index.Invalid, Index.Invalid,
                       ToStringFlags.None, pattern, noCase, ref error));
        }
예제 #15
0
 public FunctionWildcardOverload(
     string name,
     string description,
     Regex wildcardRegex,
     ReturnTypeBuilderDelegate returnTypeBuilder,
     TypeSymbol returnType,
     IEnumerable <FixedFunctionParameter> fixedArgumentTypes,
     VariableFunctionParameter?variableArgumentType,
     FunctionFlags flags = FunctionFlags.Default)
     : base(name, description, returnTypeBuilder, returnType, fixedArgumentTypes, variableArgumentType, flags)
 {
     WildcardRegex = wildcardRegex;
 }
예제 #16
0
 public override void VisitIfConditionSyntax(IfConditionSyntax syntax)
 {
     this.Visit(syntax.Keyword);
     allowedFlags = FunctionFlags.Default;
     this.Visit(syntax.ConditionExpression);
     // if-condition syntax parent is always a resource/module declaration
     // this means that we have to allow the functions that are only allowed
     // in resource bodies by our runtime (like reference() or listKeys())
     // TODO: Update when conditions can be composed together with loops
     allowedFlags = FunctionFlags.RequiresInlining;
     this.Visit(syntax.Body);
     allowedFlags = FunctionFlags.Default;
 }
예제 #17
0
 public override void VisitResourceDeclarationSyntax(ResourceDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ResoureDecorator;
     this.VisitNodes(syntax.LeadingNodes);
     this.Visit(syntax.Keyword);
     this.Visit(syntax.Name);
     this.Visit(syntax.Type);
     this.Visit(syntax.Assignment);
     allowedFlags = FunctionFlags.Default;
     this.Visit(syntax.IfCondition);
     allowedFlags = FunctionFlags.RequiresInlining;
     this.Visit(syntax.Body);
     allowedFlags = FunctionFlags.Default;
 }
예제 #18
0
        public static Symbol ResolveNamespaceQualifiedFunction(FunctionFlags allowedFlags, Symbol?foundSymbol, IdentifierSyntax identifierSyntax, NamespaceType namespaceType)
        => ResolveSymbolInternal(
            allowedFlags,
            foundSymbol,
            identifierSyntax,
            getNameSuggestions: () =>
        {
            var knowFunctionNames = namespaceType.MethodResolver.GetKnownFunctions().Keys;

            return(allowedFlags.HasAnyDecoratorFlag()
                        ? knowFunctionNames.Concat(namespaceType.DecoratorResolver.GetKnownDecoratorFunctions().Keys)
                        : knowFunctionNames);
        },
            getMissingNameError: (builder, suggestedName) => suggestedName switch {
            null => builder.FunctionDoesNotExistInNamespace(namespaceType, identifierSyntax.IdentifierName),
예제 #19
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            FunctionFlags flags,
            FunctionFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != FunctionFlags.None);
            }
        }
예제 #20
0
        public FunctionOverload(string name, string description, ReturnTypeBuilderDelegate returnTypeBuilder, TypeSymbol signatureType, IEnumerable <FixedFunctionParameter> fixedParameters, VariableFunctionParameter?variableParameter, EvaluatorDelegate?evaluator, FunctionFlags flags = FunctionFlags.Default)
        {
            Name              = name;
            Description       = description;
            ReturnTypeBuilder = returnTypeBuilder;
            Evaluator         = evaluator;
            FixedParameters   = fixedParameters.ToImmutableArray();
            VariableParameter = variableParameter;
            Flags             = flags;

            MinimumArgumentCount = FixedParameters.Count(fp => fp.Required) + (VariableParameter?.MinimumCount ?? 0);
            MaximumArgumentCount = VariableParameter == null ? FixedParameters.Length : (int?)null;

            TypeSignature       = $"({string.Join(", ", ParameterTypeSignatures)}): {signatureType}";
            TypeSignatureSymbol = signatureType;
        }
예제 #21
0
        public override void VisitFunctionCallSyntax(FunctionCallSyntax syntax)
        {
            FunctionFlags currentFlags = allowedFlags;

            this.Visit(syntax.Name);
            this.Visit(syntax.OpenParen);
            allowedFlags = allowedFlags.HasDecoratorFlag() ? FunctionFlags.Default : allowedFlags;
            this.VisitNodes(syntax.Arguments);
            this.Visit(syntax.CloseParen);
            allowedFlags = currentFlags;

            var symbol = this.LookupSymbolByName(syntax.Name, true);

            // bind what we got - the type checker will validate if it fits
            this.bindings.Add(syntax, symbol);
        }
예제 #22
0
 public FunctionWildcardOverload(
     string name,
     string genericDescription,
     string description,
     Regex wildcardRegex,
     ResultBuilderDelegate resultBuilder,
     TypeSymbol returnType,
     IEnumerable <FixedFunctionParameter> fixedArgumentTypes,
     VariableFunctionParameter?variableArgumentType,
     EvaluatorDelegate?evaluator,
     VariableGeneratorDelegate?variableGenerator = null,
     FunctionFlags flags = FunctionFlags.Default)
     : base(name, genericDescription, description, resultBuilder, returnType, fixedArgumentTypes, variableArgumentType, evaluator, variableGenerator, flags)
 {
     WildcardRegex = wildcardRegex;
 }
예제 #23
0
        public override bool Deserialize()
        {
            var result = base.Deserialize();

            NativeToken = Data.ReadUInt16();

            //OperatorPrecedence = Data.ReadByte(); // Does not appear in ME3?

            FunctionFlags = (FunctionFlags)Data.ReadInt32();

            if (FunctionFlags.HasFlag(FunctionFlags.Net))
            {
                ReplicateOffset = Data.ReadUInt16();
            }

            return(result);
        }
예제 #24
0
        /// <summary>
        /// Compress an RGB, grayscale, or CMYK image into a JPEG image.
        /// </summary>
        /// <returns>A byte array containing the compressed JPEG result.</returns>
        /// <param name="srcBuf">An image buffer containing RGB, grayscale, or CMYK pixels to be compressed.</param>
        /// <param name="width">Width (in pixels) of the source image.</param>
        /// <param name="pitch">
        ///  Bytes per line of the source image.  Normally, this should be
        ///  <c>width * format.GetPixelSize()</c> if the image is unpadded,
        ///  or <c><see cref="Library.TJPAD"/>(width * format.GetPixelSize())</c> if each line of
        ///  the image is padded to the nearest 32-bit boundary, as is the case
        ///  for Windows bitmaps.  You can also be clever and use this parameter
        ///  to skip lines, etc.  Setting this parameter to 0 is the equivalent of
        ///  setting it to <c>width * format.GetPixelSize()</c>.
        /// </param>
        /// <param name="height">Height (in pixels) of the source image.</param>
        /// <param name="format">Pixel format of the source image.</param>
        /// <param name="jpegQual">The image quality of the generated JPEG image (1 = worst, 100 = best).</param>
        /// <param name="jpegSubsamp">The level of chrominance subsampling to be used when generating the JPEG image.</param>
        /// <param name="bottomUp">If true, then the uncompressed source image is stored in bottom-up (Windows, OpenGL) order, not top-down (X11) order.</param>
        public byte[] Compress(byte[] srcBuf, int width, int pitch, int height, PixelFormat format, int jpegQual, ChrominanceSubsampling jpegSubsamp = ChrominanceSubsampling.SAMP_420, bool bottomUp = false)
        {
            if (srcBuf == null)
            {
                throw new ArgumentNullException(nameof(srcBuf));
            }

            IntPtr jpegBuf = IntPtr.Zero;

            byte[]        output;
            FunctionFlags flags = FunctionFlags.NoRealloc;

            if (bottomUp)
            {
                flags |= FunctionFlags.BottomUp;
            }

            try {
                // Although tjBufSize almost always returns a bigger buffer than we need,
                // it's better to have extra and only allocate once, instead of incurring
                // the cost of realloc and a mid compress buffer copy.
                uint jpegSize = Library.tjBufSize(width, height, jpegSubsamp);
                if (jpegSize == uint.MaxValue)
                {
                    throw new Exception(Library.tjGetErrorStr());
                }
                jpegBuf = Library.tjAlloc((int)jpegSize);
                if (jpegBuf == IntPtr.Zero)
                {
                    throw new Exception(String.Format("tjAlloc failed to allocate {0} bytes", jpegSize));
                }

                Library.tjCompress2(_handle, srcBuf, width, pitch, height, format, ref jpegBuf, ref jpegSize, jpegSubsamp, jpegQual, flags);

                output = new byte[jpegSize];

                Marshal.Copy(jpegBuf, output, 0, output.Length);
            } finally {
                if (jpegBuf != IntPtr.Zero)
                {
                    Library.tjFree(jpegBuf);
                }
            }

            return(output);
        }
예제 #25
0
 public Function(string name, FunctionFlags flags,
                 VariableType returntype, CodeBody body,
                 List <FunctionParameter> parameters = null,
                 SourcePosition start = null, SourcePosition end = null)
     : base(ASTNodeType.Function, start, end)
 {
     Name       = name;
     Body       = body;
     ReturnType = returntype;
     Flags      = flags;
     Parameters = parameters ?? new List <FunctionParameter>();
     Locals     = new List <VariableDeclaration>();
     VarType    = new DelegateType(this)
     {
         IsFunction  = true,
         Declaration = this
     };
     if (Body != null)
     {
         Body.Outer = this;
     }
 }
예제 #26
0
        public override void Serialize(IUnrealSerializer serializer)
        {
            base.Serialize(serializer);

            if (serializer.Mode == UnrealSerializationMode.Loading)
            {
                uint rawFunctionFlags = 0;
                serializer.Serialize(ref rawFunctionFlags);
                this._FunctionFlags = (FunctionFlags)rawFunctionFlags;
            }
            else if (serializer.Mode == UnrealSerializationMode.Saving)
            {
                var rawFunctionFlags = (uint)this._FunctionFlags;
                serializer.Serialize(ref rawFunctionFlags);
            }

            if ((this._FunctionFlags & FunctionFlags.Net) != 0)
            {
                serializer.Serialize(ref this._RepOffset);
            }

            serializer.Serialize(ref this._EventGraphFunction);
            serializer.Serialize(ref this._EventGraphCallOffset);
        }
예제 #27
0
 public bool HasFunctionFlag(FunctionFlags flag)
 {
     return(((uint)FunctionFlags & (uint)flag) != 0);
 }
예제 #28
0
 public static bool HasAllDecoratorFlags(this FunctionFlags functionFlags) => (functionFlags & DecoratorFlags) == DecoratorFlags;
예제 #29
0
 public bool HasFunctionFlag( FunctionFlags flag )
 {
     return ((uint)FunctionFlags & (uint)flag) != 0;
 }
예제 #30
0
        /// <summary>
        /// Losslessly transform a JPEG image into another JPEG image.  Lossless
        /// transforms work by moving the raw coefficients from one JPEG image structure
        /// to another without altering the values of the coefficients.  While this is
        /// typically faster than decompressing the image, transforming it, and
        /// re-compressing it, lossless transforms are not free.  Each lossless
        /// transform requires reading and performing Huffman decoding on all of the
        /// coefficients in the source image, regardless of the size of the destination
        /// image.  Thus, this function provides a means of generating multiple
        /// transformed images from the same source or  applying multiple
        /// transformations simultaneously, in order to eliminate the need to read the
        /// source coefficients multiple times.
        /// </summary>
        /// <param name="handle">a handle to a TurboJPEG transformer instance.</param>
        /// <param name="jpegBuf">pointer to a buffer containing the JPEG image to transform</param>
        /// <param name="dstBufs">
        /// pointer to an array of <paramref name="n"/> image buffers.  <paramref name="dstBufs"/>[i]
        /// will receive a JPEG image that has been transformed using the
        /// parameters in <paramref name="transforms"/>[i].  TurboJPEG has the ability to
        /// reallocate the JPEG buffer to accommodate the size of the JPEG image.
        /// Thus, you can choose to:
        /// <list type="bullet">
        /// <item>
        /// <description>
        /// pre-allocate the JPEG buffer with an arbitrary size using
        /// <see cref="tjAlloc"/> and let TurboJPEG grow the buffer as needed,
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// set <paramref name="dstBufs"/>[i] to NULL to tell TurboJPEG to allocate the
        /// buffer for you, or
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// pre-allocate the buffer to a "worst case" size determined by
        /// calling <see cref="tjBufSize"/> with the transformed or cropped width and
        /// height.  This should ensure that the buffer never has to be
        /// re-allocated (setting <see cref="FunctionFlags.NoRealloc"/> guarantees this.)
        /// </description>
        /// </item>
        /// </list>
        /// If you choose option 1, <paramref name="dstSizes"/>[i] should be set to
        /// the size of your pre-allocated buffer.  In any case, unless you have set
        /// <see cref="FunctionFlags.NoRealloc"/>, you should always check <paramref name="dstBufs"/>[i]
        /// upon return from this function, as it may have changed.
        /// </param>
        /// <param name="dstSizes">
        /// pointer to an array of <paramref name="n"/> unsigned long variables that will
        /// receive the actual sizes (in bytes) of each transformed JPEG image.  If
        /// <paramref name="dstBufs"/>[i] points to a pre-allocated buffer, then
        /// <paramref name="dstSizes"/>[i] should be set to the size of the buffer.  Upon return,
        /// <paramref name="dstSizes"/>[i] will contain the size of the JPEG image (in bytes.)
        /// </param>
        /// <param name="transforms">
        /// pointer to an array of <paramref name="n"/> <see cref="Transform"/> structures, each of
        /// which specifies the transform parameters and/or cropping region for
        /// the corresponding transformed output image.
        /// </param>
        /// <param name="flags">the bitwise OR of one or more of the <see cref="FunctionFlags"/>.</param>
        /// <returns>0 if successful, or -1 if an error occurred (see <see cref="tjGetErrorStr"/>.)</returns>
        /// <remarks>
        /// Defined in turbojpeg.h as:
        /// 
        /// DLLEXPORT int DLLCALL tjTransform(tjhandle handle,
        ///   const unsigned char* jpegBuf, unsigned long jpegSize, int n,
        ///   unsigned char** dstBufs, unsigned long* dstSizes, tjtransform *transforms,
        ///   int flags);
        /// </remarks>
        internal static void tjTransform(IntPtr handle, byte [] jpegBuf, IntPtr[] dstBufs, uint [] dstSizes, Transform [] transforms, FunctionFlags flags)
        {
            int retval;

            if (IsLP64)
            {
                ulong [] dstSizes64 = new ulong [dstSizes.Length];
                dstSizes.CopyTo (dstSizes64, 0);

                retval = tjTransform_64 (handle, jpegBuf, (ulong)jpegBuf.Length, transforms.Length, dstBufs, dstSizes64, transforms, flags);

                for (int i = 0; i < dstSizes.Length; ++i)
                    dstSizes [i] = (uint)dstSizes64 [i];
            }
            else
                retval = tjTransform_32 (handle, jpegBuf, (uint)jpegBuf.Length, transforms.Length, dstBufs, dstSizes, transforms, flags);

            if (retval != 0)
                throw new TurboJPEGException ();
        }
예제 #31
0
        /// <summary>
        /// Compress a set of Y, U (Cb), and V (Cr) image planes into a JPEG image.
        /// </summary>
        /// <param name="handle">a handle to a TurboJPEG compressor or transformer instance</param>
        /// <param name="srcPlanes">
        /// an array of pointers to Y, U (Cb), and V (Cr) image planes
        /// (or just a Y plane, if compressing a grayscale image) that contain a YUV
        /// image to be compressed.  These planes can be contiguous or non-contiguous in
        /// memory.  The size of each plane should match the value returned by
        /// <see cref="tjPlaneSizeYUV"/> for the given image width, height, strides, and level of
        /// chrominance subsampling.  Refer to @ref YUVnotes "YUV Image Format Notes"
        /// for more details.
        /// </param>
        /// <param name="width">
        /// width (in pixels) of the source image.  If the width is not an
        /// even multiple of the MCU block width (see <see cref="ChrominanceSubsamplingExtensions.GetMCUWidth"/>), then an intermediate
        /// buffer copy will be performed within TurboJPEG.
        /// </param>
        /// <param name="strides">
        /// an array of integers, each specifying the number of bytes per
        /// line in the corresponding plane of the YUV source image.  Setting the stride
        /// for any plane to 0 is the same as setting it to the plane width (see
        /// @ref YUVnotes "YUV Image Format Notes".)  If <c>strides</c> is NULL, then
        /// the strides for all planes will be set to their respective plane widths.
        /// You can adjust the strides in order to specify an arbitrary amount of line
        /// padding in each plane or to create a JPEG image from a subregion of a larger
        /// YUV planar image.
        /// </param>
        /// <param name="height">
        /// height (in pixels) of the source image.  If the height is not
        /// an even multiple of the MCU block height (see <see cref="ChrominanceSubsamplingExtensions.GetMCUHeight"/>), then an
        /// intermediate buffer copy will be performed within TurboJPEG.
        /// </param>
        /// <param name="subsamp">
        /// the level of chrominance subsampling used in the source
        /// image (see <see cref="ChrominanceSubsampling"/>.) 
        /// </param>
        /// <param name="jpegBuf">
        /// address of a pointer to an image buffer that will receive the
        /// JPEG image.  TurboJPEG has the ability to reallocate the JPEG buffer to
        /// accommodate the size of the JPEG image.  Thus, you can choose to:
        /// <list type="bullet">
        /// <item>
        /// <description>
        /// pre-allocate the JPEG buffer with an arbitrary size using
        /// <see cref="tjAlloc"/> and let TurboJPEG grow the buffer as needed,
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// set <paramref name="jpegBuf"/> to NULL to tell TurboJPEG to allocate the buffer
        /// for you, or
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// pre-allocate the buffer to a "worst case" size determined by calling
        /// <see cref="tjBufSize"/>.  This should ensure that the buffer never has to be
        /// re-allocated (setting <see cref="FunctionFlags.NoRealloc"/> guarantees this.)
        /// </description>
        /// </item>
        /// </list>
        /// If you choose option 1, <paramref name="jpegSize"/> should be set to the size of your
        /// pre-allocated buffer.  In any case, unless you have set <see cref="FunctionFlags.NoRealloc"/>,
        /// you should always check <c>jpegBuf</c> upon return from this function, as
        /// it may have changed.
        /// </param>
        /// <param name="jpegSize">
        /// Pointer to an unsigned long variable that holds the size of
        /// the JPEG image buffer.  If <paramref name="jpegBuf"/> points to a pre-allocated
        /// buffer, then <c>jpegSize</c> should be set to the size of the buffer.
        /// Upon return, <c>jpegSize</c> will contain the size of the JPEG image (in
        /// bytes.)  If <paramref name="jpegBuf"/> points to a JPEG image buffer that is being
        /// reused from a previous call to one of the JPEG compression functions, then
        /// <c>jpegSize</c> is ignored.
        /// </param>
        /// <param name="jpegQual">The image quality of the generated JPEG image (1 = worst, 100 = best)</param>
        /// <param name="flags">the bitwise OR of one or more of the <see cref="FunctionFlags"/>.</param>
        /// <exception cref="TurboJPEGException">Thrown if an error occured.</exception>
        /// <remarks>
        /// Defined in turbojpeg.h as:
        /// 
        /// DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle,
        ///   const unsigned char** srcPlanes, int width, const int* strides, int height,
        ///   int subsamp, unsigned char** jpegBuf, unsigned long* jpegSize, int jpegQual,
        ///   int flags);
        /// </remarks>
        internal static void tjCompressFromYUVPlanes(
			IntPtr handle,
			byte [,] srcPlanes, int width, int [] strides, int height,
			ChrominanceSubsampling subsamp, ref IntPtr jpegBuf, ref uint jpegSize, int jpegQual,
			FunctionFlags flags)
        {
            int retval;
            if (IsLP64)
            {
                ulong jpegSize64 = jpegSize;
                retval = tjCompressFromYUVPlanes_64(handle, srcPlanes, width, strides, height, subsamp, ref jpegBuf, ref jpegSize64, jpegQual, flags);
                jpegSize = (uint)jpegSize64;
            }
            else
                retval = tjCompressFromYUVPlanes_32(handle, srcPlanes, width, strides, height, subsamp, ref jpegBuf, ref jpegSize, jpegQual, flags);

            if (retval != 0)
                throw new TurboJPEGException ();
        }
예제 #32
0
        private static extern int tjDecompressToYUVPlanes_64(
			IntPtr handle,
			byte[] jpegBuf, ulong jpegSize,
			byte[,] dstPlanes, int width, int[] strides, int height, FunctionFlags flags);
예제 #33
0
        private static extern int tjCompressFromYUV_64(
			IntPtr handle,
			byte [] srcBuf, int width, int pad, int height, ChrominanceSubsampling subsamp,
			ref IntPtr jpegBuf, ref ulong jpegSize, int jpegQual, FunctionFlags flags);
예제 #34
0
        internal static extern int tjEncodeYUV3(IntPtr handle,
			byte[] srcBuf, int width, int pitch, int height, PixelFormat pixelFormat,
			IntPtr dstBuf, int pad, ChrominanceSubsampling subsamp, FunctionFlags flags);
예제 #35
0
        /// <summary>
        /// Decompress a JPEG image into separate Y, U (Cb), and V (Cr) image
        /// planes.  This function performs JPEG decompression but leaves out the color
        /// conversion step, so a planar YUV image is generated instead of an RGB image.
        /// </summary>
        /// <param name="handle">a handle to a TurboJPEG decompressor or transformer instance.</param>
        /// <param name="jpegBuf">pointer to a buffer containing the JPEG image to decompress</param>
        /// <param name="dstPlanes">
        /// an array of pointers to Y, U (Cb), and V (Cr) image planes
        /// (or just a Y plane, if decompressing a grayscale image) that will receive
        /// the YUV image.These planes can be contiguous or non-contiguous in memory.
        /// Use <see cref="tjPlaneSizeYUV"/> to determine the appropriate size for each plane based
        /// on the scaled image width, scaled image height, strides, and level of
        /// chrominance subsampling.Refer to @ref YUVnotes "YUV Image Format Notes"
        /// for more details.
        /// </param>
        /// <param name="width">
        /// desired width (in pixels) of the YUV image.  If this is
        /// different than the width of the JPEG image being decompressed, then
        /// TurboJPEG will use scaling in the JPEG decompressor to generate the largest
        /// possible image that will fit within the desired width.  If <c>width</c> is
        /// set to 0, then only the height will be considered when determining the
        /// scaled image size.  If the scaled width is not an even multiple of the MCU
        /// block width (see #tjMCUWidth), then an intermediate buffer copy will be
        /// performed within TurboJPEG.
        /// </param>
        /// <param name="strides">
        /// an array of integers, each specifying the number of bytes per
        /// line in the corresponding plane of the output image.  Setting the stride for
        /// any plane to 0 is the same as setting it to the scaled plane width (see
        /// @ref YUVnotes "YUV Image Format Notes".)  If <c>strides</c> is NULL, then
        /// the strides for all planes will be set to their respective scaled plane
        /// widths.  You can adjust the strides in order to add an arbitrary amount of
        /// line padding to each plane or to decompress the JPEG image into a subregion
        /// of a larger YUV planar image.
        /// </param>
        /// <param name="height">
        /// desired height (in pixels) of the YUV image.  If this is
        /// different than the height of the JPEG image being decompressed, then
        /// TurboJPEG will use scaling in the JPEG decompressor to generate the largest
        /// possible image that will fit within the desired height.If<tt>height</tt>
        /// is set to 0, then only the width will be considered when determining the
        /// scaled image size.If the scaled height is not an even multiple of the MCU
        /// block height (see #tjMCUHeight), then an intermediate buffer copy will be
        /// performed within TurboJPEG.
        /// </param>
        /// <param name="flags">the bitwise OR of one or more of the <see cref="FunctionFlags"/>.</param>
        /// <exception cref="TurboJPEGException">Thrown if an error occured.</exception>
        /// <remarks>
        /// Defined in turbojpeg.h as:
        /// 
        /// DLLEXPORT int DLLCALL tjDecompressToYUVPlanes (tjhandle handle,
        ///   const unsigned char* jpegBuf, unsigned long jpegSize,
        ///   unsigned char** dstPlanes, int width, int* strides, int height, int flags);
        /// </remarks>
        internal static void tjDecompressToYUVPlanes(
			IntPtr handle, byte[] jpegBuf, byte[,] dstPlanes, int width, int [] strides, int height, FunctionFlags flags)
        {
            int retval;

            if (IsLP64)
                retval = tjDecompressToYUVPlanes_64 (handle, jpegBuf, (ulong)jpegBuf.Length, dstPlanes, width, strides, height, flags);
            else
                retval = tjDecompressToYUVPlanes_32 (handle, jpegBuf, (uint)jpegBuf.Length, dstPlanes, width, strides, height, flags);

            if (retval != 0)
                throw new TurboJPEGException ();
        }
예제 #36
0
 public override void VisitOutputDeclarationSyntax(OutputDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.RequiresInlining;
     base.VisitOutputDeclarationSyntax(syntax);
     allowedFlags = FunctionFlags.Default;
 }
예제 #37
0
        /// <summary>
        /// Compress an RGB or grayscale image into a JPEG image.
        /// </summary>
        /// <param name="handle">a handle to a TurboJPEG compressor or transformer instance.</param>
        /// <param name="srcBuf">pointer to an image buffer containing RGB or grayscale pixels to be compressed.</param>
        /// <param name="width">width (in pixels) of the source image.</param>
        /// <param name="pitch">
        /// bytes per line of the source image. Normally, this should be
        /// <paramref name="width"/> * <see cref="PixelFormatExtensions.GetPixelSize"/>(<paramref name="pixelFormat"/>) if the image is unpadded, or
        /// <see cref="TJPAD"/>(<paramref name="width"/> * <see cref="PixelFormatExtensions.GetPixelSize"/>(<paramref name="pixelFormat"/>)) if each line of the image
        /// is padded to the nearest 32-bit boundary, as is the case for Windows
        /// bitmaps.  You can also be clever and use this parameter to skip lines, etc.
        /// Setting this parameter to 0 is the equivalent of setting it to
        /// <paramref name="width"/> * <see cref="PixelFormatExtensions.GetPixelSize"/>(<paramref name="pixelFormat"/>).
        /// </param>
        /// <param name="height">height (in pixels) of the source image.</param>
        /// <param name="pixelFormat">pixel format of the source image (see <see cref="PixelFormat"/>.).</param>
        /// <param name="jpegBuf">
        /// address of a pointer to an image buffer that will receive the
        /// JPEG image.  TurboJPEG has the ability to reallocate the JPEG buffer to
        /// accommodate the size of the JPEG image.  Thus, you can choose to:
        /// <list type="bullet">
        /// <item>
        /// <description>
        /// pre-allocate the JPEG buffer with an arbitrary size using
        /// <see cref="tjAlloc"/> and let TurboJPEG grow the buffer as needed,
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// set <paramref name="jpegBuf"/> to NULL to tell TurboJPEG to allocate the buffer
        /// for you, or
        /// </description>
        /// </item>
        /// <item>
        /// <description>
        /// pre-allocate the buffer to a "worst case" size determined by calling
        /// <see cref="tjBufSize"/>.  This should ensure that the buffer never has to be
        /// re-allocated (setting <see cref="FunctionFlags.NoRealloc"/> guarantees this.)
        /// </description>
        /// </item>
        /// </list>
        /// If you choose option 1, <paramref name="jpegSize"/> should be set to the size of your
        /// pre-allocated buffer.  In any case, unless you have set <see cref="FunctionFlags.NoRealloc"/>,
        /// you should always check <c>jpegBuf</c> upon return from this function, as
        /// it may have changed.
        /// </param>
        /// <param name="jpegSize">
        /// pointer to an unsigned long variable that holds the size of
        /// the JPEG image buffer.  If <paramref name="jpegBuf"/> points to a pre-allocated
        /// buffer, then <c>jpegSize</c> should be set to the size of the buffer.
        /// Upon return, <c>jpegSize</c> will contain the size of the JPEG image (in
        /// bytes.)  If <paramref name="jpegBuf"/> points to a JPEG image buffer that is being
        /// reused from a previous call to one of the JPEG compression functions, then
        /// <c>jpegSize</c> is ignored.
        /// </param>
        /// <param name="jpegSubsamp">
        /// the level of chrominance subsampling to be used when
        /// generating the JPEG image (see <see cref="ChrominanceSubsampling"/>.)
        /// </param>
        /// <param name="jpegQual">the image quality of the generated JPEG image (1 = worst, 100 = best)</param>
        /// <param name="flags">the bitwise OR of one or more of the <see cref="FunctionFlags"/>.</param>
        /// <exception cref="TurboJPEGException">Thrown if an error occurred.</exception>
        /// <remarks>
        /// Defined in turbojpeg.h as:
        /// 
        /// DLLEXPORT int DLLCALL tjCompress2 (tjhandle handle, const unsigned char* srcBuf,
        ///   int width, int pitch, int height, int pixelFormat, unsigned char** jpegBuf,
        ///   unsigned long* jpegSize, int jpegSubsamp, int jpegQual, int flags);
        /// </remarks>
        internal static void tjCompress2(IntPtr handle, byte [] srcBuf,
			int width, int pitch, int height, PixelFormat pixelFormat, ref IntPtr jpegBuf,
			ref uint jpegSize, ChrominanceSubsampling jpegSubsamp, int jpegQual, FunctionFlags flags)
        {
            int retval;
            if (IsLP64)
            {
                ulong jpegSize64 = jpegSize;
                retval = tjCompress2_64 (handle, srcBuf, width, pitch, height, pixelFormat, ref jpegBuf, ref jpegSize64, jpegSubsamp, jpegQual, flags);
                jpegSize = (uint)jpegSize64;
            }
            else
                retval = tjCompress2_32(handle, srcBuf, width, pitch, height, pixelFormat, ref jpegBuf, ref jpegSize, jpegSubsamp, jpegQual, flags);

            if (retval != 0)
                throw new TurboJPEGException ();
        }
예제 #38
0
 public override void VisitParameterDeclarationSyntax(ParameterDeclarationSyntax syntax)
 {
     allowedFlags = FunctionFlags.ParamDefaultsOnly;
     base.VisitParameterDeclarationSyntax(syntax);
     allowedFlags = FunctionFlags.Default;
 }
예제 #39
0
        private static extern int tjCompress2_64(IntPtr handle, byte [] srcBuf,
			int width, int pitch, int height, PixelFormat pixelFormat, ref IntPtr jpegBuf,
			ref ulong jpegSize, ChrominanceSubsampling jpegSubsamp, int jpegQual, FunctionFlags flags);
예제 #40
0
        private static extern int tjDecompressToYUV2_64(IntPtr handle,
			byte [] jpegBuf, ulong jpegSize, byte [] dstBuf,
			int width, int pad, int height,
			FunctionFlags flags);
예제 #41
0
        internal static extern int tjDecodeYUVPlanes(
			IntPtr handle,
			byte[,] srcPlanes, int[] strides, ChrominanceSubsampling subsamp,
			byte[] dstBuf, int width, int pitch, int height, PixelFormat pixelFormat,
			FunctionFlags flags);
예제 #42
0
        private static extern int tjCompressFromYUVPlanes_32(
			IntPtr handle,
			byte [,] srcPlanes, int width, int [] strides, int height,
			ChrominanceSubsampling subsamp, ref IntPtr jpegBuf, ref uint jpegSize, int jpegQual,
			FunctionFlags flags);
예제 #43
0
        private static extern int tjTransform_64(IntPtr handle, byte [] jpegBuf,
			ulong jpegSize, int n, IntPtr[] dstBufs, ulong [] dstSizes, Transform [] transforms, FunctionFlags flags);
예제 #44
0
        /// <summary>
        /// Decompress a JPEG image to a YUV planar image.  This function performs JPEG
        /// decompression but leaves out the color conversion step, so a planar YUV
        /// image is generated instead of an RGB image.
        /// </summary>
        /// <param name="handle">a handle to a TurboJPEG decompressor or transformer instance.</param>
        /// <param name="jpegBuf">pointer to a buffer containing the JPEG image to decompress.</param>
        /// <param name="dstBuf">
        /// pointer to an image buffer that will receive the YUV image.
        /// Use <see cref="tjBufSizeYUV2"/> to determine the appropriate size for this buffer based
        /// on the image width, height, padding, and level of subsampling.  The Y,
        /// U (Cb), and V (Cr) image planes will be stored sequentially in the buffer
        /// (refer to @ref YUVnotes "YUV Image Format Notes".)
        /// </param>
        /// <param name="width">
        /// width desired width (in pixels) of the YUV image.  If this is
        /// different than the width of the JPEG image being decompressed, then
        /// TurboJPEG will use scaling in the JPEG decompressor to generate the largest
        /// possible image that will fit within the desired width.  If <c>width</c> is
        /// set to 0, then only the height will be considered when determining the
        /// scaled image size.  If the scaled width is not an even multiple of the MCU
        /// block width (see #tjMCUWidth), then an intermediate buffer copy will be
        /// performed within TurboJPEG.
        /// </param>
        /// <param name="pad">
        /// the width of each line in each plane of the YUV image will be
        /// padded to the nearest multiple of this number of bytes (must be a power of
        /// 2.)  To generate images suitable for X Video, <tt>pad</tt> should be set to
        /// 4.
        /// </param>
        /// <param name="height">
        /// desired height (in pixels) of the YUV image.  If this is
        /// different than the height of the JPEG image being decompressed, then
        /// TurboJPEG will use scaling in the JPEG decompressor to generate the largest
        /// possible image that will fit within the desired height.If<tt>height</tt>
        /// is set to 0, then only the width will be considered when determining the
        /// scaled image size.If the scaled height is not an even multiple of the MCU
        /// block height (see #tjMCUHeight), then an intermediate buffer copy will be
        /// performed within TurboJPEG.
        /// </param>
        /// <param name="flags">the bitwise OR of one or more of the <see cref="FunctionFlags"/>.</param>
        /// <exception cref="TurboJPEGException">Thrown if an error occured.</exception>
        /// <remarks>
        /// Defined in turbojpeg.h as:
        /// 
        /// DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
        ///   const unsigned char* jpegBuf, unsigned long jpegSize, unsigned char* dstBuf,
        ///   int width, int pad, int height, int flags);
        /// </remarks>
        internal static void tjDecompressToYUV2(IntPtr handle,
			byte [] jpegBuf, byte [] dstBuf,
			int width, int pad, int height,
			FunctionFlags flags)
        {
            int retval;

            if (IsLP64)
                retval = tjDecompressToYUV2_64 (handle, jpegBuf, (ulong)jpegBuf.Length, dstBuf, width, pad, height, flags);
            else
                retval = tjDecompressToYUV2_32 (handle, jpegBuf, (uint)jpegBuf.Length, dstBuf, width, pad, height, flags);

            if (retval != 0)
                throw new TurboJPEGException ();
        }
예제 #45
0
        private static extern int tjDecompress2_64(IntPtr handle,
			byte [] jpegBuf, ulong jpegSize, byte [] dstBuf,
			int width, int pitch, int height, PixelFormat pixelFormat, FunctionFlags flags);