wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.29k stars 516 forks source link

Tiff Image Handler Orientation Fails #487

Open latkinso42 opened 7 years ago

latkinso42 commented 7 years ago

Operating system: MS Windows 10 wxPython version:4.0.0b1 Stock or custom build:Stock Python version:3.6.2 Stock or custom build:Stock

Description of the problem:Reading a a tiff image and displaying results in a vertically flipped image. Suspected culprit is https://github.com/wxWidgets/wxWidgets/blob/master/src/common/imagtiff.cpp, which does not appear to look at orientation set in metadata, ie expects ORIENTATION_TOPLEFT! LInes 417-421 / Decode to ABGR format as that is what the code, that converts to wxImage, later on expects (normally TIFFReadRGBAImageOriented is used to decode which uses an ABGR layout). /

import os,sys, getopt
import wx
import wx.lib.scrolledpanel  as scrolled
import wx.lib.sized_controls as SC
from PIL import Image

imgexts  = "IMG (*.tiff*)|*.tiff*"
MAX_CAMERA_WIDTH=4608
MAX_CAMERA_HEIGHT=3288

class DrawPane(wx.ScrolledWindow):
    VSIZE=(MAX_CAMERA_WIDTH, MAX_CAMERA_HEIGHT)
    def __init__(self, *args, **kw):
        wx.ScrolledWindow.__init__(self, *args, **kw)       

    def MyInit(self, fname):
        mmm=wx.Image(fname, wx.BITMAP_TYPE_TIFF)
        self.bitmap = wx.Bitmap(mmm)
        self.SetScrollbars(1, 1, MAX_CAMERA_WIDTH, MAX_CAMERA_HEIGHT)
        self.prepare_buffer()
        cdc = wx.ClientDC(self)
        self.PrepareDC(cdc)
        dc = wx.BufferedDC(cdc, self.buffer)
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
        self.Bind(wx.EVT_MOTION, self.on_motion)

    def prepare_buffer(self):
        self.buffer = wx.Bitmap(*DrawPane.VSIZE)
        print('buffer width  ', self.buffer.GetWidth())
        print('buffer height ', self.buffer.GetHeight())
        cdc = wx.ClientDC(self)
        self.PrepareDC(cdc)
        dc = wx.BufferedDC(cdc, self.buffer)
        dc.Clear()
        dc.DrawBitmap(self.bitmap, 0, 0, True)

    def on_paint(self, evt):
        dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)

    def on_mouse_down(self, evt):
        self.mouse_pos = self.CalcUnscrolledPosition(evt.GetPosition()).Get()

    def on_motion(self, evt):
        if evt.Dragging() and evt.LeftIsDown():
            newpos = self.CalcUnscrolledPosition(evt.GetPosition()).Get()
            coords = self.mouse_pos + newpos
            cdc = wx.ClientDC(self)
            self.PrepareDC(cdc)
            dc = wx.BufferedDC(cdc, self.buffer)
            dc.DrawLine(*coords)
            self.mouse_pos = newpos

class MyFrame(wx.Frame):
   def __init__(self, parent):
      wx.Frame.__init__(self, None, size = (640,400))
      self.s = wx.BoxSizer(wx.VERTICAL)

   def displayImg(self, fname):
      self.dp=DrawPane(self)
      self.dp.MyInit(fname)      
      self.s.Add(self.dp, 1, wx.EXPAND)
      self.SetSizer(self.s)
      self.Layout()
      self.Refresh()

if __name__ == "__main__":
    app = wx.App()
    wx.InitAllImageHandlers()
    arg1=sys.argv[1]
    fname=os.path.abspath(arg1)
    mf=MyFrame(app)
    mf.Show()
    mf.displayImg(fname)
    app.MainLoop()

Since you do not support uploading large tiff files, you will need a tiff file whose orientation is other than normal. Please consider this link: https://drive.google.com/open?id=0Bw3xhg5ZEoi-czZMWjQ1OElkTlk RULERTIFF.tiff has an orientation of 4 while RULERTIFF2.tiff has an orientation of 1

mesalu commented 7 years ago

Please open a ticket on wxWidget's issue tracker. https://trac.wxwidgets.org/

latkinso42 commented 7 years ago

Mesalu,

Site indicates it has sent an email to latkinso42@gmail.com, but I have not received it. I directed a resend but still no email from wxWidgets to verify email. I have looked in my ADS and SPAM folders too!

Cheers, Lee

On Tue, Aug 29, 2017 at 7:30 PM, Mesalu notifications@github.com wrote:

Please open a ticket on wxWidget's issue tracker. https://trac.wxwidgets.org/

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/wxWidgets/Phoenix/issues/487#issuecomment-325833765, or mute the thread https://github.com/notifications/unsubscribe-auth/AGtVPhbOO3xDjrM6eVa4ZLCcF6uNxS_Bks5sdJ8vgaJpZM4PGg0z .

mesalu commented 6 years ago

Hey @latkinso42,

Sorry, looks like I let this one slip through the cracks. Were you able to get registered on trac.wxwidgets.org, or has it not progressed further? Is the defect still present?

Cheers, Mesalu