Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    bitmap.GetPixel / SetPixel

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 846 Views
    Loading More Posts
    • 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.
    • H Offline
      Helper
      last edited by

      On 10/08/2017 at 09:41, xxxxxxxx wrote:

      I'm confused from the documentation:

      How do you get/set the pixel value of a GRAYSCALE image (i.e. one created with a color mode of c4d.COLORBYTES_GRAYf).

      bitmap.GetPixel(x,y) returns a tuple of R, G, B, not a float
      bitmap.SetPixel(x,y,r,g,b) doesn't allow for providing a float

      Are there float versions of Get/SetPixel?

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 10/08/2017 at 10:22, xxxxxxxx wrote:

        A grayscale is basicly a vector with the 3 same component.

        You can decompose a color where each component can be understand as a value from 0 to 255 (where 0 red is no red and 255 red is full red for exemple) so if you want to convert them in color space of c4d (c4d oftenly use vector from 0 for no color and 1 for the full color) so with those functions you can have everything you need

        import c4d
          
        def rgb_to_vector(data) :
            rgbv = c4d.Vector(data[0], data[1], data[2])
            return rgbv ^ c4d.Vector(1.0 / 255.0)
          
        def vector_to_rgb(vector) :
            return vector ^ c4d.Vector(255.0)
          
        def main() :
            vector = rgb_to_vector(bmp.GetPixel(0,0))
            print vector
            rgb = vector_to_rgb(vector)
            print rgb
          
        if __name__=='__main__':
            main()
        

        Hope it make more sense

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 10/08/2017 at 12:27, xxxxxxxx wrote:

          So, I guess what you're basically saying is that r, g, b for Set and GetPixel will accept/return floats :).
          Problem is: The documentation clearly states that the three color components are INT with values from 0-255 (so basically a BYTE type). Assuming all of these are the same for gray values, you would basically end up with a maximum number of 256 gray values. This is obviously NOT correct...

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 10/08/2017 at 12:48, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            So, I guess what you're basically saying is that r, g, b for Set and GetPixel will accept/return floats :).

            I never told that but I agree I should be more clear.

            I provided you functions to convert vector returned from 99% of color returned by c4d. Wich are normalized vector. But GetPixel/SetPixel didn't fit this rules. They return raw RGB data wich are as you said 3 INT with a range from 0 to 255 and where thoses 3 INT correspond in the respectif order to the Red channel, green one and blue one.

            This method (to use 0/255 range for each channel) is oftently used for describe color. And yes you only get 256gray value and that end's up with a 8bit picture. If you want to deal with more than 8bit picture I suggest you to read https://github.com/PluginCafe/cinema4d_py_sdk/blob/master/scripts/Copy32BitImage.py wich basicly use SetPixelCnt for setting pixel.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 10/08/2017 at 12:58, xxxxxxxx wrote:

              Ah, thx! Good pointer with the SetPixelCnt. I'll give it a shot.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                On 11/08/2017 at 08:08, xxxxxxxx wrote:

                Hi,

                the C++ docs have a manual about BaseBitmap, maybe the code snippet on Pixel Data might help future readers of this thread.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post