Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1165)

Unified Diff: tools/image_to_byte_array.py

Issue 15755019: more general GM setup for testing image filtering -- now with checkerboards, images, and text. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« gm/lena_bytes.h ('K') | « gm/lena_bytes.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/image_to_byte_array.py
diff --git a/tools/image_to_byte_array.py b/tools/image_to_byte_array.py
new file mode 100644
index 0000000000000000000000000000000000000000..71b5119231ad0b29f0666521e8c8530980218f3e
--- /dev/null
+++ b/tools/image_to_byte_array.py
@@ -0,0 +1,57 @@
+'''
+convert an image to an rgba array
+
+Launch with --help to see more information.
+
+Copyright 2013 Google Inc.
+
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+'''
+
+import Image
+import optparse
+import sys
+
+def DumpImage(filename, write_path, variable_name):
+ if not write_path:
+ outfile = sys.stdout
+ else:
+ try:
+ outfile = open( write_path, 'w' )
+ except:
+ raise BaseException( "Couldn't open output path %s" % write_path )
+
+ infile = Image.open( filename )
+
+ image_size = infile.size
+
+ coordinates = [(x,y) for y in range(image_size[1]) for x in range(image_size[0])]
+
+ colors = map( lambda xy: infile.getpixel(xy) + (255,) , coordinates )
+ values = [str(value) for color in colors for value in color]
+
+ print >> outfile, "unsigned char %s[] = {" % variable_name
+ print >> outfile, ', '.join(values)
+ print >> outfile, "};"
+
+ if write_path:
+ outfile.close()
+
+def Main(options, args):
+ num_args = len(args)
+ if num_args != 1:
+ raise BaseException("missing image filename")
+ DumpImage(args[0], write_path=options.write_path, variable_name=options.variable_name)
+
+if __name__ == '__main__':
+ parser = optparse.OptionParser(usage=r"usage: %prog [options] imagefile")
+ parser.add_option('-w', '--write-path',
+ action='store', type='string', default='',
+ help='Path to write the output scanline [default stdout]')
+ parser.add_option('-v', '--variable-name',
+ action='store', type='string', default='image_bytes',
+ help=r'Path to write the output scanline [default %default]')
+
+ (options, args) = parser.parse_args()
+ Main(options, args)
« gm/lena_bytes.h ('K') | « gm/lena_bytes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698