13 static char const* vil_mit_format_tag =
"mit";
16 # include <vcl_msvc_warnings.h> 27 #define MIT_UNSIGNED 0x0001 28 #define MIT_RGB 0x0002 29 #define MIT_HSB 0x0003 30 #define MIT_CAP 0x0004 31 #define MIT_SIGNED 0x0005 32 #define MIT_FLOAT 0x0006 33 #define MIT_EDGE 0x0007 35 #define MIT_UCOMPLEX 0x0101 36 #define MIT_SCOMPLEX 0x0105 37 #define MIT_FCOMPLEX 0x0106 39 #define MIT_UNSIGNED_E 0x0201 40 #define MIT_SIGNED_E 0x0205 41 #define MIT_FLOAT_E 0x0206 43 #define MIT_UCOMPLEX_E 0x0301 44 #define MIT_SCOMPLEX_E 0x0305 45 #define MIT_FCOMPLEX_E 0x0306 76 if (bpp != 1 && bpp != 8 && bpp != 16 && bpp != 32 && bpp != 64)
82 std::cerr << __FILE__
" : here we go:\n" 83 << __FILE__
" : type_ = " << type << std::endl
84 << __FILE__
" : bits_per_pixel_ = " << bpp << std::endl
85 << __FILE__
" : width_ = " << width << std::endl
86 << __FILE__
" : height_ = " << height << std::endl;
92 unsigned int ni,
unsigned int nj,
unsigned int nplanes,
100 return vil_mit_format_tag;
111 std::cerr <<
"vil_mit: cannot read file header; creating dummy 0x0 image\n";
119 return vil_mit_format_tag;
123 unsigned int ni,
unsigned int nj,
unsigned int nplanes,
125 : is_(is), ni_(ni), nj_(nj), components_(nplanes), format_(format)
196 else std::cerr << __FILE__
" : Can only write RGB or grayscale MIT images\n" 204 else std::cerr << __FILE__
" : Can only write RGB or grayscale MIT images\n" 215 else std::cerr << __FILE__
" : Can only write RGB or grayscale MIT images\n" 222 else std::cerr << __FILE__
" : Can only write grayscale float-pixel MIT images\n" 226 std::cerr << __FILE__
" : Can only write RGB or grayscale MIT images\n" 238 static inline void swap(
void* p,
int length)
242 if (length ==
sizeof(vxl_uint_32) && *(vxl_uint_32*)p != 0) {
243 std::cerr <<
"Swapping " << *(vxl_uint_32*)p;
244 if (length ==
sizeof(
float)) std::cerr <<
" (or " << *(
float*)p <<
')';
247 for (
int j=0;2*j<length;++j) {
char c = t[j]; t[j] = t[length-j-1]; t[length-j-1] = c; }
249 if (length ==
sizeof(vxl_uint_32) && *(vxl_uint_32*)p != 0) {
250 std::cerr <<
" to " << *(vxl_uint_32*)p;
251 if (length ==
sizeof(
float)) std::cerr <<
" (or " << *(
float*)p <<
')';
258 unsigned int y0,
unsigned int ys)
const 265 std::cerr <<
"vil_mit_image::get_copy_view(): Warning: x0 should be a multiple of 8 for this type of image\n";
268 vxl_uint_32 rowsize = (pix_size*xs+7)/8;
270 auto* ib = reinterpret_cast<vxl_byte*>(buf->data());
271 for (
unsigned int y = y0; y < y0+ys; ++y)
273 is_->
seek(8L + y*((
ni_*pix_size+7)/8) + x0*pix_size/8);
278 ib = reinterpret_cast<vxl_byte*>(buf->data());
283 #define ARGS(T) buf, reinterpret_cast<T*>(buf->data()), xs,ys,components_, components_,xs*components_,1 305 unsigned int ni = buf.
ni();
306 unsigned int nj = buf.
nj();
308 std::cerr<<
"vil_mit_image::put_view() : buf=" 310 <<
" at ("<<x0<<
','<<y0<<
")\n";
313 bool buf_is_planar =
false;
316 buf_is_planar =
false;
317 else if (ibuf.istep() == 1 && ibuf.jstep() == int(
ni) &&
319 buf_is_planar =
true;
322 std::cerr <<
"ERROR: " << __FILE__ <<
":\n" 323 <<
" view does not fit: istep="<<ibuf.
istep()
324 <<
", jstep="<<ibuf.jstep()
325 <<
", planestep="<<ibuf.planestep()
327 <<
" or 1,"<<
ni<<
','<<
ni*
nj<<
'\n';
328 return buf_is_planar;
334 std::cerr <<
"vil_mit_image::put_view(): Warning: x0 should be a multiple of 8 for this type of image\n";
337 vxl_uint_32 rowsize = (pix_size*
ni+7)/8;
344 for (
unsigned int y = y0; y < y0+
nj; ++y)
345 for (
unsigned int x = x0; x < x0+
ni; ++x)
347 is_->
seek(8L + y*((
ni_*pix_size+7)/8) + x*pix_size/8);
350 std::cerr <<
"WARNING: " << __FILE__ <<
":\n" 351 <<
" could not write "<<sz<<
" bytes to stream; y,x="<<y<<
','<<x<<
'\n';
354 std::cerr <<
"written "<<sz<<
" bytes to stream; y,x="<<y<<
','<<x<<
'\n';
360 for (
unsigned int y = y0; y < y0+
nj; ++y)
362 is_->
seek(8L + y*((
ni_*pix_size+7)/8) + x0*pix_size/8);
364 std::cerr <<
"WARNING: " << __FILE__ <<
":\n" 365 <<
" could not write "<<rowsize<<
" bytes to stream; y="<<y<<
'\n';
368 std::cerr <<
"written "<<rowsize<<
" bytes to stream; y="<<y<<
'\n';
379 for (
unsigned int y = y0; y < y0+
nj; ++y)
380 for (
unsigned int x = x0; x < x0+
ni; ++x)
383 std::memcpy(tempbuf+p*sz, ob+p*
ni*
nj, sz);
384 swap(tempbuf+p*sz,sz);
388 std::cerr <<
"WARNING: " << __FILE__ <<
":\n" 389 <<
" could not write "<<
components_*sz<<
" bytes to stream; y,x="<<y<<
','<<x<<
'\n';
392 std::cerr <<
"written "<<
components_*sz<<
" bytes to stream; y,x="<<y<<
','<<x<<
'\n';
400 auto* tempbuf =
new vxl_byte[rowsize];
401 for (
unsigned int y = y0; y < y0+
nj; ++y)
403 std::memcpy(tempbuf, ob, rowsize);
408 std::cerr <<
"WARNING: " << __FILE__ <<
":\n" 409 <<
" could not write "<<rowsize<<
" bytes to stream; y="<<y<<
'\n';
412 std::cerr <<
"written "<<rowsize<<
" bytes to stream; y="<<y<<
'\n';
~vil_mit_image() override
Stream interface for VIL image loaders.
An abstract base class of smart pointers to actual image data in memory.
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.
unsigned int ni() const override
Dimensions. W x H x Components.
void swap(double &a, double &b)
bool put_view(vil_image_view_base const &buf, unsigned int x0, unsigned int y0) override
Write buf into this at position (x0,y0).
virtual vil_streampos write(void const *buf, vil_streampos n)=0
Write n bytes from buf. Returns number of bytes written.
read numbers from vil_stream
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.
unsigned ni() const
Width.
Stream interface for VIL image loaders.
unsigned nj() const
Height.
virtual enum vil_pixel_format pixel_format() const =0
Return a description of the concrete data pixel type.
Indicates that some reference was made to pixels beyond the bounds of an image.
vil_mit_image(vil_stream *is)
write integers to vil_stream
void vil_stream_write_little_endian_uint_16(vil_stream *s, vxl_uint_16 w)
unsigned int bytes_per_pixel() const
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.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
enum vil_pixel_format format_
unsigned nplanes() const
Number of planes.
Generic image implementation for MIT files.
vxl_uint_16 vil_stream_read_little_endian_uint_16(vil_stream *s)
unsigned int nj() const override
Dimensions: Planes x ni x nj.
virtual vil_streampos file_size() const =0
Amount of data in the stream.
void vil_exception_warning(T exception)
Throw an exception indicating a potential problem.
Representation of a generic image source or destination.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
bool get_property(char const *tag, void *prop=nullptr) const override
Extra property information.
char const * file_format() const override
Return a string describing the file format.