Пример #1
0
        /// <summary>
        /// This method loads the image into whole_image during the first call on
        /// get_pixel_rows.
        /// </summary>
        private int preload_image()
        {
            cdjpeg_progress_mgr progress = cinfo.Progress as cdjpeg_progress_mgr;

            /* Read the data into a virtual array in input-file row order. */
            for (int row = 0; row < cinfo.Image_height; row++)
            {
                if (progress != null)
                {
                    progress.Pass_counter = row;
                    progress.Pass_limit   = cinfo.Image_height;
                    progress.Updated();
                }

                byte[][] image_ptr  = whole_image.Access(row, 1);
                int      imageIndex = 0;
                for (int col = row_width; col > 0; col--)
                {
                    /* inline copy of read_byte() for speed */
                    int c = input_file.ReadByte();
                    if (c == -1)
                    {
                        cinfo.ERREXIT(J_MESSAGE_CODE.JERR_INPUT_EOF);
                    }

                    image_ptr[0][imageIndex] = (byte)c;
                    imageIndex++;
                }
            }

            if (progress != null)
            {
                progress.completed_extra_passes++;
            }

            /* Set up to read from the virtual array in top-to-bottom order */
            switch (bits_per_pixel)
            {
            case 8:
                m_pixelRowsMethod = PixelRowsMethod.use8bit;
                break;

            case 24:
                m_pixelRowsMethod = PixelRowsMethod.use24bit;
                break;

            case 32:
                m_pixelRowsMethod = PixelRowsMethod.use32bit;
                break;

            default:
                cinfo.ERREXIT((int)ADDON_MESSAGE_CODE.JERR_BMP_BADDEPTH);
                break;
            }

            source_row = cinfo.Image_height;

            /* And read the first row */
            return(get_pixel_rows());
        }
Пример #2
0
        /// <summary>
        /// Finish up at the end of the file.
        /// Here is where we really output the BMP file.
        /// </summary>
        public override void finish_output()
        {
            /* Write the header and colormap */
            if (is_os2)
            {
                write_os2_header();
            }
            else
            {
                write_bmp_header();
            }

            cdjpeg_progress_mgr progress = cinfo.Progress as cdjpeg_progress_mgr;

            /* Write the file body from our virtual array */
            for (int row = cinfo.Output_height; row > 0; row--)
            {
                if (progress != null)
                {
                    progress.Pass_counter = cinfo.Output_height - row;
                    progress.Pass_limit   = cinfo.Output_height;
                    progress.Updated();
                }

                byte[][] image_ptr  = whole_image.Access(row - 1, 1);
                int      imageIndex = 0;
                for (int col = row_width; col > 0; col--)
                {
                    output_file.WriteByte(image_ptr[0][imageIndex]);
                    imageIndex++;
                }
            }

            if (progress != null)
            {
                progress.completed_extra_passes++;
            }

            /* Make sure we wrote the output file OK */
            output_file.Flush();
        }