🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.os.linux.programowanie
Article #602

Re: wyciąganie info z GIFów i JPEGów

#602
From: Cezary H. Noweta
Date: Fri, 24 Sep 1999 18:57
136 lines
3403 bytes
Witam,

Bart Ogryczak wrote:
> Czy są jakieś proste narzędzia do wyciągnięcia
> rozmiaru z plików GIF i JPEG?

---
  gifsize.c
---
#include <stdio.h>

void err(int err_num)
{
  printf("0\n0\n");
  exit(err_num);
}

int main(int argc, char *argv[])
{
  FILE *f = stdin;
  unsigned char buff[10];

  if ( argc > 1 && !(f = fopen(argv[1], "rb")) )
    err(-1);

  if ( !fread(buff, 10, 1, f) )
    err(-2);

  if ( strncmp("GIF", buff, 3) )
    err(-3);

  printf("%d\n%d\n", buff[6] + buff[7] * 0x0100, buff[8] + buff[9] * 0x0100);

  return(0);
}
---

---
  jpegsize.c
---
#include <stdio.h>

void err(int err_num)
{
  printf("0\n0\n");
  exit(err_num);
}

int next_mark(FILE *f)
{
  int c = getc(f);

  if ( c != 0xFF )
    err(-3);

  while ( (c = getc(f)) == 0xFF );

  if ( c == EOF )
    err(-2);

  return(c);  
}

void reach_end(FILE *f)
{
  int i, c1, c2;

  if ( (c1 = getc(f)) == EOF || (c2 = getc(f)) == EOF )
    err(-2);

  for ( i = c1 * 0x0100 + c2 - 2; i--; getc(f) == EOF ? err(-2) : 0 );
}

void reach_mark(int mark, FILE *f)
{
  int m;

  while ( (m = next_mark(f)) != mark ) {
    if ( !m )
      err(-3);
    if ( m != 0x01 && m < 0xD0 || m > 0xD9 )
      reach_end(f);
  }
}

void reach_soi(FILE *f)
{
  reach_mark(0xD8, f);
}

void reach_sof(FILE *f)
{
  int m;

  while ( (m = next_mark(f)) < 0xC0 || m > 0xCF || m == 0xC8 ) {
    if ( !m || m == 0xD9 )
      err(-3);
    if ( m != 0x01 && m < 0xD0 || m > 0xD9 )
      reach_end(f);
  }
}

int main(int argc, char *argv[])
{
  FILE *f = stdin;
  unsigned char buff[7];

  if ( argc > 1 && !(f = fopen(argv[1], "rb")) )
    err(-1);

  reach_soi(f);
  reach_sof(f);
  if ( !fread(buff, 7, 1, f) )
    err(-2);

  printf("%d\n%d\n", buff[5] * 0x0100 + buff[6], buff[3] * 0x0100 + buff[4]);

  return(0);
}
---

Programy wypisuja rozmiar w formie:

200
300

gdzie 200 to szerokosc, a 300 to wysokosc. Jesli wystapi blad, to wypisuja
rozmiar 0 0 i zwracaja: -1 - blad otwarcia pliku, -2 - blad odczytu pliku,
-3 - bledny format. Testowalem na 5 GIFach i 1 JPEGu.

  -- pozdrawiam

-- 
Cezary H. Noweta                 90-237 LODZ, ul. J.Matejki 34/38 POLAND
(chn@irys.usun.drugiitrzeciczlon.uni.lodz.pl)    +48 42 6356013, 6356012
University of Lodz - Main Library                            fax 6781678
Technical Details
Message-ID: <37EBC9AB.3DF15E80@irys.usundrugiczlon.uni.lodz.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!uw.edu.pl!news.swierk.pl!paa.gov.pl!opoka-warszawa!orion.cst.tpsa.pl!news.task.gda.pl!news.man.lodz.pl!not-for-mail
References: <slrn7ukfa1.1f5.B.Ogryczak@ubik.melog.com.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!uw.edu.pl!news.swierk.pl!paa.gov.pl!opoka-warszawa!orion.cst.tpsa.pl!news.task.gda.pl!news.man.lodz.pl!not-for-mail
From: "Cezary H. Noweta" <chn@irys.usundrugiczlon.uni.lodz.pl>
Newsgroups: pl.comp.os.linux.programowanie
Subject: Re: wyciąganie info z GIFów i
  JPEGów
Date: Fri, 24 Sep 1999 20:57:47 +0200
Organization: Biblioteka Uniwersytecka w Lodzi
Lines: 136
Message-ID: <37EBC9AB.3DF15E80@irys.usundrugiczlon.uni.lodz.pl>
References: <slrn7ukfa1.1f5.B.Ogryczak@ubik.melog.com.pl>
NNTP-Posting-Host: chncc.bul.uni.lodz.pl
Mime-Version: 1.0
X-Trace: kujawiak.man.lodz.pl 938199462 17291 212.191.71.33 (24 Sep 1999 18:57:42 GMT)
X-Complaints-To: abuse@man.lodz.pl
NNTP-Posting-Date: 24 Sep 1999 18:57:42 GMT
X-Mailer: Mozilla 4.61 [en] (Win95; I)
X-Accept-Language: pl,en
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit