Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

What is the ImageDataPtr class

Sathish_S_
Beginner
711 Views

Hello,

I need to write code for the JPEG encryption. I got the sample source code. To write my client app, I need to provide the parameters. B

I am struct-king with providing one parameter i,.e ImageDataPtr class method i,.e

 

UIC::ImageDataPtr dataPtr;
    dataPtr.p8u = //what I need to provide here;

could you please suggest me.

 

Regards,

sathish.

 

0 Kudos
18 Replies
Sergey_K_Intel
Employee
711 Views

Hi Sathish,

As far as I see it's a kind of "mutable" pointer to image data buffer. Basically, you need to typecast you buffer pointer to requested data type, for example,

  dataPtr.p8u = (Ipp8u*)dataPtr.m_myBufferPointer;

I cannot say more without clue of your implementation specifics.

0 Kudos
Sathish_S_
Beginner
711 Views

Hi Sergey,

Thank you for the reply.

what is the image data buffer here. what information we need to store. do we need to store the pixel value in the buffer.

Actually I am providing like this 

CStdFileInput inFile;
    UIC::BaseStream::TStatus tStatus;
    UIC::BaseStream::TSize   nCnt;

    tStatus = inFile.Open(m_cpIfnName);
    if (UIC::BaseStream::StatusOk != tStatus)
        return false;
    
    const int nSize = m_nInWidth * m_nInHeight * m_nInBands;
    ptr1 = new unsigned char[nSize];
        
    tStatus = inFile.Read((Ipp8u*)ptr1, nSize, nCnt);

    if (UIC::BaseStream::StatusOk != tStatus)
        return false;

But this code is not working for all the input files. I do have different file formats like .tiff , .img  so on . does this Read() method will work for all the file formats?. or which info we need to store in that buffer.

could you please comment.

 

Regards,

sathish.

0 Kudos
Sergey_K_Intel
Employee
711 Views

The list of image formats supported by UIC depends on version of IPP samples used for prototyping. In IPP 7.0.x samples the list was as follows: bmp, dds, jpg, j2k, jxr, png, pnm, tiff. For IPP 7.1.x samples only bmp, jpg, j2k, jxr and png are supported.
 

If you want, you may take IPP 7.0.7 samples from http://registrationcenter.intel.com/irc_nas/2582/w_ipp-samples_p_7.0.7.064.zip for TIFF codec. You need uic/src/codec/image/tiff/* source files from that package.

Regarding other image file formats, UIC doesn't support them. You may create your own codecs based on BaseImageDecoder abstract class. BMP file decoder can be taken as an example of simple image decoder. Look into UIC::OwnBMPDecoder::ReadHeader and UIC::OwnBMPDecoder::ReadData functions of BMP decoder.

0 Kudos
Sathish_S_
Beginner
711 Views

Yes , IPP is supporting for limited formats only.

Here I am doing encoder(writing any raster file info into JPEG). In this case how to provide the input buffer. what information it will have.

dataPtr.p8u = (Ipp8u*)dataPtr.m_myBufferPointer;

what information m_myBufferPointer will have here.

Regards,

sathish.

 

0 Kudos
Sathish_S_
Beginner
711 Views

Hi Sirgey,

I don't have any idea on Intel IPP. I am strucking with providing the input buffer. 

could you please help me in this regard.

Regards,

sathish.

0 Kudos
Sergey_K_Intel
Employee
711 Views

OK, let's look how it's done in BMP encoder as in simplest image encoder.

In fact, you don't need UIC::ImageDataPtr objects to do image encoding. There are too much unnecessary C++ code in UIC, which can be avoided in real applications.

In BMP's UIC::OwnBMPEncoder::WriteData() function the usage is

    Ipp8u*              ptr;
...
    const ImageDataPtr*   data      = m_image->Buffer().DataPtr();
...
    ptr = (Ipp8u*)data[0].p8u + step * (height - 1);
...
    for(i = 0; i < height; i++)
    {
      status = m_stream->Write(ptr - i * step,bmpwidth,cnt);
...
    }

I think, for example, that there is no need in local "ImageDataPtr *data" object, if using

  Ipp8u*              ptr;
...
  ptr = m_image->Buffer().DataPtr()->p8u + step * (height - 1);
...
    for(i = 0; i < height; i++)
    {
      status = m_stream->Write(ptr - i * step,bmpwidth,cnt);
...
    }

Then, ImageDataPtr object comes from UIC::OwnBMPEncode object as return type of DataPtr() function. This is just to make DataPtr output universal for all possible image data types. If your image codec deals with "unsigned char" pixels only (for example, "unsigned char" RGB - one byte for R, one for G and one for B), you could define DataPtr as "unsigned char *DataPtr()" and could have no need for ImageDataPtr structure (union).

Actually, I don't understand how did you stick to ImageDataPtr in your code. Suppose, you have your image raster data in buffer of "float" pixels. You can create ImageDataPtr object at any time with

    ImageDataPtr myDataPtr;
...
    myDataPtr.p32f = myFloatRasterImageBuffer;

If you like, we can continue discussion in private thread ("Send Author A Message" button) to keep details your code confident and to not mess the forum threads.

0 Kudos
Sathish_S_
Beginner
711 Views

Now, I am understading littel better now.

here m_image->Buffer().DataPtr() means pixel data. Please confirm. If that is the case how to fill the pixel info into buffer. Actually I have pixel values row by row.

I would like to continue the discussion in the private thread but when I click on "Send Author A Message" button it showing it as "No messages available".

Regards,

sathish.

0 Kudos
Sergey_K_Intel
Employee
711 Views

Sathish S. wrote:

here m_image->Buffer().DataPtr() means pixel data. Please confirm. If that is the case how to fill the pixel info into buffer. Actually I have pixel values row by row.

Exactly.

Sathish S. wrote:

I would like to continue the discussion in the private thread but when I click on "Send Author A Message" button it showing it as "No messages available".

Oops, this is forum engine problem. Sorry.

0 Kudos
Sathish_S_
Beginner
711 Views

Thank you for the confirmation. 

Actually I am using some input image having the following properties

width = height = 9240

and Gray scale image i,.e nOfBands = 1

so unsigned char* dest_buff = new unsigned char[widh * height * nOfbands]

In our code we have some functions that will return the pixel data for each row.

how to fill the dest_buff row by row.

could you help me in this regard.

Regards,

sathish

 

0 Kudos
Sathish_S_
Beginner
711 Views

 

I did the development for 8bit data single band image . Now, it is working fine.

But I am strucking with 3 band data . because I will get the info layer by layer . how should I provide this info to the ImageDataPtr

could you please guide me in this regard.

Regards,

sathish.

0 Kudos
Sergey_K_Intel
Employee
711 Views

In fact, there is no difference in ImageDataPtr usage between 1 byte-per-pixel or 3 bytes-per-pixel formats. In both cases with .p8u union data member you point to the first byte of your image data buffer.

If you get image color planes in different buffers, each of them is of [width*height*1] size, you can combine them into single image data buffer of [width*height*3] size using "ippiCopy_8u_P3C3R" function before encoding.

0 Kudos
Sathish_S_
Beginner
711 Views

Thank you so much for the information.

how to use the ippiCopy_8u_P3C3R function ,because I didnt found the help for this function. 

could you please provide the sample code for that function usage.

Regards,

sathish

0 Kudos
Sergey_K_Intel
Employee
711 Views

If I am not wrong, the usage should like this:

    const int width = 1920, height = 1080;
    Ipp8u red[width * height * 1];
    Ipp8u green[width * height * 1];
    Ipp8u blue[width * height * 1];
    Ipp8u combImage[width * height * 3];
    Ipp8u* pColorPlanes[3] = { red, green, blue };
    IppiSize roi = { 1920, 1080 };

    ippiCopy_8u_P3C3R(pColorPlanes, width, combImage, width * 3, roi);

 

0 Kudos
Sathish_S_
Beginner
711 Views

Hi Sergey,

Here is my code. This code is working correctly for single band image uint8 data. But I need to make it work for 3 band uint8 data.

I used the function ippiCopy_8u_P3C3R() to combine the three layers data into single buffer . But my output image is not mathching with input.

could you please see the code and please let me know my faults.

UINT64 numberOfPixels = numberOfBands * width * height;
UINT8* data = emsc_New(numberOfPixels, UINT8);

int cnt = width * height;

if (numberOfBands == 1)

    {
        for (UINT32 band = 0; band < numberOfBands; ++band)
        {
            data = (UINT8*)(prs->datalayer[g_vbands[band]]->data);
        }
    }

    UINT8* test1 = new unsigned char[cnt];
    UINT8* test2 = new unsigned char[cnt];
    UINT8* test3 = new unsigned char[cnt];
    Ipp8u*  pSrc8u[3];
    IppiSize roi = { width, height };
    IppStatus status;
    if (numberOfBands == 3)
    {
        test1 = (UINT8*)(prs->datalayer[g_vbands[0]]->data);
        test2 = (UINT8*)(prs->datalayer[g_vbands[1]]->data);
        test3 = (UINT8*)(prs->datalayer[g_vbands[2]]->data);
        pSrc8u[0] = test1;
        pSrc8u[1] = test2;
        pSrc8u[2] = test3;

        status = ippiCopy_8u_P3C3R(pSrc8u, width, data, width * 3, roi);
                
    }


    UIC::BaseStream::TStatus tStatus;
    UIC::BaseStream::TSize   nCnt;

    if (UIC::BaseStream::StatusOk != tStatus)

       return false;

int du = (((PRECESION & 255) + 7) / 8);//here #define PRECESION  8
    int LineStep = m_nInWidth * m_nInBands * du;

//construct and init the jpeg encoder
    UIC::JPEGEncoder uicEncoder;
    UIC::Image srcImg;
    ExcStatus resStatus = ExcStatusOk;
    uicEncoder.Init();

    //attach the output stream with output buffer to the encoder
    CStdFileOutput outFile;
    tStatus = outFile.Open(m_cpOfnName);
    if (!BaseStream::IsOk(tStatus))
        return false;

resStatus = uicEncoder.AttachStream(outFile);
    if (resStatus != ExcStatusOk)
        return false;
JCOLOR dstClr = JC_UNKNOWN;
    switch (m_nInBands)
    {

    case 1:
        dstClr = JC_GRAY;
        break;

    case 3:
        dstClr = JC_RGB;
        break;

    case 4:
        dstClr = JC_CMYK;
        break;

    default:
        dstClr = JC_UNKNOWN;
        break;
    }

//attach the input source image with input buffer
    UIC::ImageSamplingGeometry samplingGeometry;
    samplingGeometry.SetRefGridRect(UIC::Rect(UIC::Point(0, 0), RectSize(m_nInWidth, m_nInHeight)));
    samplingGeometry.ReAlloc(m_nInBands);
    samplingGeometry.SetEnumSampling(UIC::S444);

    UIC::ImageDataOrder imageDataOrder;
    imageDataOrder.ReAlloc(UIC::Interleaved, m_nInBands);
    imageDataOrder.PixelStep()[0] = m_nInBands;
    imageDataOrder.LineStep()[0] = LineStep;
    imageDataOrder.SetDataType(T8u);

UIC::ImageDataPtr dataPtr;
    
    dataPtr.p8u = data;
    srcImg.Buffer().Attach(&dataPtr, imageDataOrder, samplingGeometry);

srcImg.ColorSpec().ReAlloc(m_nInBands);
    UIC::ImageEnumColorSpace srcClrSpace = m_bGrayScale ? UIC::Grayscale : UIC::BGR;
    srcImg.ColorSpec().SetColorSpecMethod(UIC::Enumerated);
    srcImg.ColorSpec().SetComponentToColorMap(UIC::Direct);
    srcImg.ColorSpec().SetEnumColorSpace(srcClrSpace);

for (int i = 0; i < m_nInBands; i++)
    {
        srcImg.ColorSpec().DataRange().SetAsRange8u(255);
    }

    resStatus = uicEncoder.AttachImage(srcImg);
    if (resStatus != ExcStatusOk)
        return false;

   JSS sampling = m_bGrayScale ? JS_444 : JS_422;
    resStatus = uicEncoder.SetParams(JPEG_BASELINE, dstClr, sampling, 0, 0, 75);
    if (resStatus != ExcStatusOk)
        return false;
    
    //encode the image to the output File
    resStatus = uicEncoder.WriteHeader();
    if (resStatus != ExcStatusOk)
        return false;
    
    resStatus = uicEncoder.WriteData();
    if (resStatus != ExcStatusOk)
        return false;

outFile.Close();

    return (true);

 

could you please help me.

Regards,

sathish.

0 Kudos
Sathish_S_
Beginner
711 Views

Hi Sergey,

could you please comment on my above email.

Regards,

sathish.

0 Kudos
Sergey_K_Intel
Employee
711 Views

Comments:

    //UINT8* test1 = new unsigned char[cnt];
    //UINT8* test2 = new unsigned char[cnt];
    //UINT8* test3 = new unsigned char[cnt];
    Ipp8u*  pSrc8u[3];
    IppiSize roi = { width, height };
    IppStatus status;
    if (numberOfBands == 3)
    {
        pSrc8u[0] /*test1*/ = (UINT8*)(prs->datalayer[g_vbands[0]]->data);
        pSrc8u[1] /*test2*/ = (UINT8*)(prs->datalayer[g_vbands[1]]->data);
        pSrc8u[2] /*test3*/ = (UINT8*)(prs->datalayer[g_vbands[2]]->data);
        //pSrc8u[0] = test1;
        //pSrc8u[1] = test2;
        //pSrc8u[2] = test3;

        status = ippiCopy_8u_P3C3R(pSrc8u, width, data, width * 3, roi);
    }

What do you mean by "output image is not mathching with input" ? After decoding you get incorrect image ?  Distorted picture ? Wrong colors ?

Could you step-by-step go through "uic_transcoder_con" sample tracking the same operations you want to implement ?

0 Kudos
Sathish_S_
Beginner
711 Views

Actually, I am getting the wrong colors and also the incorrect pixel values for one layer3.

I have hardcoded  three layers data with the following 

        memset(pSrc8u[0], unsigned char(0), cnt);
        memset(pSrc8u[1], unsigned char(0), cnt);
        memset(pSrc8u[2], unsigned char(0), cnt);

     status = ippiCopy_8u_P3C3R(pSrc8u, width, data, width * 3, roi);

In the outputfile,  I am getting the following pixel vaues

Layer 1 : All pixel values are zeroes

layer 2 : All pixel values are 135

layer 3 : All pixel values are zeroes

Actually, It has to display all the layers pixel values as zero. If I am not wrong. But, why layer 2 is showing it as 135.

here I provided the hardcoded values and provided the buffer to the ImageDataPtr. 

Any idea why its behaving like that.

Regards,

sathish.

0 Kudos
Sathish_S_
Beginner
711 Views

 

Forgot to add the parameters for the above test

resStatus = uicEncoder.SetParams(JPEG_BASELINE, JC_YCBCR, JS_444, 0, 0, 75);

could you help us in this regard.

Regards,

sathish.

0 Kudos
Reply