00001 // This is brl/bbas/vidl2/vidl2_frame.cxx 00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00003 #pragma implementation 00004 #endif 00005 //: 00006 // \file 00007 // \author Matt Leotta 00008 // \date 13 Jan 2006 00009 // 00010 //----------------------------------------------------------------------------- 00011 00012 #include "vidl2_frame.h" 00013 #include <vcl_cassert.h> 00014 #include <vil/vil_image_view.h> 00015 00016 //----------------------------------------------------------------------------- 00017 00018 //: Decrement reference count 00019 void 00020 vidl2_frame::unref() 00021 { 00022 assert (ref_count_ >0); 00023 ref_count_--; 00024 if (ref_count_==0) 00025 { 00026 delete this; 00027 } 00028 } 00029 00030 //----------------------------------------------------------------------------- 00031 00032 //: Constructor - from a vil_image_view 00033 // return an invalid frame if the image format can not be wrapped 00034 vidl2_memory_chunk_frame:: 00035 vidl2_memory_chunk_frame(const vil_image_view_base& image, 00036 vidl2_pixel_format fmt) 00037 : vidl2_frame(), memory_(NULL) 00038 { 00039 ni_ = image.ni(); 00040 nj_ = image.nj(); 00041 if (image.pixel_format() == VIL_PIXEL_FORMAT_UINT_16 && 00042 image.nplanes() == 1) 00043 { 00044 vil_image_view<vxl_uint_16> img = image; 00045 if(!img.is_contiguous()) 00046 return; 00047 memory_ = img.memory_chunk(); 00048 format_ = VIDL2_PIXEL_FORMAT_MONO_16; 00049 } 00050 else if (image.pixel_format() == VIL_PIXEL_FORMAT_BYTE) 00051 { 00052 vil_image_view<vxl_byte> img = image; 00053 if(!img.is_contiguous()) 00054 return; 00055 memory_ = img.memory_chunk(); 00056 if (img.nplanes() == 1) 00057 { 00058 format_ = VIDL2_PIXEL_FORMAT_MONO_8; 00059 } 00060 else if (img.nplanes() == 3) 00061 { 00062 if (img.planestep() == 1){ 00063 if(fmt == VIDL2_PIXEL_FORMAT_UYV_444) 00064 format_ = VIDL2_PIXEL_FORMAT_UYV_444; 00065 else 00066 format_ = VIDL2_PIXEL_FORMAT_RGB_24; 00067 } 00068 else 00069 { 00070 if(fmt == VIDL2_PIXEL_FORMAT_YUV_444P) 00071 format_ = VIDL2_PIXEL_FORMAT_YUV_444P; 00072 else 00073 format_ = VIDL2_PIXEL_FORMAT_RGB_24P; 00074 } 00075 } 00076 else if (img.nplanes() == 4) 00077 { 00078 if (img.planestep() == 1) 00079 format_ = VIDL2_PIXEL_FORMAT_RGBA_32; 00080 else 00081 format_ = VIDL2_PIXEL_FORMAT_RGBA_32P; 00082 } 00083 } 00084 00085 if(fmt != VIDL2_PIXEL_FORMAT_UNKNOWN && 00086 fmt != format_) 00087 format_ = VIDL2_PIXEL_FORMAT_UNKNOWN; 00088 00089 if(format_ == VIDL2_PIXEL_FORMAT_UNKNOWN) 00090 memory_ = NULL; 00091 } 00092 00093
1.4.4