File: in_jpeg.cpp

package info (click to toggle)
sam2p 0.49.2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,696 kB
  • sloc: cpp: 14,363; ansic: 9,011; tcl: 973; sh: 692; makefile: 157; xml: 100; perl: 67
file content (37 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * in_jpeg.cpp -- read JPEG (JFIF and other) files with djpeg
 * by pts@fazekas.hu at Sun Apr 14 14:50:30 CEST 2002
 */

#ifdef __GNUC__
#pragma implementation
#endif

#include "image.hpp"

#if USE_IN_JPEG

#include "error.hpp"
#include "gensio.hpp"
#include "helpere.hpp"
#include <string.h> /* memchr() */
#include <stdio.h> /* printf() */

static Image::Sampled *in_jpeg_reader(Image::Loader::UFD *ufd, SimBuffer::Flat const&) {
  // Error::sev(Error::EERROR) << "Cannot load JPEG images yet." << (Error*)0;
  HelperE helper("djpeg"); /* Run external process `djpeg' to convert JPEG -> PNM */
  Encoder::writeFrom(*(Filter::PipeE*)&helper, *(Filter::UngetFILED*)ufd);
  ((Filter::PipeE*)&helper)->vi_write(0,0); /* Signal EOF */
  return helper.getImg();
}

static Image::Loader::reader_t in_jpeg_checker(char buf[Image::Loader::MAGIC_LEN], char [Image::Loader::MAGIC_LEN], SimBuffer::Flat const& loadHints, Image::Loader::UFD*) {
  return (0==memcmp(buf, "\xff\xd8", 2)) && loadHints.findFirst((char const*)",asis,",6)==loadHints.getLength()
         ? in_jpeg_reader : 0;
}

#else
#define in_jpeg_checker (Image::Loader::checker_t)NULLP
#endif /* USE_IN_XPM */

Image::Loader in_jpeg_loader = { "JPEG", in_jpeg_checker, 0 };