Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to create gray scale QImage(QImage::Format_Indexed) without copying memory
QtWS25 Last Chance

[Solved] How to create gray scale QImage(QImage::Format_Indexed) without copying memory

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 8.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joonhwan
    wrote on last edited by
    #1

    I'm trying to create QImage that wrap a existing image buffer that is created by OpenCv I was considering use following constructor to do this.

    @QImage::QImage ( const uchar * data, int width, int height,
    int bytesPerLine, Format format )@

    so, my code is like

    @
    QImage qimage((const uchar*)iplImage->imageData,
    iplImage->width, iplImage->height,
    iplImage->widthStep,
    QImage::Format_Indexed); // qimage's buffer is now just pointing the 'iplImage->imageData'
    // without allocating and copying buffer.
    qimage.setColorTable(grayScaleColorTable); // color table's item count 256 for grayscale.
    // now new image buffer is allocated and copied from original here.
    @

    Ok, no memory copy actually was done at the time of calling this ctor. But, here comes my problem. QImage::setColorTables() is non const member function where QImage allocates new image buffer for copying by its internal detach() function.

    I found there was Qt3 support for this kind of problem where ctor could accept color table as argument in its ctor, but I've not found any such support in > Qt4.

    How can I create gray scale QImage for existing image buffer?

    Thanks for in advance

    joonhwan at gmail dot com

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joonhwan
      wrote on last edited by
      #2

      I got feedback from "SO post":http://stackoverflow.com/questions/13597058/how-to-create-gray-scale-qimageqimageformat-indexed-without-copying-memory

      I should have used

      @
      QImage ( uchar * data, int width, int height, Format format )
      QImage ( uchar * data, int width, int height, int bytesPerLine, Format format )
      @

      instead of

      @
      QImage ( const uchar * data, int width, int height, Format format )
      QImage ( const uchar * data, int width, int height, int bytesPerLine, Format format )
      @

      joonhwan at gmail dot com

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rahul Das
        wrote on last edited by
        #3

        Nice..


        Declaration of (Platform) independence.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved