GetColorMode [SOLVED]



  • On 12/12/2014 at 11:58, xxxxxxxx wrote:

    Hello,

    testing all available colormodes, it seems that the 16Bit varaibles are broken.
    digging deeper I don´t understand why

    bmp.GetColorMode()

    gives me other values than

    e.g. c4d.COLORBYTES_ARGBf

      
          colorMode = bmp.GetColorMode()     
          print colorMode  ,"colorMode"  
          #(1 byte = 8 bits)  
          #Grayscale  
          print c4d.COLORBYTES_GRAY,    "8Bit Grayscale"  
          print c4d.COLORBYTES_AGRAY,   "8Bit Grayscale + ALPHA"  
          #print c4d.COLORBYTES_GRAYw,   "16Bit Grayscale"  
          #print c4d.COLORBYTES_AGRAYw,  "16Bit Grayscale + ALPHA"  
          print c4d.COLORBYTES_GRAYf,   "32Bit Grayscale"  
          print c4d.COLORBYTES_AGRAYf,  "32Bit Grayscale + ALPHA"  
          #RGB  
          print c4d.COLORBYTES_RGB,     "8Bit RGB"                    #/////inc 3 /////depth 24/////  
          print c4d.COLORBYTES_ARGB,    "8Bit RGB + ALPHA"            #/////inc 4 /////depth 32/////  
          #print c4d.COLORBYTES_RGBw,    "16Bit RGB"                  #/////inc 6 /////depth 48/////  
          #print c4d.COLORBYTES_ARGBw,   "16Bit RGB + ALPHA"          #/////inc 8 /////depth 64/////  
          print c4d.COLORBYTES_RGBf,    "32Bit RGB"                   #/////inc 12/////depth 96/////  
          print c4d.COLORBYTES_ARGBf,   "32Bit RGB + ALPHA"           #/////inc 16/////depth 128/////  
          #CMYK  
          print c4d.COLORBYTES_CMYK,    "8Bit CMYK"  
          print c4d.COLORBYTES_ACMYK,   "8Bit CMYK + ALPHA"  
          print c4d.COLORBYTES_MAX,     "max"  
            
      
          # colorMode values  
          #5    =ARGB  8bit/////inc 4 /////depth 32/////c4d.COLORBYTES_ARGB  
          #21   =ARGB 16bit/////inc 8 /////depth 48/////c4d.COLORBYTES_ARGBw  
          #37   =ARGB 32bit/////inc 16/////depth 96/////c4d.COLORBYTES_ARGBf  
    

    any ideas ??

    Thanks in advance
    Martin



  • On 14/12/2014 at 13:26, xxxxxxxx wrote:

    ok,

    GetColorMode() gives you an id which is not identical to the byte increment per pixel.
    You will get the byte increment if you check e.g. c4d.COLORBYTES_GRAY.
    The byte increment could be the same for different colormodes, thats why the ids from get colormode are unique.

    Just in case someone needs it, here is a dict which gives you the right byte increment for the corresponding color mode to build a proper bitmap buffer.(for GetPixelCount(),SetPixelCount()e.g.)

      
              size = bmp.GetSize()  
              colorMode = bmp.GetColorMode()  
              print colorMode ,"colorMode"  
              colordict = {2:1,3:2,4:3,5:4,6:4,7:4,18:2,19:4,20:6,21:8,34:4,35:8,36:12,37:16}  
              inc = colordict[colorMode]  
              # prepare storage  
              sq = storage.ByteSeq(None, size*inc)  
      
    

    to show what´s is going on an if, elif ,else statement:

      
              #GRAY  
              if colorMode == 2:#gray/8bit  
                  inc = 1  
              elif colorMode == 3:#gray/8bit/Alpha  
                  inc = 2  
              elif colorMode == 18:#gray/16bit  
                  inc = 2  
              elif colorMode == 19:#gray/16bit  
                  inc = 4  
              elif colorMode == 34:#gray/32bit  
                  inc = 4  
              elif colorMode == 35:#gray/32bit/Alpha  
                  inc = 8  
      
              #CMYK  
              elif colorMode == 6:#cmyk/8bit  
                  inc = 4  
              elif colorMode == 7:#cmyk/8bit/Alpha  
                  inc = 5  
      
              #RGB  
              elif colorMode == 4:#rgb/8bit  
                  inc = 3  
              elif colorMode == 5:#rgb/8bit/Alpha  
                  inc = 4  
              elif colorMode == 20:#rgb/16bit  
                  inc = 6  
              elif colorMode == 21:#rgb/16bit/Alpha  
                  inc = 8  
              elif colorMode == 36:#rgb/32bit  
                  inc = 12      
              elif colorMode == 37:#rgb/32bit/Alpha  
                  inc = 16  
              else:  
                  inc = 16  
      
    

    Could someone from the support team check the 16bit variables, please?
    Best wishes
    Martin



  • On 14/12/2014 at 20:12, xxxxxxxx wrote:

    Hi Martin,

    What you state in your second reply is correct, but I'd like to provide some clarifications:

    Although in Python GetColorMode() returns an int, it's really coming from an enum type in C++ inside Cinema 4D.  Therefore, what it returns does not have any relation to any other return value in terms of mathematical formulas, increments, etc.  The only relation any return value has to another is to be not equal if it's meant to represent a different color mode, or equal if it's for the same color mode.

    ie It's abstracted to FIRST_MODE = 1, SECOND_MODE = 2, ... SOME_OTHER_MODE = 20, A_FUTURE_MODE_MIGHT_BE = 25 etc.

    To calculate the amount of bytes required for a particular mode to create a properly sized bitmap buffer, you have to calculate that yourself according to the mode.  You multiply the bit depth by the amount of channels, and then add the same bit depth if there's an alpha channel.  The available bit depths are 8 bit (1 byte), 16 bit (2 bytes), and 32 bit (4 bytes).

    So since you asked about the 16 bit values, here are the possibilities:

    grayscale (1 channel) 16 bit = 2 bytes
    grayscale 16 bit with alpha channel = 4 bytes
    RGB (3 channels) 16 bit = 6 bytes
    RGB 16 bit with alpha channel = 8 bytes

    I hope that answers your questions.

    Joey Gaspe
    SDK Support Engineer



  • On 14/12/2014 at 20:52, xxxxxxxx wrote:

    For another reference you could look at the paintchannels.h file that is part of the C++ painting example plugin

    cinema4dsdk/source/painting/advanced/paintchannels.h

    There is a method there called GetChannelInfo that will return the bitdepth and number of channels for a given color mode.

      
    Bool GetChannelInfo(PaintLayerBmp *paintBmp, int &bitdepth;, int &numChannels;)   
    {   
    ...   
    COLORMODE colorMode = (COLORMODE)paintBmp->GetColorMode();   
    switch(colorMode)   
    {   
    case COLORMODE_ALPHA:     // only alpha channel   
    bitdepth = 8;   
    numChannels = 1;   
    supported = true;   
    break;   
    case COLORMODE_GRAY:   
    bitdepth = 8;   
    numChannels = 1;   
    supported = true;   
    break;   
    case COLORMODE_AGRAY:   
    bitdepth = 8;   
    numChannels = 2;   
    supported = true;   
    break;   
    case COLORMODE_RGB:   
    bitdepth = 8;   
    numChannels = 3;   
    supported = true;   
    break;   
    case COLORMODE_ARGB:   
    bitdepth = 8;   
    numChannels = 4;   
    supported = true;   
    break;   
    ...   
    }   
    

    And below that is another method that is used to actually set the pixels. This method is also used to increment the index into a line, by looking at this you will see that it increments by the number of bytes for each colormode. So you can use this as a source for this information as well.

      
    inline void SetPixel(COLORMODE colorMode, UInt &idx;, UChar *pBuffer, Float32 falloff, UChar *colBuffer, const BaseBitmap *pBitmap = nullptr, int sourceX = 0, int sourceY = 0)   
    {   
    ...   
    switch(colorMode)   
    {   
    case COLORMODE_ALPHA:     // only alpha channel   
    idx += 1;   
    break;   
    case COLORMODE_GRAY:   
    idx += 1;   
    break;   
    case COLORMODE_AGRAY:   
    idx += 2;   
    break;   
    case COLORMODE_RGB:   
    idx += 3;   
    break;   
    case COLORMODE_ARGB:   
    idx += 4;   
    break;   
    ...   
    }   
    


  • On 15/12/2014 at 01:09, xxxxxxxx wrote:

    Hello Joey, Hello Ken,

    thank you very much for clarification on this subject! Very clear now

    @Joey
    as you might have noticed in the if statement I posted, I already found out what are the proper bytes for 16 bit bitmaps, but if I write:
    c4d.COLORBYTES_RGBw
    to the consule window it is unknown(not tinted), that´s why I assume it is broken.
    Could you please give it a try?

    Best wishes
    Martin



  • On 15/12/2014 at 13:56, xxxxxxxx wrote:

    Hi Martin,

    I tried out the code, and I now know what you mean by it being broken: not only does it display an error message, but it doesn't even highlight (tint) to orange for the 16 bit bitmap entries.  I tried pinpointing its origin, but I discovered the Python integration is pretty complex, so I'll tell the dev team that you probably found a bug.

    In the mean time, you'll have to rely on calculating the totals yourself.

    As a side note, I saw how none of these entries are listed in the Python documentation.  Do you happen to remember how you found out at least some of these COLORBYTES_*  attributes were accessible through c4d?

    Thanks,

    Joey Gaspe
    SDK Support Engineer



  • On 15/12/2014 at 15:00, xxxxxxxx wrote:

    Hi Joey,

    thanks for checking this! hope we can use it soon!
    I searched for this:
    PaintLayerBmp.GetPixelCnt( x , y , cnt , buffer , dstmode , flags )
    and later on for this:
    ColorProfile.CheckColorMode( colormode )
    than I checked the Copy32BitImage.py file from the example folder and did some tests and calculations on every possible colormode.

    I hope this answers your question?
    Best wishes
    Martin



  • On 15/12/2014 at 15:16, xxxxxxxx wrote:

    Hi Martin,

    Unfortunately, no, that does not answer my question, as that's the color 'mode' set of values, not the color 'bytes' set of values:

    COLORBYTES_* (not described anywhere in the Python docs, only in the C++ docs)
    vs.
    COLORMODE_*  (described in both the Python and C++ docs)

    Anyway, it's OK if you don't remember exactly where, you might have found them in the C++ docs and tried them out by typing them in, like the color mode series (ie c4d.<attribute>).

    Thanks,

    Joey Gaspe
    SDK Support Engineer



  • On 15/12/2014 at 15:41, xxxxxxxx wrote:

    Hi Joey,

    I see, COLORBYTES. yes nothing about it in the python docs.
    Unfortunately I didn´t check the c++ docs. It was a testserie with an userarea where I checked if the Bitmap was showed correctly. A roundabout way :{

    Best wishes
    Martin


Log in to reply