Pelles C forum

C language => Beginner questions => Topic started by: luca.crovato on November 14, 2011, 12:59:47 PM

Title: How to read info about JPEG
Post by: luca.crovato on November 14, 2011, 12:59:47 PM
Hi all ,
I need to read info from jpg file ( H, W etc)  how i can do it?

Ciao
Luca
Title: Re: How to read info about JPEG
Post by: Bitbeisser on November 14, 2011, 04:59:47 PM
Quote from: luca.crovato on November 14, 2011, 12:59:47 PM
Hi all ,
I need to read info from jpg file ( H, W etc)  how i can do it?

Ciao
Luca
Are you asking about how to open and read a binary file or do you ask about the structure of the JPEG file format?

Ralf
Title: Re: How to read info about JPEG
Post by: luca.crovato on November 14, 2011, 05:53:28 PM
Dear Ralf

I'm asking how to read the structure.
I'm tryng to build library based on libjpeg but without success.

br
Luca
Title: Re: How to read info about JPEG
Post by: TimoVJL on November 14, 2011, 07:54:45 PM
Here is smaller library for that ?
http://keyj.emphy.de/nanojpeg/ (http://keyj.emphy.de/nanojpeg/)

EDIT:
QuoteI'm tryng to build library based on libjpeg but without success.
with source from http://www.ijg.org/ (http://www.ijg.org/)
- copy jconfig.vc to jconfig.h
- use Import MSVC project wizard to import makejdsp.vc6

or try jpeglib.ppj from attachment

#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>
#include <jerror.h>

#pragma comment(lib, "jpeglib.lib")

int main(int argc, char** argv)
{
  struct jpeg_decompress_struct cinfo;
  struct jpeg_error_mgr jerr;
  FILE *infile;

  if ((infile = fopen(argv[1], "rb")) == NULL)
  {
    fprintf(stderr, "Can't open %s\n", argv[1]);
    exit(1);
  }

  // Create decompression object.
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_decompress(&cinfo);
  jpeg_stdio_src(&cinfo, infile);

  // Get all compression parameters.
  jpeg_read_header(&cinfo, TRUE);
  fprintf(stdout, "w: %d h: %d\n", cinfo.image_width, cinfo.image_height);

  // Destroy decompression object.
  jpeg_destroy_decompress(&cinfo);
  fclose(infile);
  return 0;
}
Title: Re: How to read info about JPEG
Post by: luca.crovato on November 15, 2011, 01:52:29 PM
Dear timovjl

thanks a lot.

It works.

Ciao
Luca