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. Memory usage while printing
Forum Updated to NodeBB v4.3 + New Features

Memory usage while printing

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 2.8k Views 2 Watching
  • 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.
  • Roy44R Offline
    Roy44R Offline
    Roy44
    wrote on last edited by
    #3

    Sorry for my very bad english.
    I mean if call painter.drawImage in my loop, a lot of memory is used like 2Go for example.

    for(OdInt32 u = 0; u < iHorizontalTileCount; u++)
        {
            OdInt32 printerY = iVStep == 1 ? 0 : uiHeight;
            for(OdInt32 v = 0;  v < iVerticalTileCount; v++)
            {
                OdUInt32 uiCurrentTileWidth = odmin(uiTileWidth, uiWidth - (uiTileWidth * u));
                OdUInt32 uiCurrentTileHeight = odmin(uiTileHeight, uiHeight - (uiTileHeight * v));
                OdInt32 tileX = u * uiTileWidth;
                OdInt32 tileY = v * uiTileHeight;
                OdGsDCRect tileRect(tileX, tileX + uiCurrentTileWidth, tileY, tileY + uiCurrentTileHeight);
    
                OdGsDCRect snapShotRegion =  regenTile(viewportSize, tileRect);
    
    //render image
                OdGiRasterImagePtr pImage;
                m_pTeighaPrinter->getSnapShot(pImage, snapShotRegion);
                width = pImage->pixelWidth();
                height = pImage->pixelHeight();
                const OdUInt8* pData = pImage->scanLines();
    
    // create image
                QImage qtImg((const uchar *) pData, width, height, fmt);
    
    // paint
                painter.drawImage(iHStep == 1 ? printerX : (printerX - width),
                                   iVStep == 1 ? printerY : (printerY - height),
                                  qtImg,0, 0, width, height);
    
    
                printerY += iVStep * height;
    
                if(!bRestored)
                {
                    pCoreApp->setMtMode(iMtMode);
                    bRestored = true;
                }
    
                // progression
                emit sg_progress(iProgress);
                iProgress++;
            }
            printerX += iHStep * width;
        }
    

    If I remove line painter.drawImage and store image on list, the memory is not growing.
    I would not pretend that's a memory leak but my problem is like a memory leak.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi
      You can try to new it so u can delete it after
      drawing. Not sure why painter.drawImage should change anything.

      QImage  *qtImg=new QImage ((const uchar *) pData, width, height, fmt);
                  painter.drawImage(iHStep == 1 ? printerX : (printerX - width) xxx
      delete qtImg;
      

      Also the pData use to create the Image, its deleted else where ? ( or dont need deletion)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi,

        How many images are you painting ? Which size are they ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Roy44R Offline
          Roy44R Offline
          Roy44
          wrote on last edited by
          #6

          this size is fixed for the printing.
          I make 1000 * 1000 by default
          The number of images depends on the size of paper and the DPI

          1 Reply Last reply
          0
          • Roy44R Offline
            Roy44R Offline
            Roy44
            wrote on last edited by
            #7

            My goal is to be able to print on plotter (sorry google translate)
            Printing on paper with large size (ex 1040mm * 3800mm)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              So basically you are drawing several tiles that are about 4MB each ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Roy44R Offline
                Roy44R Offline
                Roy44
                wrote on last edited by
                #9

                I made a try:
                store all QImages in list intead of calling drawImage and the memory usage is completely different.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  It's not the same use case

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Roy44R Offline
                    Roy44R Offline
                    Roy44
                    wrote on last edited by
                    #11

                    I compared my code with a MFC code. And the memory usage is totally different.
                    I will try another way:
                    Is it possible to print with vectorized data, i mean using HPGL to print my plan.
                    My goal is to be able to print dwg plan with scale 1:1.

                    Thanks.

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #12

                      Hi
                      I would see if you could reuse the dwg reading code from
                      https://github.com/LibreCAD/LibreCAD
                      That would allow true vector output.

                      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