From 454f137f2d0a970f8f80de71aab1ed67dc675aab Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Sun, 22 Jun 2014 14:00:50 +0800
Subject: [PATCH] query image format only when necessary.

---
 src/c_wrapper/image.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/c_wrapper/image.h b/src/c_wrapper/image.h
index 3fa5c171..85a95d33 100644
--- a/src/c_wrapper/image.h
+++ b/src/c_wrapper/image.h
@@ -15,20 +15,22 @@ public:
     PYOPENCL_DEF_CL_CLASS(IMAGE);
     PYOPENCL_INLINE
     image(cl_mem mem, bool retain, const cl_image_format *fmt=0)
-        : memory_object(mem, retain)
+        : memory_object(mem, retain), m_format(fmt ? *fmt : cl_image_format())
+    {}
+    PYOPENCL_INLINE const cl_image_format&
+    format()
     {
-        if (fmt) {
-            m_format = *fmt;
-        } else {
+        if (!m_format.image_channel_data_type) {
             pyopencl_call_guarded(clGetImageInfo, this, CL_IMAGE_FORMAT,
                                   size_arg(m_format), nullptr);
         }
+        return m_format;
     }
     PYOPENCL_USE_RESULT generic_info get_image_info(cl_image_info param) const;
     PYOPENCL_INLINE type_t
     get_fill_type()
     {
-        switch (m_format.image_channel_data_type) {
+        switch (format().image_channel_data_type) {
         case CL_SIGNED_INT8:
         case CL_SIGNED_INT16:
         case CL_SIGNED_INT32:
-- 
GitLab