/// <summary> /// 生成HObject类型图像 /// </summary> /// <param name="width">图像宽度</param> /// <param name="height">图像高度</param> /// <param name="pixelType">像素类型</param> /// <param name="colorFormat">颜色格式(planar = null, packed = HColorFormat)</param> /// <param name="pixelPointers">像素指针(单通道或RGB顺序 + [清理内存函数指针])</param> /// <returns></returns> protected HObject GenHImage(int width, int height, HPixelType pixelType, HColorFormat?colorFormat, params IntPtr[] pixelPointers) { HObject image = null; string type = Enum.GetName(typeof(HPixelType), pixelType); if (colorFormat == null) { if (pixelPointers.Length == 1) { HOperatorSet.GenImage1(out image, type, width, height, pixelPointers[0]); } else if (pixelPointers.Length == 2) { HOperatorSet.GenImage1Extern(out image, type, width, height, pixelPointers[0], pixelPointers[1]); } else if (pixelPointers.Length == 3) { HOperatorSet.GenImage3(out image, type, width, height, pixelPointers[0], pixelPointers[1], pixelPointers[2]); } else if (pixelPointers.Length == 4) { HOperatorSet.GenImage3Extern(out image, type, width, height, pixelPointers[0], pixelPointers[1], pixelPointers[2], pixelPointers[3]); } } else { if (pixelPointers.Length == 1) { HOperatorSet.GenImageInterleaved(out image, pixelPointers[0], Enum.GetName(typeof(HColorFormat), colorFormat), width, height, -1, type, 0, 0, 0, 0, -1, 0); } } return(image); }
/// <summary> /// 获取像素类型和颜色格式 /// </summary> /// <param name="type">需要转换的像素类型</param> /// <param name="pixelType">像素类型</param> /// <param name="colorFormat">颜色格式</param> protected virtual void GetHColorFormatAndHPixelType(object type, out HPixelType pixelType, out HColorFormat?colorFormat) { pixelType = HPixelType.@byte; colorFormat = null; }
/// <summary> /// 获取颜色格式和像素类型 /// </summary> /// <param name="type">Basler相机像素类型</param> /// <param name="pixelType">像素类型</param> /// <param name="colorFormat">颜色格式</param> protected override void GetHColorFormatAndHPixelType(object type, out HPixelType pixelType, out HColorFormat?colorFormat) { pixelType = HPixelType.@byte; colorFormat = null; switch ((PixelType)type) { case PixelType.Undefined: break; case PixelType.Mono1packed: break; case PixelType.Mono2packed: break; case PixelType.Mono4packed: break; case PixelType.Mono8: pixelType = HPixelType.@byte; colorFormat = null; break; case PixelType.Mono8signed: pixelType = HPixelType.int1; colorFormat = null; break; case PixelType.Mono10: break; case PixelType.Mono10packed: break; case PixelType.Mono10p: break; case PixelType.Mono12: break; case PixelType.Mono12packed: break; case PixelType.Mono12p: break; case PixelType.Mono16: pixelType = HPixelType.uint2; colorFormat = null; break; case PixelType.BayerGR8: break; case PixelType.BayerRG8: break; case PixelType.BayerGB8: break; case PixelType.BayerBG8: break; case PixelType.BayerGR10: break; case PixelType.BayerRG10: break; case PixelType.BayerGB10: break; case PixelType.BayerBG10: break; case PixelType.BayerGR12: break; case PixelType.BayerRG12: break; case PixelType.BayerGB12: break; case PixelType.BayerBG12: break; case PixelType.RGB8packed: pixelType = HPixelType.@byte; colorFormat = HColorFormat.rgb; break; case PixelType.BGR8packed: pixelType = HPixelType.@byte; colorFormat = HColorFormat.bgr; break; case PixelType.RGBA8packed: pixelType = HPixelType.@byte; colorFormat = HColorFormat.rgbx; break; case PixelType.BGRA8packed: pixelType = HPixelType.@byte; colorFormat = HColorFormat.bgrx; break; case PixelType.RGB10packed: break; case PixelType.BGR10packed: break; case PixelType.RGB12packed: break; case PixelType.BGR12packed: break; case PixelType.RGB16packed: pixelType = HPixelType.uint2; colorFormat = HColorFormat.rgb48; break; case PixelType.BGR10V1packed: break; case PixelType.BGR10V2packed: break; case PixelType.YUV411packed: break; case PixelType.YUV422packed: break; case PixelType.YUV444packed: break; case PixelType.RGB8planar: pixelType = HPixelType.@byte; colorFormat = null; break; case PixelType.RGB10planar: break; case PixelType.RGB12planar: break; case PixelType.RGB16planar: pixelType = HPixelType.uint2; colorFormat = null; break; case PixelType.YUV444planar: break; case PixelType.YUV422planar: break; case PixelType.YUV420planar: break; case PixelType.YUV422_YUYV_Packed: break; case PixelType.BayerGR12Packed: break; case PixelType.BayerRG12Packed: break; case PixelType.BayerGB12Packed: break; case PixelType.BayerBG12Packed: break; case PixelType.BayerGR10pp: break; case PixelType.BayerRG10pp: break; case PixelType.BayerGB10pp: break; case PixelType.BayerBG10pp: break; case PixelType.BayerGR12p: break; case PixelType.BayerRG12p: break; case PixelType.BayerGB12p: break; case PixelType.BayerBG12p: break; case PixelType.BayerGR16: break; case PixelType.BayerRG16: break; case PixelType.BayerGB16: break; case PixelType.BayerBG16: break; case PixelType.RGB12V1packed: break; case PixelType.Double: break; default: break; } }