22 # include <vcl_msvc_warnings.h> 24 #include <vxl_config.h> 37 if (n !=
sizeof(magic)) {
38 std::cerr << __FILE__ <<
" : vil_stream::read() failed\n";
43 return (magic[0] ==
char(0xFF)) && (magic[1] == char(0xD8));
47 static char const jpeg_string[] =
"jpeg";
72 std::cout<<
"ERROR! vil_jpeg_file_format::make_output_image()\n" 73 <<
"Pixel format should be byte, but is "<<format<<
" instead.\n";
113 std::cerr <<
"Sorry -- pixel format " << format <<
" not yet supported\n";
122 jc->
jobj.image_width = nx;
123 jc->
jobj.image_height = ny;
125 std::cerr <<
"w h = " << nx <<
' ' << ny <<
'\n';
152 std::cerr <<
"attempted get_copy_view() failed -- no jpeg decompressor\n";
156 std::cerr <<
"get_copy_view " <<
' ' << x0 <<
' ' << nx <<
' ' << y0 <<
' ' << ny <<
'\n';
160 unsigned bpp =
jd->
jobj.output_components;
164 for (
unsigned int i=0; i<ny; ++i) {
169 std::memcpy(reinterpret_cast<char*>(chunk->data()) + i*nx*bpp, &scanline[x0*bpp], nx*bpp);
172 return new vil_image_view<vxl_byte>(chunk, reinterpret_cast<vxl_byte *>(chunk->data()), nx, ny, bpp, bpp, bpp*nx, 1);
179 unsigned x0,
unsigned y0)
189 std::cerr <<
"attempted put_view() failed -- no jpeg compressor\n";
195 std::cerr <<
"vil_jpeg_image::put_view() failed -- can only deal with byte images\n";
205 if (x0 != 0 || view2.ni() !=
jc->
jobj.image_width) {
206 std::cerr << __FILE__ <<
" : Can only compress complete scanlines\n";
209 if (y0 !=
jc->
jobj.next_scanline) {
210 std::cerr << __FILE__ <<
" : Scanlines must be sent sequentially\n";
215 if ((view2.planestep() == 1 || view2.nplanes() == 1) && view2.istep() ==
jc->
jobj.input_components)
217 assert(view2.istep() > 0);
218 assert(view2.istep() ==
jc->
jobj.input_components);
219 for (
unsigned int j=0; j<view2.nj(); ++j) {
220 auto const *scanline = (JSAMPLE
const*)
232 for (
unsigned int j=0; j<view2.nj(); ++j)
235 for (
unsigned i = 0; i < view2.ni(); ++i)
236 for (
unsigned p = 0; p < view2.nplanes(); ++p)
237 line(i,0,p) = view2(i,j,p);
251 if (
jd)
return jd->
jobj.output_width;
252 if (
jc)
return jc->
jobj.image_width;
258 if (
jd)
return jd->
jobj.output_height;
259 if (
jc)
return jc->
jobj.image_height;
265 if (
jd)
return jd->
jobj.output_components;
266 if (
jc)
return jc->
jobj.input_components;
char const * file_format() const override
returns "jpeg".
Stream interface for VIL image loaders.
An abstract base class of smart pointers to actual image data in memory.
generic_image implementation for JPEG files.
bool put_view(const vil_image_view_base &im, unsigned i0, unsigned j0) override
Put the data in this view back into the image source.
virtual bool view_fits(const vil_image_view_base &im, unsigned i0, unsigned j0)
Check that a view will fit into the data at the given offset.
bool write_scanline(unsigned line, JSAMPLE const *)
enum vil_pixel_format pixel_format() const override
Pixel Format.
unsigned ni() const override
Dimensions: Planes x ni x nj.
Concrete view of image data of type T held in memory.
virtual void seek(vil_streampos position)=0
Goto file pointer.
virtual vil_streampos read(void *buf, vil_streampos n)=0
Read n bytes into buf. Returns number of bytes read.
Exceptions thrown by vil, and a mechanism for turning them off.
bool get_property(char const *tag, void *prop=nullptr) const override
Extra property information.
JSAMPLE const * read_scanline(unsigned line)
Do not delete the return value.
void set_quality(int quality)
set the quality for compression.
Stream interface for VIL image loaders.
virtual enum vil_pixel_format pixel_format() const =0
Return a description of the concrete data pixel type.
vil_jpeg_image(vil_stream *is)
Indicates that some reference was made to pixels beyond the bounds of an image.
void set_quality(int quality)
bool vil_jpeg_file_probe(vil_stream *vs)
the file probe, as a C function.
vil_jpeg_decompressor * jd
void ref()
up/down the reference count.
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
A base class reference-counting view of some image data.
Ref. counted block of data on the heap.
unsigned nplanes() const override
Dimensions: planes x width x height x components.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
~vil_jpeg_image() override
void vil_exception_warning(T exception)
Throw an exception indicating a potential problem.
unsigned nj() const override
Dimensions: Planes x ni x nj.
struct jpeg_decompress_struct jobj
struct jpeg_compress_struct jobj