PyQt で画像のビューアを作る 8 version 1
:追加された部分
:削除された部分
(差分が大きい場合、文字単位では表示しません)
トーンカーブ
```
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QPointF ,QRectF ,Qt
from PyQt5.QtGui import QPainterPath ,QPainter ,QPen
from scipy import interpolate
class App(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('hogetta')
self.setGeometry( 500, 50 , 500 , 500 )
# self.setMouseTracking (True) # <----------------*****
# self.list=[[0,255] , [125, 125 ] , [255,0] ] # curve points 0,2:fix 1:variable
self.x=[0,125,255] # to use scipy function
self.y=[255,125,0]
self.f_list=[] # look up table ( curve )
for l in range(256):
self.f_list.append(QPointF( l , l)) # make initial table --> line
self.a = QPointF(4,4) # Tolerance in detecting point
self.pselected = -1 # selectedpoint
self.pmove = 0 # move flag
self.show()
def mouseMoveEvent(self ,e):
if self.pmove : # Dorag ing
# self.list[1] = e.pos() # 1 only now
self.x[1] = e.pos().x()
self.y[1] = e.pos().y()
self.makedata()
self.update()
def mousePressEvent(self ,e):
self.pmove = True
def mouseReleaseEvent(self ,e):
self.pmove = False
def makedata(): # make function , make table
func = interpolate.interp1d(x, y, kind="cubic") # <------------
for l in range(256):
self.f_list[l] = QPointF( l , func(l) )
def paintEvent (self,e):
painter= QPainter()
painter.begin(self)
for l in range( 256 )
painter.drawPoint( self.f_list[l] )
painter.end()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
```
import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QPointF ,QRectF ,Qt
from PyQt5.QtGui import QPainterPath ,QPainter ,QPen
from scipy import interpolate
class App(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('hogetta')
self.setGeometry( 500, 50 , 500 , 500 )
# self.setMouseTracking (True) # <----------------*****
# self.list=[[0,255] , [125, 125 ] , [255,0] ] # curve points 0,2:fix 1:variable
self.x=[0,125,255] # to use scipy function
self.y=[255,125,0]
self.f_list=[] # look up table ( curve )
for l in range(256):
self.f_list.append(QPointF( l , l)) # make initial table --> line
self.a = QPointF(4,4) # Tolerance in detecting point
self.pselected = -1 # selectedpoint
self.pmove = 0 # move flag
self.show()
def mouseMoveEvent(self ,e):
if self.pmove : # Dorag ing
# self.list[1] = e.pos() # 1 only now
self.x[1] = e.pos().x()
self.y[1] = e.pos().y()
self.makedata()
self.update()
def mousePressEvent(self ,e):
self.pmove = True
def mouseReleaseEvent(self ,e):
self.pmove = False
def makedata(): # make function , make table
func = interpolate.interp1d(x, y, kind="cubic") # <------------
for l in range(256):
self.f_list[l] = QPointF( l , func(l) )
def paintEvent (self,e):
painter= QPainter()
painter.begin(self)
for l in range( 256 )
painter.drawPoint( self.f_list[l] )
painter.end()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())