{"id":813,"date":"2013-12-27T17:40:26","date_gmt":"2013-12-27T08:40:26","guid":{"rendered":"http:\/\/www.rainyman.net\/nest\/?p=813"},"modified":"2015-03-06T14:43:39","modified_gmt":"2015-03-06T05:43:39","slug":"python3%e3%81%a7freeimage","status":"publish","type":"post","link":"https:\/\/blog.rainyman.jp\/nest\/?p=813","title":{"rendered":"Python3\u3067FreeImage"},"content":{"rendered":"<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u306a\u3044\u95a2\u6570<\/a><\/li><\/ul><\/div>\n<p>\u3042\u3093\u307e\u308aPython\u306e\u4e16\u754c\u306e\u3053\u3068\u306f\u8a73\u3057\u304f\u306a\u3044\u3093\u3067\u3059\u304c\uff0c\u3044\u307e\u306ePython\u3063\u3066\u30ec\u30ac\u30b7\u30fc\u306a2\u7cfb\u3092\u7dad\u6301\u3057\u3064\u3064\uff0c3\u7cfb\u306b\u6ce8\u529b\u3057\u3066\u3044\u308b\uff0c\u3063\u3066\u611f\u3058\u306a\u3093\u3067\u3059\u304b\u306d\uff0e<\/p>\n\n<p>\u81ea\u5206\u306e\u4f5c\u3063\u3066\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4e00\u90e8\u306e\u6319\u52d5\u3092\uff0cPython\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u5316\u3057\u305f\u304b\u3063\u305f\u3093\u3067\u3059\u304c\uff0c\u307e\u3041\u3069\u3046\u305b\u306a\u3089\u672a\u6765\u306e\u3042\u308bPython3\u3092\u4f7f\u3063\u3066\u307f\u3088\u3046\u304b\u3068\uff0e<\/p>\n\n<p>\u3067\uff0c\u305d\u306e\u306a\u304b\u3067<a href=\"http:\/\/freeimage.sourceforge.net\/\">FreeImage<\/a>\u3092Python\u304b\u3089\u305f\u305f\u304f\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\uff0cPython3\u3067\u52d5\u304b\u305d\u3046\u3068\u601d\u3063\u305f\u3089\u82e5\u5e72\u5927\u5909\u3067\u3057\u305f\uff0e<\/p>\n\n<p>FreeImage\u306e\u30b5\u30a4\u30c8\u306e\u8aac\u660e\u306b\u306f\uff0c<\/p>\n\n<blockquote>\n  <p>Thanks to it&#8217;s ANSI C interface, FreeImage is usable in many languages\n  including C, C++, VB, C#, Delphi, Java and also in common scripting \n  languages such as Perl, Python, PHP, TCL or Ruby.<\/p>\n<\/blockquote>\n\n<p>\u3063\u3066\u66f8\u3044\u3066\u3042\u308b\u3093\u3067\u3059\u304c\uff0c\u3053\u308c\u8981\u3059\u308b\u306b\u300c<strong>C\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u6301\u3063\u3066\u308b\u304b\u3089\uff5e\u306e\u8a00\u8a9e\u304b\u3089\u4f7f\u7528\u53ef\u80fd\u3060\u3088\uff01<\/strong>\u300d\u3063\u3066\u3060\u3051\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30e1\u30f3\u30c6\u30ca\u304c\u5168\u3066\u306e\u8a00\u8a9e\u3078\u306e\u30d0\u30a4\u30f3\u30c9\u3092\u63d0\u4f9b\u3057\u3066\u3044\u308b\u308f\u3051\u3058\u3083\u306a\u3044\u3093\u3067\u3059\u306d\uff0e\u306a\u3093\u304b\u8a50\u6b3a\u304f\u3055\u3044\u66f8\u304d\u65b9\u3060\u306a\u3041\uff0e<\/p>\n\n<p>FreeImage\u306e\u30bd\u30fc\u30b9\u306b\u542b\u307e\u308c\u3066\u3044\u308b\u30d0\u30a4\u30f3\u30c9\u306fC++\u3068C#\u3060\u3051\u3067\u3059\uff0e\n\u3060\u308c\u304bPython\u7528\u306e\u30d0\u30a4\u30f3\u30c9\u3092\u66f8\u3044\u3066\u306a\u3044\u304b\u306a\u30fc\uff0c\u3068\u601d\u3063\u305f\u3089\u4e00\u5fdc\u3042\u308b\u3088\u3046\u3067\u3059 \u2192 \n<a href=\"http:\/\/freeimagepy.sourceforge.net\/\">FreeImagePy<\/a><\/p>\n\n<p>\u305f\u3060\u3057\u3053\u308c\u306fPython2\u7528\u306a\u306e\u3067\u4e00\u90e8\u66f8\u304d\u63db\u3048\u306e\u5fc5\u8981\u304c\u3042\u308a\u307e\u3057\u305f\uff0e\n\u3084\u3063\u305f\u3053\u3068\u306f\uff0c<\/p>\n\n<ul>\n<li><a href=\"http:\/\/docs.python.org\/3.3\/library\/2to3.html\">2to3<\/a>\u3067\u5909\u63db<\/li>\n<li>\u30bf\u30a4\u30d7\u30c1\u30a7\u30c3\u30af<code>type(x) == ctypes.IntType<\/code>\u3092<code>isinstance(x, int)<\/code>\u306b\u66f8\u304d\u63db\u3048<\/li>\n<li><code>PyString_FromStringAndSize<\/code>\u3092<code>PyUnicode_FromStringAndSize<\/code>\u306b\u66f8\u304d\u63db\u3048<\/li>\n<\/ul>\n\n<p>\u304f\u3089\u3044\uff0e\u4e00\u5fdc\u30d1\u30c3\u30c1\u3068\uff0c\u30d1\u30c3\u30c1\u5f53\u3066\u6e08\u307f\u306e\u3082\u306e\u3092\u7f6e\u3044\u3066\u304a\u304d\u307e\u3059\uff0e<\/p>\n\n<ul>\n<li><a href=\"http:\/\/www.rainyman.net\/nest\/wp-content\/uploads\/2013\/12\/FreeImagePy_python3.patch_.txt\">FreeImagePy_python3.patch<\/a><\/li>\n<li><a href=\"http:\/\/www.rainyman.net\/nest\/wp-content\/uploads\/2013\/12\/FreeImagePy_python3.7z\">FreeImagePy_python3.7z<\/a><\/li>\n<\/ul>\n\n<p>\u3082\u3061\u308d\u3093\uff0c\u30d1\u30b9\u306bFreeImage.dll\u304c\u5165\u3063\u3066\u306a\u3044\u3068\u52d5\u304d\u307e\u305b\u3093\uff0e<\/p>\n\n<h2><span id=\"i\">\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/span><\/h2>\n\n<p>\u8272\u6df1\u5ea632bit\uff0c\u7e26\u6a2a512\u30d4\u30af\u30bb\u30eb\u306e\u753b\u50cf\u3092\u4f5c\u3063\u3066\u767d\u304f\u5857\u308a\u3064\u3076\u3057\u3066PNG\u5f62\u5f0f\u3067\u4fdd\u5b58\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\uff0e<\/p>\n\n<div><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport ctypes as C\nimport FreeImagePy as FIP\n\nfi = FIP.freeimage()\n\nfi.Initialise(True)\n\nwidth = 512\nheight = 512\ndib = fi.Allocate(width, height, 32)\n\nfor y in range(height):\n    for x in range(width):\n        rgbq = FIP.RGBQUAD()\n        rgbq.rgbRed = 255\n        rgbq.rgbGreen = 255\n        rgbq.rgbBlue = 255\n        rgbq.rgbReserved = 255\n        fi.SetPixelColor(dib,x,y,C.pointer(rgbq))\n\nfi.FlipVertical(dib)\nfi.Save(FIP.FIF_PNG, dib, &quot;test.png&quot;)\nfi.Unload(dib)\n\nfi.DeInitialise()\n<\/pre><\/div>\n\n<p>\u3044\u307e\u3044\u3061Python\u306e\u4f5c\u6cd5\u3092\u77e5\u3089\u306a\u3044\u306e\u3067\u6238\u60d1\u3044\u307e\u3057\u305f\u304c\uff0c\u30dd\u30a4\u30f3\u30bf\u3092\u3068\u308b\u5834\u9762\u3067\u306f<a href=\"http:\/\/docs.python.org\/dev\/library\/ctypes.html\">ctypes.POINTER<\/a>\u3068\u3044\u3046\u30d5\u30a1\u30af\u30c8\u30ea\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3088\u3046\u3067\u3059\u306d\uff0e<\/p>\n\n<h2><span id=\"i-2\">\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u306a\u3044\u95a2\u6570<\/span><\/h2>\n\n<p>\u3069\u3046\u3082\u3053\u306eFreeImagePy\u3063\u3066\u30e2\u30b8\u30e5\u30fc\u30eb\uff0c\u3042\u3093\u307e\u308a\u30e1\u30f3\u30c6\u3055\u308c\u3066\u3044\u308b\u30e2\u30ce\u3067\u306f\u306a\u3044\u3089\u3057\u304f\n\u3044\u304f\u3064\u304bFreeImage\u306e\u95a2\u6570\u304c\u629c\u3051\u3066\u308b\u3053\u3068\u3082\u3042\u308b\u3088\u3046\u3067\u3059(\u307e\u3041\uff0c\u30b5\u30a4\u30c8\u306b&#8221;A lot of function bound, but not all, sorry!&#8221;\u3063\u3066\u66f8\u3044\u3066\u3042\u308b\u3057\u306d)\uff0e<\/p>\n\n<p>\u898b\u3064\u3051\u305f\u9650\u308a\u3067\u306f<code>FreeImage_FlipVertical<\/code>\u3068\u304b<code>FreeImage_FlipHorizontal<\/code>\u304c\u629c\u3051\u3066\u3044\u307e\u3057\u305f\uff0e\u4e0d\u8db3\u3057\u3066\u3044\u308b\u95a2\u6570\u3092\u88dc\u3046\u306b\u306f\uff0c\u4ee5\u4e0b\u306e\u624b\u9806\u304c\u5fc5\u8981\u3067\u3059\uff0e<\/p>\n\n<ul>\n<li><code>FreeImagePy.py<\/code>\u306b\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0<\/li>\n<li><code>function_list.py<\/code>\u306bDLL\u95a2\u6570\u540d\u3092\u8ffd\u52a0<\/li>\n<\/ul>\n\n<p>\u305f\u3068\u3048\u3070\uff0c<code>FreeImage_FlipVertical<\/code>\/<code>FreeImage_FlipHorizontal<\/code>\u306e\u5834\u5408\u306a\u3089\uff0c\n<code>FreeImagePy.py<\/code>\u306eFreeImage\u30af\u30e9\u30b9\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u3066\u2026<\/p>\n\n<div><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n    # Flip\n    def FlipHorizontal(self, dib):\n        return self.__lib.FlipHorizontal(dib)    \n    def FlipVertical(self, dib):\n        return self.__lib.FlipVertical(dib)\n<\/pre><\/div>\n\n<p><code>function_list.py<\/code>\u306e<code>FUNCTION_LIST<\/code>\u30ea\u30b9\u30c8\u306b\u4ee5\u4e0b\u3092\u8ffd\u52a0\u3057\u307e\u3059\uff0e<\/p>\n\n<div><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n    ('FreeImage_FlipHorizontal',    '@4'),\n    ('FreeImage_FlipVertical',    '@4')    \n<\/pre><\/div>\n\n<p>\u5404\u30a8\u30f3\u30c8\u30ea\u306e\u4e8c\u500b\u76ee\u306f<code>dumpbin \/exports FreeImage.dll<\/code>\u3067\u51fa\u3066\u304f\u308b\u30b7\u30f3\u30dc\u30eb\u540d\u306e\u5f8c\u308d\u306b\u4ed8\u3044\u3066\u3044\u308b\u3084\u3064\u306e\u3088\u3046\u3067\u3059\uff0e3\u3064\u3081\u4ee5\u964d\u306f\u623b\u308a\u5024\u578b\u306e\u3088\u3046\u3067\u3059\u304c\u8a73\u7d30\u306f\u3088\u304f\u308f\u304b\u308a\u307e\u305b\u3093\uff0e<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b211 \u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c92 \u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u306a\u3044\u95a2\u6570 \u3042\u3093\u307e\u308aPython\u306e\u4e16\u754c\u306e\u3053\u3068\u306f\u8a73\u3057\u304f\u306a\u3044\u3093\u3067\u3059\u304c\uff0c\u3044\u307e\u306ePython\u3063\u3066\u30ec\u30ac\u30b7\u30fc\u306a2\u7cfb\u3092\u7dad\u6301\u3057\u3064\u3064\uff0c3\u7cfb\u306b\u6ce8\u529b\u3057\u3066\u3044\u308b\uff0c\u3063\u3066\u611f\u3058\u306a\u3093\u3067\u3059\u304b\u306d\uff0e \u81ea\u5206\u306e\u4f5c\u3063\u3066\u308b\u30d7\u30ed\u30b0 [&hellip;]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=\/wp\/v2\/posts\/813"}],"collection":[{"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=813"}],"version-history":[{"count":17,"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions"}],"predecessor-version":[{"id":1180,"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=\/wp\/v2\/posts\/813\/revisions\/1180"}],"wp:attachment":[{"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rainyman.jp\/nest\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}