- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am having problems with encoding a bytestream into Jpeg when the output is memory (CMemBuffOutput) but no problems at all when the output is a file (CStdFileOutput).
The encoding code is called from C# using pinvoke.
[csharp]
public static class FrameEncoder
{
public static MemoryStream EncodeJPG(IntPtr data, int width, int height, int stride, int pxFormat, bool needFlipY, int size)
{
var jpeg = new byte[size];
MyDll.EncodeJpg(data, jpeg, size, 3, width, height, stride);
var stream = new MemoryStream(jpeg, 0, size, false, true);
return stream;
}
}
[DllImport("encoderDll.dll")]
private static extern int encodeJpeg(IntPtr input, byte[] output, int length, int numChannels, int width,
int height, int step);
public static int EncodeJpg(IntPtr input, byte[] output, int length, int numChannels, int width, int height,
int step)
{
return encodeJpeg(input, output, length, numChannels, width, height, step);
}
[/csharp]
[cpp]
int WINAPI encodeJpeg(unsigned char* input, unsigned char* output, int length, int numChannels, int width, int height, int step)
{
//copied from UIC sample
CMemBuffOutput out;
UIC::Point origin;
UIC::RectSize size;
UIC::Rect refGrid;
UIC::Image imgCn;
UIC::JPEGEncoder encoder;
UIC::ImageDataPtr dataPtr;
UIC::ImageColorSpec colorSpec;
UIC::ImageDataOrder dataOrder;
UIC::ImageSamplingGeometry geo;
UIC::ExcStatus status;
if(!BaseStream::IsOk(out.Open(output, length)))
{
return -1;
}
// test
/*char* outputFile = "test.jpg";
CStdFileOutput outputF;*/
/*if(!BaseStream::IsOk(outputF.Open(outputFile)))
{
return -1;
}*/
status = encoder.Init();
if(status == ExcStatusFail)
{
return -1;
}
status = encoder.AttachStream(out);
//status = encoder.AttachStream(outputF);
dataOrder.SetDataType(UIC::ImageDataType::T8u);
size.SetWidth(width);
size.SetHeight(height);
origin.SetX(0);
origin.SetY(0);
refGrid.SetOrigin(origin);
refGrid.SetSize(size);
geo.SetRefGridRect(refGrid);
geo.ReAlloc(numChannels);
dataOrder.ReAlloc(UIC::ImageComponentOrder::Interleaved, numChannels);
dataOrder.PixelStep()[0] = numChannels;
dataOrder.LineStep()[0] = step;
status = imgCn.ColorSpec().ReAlloc(numChannels);
imgCn.ColorSpec().SetColorSpecMethod(Enumerated);
imgCn.ColorSpec().SetComponentToColorMap(Direct);
for(int i = 0; i < numChannels; i++)
{
imgCn.ColorSpec().DataRange().SetAsRange8u(255);
}
imgCn.ColorSpec().SetEnumColorSpace(UIC::ImageEnumColorSpace::RGB);
dataPtr.p8u = input;
status = imgCn.Buffer().Attach(&dataPtr, dataOrder, geo);
if(status == ExcStatusFail)
{
return -1;
}
status = encoder.AttachImage(imgCn);
if(status == ExcStatusFail)
{
return -1;
}
status = encoder.SetParams(JMODE::JPEG_BASELINE, JCOLOR::JC_RGB, JSS::JS_444, 0, 0, 75);
if(status == ExcStatusFail)
{
return -1;
}
status = encoder.WriteHeader();
if(status == ExcStatusFail)
{
return -1;
}
status = encoder.WriteData();
if(status == ExcStatusFail)
{
return -1;
}
[/cpp]
When output is CMemBuffOutput, the values in output are always the same, even when the input data (the camera captured image) has changed. For instance if i cover the camera (total black) the input data values reflect this but output values don't change.
Any idea what i'm doing wrong?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
It is not easy to catch some error from the code piece. You may possiblly debug into the following function, see find why the write is actually not happenning.
JERRCODE CMemBuffOutput::Write(void* buf,uic_size_t len,uic_size_t* cnt) {....}
Thanks,
Chao
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am also facing the same issue.
did you found the solution for it?. If so could you please share it.
Regards,
Sathish

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page