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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
« gm/lena_bytes.h ('K') | « gm/lena_bytes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 '''
2 convert an image to an rgba array
3
4 Launch with --help to see more information.
5
6 Copyright 2013 Google Inc.
7
8 Use of this source code is governed by a BSD-style license that can be
9 found in the LICENSE file.
10 '''
11
12 import Image
13 import optparse
14 import sys
15
16 def DumpImage(filename, write_path, variable_name):
17 if not write_path:
18 outfile = sys.stdout
19 else:
20 try:
21 outfile = open( write_path, 'w' )
22 except:
23 raise BaseException( "Couldn't open output path %s" % write_path )
24
25 infile = Image.open( filename )
26
27 image_size = infile.size
28
29 coordinates = [(x,y) for y in range(image_size[1]) for x in range(image_size[0 ])]
30
31 colors = map( lambda xy: infile.getpixel(xy) + (255,) , coordinates )
32 values = [str(value) for color in colors for value in color]
33
34 print >> outfile, "unsigned char %s[] = {" % variable_name
35 print >> outfile, ', '.join(values)
36 print >> outfile, "};"
37
38 if write_path:
39 outfile.close()
40
41 def Main(options, args):
42 num_args = len(args)
43 if num_args != 1:
44 raise BaseException("missing image filename")
45 DumpImage(args[0], write_path=options.write_path, variable_name=options.variab le_name)
46
47 if __name__ == '__main__':
48 parser = optparse.OptionParser(usage=r"usage: %prog [options] imagefile")
49 parser.add_option('-w', '--write-path',
50 action='store', type='string', default='',
51 help='Path to write the output scanline [default stdout]')
52 parser.add_option('-v', '--variable-name',
53 action='store', type='string', default='image_bytes',
54 help=r'Path to write the output scanline [default %default ]')
55
56 (options, args) = parser.parse_args()
57 Main(options, args)
OLDNEW
« 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