<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 4, 2017 at 10:30 AM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">On Fri, Aug 4, 2017 at 7:45 AM, Aron Helser <span dir="ltr"><<a href="mailto:aron.helser@kitware.com" target="_blank">aron.helser@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi David, all,<div><br><div>I'm trying to re-write a C++ VTK method used in VTK web, <span style="font-size:12.8px">to get rid of a base-64 string encoding of an image - so the C++ method I'm working on returns a buffer in a vtkUnsignedCharArray* to python. As a result, the python wrapping seems to return a 'str' type in both Python 2 and 3.</span></div></div></div></blockquote><div><br></div></span><div>The 'str' part doesn't make sense to me.  What method are you calling to get an 'str' from a vtkUnsignedCharArray?  </div><span class="gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><span style="font-size:12.8px">The new result I want to return is a binary buffer (a raw JPG) - I tried returning the new result with the same type, and it gets cut off at the first null in the buffer. Is there a vtk return type should I be using instead?</span></div></div></div></blockquote><div><br></div></span><div>You'll have to show me the python code that you're using.  There is nothing in the wrappers themselves that would treat the contents of a vtkUnsignedCharArray is if they were a c-style string.  Are you using a python "bytes" object as an intermediate?</div></div></div></div></blockquote><div><br></div><div>Sure thing. And as I trace the code more carefully, I found at least part of the issue. </div><div><br></div><div>I miss-spoke - the method in question is in ParaView, an override of a method in VTK:</div><div><br></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div>ParaView/Web/Core/vtkPVWebApplication.cxx:</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>vtkUnsignedCharArray* vtkPVWebApplication::StillRender(vtkSMViewProxy* view, int quality)</div></div><div><br></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div>However, that method is wrapped in const char* vtkPVWebApplication::StillRenderToString(), which does this:</div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>return reinterpret_cast<char*>(array->GetPointer(0));<br></div><div><br></div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div>So that's where the 'char *' to python 'str' conversion happens.</div><div><br></div><div>If I avoid that wrapper and return vtkUnsignedCharArray* directly, can I get a python 'bytes' object out of it in the Python code without copying?</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div> - David</div></font></span></div></div></div>
</blockquote></div><br></div></div>