BitMiracle.LibJpeg.Classic.jpeg_decompress_struct.jpeg_read_header C# (CSharp) Method

jpeg_read_header() public method

Decompression startup: this will read the source datastream header markers, up to the beginning of the compressed data proper.
Need only initialize JPEG object and supply a data source before calling.
On return, the image dimensions and other info have been stored in the JPEG object. The application may wish to consult this information before selecting decompression parameters.
This routine is now just a front end to jpeg_consume_input, with some extra error checking.
public jpeg_read_header ( bool require_image ) : ReadResult
require_image bool Read a description of Return Value.
return ReadResult
        public ReadResult jpeg_read_header(bool require_image)
        {
            if (m_global_state != JpegState.DSTATE_START && m_global_state != JpegState.DSTATE_INHEADER)
                ERREXIT(J_MESSAGE_CODE.JERR_BAD_STATE, (int)m_global_state);

            ReadResult retcode = jpeg_consume_input();

            switch (retcode)
            {
                case ReadResult.JPEG_REACHED_SOS:
                    return ReadResult.JPEG_HEADER_OK;
                case ReadResult.JPEG_REACHED_EOI:
                    if (require_image)      /* Complain if application wanted an image */
                        ERREXIT(J_MESSAGE_CODE.JERR_NO_IMAGE);
                    /* Reset to start state; it would be safer to require the application to
                    * call jpeg_abort, but we can't change it now for compatibility reasons.
                    * A side effect is to free any temporary memory (there shouldn't be any).
                    */
                    jpeg_abort(); /* sets state = DSTATE_START */
                    return ReadResult.JPEG_HEADER_TABLES_ONLY;

                case ReadResult.JPEG_SUSPENDED:
                    /* no work */
                    break;
            }

            return ReadResult.JPEG_SUSPENDED;
        }

Usage Example

Example #1
0
 static int[][] getDct(string filename)
 {
     jpeg_decompress_struct cinfo = new jpeg_decompress_struct();
     FileStream objFileStreamHeaderImage = new FileStream(filename, FileMode.Open, FileAccess.Read);
     cinfo.jpeg_stdio_src(objFileStreamHeaderImage);
     cinfo.jpeg_read_header(true);
     var coeffs = cinfo.jpeg_read_coefficients();
     const int size = 64;
     int height = cinfo.Image_height / size;
     int width = cinfo.Image_width / size;
     int[][] result = new int[height * width][];
     var dct = coeffs[0].Access(0, height);
     for (int i = 0; i < height * width; i++)
     {
         result[i] = new int[size];
     }
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             for (int k = 0; k < 64; k++)
             {
                 result[i * width + j][k] = dct[i][j][k];
             }
         }
     }
     return result;
 }
All Usage Examples Of BitMiracle.LibJpeg.Classic.jpeg_decompress_struct::jpeg_read_header