Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1ebe1b

Browse files
committed
added bgra for qt backend
svn path=/trunk/matplotlib/; revision=901
1 parent d906efd commit a1ebe1b

9 files changed

Lines changed: 120 additions & 27 deletions

File tree

.matplotlibrc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# - an rgb tuple, such as (1.0, 0.5, 0.0)
2626
# - a hex string, such as ff00ff (no '#' symbol)
2727
# - a scalar grayscale intensity such as 0.75
28+
# - a legal html color name, eg red, blue, darkslategray
2829

2930
#### CONFIGURATION BEGINS HERE
3031
backend : GTKAgg # the default backend
@@ -45,10 +46,10 @@ timezone : UTC # a pytz timezone string, eg US/Central or Europe/Pari
4546
# use the Agg backend (or TkAgg, GTKAgg, WxAgg)
4647
lines.linewidth : 0.5 # line width in points
4748
lines.linestyle : - # solid line
48-
lines.color : b # blue
49+
lines.color : blue
4950
lines.marker : None # the default marker
50-
lines.markerfacecolor : b # blue
51-
lines.markeredgecolor : k # black
51+
lines.markerfacecolor : blue
52+
lines.markeredgecolor : black
5253
lines.markeredgewidth : 0.5 # the line width around the marker symbol
5354
lines.markersize : 6 # markersize, in points
5455
lines.antialiased : True # render lines in antialised (no jaggies)
@@ -62,8 +63,8 @@ lines.data_clipping : False # Use data clipping in addition to viewport
6263
# http://matplotlib.sourceforge.net/matplotlib.patches.html for more
6364
# information on patch properties
6465
patch.linewidth : 1.0 # edge width in points
65-
patch.facecolor : b
66-
patch.edgecolor : k
66+
patch.facecolor : blue
67+
patch.edgecolor : black
6768
patch.antialiased : True # render patches in antialised (no jaggies)
6869

6970
### FONT
@@ -120,19 +121,19 @@ font.monospace : Andale Mono, Bitstream Vera Sans Mono, Nimbus Mono L, Cour
120121
# text properties used by text.Text. See
121122
# http://matplotlib.sourceforge.net/matplotlib.Text.html for more
122123
# information on text properties
123-
text.color : k # black
124+
text.color : black
124125

125126
### AXES
126127
# default face and edge color, default tick sizes,
127128
# default fontsizes for ticklabels, and so on
128129
axes.hold : True # whether to clear the axes by default on
129-
axes.facecolor : w # background color; white
130-
axes.edgecolor : k # edge color; black
130+
axes.facecolor : white # axes background color
131+
axes.edgecolor : black # axes edge color
131132
axes.linewidth : 1.0 # edge linewidth
132133
axes.grid : False # display grid or not
133134
axes.titlesize : 14 # fontsize of the axes title
134135
axes.labelsize : 12 # fontsize of the x any y labels
135-
axes.labelcolor : k # black
136+
axes.labelcolor : black
136137

137138
polaraxes.grid : True # display grid on polar axes
138139

@@ -141,19 +142,19 @@ tick.major.size : 4 # major tick size in points
141142
tick.minor.size : 2 # minor tick size in points
142143
tick.major.pad : 4 # distance to major tick label in points
143144
tick.minor.pad : 4 # distance to the minor tick label in points
144-
tick.color : k # color of the tick labels
145+
tick.color : black # color of the tick labels
145146
tick.labelsize : 10 # fontsize of the tick labels
146147

147148
### Grids
148-
grid.color : k # grid color
149+
grid.color : black # grid color
149150
grid.linestyle : : # dotted
150151
grid.linewidth : 0.5 # in points
151152

152153
### FIGURE
153154
figure.figsize : 8, 6 # figure size in inches
154155
figure.dpi : 80 # figure dots per inch
155156
figure.facecolor : 0.75 # figure facecolor; 0.75 is scalar gray
156-
figure.edgecolor : w # figure edgecolor; w is white
157+
figure.edgecolor : white # figure edgecolor
157158

158159
### images
159160
image.aspect : free # free | preserve
@@ -167,11 +168,11 @@ image.origin : upper # lower | upper
167168
# Eg, you may want a higher resolution, or to make the figure
168169
# background white
169170
savefig.dpi : 100 # figure dots per inch
170-
savefig.facecolor : w # figure facecolor; 0.75 is scalar gray
171-
savefig.edgecolor : w # figure edgecolor; w is white
171+
savefig.facecolor : white # figure facecolor when saving
172+
savefig.edgecolor : white # figure edgecolor when saving
172173

173174
tk.window_focus : False # Maintain shell focus for TkAgg
174-
175+
tk.pythoninspect : False # tk sets PYTHONINSEPCT
175176

176177
# Set the verbose flags. This controls how much information
177178
# matplotlib gives you at runtime and where it goes. Ther verbosity

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ New entries should be added at the top
22

33
2005-01-30 Added backend_qtagg.py provided by Sigve Tjora - SC
44

5+
2005-01-28 Added tk.inspect rc param to .matplotlibrc. IDLE users
6+
should set tk.pythoninspect:True and interactive:True and
7+
backend:TkAgg
8+
59
2005-01-28 Replaced examples/interactive.py with an updated script from
610
Fernando Perez - SC
711

TODO

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,6 @@ ZeroDivisionError: SeparableTransformation::eval_scalars yin interval is zero; c
640640
show()
641641

642642

643-
-- fix contour mappable to work under changes in clim, cmap
643+
-- fix contour mappable to work under changes in clim, cmap
644+
645+
-- port colorbar, current mappable to API

lib/matplotlib/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,16 @@ def validate_color(s):
394394
try: return float(s)
395395
except ValueError:
396396
raise ValueError('Could not convert "%s" to float' % s)
397-
398-
if len(s)==6 and s.isalnum: # looks like hex
397+
398+
399+
if len(s)==6 and s.isalnum(): # looks like hex
399400
return '#' + s
400401

401-
raise ValueError('"s" does not look like color arg')
402+
if s.isalpha():
403+
#assuming a color name, hold on
404+
return s
405+
406+
raise ValueError('"s" does not look like color arg')
402407

403408
def validate_comma_sep_str(s):
404409
'return a list'
@@ -558,6 +563,7 @@ def validate_verbose_erro(s):
558563
'savefig.orientation' : [ 'portait', validate_orientation], # edgecolor; white
559564

560565
'tk.window_focus' : [ False, validate_bool], # Maintain shell focus for TkAgg
566+
'tk.pythoninspect' : [ False, validate_bool], # Set PYTHONINSPECT
561567
'plugins.directory' : ['.matplotlib_plugins', str], # where plugin directory is locate
562568

563569
}

lib/matplotlib/backends/backend_agg.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ def points_to_pixels(self, points):
257257
def tostring_rgb(self):
258258
if __debug__: verbose.report('RendererAgg.tostring_rgb', 'debug-annoying')
259259
return self._renderer.tostring_rgb()
260+
261+
def tostring_argb(self):
262+
if __debug__: verbose.report('RendererAgg.tostring_argb', 'debug-annoying')
263+
return self._renderer.tostring_argb()
260264

261265
def buffer_rgba(self):
262266
if __debug__: verbose.report('RendererAgg.buffer_rgba', 'debug-annoying')
@@ -310,6 +314,10 @@ def draw(self):
310314
def tostring_rgb(self):
311315
if __debug__: verbose.report('FigureCanvasAgg.tostring_rgb', 'debug-annoying')
312316
return self.renderer.tostring_rgb()
317+
318+
def tostring_argb(self):
319+
if __debug__: verbose.report('FigureCanvasAgg.tostring_argb', 'debug-annoying')
320+
return self.renderer.tostring_argb()
313321

314322
def buffer_rgba(self):
315323
if __debug__: verbose.report('FigureCanvasAgg.buffer_rgba', 'debug-annoying')

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,16 @@ def draw(self):
142142
"""
143143
FigureCanvasAgg.draw(self)
144144
self.stringBuffer = str(self.buffer_rgba())
145+
#self.stringBuffer = self.tostring_argb()
146+
self.stringBuffer = self.renderer._renderer.tostring_bgra()
145147
self.qimage = qt.QImage(self.stringBuffer,
146-
self.renderer.width,
147-
self.renderer.height,
148-
32,
149-
None,
150-
0,
151-
qt.QImage.IgnoreEndian)
148+
self.renderer.width,
149+
self.renderer.height,
150+
32,
151+
None,
152+
0,
153+
qt.QImage.IgnoreEndian,
154+
)
152155
self.update()
153156

154157
def paintEvent(self, ev):

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def show():
6868
manager.show()
6969
import matplotlib
7070
matplotlib.interactive(True)
71-
os.environ['PYTHONINSPECT'] = '1'
71+
if rcParams['tk.pythoninspect']:
72+
os.environ['PYTHONINSPECT'] = '1'
7273
if show._needmain:
7374
Tk.mainloop()
7475
show._needmain = False

src/_backend_agg.cpp

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,67 @@ RendererAgg::tostring_rgb(const Py::Tuple& args) {
11261126
return Py::asObject(o);
11271127
}
11281128

1129+
1130+
Py::Object
1131+
RendererAgg::tostring_argb(const Py::Tuple& args) {
1132+
//"Return the rendered buffer as an RGB string";
1133+
1134+
_VERBOSE("RendererAgg::tostring_argb");
1135+
1136+
args.verify_length(0);
1137+
int row_len = width*4;
1138+
unsigned char* buf_tmp = new unsigned char[row_len * height];
1139+
if (buf_tmp ==NULL) {
1140+
//todo: also handle allocation throw
1141+
throw Py::MemoryError("RendererAgg::tostring_argb could not allocate memory");
1142+
}
1143+
agg::rendering_buffer renderingBufferTmp;
1144+
renderingBufferTmp.attach(buf_tmp,
1145+
width,
1146+
height,
1147+
row_len);
1148+
1149+
color_conv(&renderingBufferTmp, renderingBuffer, agg::color_conv_rgba32_to_argb32());
1150+
1151+
1152+
//todo: how to do this with native CXX
1153+
PyObject* o = Py_BuildValue("s#",
1154+
buf_tmp,
1155+
row_len * height);
1156+
delete [] buf_tmp;
1157+
return Py::asObject(o);
1158+
}
1159+
1160+
Py::Object
1161+
RendererAgg::tostring_bgra(const Py::Tuple& args) {
1162+
//"Return the rendered buffer as an RGB string";
1163+
1164+
_VERBOSE("RendererAgg::tostring_bgra");
1165+
1166+
args.verify_length(0);
1167+
int row_len = width*4;
1168+
unsigned char* buf_tmp = new unsigned char[row_len * height];
1169+
if (buf_tmp ==NULL) {
1170+
//todo: also handle allocation throw
1171+
throw Py::MemoryError("RendererAgg::tostring_bgra could not allocate memory");
1172+
}
1173+
agg::rendering_buffer renderingBufferTmp;
1174+
renderingBufferTmp.attach(buf_tmp,
1175+
width,
1176+
height,
1177+
row_len);
1178+
1179+
color_conv(&renderingBufferTmp, renderingBuffer, agg::color_conv_rgba32_to_bgra32());
1180+
1181+
1182+
//todo: how to do this with native CXX
1183+
PyObject* o = Py_BuildValue("s#",
1184+
buf_tmp,
1185+
row_len * height);
1186+
delete [] buf_tmp;
1187+
return Py::asObject(o);
1188+
}
1189+
11291190
Py::Object
11301191
RendererAgg::buffer_rgba(const Py::Tuple& args) {
11311192
//"expose the rendered buffer as Python buffer object";
@@ -1137,6 +1198,7 @@ RendererAgg::buffer_rgba(const Py::Tuple& args) {
11371198
return Py::asObject(PyBuffer_FromMemory( pixBuffer, row_len*height));
11381199
}
11391200

1201+
11401202
agg::rgba
11411203
RendererAgg::get_color(const Py::Object& gc) {
11421204

@@ -1352,10 +1414,14 @@ void RendererAgg::init_type()
13521414
"write_png(fname)");
13531415
add_varargs_method("tostring_rgb", &RendererAgg::tostring_rgb,
13541416
"s = tostring_rgb()");
1417+
add_varargs_method("tostring_argb", &RendererAgg::tostring_argb,
1418+
"s = tostring_argb()");
1419+
add_varargs_method("tostring_bgra", &RendererAgg::tostring_bgra,
1420+
"s = tostring_bgra()");
13551421
add_varargs_method("buffer_rgba", &RendererAgg::buffer_rgba,
13561422
"buffer = buffer_rgba()");
13571423
add_varargs_method("clear", &RendererAgg::clear,
1358-
"clear()");
1424+
"clear()");
13591425

13601426
}
13611427

src/_backend_agg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class RendererAgg: public Py::PythonExtension<RendererAgg> {
6363
Py::Object write_rgba(const Py::Tuple & args);
6464
Py::Object write_png(const Py::Tuple & args);
6565
Py::Object tostring_rgb(const Py::Tuple & args);
66+
Py::Object tostring_argb(const Py::Tuple & args);
67+
Py::Object tostring_bgra(const Py::Tuple & args);
6668
Py::Object buffer_rgba(const Py::Tuple & args);
6769
Py::Object clear(const Py::Tuple & args);
6870

0 commit comments

Comments
 (0)