8 # include <vcl_msvc_warnings.h> 11 static char const* vil_viff_format_tag =
"viff";
19 static inline void swap(
void* p,
int length)
23 if (length ==
sizeof(vxl_uint_32) && *(vxl_uint_32*)p != 0) {
24 std::cerr <<
"Swapping " << *(vxl_uint_32*)p;
25 if (length ==
sizeof(
float))
26 std::cerr <<
" (or " << *(
float*)p <<
')';
29 for (
int j=0;2*j<length;++j)
36 if (length ==
sizeof(vxl_uint_32) && *(vxl_uint_32*)p != 0) {
37 std::cerr <<
" to " << *(vxl_uint_32*)p;
38 if (length ==
sizeof(
float))
39 std::cerr <<
" (or " << *(
float*)p <<
')';
48 if (!is)
return nullptr;
51 if (VIFF_HEADERSIZE != is->
read((
void*)(&header),VIFF_HEADERSIZE))
54 if (header.
identifier != (
char)XV_FILE_MAGIC_NUM ||
55 header.
file_type != (char)XV_FILE_TYPE_XVIFF)
59 if ((dst & 0xff) == 0)
60 swap(&dst,
sizeof(dst));
73 std::cout <<
"vil_viff: non supported data type: VFF_TYP " 80 unsigned int ni,
unsigned int nj,
unsigned int nplanes,
88 return vil_viff_format_tag;
99 std::cerr <<
"vil_viff: cannot read file header; creating dummy 0x0 image\n";
108 return vil_viff_format_tag;
112 unsigned int ni,
unsigned int nj,
unsigned int nplanes,
114 : is_(is), ni_(ni), nj_(nj),
115 nplanes_(nplanes), start_of_data_(VIFF_HEADERSIZE),
116 format_(format), endian_consistent_(true)
140 if (VIFF_HEADERSIZE !=
is_->
read((
void*)(&
header_),VIFF_HEADERSIZE))
162 swap(&rs,
sizeof(rs));
163 swap(&cs,
sizeof(cs));
164 swap(&dst,
sizeof(dst));
165 swap(&ndb,
sizeof(ndb));
195 std::cout <<
"vil_viff: non supported data type: VFF_TYP " << dst <<
'\n';
225 std::cout <<
"vil_viff: non supported data type: " << (short)
format_ <<
'\n';
243 unsigned int y0,
unsigned int ys)
const 250 std::cerr <<
"vil_viff_image::get_copy_view(): Warning: x0 should be a multiple of 8 for this type of image\n";
252 vxl_uint_32 rowsize = (pix_size*xs+7)/8;
253 vxl_uint_32 tbytes = rowsize*ys*
nplanes_;
255 auto* ib = reinterpret_cast<vxl_byte*>(buf->data());
256 for (
unsigned int p = 0; p<
nplanes_; ++p) {
257 for (
unsigned int y = y0; y < y0+ys; ++y) {
259 + y*((
ni_*pix_size+7)/8)
266 ib = reinterpret_cast<vxl_byte*>(buf->data());
267 for (
unsigned int i=0;i<tbytes;i+=(pix_size+7)/8)
268 swap(ib+i,(pix_size+7)/8);
271 #define ARGS(T) buf, reinterpret_cast<T*>(buf->data()), xs,ys,nplanes_, 1,xs,xs*ys 292 unsigned int ni = buf.
ni();
293 unsigned int nj = buf.
nj();
295 std::cerr <<
"vil_viff_image::put_view() : buf=" 297 <<
" at ("<<x0<<
','<<y0<<
")\n";
302 if (ibuf.istep() != 1 || ibuf.jstep() != int(
ni) ||
303 (ibuf.planestep() != int(
ni*
nj) &&
nplanes() != 1))
305 std::cerr <<
"ERROR: " << __FILE__ <<
":\n" 306 <<
" view does not fit: istep="<<ibuf.
istep()
307 <<
", jstep="<<ibuf.jstep()
308 <<
", planestep="<<ibuf.planestep()
309 <<
" instead of 1,"<<
ni<<
','<<
ni*
nj<<
'\n';
312 const vxl_byte* ob = ibuf.top_left_ptr();
316 std::cerr <<
"vil_viff_image::put_view(): Warning: x0 should be a multiple of 8 for this type of image\n";
318 vxl_uint_32 rowsize = (pix_size*
ni+7)/8;
320 for (
unsigned int p = 0; p<
nplanes_; ++p)
321 for (
unsigned int y = y0; y < y0+
nj; ++y) {
323 + y*((
ni_*pix_size+7)/8)
326 std::cerr <<
"WARNING: " << __FILE__ <<
":\n" 327 <<
" could not write "<<rowsize<<
" EC bytes to stream;\n" 328 <<
" p="<<p<<
", y="<<y<<
'\n';
331 std::cerr <<
"written "<<rowsize<<
" EC bytes to stream; p="<<p<<
", y="<<y<<
'\n';
336 auto* tempbuf =
new vxl_byte[rowsize];
337 for (
unsigned int p = 0; p<
nplanes_; ++p)
338 for (
unsigned int y = y0; y < y0+
nj; ++y) {
339 std::memcpy(tempbuf, ob, rowsize);
340 for (
unsigned int i=0; i<rowsize; i+=pix_size/8)
341 swap(tempbuf+i,pix_size/8);
344 std::cerr <<
"WARNING: " << __FILE__ <<
":\n" 345 <<
" could not write "<<rowsize<<
" NEC bytes to stream;\n" 346 <<
" p="<<p<<
", y="<<y<<
'\n';
349 std::cerr <<
"written "<<rowsize<<
" NEC bytes to stream; p="<<p<<
", y="<<y<<
'\n';
370 std::cerr <<
"Endian is Consistent\n";
372 std::cerr <<
"Endian is NOT Consistent\n";
380 int longsize =
sizeof(vxl_uint_32);
381 auto* bytes =
new vxl_byte[longsize];
382 std::memcpy(bytes,&
ispare1,longsize);
384 swap(bytes,longsize);
394 int longsize =
sizeof(vxl_uint_32);
395 auto* bytes =
new vxl_byte[longsize];
396 std::memcpy(bytes,&
ispare2,longsize);
398 swap(bytes,longsize);
408 int floatsize =
sizeof(float);
409 auto* bytes =
new vxl_byte[floatsize];
410 std::memcpy(bytes,&
fspare1,floatsize);
412 swap(bytes,floatsize);
423 int floatsize =
sizeof(float);
424 auto* bytes =
new vxl_byte[floatsize];
425 std::memcpy(bytes,&
fspare2,floatsize);
427 swap(bytes,floatsize);
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.
vxl_uint_32 ispare2() const
virtual vil_streampos tell() const =0
Return file pointer.
void swap(double &a, double &b)
vil_streampos start_of_data_
virtual vil_streampos write(void const *buf, vil_streampos n)=0
Write n bytes from buf. Returns number of bytes written.
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.
void set_fspare1(float fspare1)
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.
~vil_viff_image() override
enum vil_pixel_format format_
unsigned ni() const
Width.
Stream interface for VIL image loaders.
unsigned nj() const
Height.
void set_fspare2(float fspare2)
virtual enum vil_pixel_format pixel_format() const =0
Return a description of the concrete data pixel type.
unsigned int nj() const override
Dimensions: Planes x ni x nj.
Indicates that some reference was made to pixels beyond the bounds of an image.
void set_ispare1(vxl_uint_32 ispare1)
unsigned int nplanes() const override
Dimensions: Planes x ni x nj.
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.
vxl_uint_32 data_storage_type
Ref. counted block of data on the heap.
unsigned int ni() const override
Dimensions. Planes x W x H.
vxl_uint_32 num_data_bands
unsigned nplanes() const
Number of planes.
void set_ispare2(vxl_uint_32 ispare2)
bool put_view(vil_image_view_base const &buf, unsigned int x0, unsigned int y0) override
Write buf into this at position (x0,y0).
void vil_exception_warning(T exception)
Throw an exception indicating a potential problem.
Representation of a generic image source or destination.
Generic image implementation for VIFF (Khoros) files.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
vil_viff_image(vil_stream *is)
Loader for Khoros 1.0 images.
vxl_uint_32 ispare1() const
User defined spare values in header.