Jenom takovy napad - nebylo by lepsi fp = C.pythonapi.PyFile_AsFile(open("phototest.tif")) ?<div><br></div><div>PM</div><div><br><br><div class="gmail_quote">2010/11/24 Zdenko Podobný <span dir="ltr"><<a href="mailto:zdposter@gmail.com">zdposter@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Zdravim,<br><br>potrebujem v pythone robit s viacstrankovymi tiff subormi a po roznych testoch a googlovani som skoncil na tom, ze cisto python riesenie neexistuje. Najrozumnejsie sa mi javi pouzitie ctypes a kniznice leptonica. Problem je v tom, ze v niektorych pripadoch jej potrebujem posunut file object.<br>
<br>Napr. (C kod):<br>filein = "phototest.tif";<br>fp = fopen(filein, "r");<br>tiffGetCount(fp, &npages);<br>fprintf(stderr, " Tiff: %d pages\n", npages);<br>fclose(fp);<br><br>Ked to skusim spravit v pythone, tak dostanem chybu:<br>
<br>import ctypes<br>leptonica = ctypes.CDLL("liblept.so")<br>filein = "phototest.tif"<br>fp = open(filein, "r")<br>npages = leptonica.tiffGetCount(fp)<br>Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: Don't know how to convert parameter 1<br><br><br>Skusal som to aj cez PyFile_AsFile ale to tiez skonci s chybou:<br>
<br>>>> import ctypes as C<br>>>> lib = C.CDLL("liblept.so")<br>>>> class FILE(C.Structure):<br>... pass<br>... <br>>>> FILE_P = C.POINTER(FILE)<br>>>> C.pythonapi.PyFile_AsFile.argtypes = [C.py_object]<br>
>>> C.pythonapi.PyFile_AsFile.restype = FILE_P<br>>>> fp = C.pythonapi.PyFile_AsFile("phototest.tif")<br>>>> npages = lib.tiffGetCount(fp)<br>Error in tiffGetCount: stream not defined<br>
<br>Skusal som googlovat, ale sa nic funkcne sa mi nepodarilo zostavit... Vie mi s tym niekto pomoc?<br><br>Zd.<br>
<br>_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@py.cz">Python@py.cz</a><br>
<a href="http://www.py.cz/mailman/listinfo/python" target="_blank">http://www.py.cz/mailman/listinfo/python</a><br></blockquote></div><br></div>