Results 1 to 20 of 21

Thread: Problems working with 8bpp and 24bpp images

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems working with 8bpp and 24bpp images

    Hi. First, I post the code that finally I have implemented using the code by Cesar. After I comment a problem with this code:

    Qt Code:
    1. void FotoEditorFotos::paintRect(const QColor &color, const QRect &rectAPintar)
    2. {
    3. int xMin = rectAPintar.x();
    4. int xMax = xMin + rectAPintar.width() - 1;
    5. int yMin = rectAPintar.y();
    6. int yMax = yMin + rectAPintar.height() - 1;
    7.  
    8. if (!imatge.valid(xMin, yMin) || !imatge.valid(xMax, yMax)) return;
    9.  
    10. QRgb colorRgb = color.rgba();
    11.  
    12. quint8 *pixelsLiniaFoto;
    13. quint8 color8, colorVermell, colorVerd, colorBlau, colorAlpha;
    14.  
    15. int bytesPixel = (imatge.depth()) >> 3;
    16.  
    17. if (bytesPixel == 1)
    18. color8 = (imatge.isGrayScale()) ? qGray(colorRgb) : obtenirIndexColor(valorColor);
    19. else
    20. {
    21. colorVermell = qRed(colorRgb);
    22. colorVerd = qGreen(colorRgb);
    23. colorBlau = qBlue(colorRgb);
    24. colorAlpha = qAlpha(colorRgb);
    25. }
    26.  
    27. for (int j = yMin; j <= yMax; j++)
    28. {
    29. pixelsLiniaFoto = static_cast<quint8 *>(imatge.scanLine(j)) + (xMin * bytesPixel);
    30.  
    31. for (int i = xMin; i <= xMax; i++)
    32. {
    33. switch (bytesPixel)
    34. {
    35. // Qt only manages 1, 8 or 32bpp
    36. case 1:
    37. *(pixelsLiniaFoto++) = color8;
    38. break;
    39.  
    40. case 4:
    41. *(pixelsLiniaFoto++) = colorVermell;
    42. *(pixelsLiniaFoto++) = colorVerd;
    43. *(pixelsLiniaFoto++) = colorBlau;
    44. *(pixelsLiniaFoto++) = colorAlpha;
    45. break;
    46. }
    47. }
    48. }
    49.  
    50. update();
    51. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that with images with 32bpp it paints the area that I want but with an invalid color, different from the color that I pass to the function. Anoybody could explain where's the mistake?

  2. #2
    Cesar Guest

    Default Re: Problems working with 8bpp and 24bpp images

    The only problem I could imagine is the following: your imatge object uses the different places for colours, rather then RGBA. I suggest you to temporarily the code to
    Qt Code:
    1. //[SKIP]
    2. case 4:
    3. *(pixelsLiniaFoto++) = 0xff;
    4. *(pixelsLiniaFoto++) = 0x00;
    5. *(pixelsLiniaFoto++) = 0x00;
    6. *(pixelsLiniaFoto++) = 0x00;
    7. //[SKIP]
    To copy to clipboard, switch view to plain text mode 
    and watch for the results. This way you will fill the QRect with the pure color. Let's pretend you have got blue QRect. Then your first line should be changed to
    Qt Code:
    1. *(pixelsLiniaFoto++) = colorBlau;
    To copy to clipboard, switch view to plain text mode 
    This way you can check, which colour is the first, which is the second and what is the place of alpha channel

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems working with 8bpp and 24bpp images

    Thanks again Cesar, it's really strange if I try to put the value 255 in one posistion and the rest at 0, the result is always the same. It paints the selection with the same gray color. I attach an image of the result.
    Attached Images Attached Images
    Last edited by SkripT; 14th February 2006 at 15:05.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.