Example #1
0
        public void TestGenerateDefaultJBlock()
        {
            var jBlock = new JBlock();

            //  verify the index is 0, that is, that the index was properly initialized
            Assert.AreEqual(jBlock.Index, 0);
        }
Example #2
0
        JExpression WrapFunctionAndInvoke(ResolveResult instanceContext, JBlock func, params JExpression[] args)
        {
            if (args.IsNotNullOrEmpty())
            {
                throw new NotImplementedException();
            }
            var retType = instanceContext.Type;

            return(new JMultiStatementExpression {
                Statements = func.Statements.ToList(), Type = retType.JAccess()
            });
            //var retType2 = J.CreateTypeRef(retType);
            //return J.CreateFunc(retType2, func).Member("invoke").Invoke();
            //////return Js.Code("new java.lang.Runnable(){@Override public void run(){
            ////JExpression instanceContext2 = null;
            ////var me = instanceContext.GetCurrentMethod();
            ////if (me == null)
            ////{
            ////    //TODO: WARN
            ////    instanceContext2 = J.This();
            ////}
            ////else if (IsNonStatic(me))
            ////    instanceContext2 = J.This();

            ////return func.Parentheses().InvokeWithContextIfNeeded(instanceContext2, args);
        }
Example #3
0
        public JpegDCoefController(JpegDecompressStruct cinfo, bool need_full_buffer)
        {
            m_cinfo = cinfo;

            /* Create the coefficient buffer. */
            if (need_full_buffer)
            {
                /* Allocate a full-image virtual array for each component, */
                /* padded to a multiple of samp_factor DCT blocks in each direction. */
                /* Note we ask for a pre-zeroed array. */
                for (var ci = 0; ci < cinfo.numComponents; ci++)
                {
                    m_whole_image[ci] = JpegCommonStruct.CreateBlocksArray(
                        JpegUtils.jround_up(cinfo.CompInfo[ci].Width_in_blocks, cinfo.CompInfo[ci].H_samp_factor),
                        JpegUtils.jround_up(cinfo.CompInfo[ci].height_in_blocks, cinfo.CompInfo[ci].V_samp_factor));
                    m_whole_image[ci].ErrorProcessor = cinfo;
                }

                m_useDummyConsumeData = false;
                m_decompressor        = DecompressorType.Ordinary;
                m_coef_arrays         = m_whole_image; /* link to virtual arrays */
            }
            else
            {
                /* We only need a single-MCU buffer. */
                for (var i = 0; i < JpegConstants.D_MAX_BLOCKS_IN_MCU; i++)
                {
                    m_MCU_buffer[i] = new JBlock();
                }

                m_useDummyConsumeData = true;
                m_decompressor        = DecompressorType.OnePass;
                m_coef_arrays         = null; /* flag for no virtual arrays */
            }
        }
Example #4
0
        public static JNewAnonymousClassExpression CreateActionOrFunc(JBlock body, JParameterDeclaration[] prms, JMemberExpression retType, NProject2 project)
        {
            if (prms == null)
            {
                prms = new JParameterDeclaration[0];
            }
            var argTypes    = prms.Select(t => t.Type).ToList();
            var delTypeName = "system.Action";
            var netTypeName = "System.Action";

            if (retType != null)
            {
                delTypeName = "system.Func";
                netTypeName = "System.Func";
                argTypes.Add(retType);
            }
            if (prms.Length > 0)
            {
                delTypeName += prms.Length;
            }
            var delType = CreateTypeRef(delTypeName, argTypes.ToArray());

            if (argTypes.Count > 0)
            {
                netTypeName += "`" + argTypes.Count;
            }
            delType.TypeRef = project.FindType(netTypeName);
            return(CreateDelegate(delType, prms, retType, body));
        }
Example #5
0
 public static JBlock Add(this JBlock block, JStatement st)
 {
     if (block.Statements == null)
     {
         block.Statements = new List <JStatement>();
     }
     block.Statements.Add(st);
     return(block);
 }
Example #6
0
 public static void resetColors()
 {
     OBlock.resetColor();
     IBlock.resetColor();
     TBlock.resetColor();
     JBlock.resetColor();
     LBlock.resetColor();
     SBlock.resetColor();
     ZBlock.resetColor();
 }
Example #7
0
        private void DiscardColors(OptionArgs args)
        {
            OBlock.resetColor();
            IBlock.resetColor();
            TBlock.resetColor();
            JBlock.resetColor();
            LBlock.resetColor();
            SBlock.resetColor();
            ZBlock.resetColor();

            ColorData.saveColors();
        }
Example #8
0
        public void VisitBlock(JBlock node)
        {
            BeginBlock();
            VisitEach(node.Statements);
            if (node.Comments.IsNotNullOrEmpty())
            {
                WriteComments(node.Comments);
            }
            var parent = node.Parent;

            EndBlock(parent != null && parent is JFunction);
        }
Example #9
0
        private void Reset(OptionArgs args)
        {
            BlockType.textureAsset = "Game/Bricks/Cat-Eye Brick";

            OBlock.resetColor();
            IBlock.resetColor();
            TBlock.resetColor();
            JBlock.resetColor();
            LBlock.resetColor();
            SBlock.resetColor();
            ZBlock.resetColor();

            ColorData.saveColors();
        }
Example #10
0
        public JNode VisitBlockStatement(BlockStatement node)
        {
            CommentsExporter cmt = null;

            if (ExportComments)
            {
                cmt = new CommentsExporter {
                    Nodes = node.Children.ToList()
                }
            }
            ;
            var statements = new List <JStatement>();

            foreach (var st in node.Statements)
            {
                var st2 = VisitStatement(st);
                if (cmt != null)
                {
                    st2.Comments = cmt.ExportCommentsUptoNode(st);
                }
                statements.Add(st2);
            }
            var block = new JBlock {
                Statements = new List <JStatement>()
            };

            if (cmt != null)
            {
                block.Comments = cmt.ExportAllLeftoverComments();
            }
            foreach (var st in statements)
            {
                if (st is JBlock)
                {
                    var block2 = (JBlock)st;
                    if (block2.Statements != null)
                    {
                        block.Statements.AddRange(block2.Statements);
                    }
                }
                else
                {
                    block.Statements.Add(st);
                }
            }
            return(block);
        }
Example #11
0
        public void TestGenerateJBlock()
        {
            var jBlock = new JBlock();

            //  don't create default block, add some data
            jBlock.Data = new CryptoTransaction()
            {
                SourceWalletId      = testSourceWalledId,
                DestinationWalletId = testDestinationWalledId,
                Amount = testAmount
            };

            //  verify that object is properly constructed
            Assert.AreEqual(jBlock.Index, 0);
            Assert.AreEqual(jBlock.Data.SourceWalletId, testSourceWalledId);
            Assert.AreEqual(jBlock.Data.DestinationWalletId, testDestinationWalledId);
            Assert.AreEqual(jBlock.Data.Amount, testAmount);
        }
Example #12
0
        BlockType randomize()
        {
            BlockType randomBlock;

            switch (random.Next(1, 8))
            {
            case 1:
                randomBlock = new OBlock();
                break;

            case 2:
                randomBlock = new IBlock();
                break;

            case 3:
                randomBlock = new TBlock();
                break;

            case 4:
                randomBlock = new LBlock();
                break;

            case 5:
                randomBlock = new JBlock();
                break;

            case 6:
                randomBlock = new SBlock();
                break;

            case 7:
                randomBlock = new ZBlock();
                break;

            default:
                randomBlock = new LBlock();
                break;
            }

            randomBlock.load(Game.Content);

            return(randomBlock);
        }
Example #13
0
        public MyCCoefController(JpegCompressStruct cinfo, bool need_full_buffer)
        {
            m_cinfo = cinfo;

            /* Create the coefficient buffer. */
            if (need_full_buffer)
            {
                /* Allocate a full-image virtual array for each component, */
                /* padded to a multiple of samp_factor DCT blocks in each direction. */
                for (var ci = 0; ci < cinfo.m_num_components; ci++)
                {
                    m_whole_image[ci] = JpegCommonStruct.CreateBlocksArray(
                        JpegUtils.jround_up(cinfo.Component_info[ci].Width_in_blocks, cinfo.Component_info[ci].H_samp_factor),
                        JpegUtils.jround_up(cinfo.Component_info[ci].height_in_blocks, cinfo.Component_info[ci].V_samp_factor));
                    m_whole_image[ci].ErrorProcessor = cinfo;
                }
            }
            else
            {
                /* We only need a single-MCU buffer. */
                var buffer = new JBlock[JpegConstants.C_MAX_BLOCKS_IN_MCU];
                for (var i = 0; i < JpegConstants.C_MAX_BLOCKS_IN_MCU; i++)
                {
                    buffer[i] = new JBlock();
                }

                for (var i = 0; i < JpegConstants.C_MAX_BLOCKS_IN_MCU; i++)
                {
                    m_MCU_buffer[i] = new JBlock[JpegConstants.C_MAX_BLOCKS_IN_MCU - i];
                    for (var j = i; j < JpegConstants.C_MAX_BLOCKS_IN_MCU; j++)
                    {
                        m_MCU_buffer[i][j - i] = buffer[j];
                    }
                }

                /* flag for no virtual arrays */
                m_whole_image[0] = null;
            }
        }
Example #14
0
        /// <summary>
        /// <para>Initialize coefficient buffer controller.</para>
        /// <para>
        /// Each passed coefficient array must be the right size for that
        /// coefficient: width_in_blocks wide and height_in_blocks high,
        /// with unit height at least v_samp_factor.
        /// </para>
        /// </summary>
        public MyTransCCoefController(JpegCompressStruct cinfo, JVirtArray <JBlock>[] coef_arrays)
        {
            m_cinfo = cinfo;

            /* Save pointer to virtual arrays */
            m_whole_image = coef_arrays;

            /* Allocate and pre-zero space for dummy DCT blocks. */
            var buffer = new JBlock[JpegConstants.C_MAX_BLOCKS_IN_MCU];

            for (var i = 0; i < JpegConstants.C_MAX_BLOCKS_IN_MCU; i++)
            {
                buffer[i] = new JBlock();
            }

            for (var i = 0; i < JpegConstants.C_MAX_BLOCKS_IN_MCU; i++)
            {
                m_dummy_buffer[i] = new JBlock[JpegConstants.C_MAX_BLOCKS_IN_MCU - i];
                for (var j = i; j < JpegConstants.C_MAX_BLOCKS_IN_MCU; j++)
                {
                    m_dummy_buffer[i][j - i] = buffer[j];
                }
            }
        }
Example #15
0
        /// <summary>
        /// Consume input data and store it in the full-image coefficient buffer.
        /// We read as much as one fully interleaved MCU row ("iMCU" row) per call,
        /// ie, v_samp_factor block rows for each component in the scan.
        /// </summary>
        public ReadResult ConsumeData()
        {
            if (m_useDummyConsumeData)
            {
                return(ReadResult.JPEG_SUSPENDED);  /* Always indicate nothing was done */
            }

            var buffer = new JBlock[JpegConstants.MAX_COMPS_IN_SCAN][][];

            /* Align the virtual buffers for the components used in this scan. */
            for (var ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
            {
                var componentInfo = m_cinfo.CompInfo[m_cinfo.m_cur_comp_info[ci]];

                buffer[ci] = m_whole_image[componentInfo.Component_index].Access(
                    m_cinfo.inputIMcuRow * componentInfo.V_samp_factor, componentInfo.V_samp_factor);

                /* Note: entropy decoder expects buffer to be zeroed,
                 * but this is handled automatically by the memory manager
                 * because we requested a pre-zeroed array.
                 */
            }

            /* Loop to process one whole iMCU row */
            for (var yoffset = m_MCU_vert_offset; yoffset < m_MCU_rows_per_iMCU_row; yoffset++)
            {
                for (var MCU_col_num = m_MCU_ctr; MCU_col_num < m_cinfo.m_MCUs_per_row; MCU_col_num++)
                {
                    /* Construct list of pointers to DCT blocks belonging to this MCU */
                    var blkn = 0;           /* index of current DCT block within MCU */
                    for (var ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
                    {
                        var componentInfo = m_cinfo.CompInfo[m_cinfo.m_cur_comp_info[ci]];
                        var start_col     = MCU_col_num * componentInfo.MCU_width;
                        for (var yindex = 0; yindex < componentInfo.MCU_height; yindex++)
                        {
                            for (var xindex = 0; xindex < componentInfo.MCU_width; xindex++)
                            {
                                m_MCU_buffer[blkn] = buffer[ci][yindex + yoffset][start_col + xindex];
                                blkn++;
                            }
                        }
                    }

                    /* Try to fetch the MCU. */
                    if (!m_cinfo.m_entropy.decodeMcu(m_MCU_buffer))
                    {
                        /* Suspension forced; update state counters and exit */
                        m_MCU_vert_offset = yoffset;
                        m_MCU_ctr         = MCU_col_num;
                        return(ReadResult.JPEG_SUSPENDED);
                    }
                }

                /* Completed an MCU row, but perhaps not an iMCU row */
                m_MCU_ctr = 0;
            }

            /* Completed the iMCU row, advance counters for next one */
            m_cinfo.inputIMcuRow++;
            if (m_cinfo.inputIMcuRow < m_cinfo.m_total_iMCU_rows)
            {
                StartiMCURow();
                return(ReadResult.JPEG_ROW_COMPLETED);
            }

            /* Completed the scan */
            m_cinfo.m_inputctl.FinishInputPass();
            return(ReadResult.JPEG_SCAN_COMPLETED);
        }
Example #16
0
        /// <summary>
        /// <para>
        /// Process some data.
        /// We process the equivalent of one fully interleaved MCU row ("iMCU" row)
        /// per call, ie, v_samp_factor block rows for each component in the scan.
        /// The data is obtained from the virtual arrays and fed to the entropy coder.
        /// Returns true if the iMCU row is completed, false if suspended.
        /// </para>
        /// <para>NB: input_buf is ignored; it is likely to be a null pointer.</para>
        /// </summary>
        public virtual bool CompressData(byte[][][] input_buf)
        {
            /* Align the virtual buffers for the components used in this scan. */
            var buffer = new JBlock[JpegConstants.MAX_COMPS_IN_SCAN][][];

            for (var ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
            {
                var componentInfo = m_cinfo.Component_info[m_cinfo.m_cur_comp_info[ci]];
                buffer[ci] = m_whole_image[componentInfo.Component_index].Access(
                    m_iMCU_row_num * componentInfo.V_samp_factor, componentInfo.V_samp_factor);
            }

            /* Loop to process one whole iMCU row */
            var last_MCU_col  = m_cinfo.m_MCUs_per_row - 1;
            var last_iMCU_row = m_cinfo.m_total_iMCU_rows - 1;
            var MCU_buffer    = new JBlock[JpegConstants.C_MAX_BLOCKS_IN_MCU][];

            for (var yoffset = m_MCU_vert_offset; yoffset < m_MCU_rows_per_iMCU_row; yoffset++)
            {
                for (var MCU_col_num = m_mcu_ctr; MCU_col_num < m_cinfo.m_MCUs_per_row; MCU_col_num++)
                {
                    /* Construct list of pointers to DCT blocks belonging to this MCU */
                    var blkn = 0;           /* index of current DCT block within MCU */
                    for (var ci = 0; ci < m_cinfo.m_comps_in_scan; ci++)
                    {
                        var componentInfo = m_cinfo.Component_info[m_cinfo.m_cur_comp_info[ci]];
                        var start_col     = MCU_col_num * componentInfo.MCU_width;
                        var blockcnt      = (MCU_col_num < last_MCU_col) ? componentInfo.MCU_width : componentInfo.last_col_width;
                        for (var yindex = 0; yindex < componentInfo.MCU_height; yindex++)
                        {
                            int xindex;
                            if (m_iMCU_row_num < last_iMCU_row || yindex + yoffset < componentInfo.last_row_height)
                            {
                                /* Fill in pointers to real blocks in this row */
                                for (xindex = 0; xindex < blockcnt; xindex++)
                                {
                                    var bufLength = buffer[ci][yindex + yoffset].Length;
                                    var start     = start_col + xindex;
                                    MCU_buffer[blkn] = new JBlock[bufLength - start];
                                    for (var j = start; j < bufLength; j++)
                                    {
                                        MCU_buffer[blkn][j - start] = buffer[ci][yindex + yoffset][j];
                                    }

                                    blkn++;
                                }
                            }
                            else
                            {
                                /* At bottom of image, need a whole row of dummy blocks */
                                xindex = 0;
                            }

                            /* Fill in any dummy blocks needed in this row.
                             * Dummy blocks are filled in the same way as in jccoefct.c:
                             * all zeroes in the AC entries, DC entries equal to previous
                             * block's DC value.  The init routine has already zeroed the
                             * AC entries, so we need only set the DC entries correctly.
                             */
                            for (; xindex < componentInfo.MCU_width; xindex++)
                            {
                                MCU_buffer[blkn]       = m_dummy_buffer[blkn];
                                MCU_buffer[blkn][0][0] = MCU_buffer[blkn - 1][0][0];
                                blkn++;
                            }
                        }
                    }

                    /* Try to write the MCU. */
                    if (!m_cinfo.m_entropy.encodeMcu(MCU_buffer))
                    {
                        /* Suspension forced; update state counters and exit */
                        m_MCU_vert_offset = yoffset;
                        m_mcu_ctr         = MCU_col_num;
                        return(false);
                    }
                }

                /* Completed an MCU row, but perhaps not an iMCU row */
                m_mcu_ctr = 0;
            }

            /* Completed the iMCU row, advance counters for next one */
            m_iMCU_row_num++;
            StartIMcuRow();
            return(true);
        }
Example #17
0
        protected JBlock ExportConstructorBody(IMethod ctor)
        {
            var            ctorNode = (ConstructorDeclaration)ctor.GetDeclaration();
            BlockStatement ccc      = null;

            if (ctorNode != null)
            {
                ccc = ctorNode.Body;
            }
            //var ccc = ctor.GetDefinition();//.decl as CsConstructor;
            //var ccc = ctor.GetDefinition();
            var block2 = (JBlock)JsCodeImporter.Visit(ccc);

            if (block2 == null)
            {
                block2 = new JBlock {
                    Statements = new List <JStatement>()
                }
            }
            ;
            var ce          = ctor.GetDeclaringTypeDefinition();
            var isClr       = JMeta.IsClrType(ce);
            var isPrototype = JMeta.IsNativeType(ce);
            var statements  = new List <JStatement>();

            if (!ctor.IsStatic)
            {
                //TODO:
                //base/this ctor invocation
                var invocation = GetConstructorBaseOrThisInvocation2(ctor);
                if (invocation.Arguments.Count > 0)
                {
                    var exp2 = (JNewObjectExpression)JsCodeImporter.VisitExpression(invocation);
                    var exp3 = exp2.Invocation;
                    exp3.Member = J.Member("super");
                    statements.Insert(0, exp3.Statement());
                }
            }
            if (block2.Statements == null)
            {
                block2.Statements = new List <JStatement>();
            }
            block2.Statements.InsertRange(0, statements);

            return(block2);
        }

        void ExportConstructorParameters(IMethod ctor, JFunction func)
        {
            var ce   = ctor.GetDeclaringTypeDefinition();
            var list = new List <string>();

            if (!JMeta.IgnoreTypeArguments(ce))
            {
                //danel
                var gprms = ce.TypeParameters.ToList();//.GetGenericArguments().Where(ga => ga.isGenericParam()).ToList();
                if (gprms.IsNotNullOrEmpty())
                {
                    var i = 0;
                    foreach (var gprm in gprms)
                    {
                        func.Parameters.Add(gprm.Name);
                        if (!ctor.IsStatic && func.Block != null)
                        {
                            func.Block.Statements.Insert(i, J.This().Member(gprm.Name).Assign(J.Member(gprm.Name)).Statement());
                            i++;
                        }
                    }
                }
            }
            var prms = ctor.Parameters;

            if (prms != null)
            {
                func.Parameters.AddRange(prms.Select(t => t.Name));
            }
        }
Example #18
0
        public static JNewAnonymousClassExpression CreateDelegate(JMemberExpression delType, JParameterDeclaration[] prms2, JMemberExpression returnType, JBlock body)
        {
            if (prms2 == null)
            {
                prms2 = new JParameterDeclaration[0];
            }
            if (returnType == null)
            {
                returnType = J.Member("void");
            }
            var ce = NewAnonymousType(delType);
            var me = new JMethodDeclaration
            {
                MethodBody  = body,
                Parameters  = prms2.ToList(),
                Annotations = { new JAnnotationDeclaration {
                                    Name = "Override"
                                } },
                Type      = returnType,
                Name      = "invoke",
                Modifiers = { IsPublic = true },
            };

            ce.Declarations.Add(me);
            return(ce);
        }
Example #19
0
        /// <summary>
        /// Variant of decompress_data for use when doing block smoothing.
        /// </summary>
        private ReadResult DecompressSmoothData(ComponentBuffer[] output_buf)
        {
            /* Force some input to be done if we are getting ahead of the input. */
            while (m_cinfo.inputScanNumber <= m_cinfo.outputScanNumber && !m_cinfo.m_inputctl.EOIReached())
            {
                if (m_cinfo.inputScanNumber == m_cinfo.outputScanNumber)
                {
                    /* If input is working on current scan, we ordinarily want it to
                     * have completed the current row.  But if input scan is DC,
                     * we want it to keep one row ahead so that next block row's DC
                     * values are up to date.
                     */
                    var delta = (m_cinfo.m_Ss == 0) ? 1 : 0;
                    if (m_cinfo.inputIMcuRow > m_cinfo.outputIMcuRow + delta)
                    {
                        break;
                    }
                }

                if (m_cinfo.m_inputctl.ConsumeInput() == ReadResult.JPEG_SUSPENDED)
                {
                    return(ReadResult.JPEG_SUSPENDED);
                }
            }

            var last_iMCU_row = m_cinfo.m_total_iMCU_rows - 1;

            /* OK, output from the virtual arrays. */
            for (var ci = 0; ci < m_cinfo.numComponents; ci++)
            {
                var componentInfo = m_cinfo.CompInfo[ci];

                /* Don't bother to IDCT an uninteresting component. */
                if (!componentInfo.component_needed)
                {
                    continue;
                }

                int  block_rows;
                int  access_rows;
                bool last_row;
                /* Count non-dummy DCT block rows in this iMCU row. */
                if (m_cinfo.outputIMcuRow < last_iMCU_row)
                {
                    block_rows  = componentInfo.V_samp_factor;
                    access_rows = block_rows * 2; /* this and next iMCU row */
                    last_row    = false;
                }
                else
                {
                    /* NB: can't use last_row_height here; it is input-side-dependent! */
                    block_rows = componentInfo.height_in_blocks % componentInfo.V_samp_factor;
                    if (block_rows == 0)
                    {
                        block_rows = componentInfo.V_samp_factor;
                    }

                    access_rows = block_rows; /* this iMCU row only */
                    last_row    = true;
                }

                bool first_row;
                var  bufferRowOffset = 0;

                /* Align the virtual buffer for this component. */
                JBlock[][] buffer;
                if (m_cinfo.outputIMcuRow > 0)
                {
                    access_rows    += componentInfo.V_samp_factor; /* prior iMCU row too */
                    buffer          = m_whole_image[ci].Access((m_cinfo.outputIMcuRow - 1) * componentInfo.V_samp_factor, access_rows);
                    bufferRowOffset = componentInfo.V_samp_factor; /* point to current iMCU row */
                    first_row       = false;
                }
                else
                {
                    buffer    = m_whole_image[ci].Access(0, access_rows);
                    first_row = true;
                }

                /* Fetch component-dependent info */
                var coefBitsOffset = ci * SAVED_COEFS;
                int Q00            = componentInfo.quant_table.quantBal[0];
                int Q01            = componentInfo.quant_table.quantBal[Q01_POS];
                int Q10            = componentInfo.quant_table.quantBal[Q10_POS];
                int Q20            = componentInfo.quant_table.quantBal[Q20_POS];
                int Q11            = componentInfo.quant_table.quantBal[Q11_POS];
                int Q02            = componentInfo.quant_table.quantBal[Q02_POS];
                var outputIndex    = ci;

                /* Loop over all DCT blocks to be processed. */
                for (var block_row = 0; block_row < block_rows; block_row++)
                {
                    var bufferIndex = bufferRowOffset + block_row;

                    int prev_block_row;
                    if (first_row && block_row == 0)
                    {
                        prev_block_row = bufferIndex;
                    }
                    else
                    {
                        prev_block_row = bufferIndex - 1;
                    }

                    int next_block_row;
                    if (last_row && block_row == block_rows - 1)
                    {
                        next_block_row = bufferIndex;
                    }
                    else
                    {
                        next_block_row = bufferIndex + 1;
                    }

                    /* We fetch the surrounding DC values using a sliding-register approach.
                     * Initialize all nine here so as to do the right thing on narrow pics.
                     */
                    int DC1 = buffer[prev_block_row][0][0];
                    var DC2 = DC1;
                    var DC3 = DC1;

                    int DC4 = buffer[bufferIndex][0][0];
                    var DC5 = DC4;
                    var DC6 = DC4;

                    int DC7 = buffer[next_block_row][0][0];
                    var DC8 = DC7;
                    var DC9 = DC7;

                    var output_col        = 0;
                    var last_block_column = componentInfo.Width_in_blocks - 1;
                    for (var block_num = 0; block_num <= last_block_column; block_num++)
                    {
                        /* Fetch current DCT block into workspace so we can modify it. */
                        var workspace = new JBlock();
                        Buffer.BlockCopy(buffer[bufferIndex][0].data, 0, workspace.data, 0, workspace.data.Length * sizeof(short));

                        /* Update DC values */
                        if (block_num < last_block_column)
                        {
                            DC3 = buffer[prev_block_row][1][0];
                            DC6 = buffer[bufferIndex][1][0];
                            DC9 = buffer[next_block_row][1][0];
                        }

                        /* Compute coefficient estimates per K.8.
                         * An estimate is applied only if coefficient is still zero,
                         * and is not known to be fully accurate.
                         */
                        /* AC01 */
                        var Al = m_coef_bits_latch[m_coef_bits_savedOffset + coefBitsOffset + 1];
                        if (Al != 0 && workspace[1] == 0)
                        {
                            int pred;
                            var num = 36 * Q00 * (DC4 - DC6);
                            if (num >= 0)
                            {
                                pred = ((Q01 << 7) + num) / (Q01 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }
                            }
                            else
                            {
                                pred = ((Q01 << 7) - num) / (Q01 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }

                                pred = -pred;
                            }

                            workspace[1] = (short)pred;
                        }

                        /* AC10 */
                        Al = m_coef_bits_latch[m_coef_bits_savedOffset + coefBitsOffset + 2];
                        if (Al != 0 && workspace[8] == 0)
                        {
                            int pred;
                            var num = 36 * Q00 * (DC2 - DC8);
                            if (num >= 0)
                            {
                                pred = ((Q10 << 7) + num) / (Q10 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }
                            }
                            else
                            {
                                pred = ((Q10 << 7) - num) / (Q10 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }

                                pred = -pred;
                            }

                            workspace[8] = (short)pred;
                        }

                        /* AC20 */
                        Al = m_coef_bits_latch[m_coef_bits_savedOffset + coefBitsOffset + 3];
                        if (Al != 0 && workspace[16] == 0)
                        {
                            int pred;
                            var num = 9 * Q00 * (DC2 + DC8 - (2 * DC5));
                            if (num >= 0)
                            {
                                pred = ((Q20 << 7) + num) / (Q20 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }
                            }
                            else
                            {
                                pred = ((Q20 << 7) - num) / (Q20 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }

                                pred = -pred;
                            }

                            workspace[16] = (short)pred;
                        }

                        /* AC11 */
                        Al = m_coef_bits_latch[m_coef_bits_savedOffset + coefBitsOffset + 4];
                        if (Al != 0 && workspace[9] == 0)
                        {
                            int pred;
                            var num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
                            if (num >= 0)
                            {
                                pred = ((Q11 << 7) + num) / (Q11 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }
                            }
                            else
                            {
                                pred = ((Q11 << 7) - num) / (Q11 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }

                                pred = -pred;
                            }

                            workspace[9] = (short)pred;
                        }

                        /* AC02 */
                        Al = m_coef_bits_latch[m_coef_bits_savedOffset + coefBitsOffset + 5];
                        if (Al != 0 && workspace[2] == 0)
                        {
                            int pred;
                            var num = 9 * Q00 * (DC4 + DC6 - (2 * DC5));
                            if (num >= 0)
                            {
                                pred = ((Q02 << 7) + num) / (Q02 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }
                            }
                            else
                            {
                                pred = ((Q02 << 7) - num) / (Q02 << 8);
                                if (Al > 0 && pred >= (1 << Al))
                                {
                                    pred = (1 << Al) - 1;
                                }

                                pred = -pred;
                            }

                            workspace[2] = (short)pred;
                        }

                        /* OK, do the IDCT */
                        m_cinfo.m_idct.Inverse(componentInfo.Component_index, workspace.data, output_buf[outputIndex], 0, output_col);

                        /* Advance for next column */
                        DC1 = DC2;
                        DC2 = DC3;
                        DC4 = DC5;
                        DC5 = DC6;
                        DC7 = DC8;
                        DC8 = DC9;

                        bufferIndex++;
                        prev_block_row++;
                        next_block_row++;

                        output_col += componentInfo.DCT_h_scaled_size;
                    }

                    outputIndex += componentInfo.DCT_v_scaled_size;
                }
            }

            m_cinfo.outputIMcuRow++;
            if (m_cinfo.outputIMcuRow < m_cinfo.m_total_iMCU_rows)
            {
                return(ReadResult.JPEG_ROW_COMPLETED);
            }

            return(ReadResult.JPEG_SCAN_COMPLETED);
        }
Example #20
0
 public static JNewAnonymousClassExpression CreateFunc(JMemberExpression retType, JBlock body, NProject2 project)
 {
     return(CreateActionOrFunc(body, null, retType, project));
 }
Example #21
0
 public static JNewAnonymousClassExpression CreateAction(JBlock body, NProject2 project)
 {
     return(CreateActionOrFunc(body, null, null, project));
 }