1 // This is core/vidl/vidl_frame.cxx 2 //: 3 // \file 4 // \author Matt Leotta 5 // \date 13 Jan 2006 6 // 7 //----------------------------------------------------------------------------- 8 9 #include "vidl_frame.h" 10 #include <cassert> 11 #ifdef _MSC_VER 12 # include "vcl_msvc_warnings.h" 13 #endif 14 #include "vil/vil_image_view.h" 15 16 //----------------------------------------------------------------------------- 17 18 //: Decrement reference count 19 void unref()20vidl_frame::unref() 21 { 22 assert(ref_count_ > 0); 23 ref_count_--; 24 if (ref_count_ == 0) 25 { 26 delete this; 27 } 28 } 29 30 //----------------------------------------------------------------------------- 31 32 //: Constructor - from a vil_image_view 33 // return an invalid frame if the image format can not be wrapped vidl_memory_chunk_frame(const vil_image_view_base & image,vidl_pixel_format fmt)34vidl_memory_chunk_frame::vidl_memory_chunk_frame(const vil_image_view_base & image, vidl_pixel_format fmt) 35 : vidl_frame() 36 , memory_(nullptr) 37 { 38 ni_ = image.ni(); 39 nj_ = image.nj(); 40 // use the pixel component format to account for 41 // images of type vil_rgb<T>, vil_rgba<T>, etc. 42 vil_pixel_format cmp_format = vil_pixel_format_component_format(image.pixel_format()); 43 unsigned int num_cmp = vil_pixel_format_num_components(image.pixel_format()); 44 unsigned int num_channels = image.nplanes() * num_cmp; 45 46 if (cmp_format == VIL_PIXEL_FORMAT_UINT_16 && num_channels == 1) 47 { 48 vil_image_view<vxl_uint_16> img = image; 49 if (!img.is_contiguous()) 50 return; 51 memory_ = img.memory_chunk(); 52 format_ = VIDL_PIXEL_FORMAT_MONO_16; 53 } 54 else if (cmp_format == VIL_PIXEL_FORMAT_BYTE) 55 { 56 vil_image_view<vxl_byte> img = image; 57 if (!img.is_contiguous()) 58 return; 59 memory_ = img.memory_chunk(); 60 if (img.nplanes() == 1) 61 { 62 format_ = VIDL_PIXEL_FORMAT_MONO_8; 63 } 64 else if (img.nplanes() == 3) 65 { 66 if (img.planestep() == 1) 67 { 68 if (fmt == VIDL_PIXEL_FORMAT_UYV_444) 69 format_ = VIDL_PIXEL_FORMAT_UYV_444; 70 else 71 format_ = VIDL_PIXEL_FORMAT_RGB_24; 72 } 73 else 74 { 75 if (fmt == VIDL_PIXEL_FORMAT_YUV_444P) 76 format_ = VIDL_PIXEL_FORMAT_YUV_444P; 77 else 78 format_ = VIDL_PIXEL_FORMAT_RGB_24P; 79 } 80 } 81 else if (img.nplanes() == 4) 82 { 83 if (img.planestep() == 1) 84 format_ = VIDL_PIXEL_FORMAT_RGBA_32; 85 else 86 format_ = VIDL_PIXEL_FORMAT_RGBA_32P; 87 } 88 } 89 else if (cmp_format == VIL_PIXEL_FORMAT_FLOAT) 90 { 91 vil_image_view<vxl_ieee_32> img = image; 92 if (!img.is_contiguous()) 93 return; 94 memory_ = img.memory_chunk(); 95 if (img.nplanes() == 1) 96 format_ = VIDL_PIXEL_FORMAT_MONO_F32; 97 else if (img.nplanes() == 3) 98 { 99 if (img.planestep() == 1) 100 format_ = VIDL_PIXEL_FORMAT_RGB_F32; 101 else 102 format_ = VIDL_PIXEL_FORMAT_RGB_F32P; 103 } 104 } 105 106 if (fmt != VIDL_PIXEL_FORMAT_UNKNOWN && fmt != format_) 107 format_ = VIDL_PIXEL_FORMAT_UNKNOWN; 108 109 if (format_ == VIDL_PIXEL_FORMAT_UNKNOWN) 110 memory_ = nullptr; 111 } 112