[go: up one dir, main page]

Menu

[72b583]: / tests / python / image.py  Maximize  Restore  History

Download this file

150 lines (125 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# (c) GPL
# This example is not complete
# 1. the alpha-image segfault.
# 2. the memoryoperations are nyi
IMAGEPATH = "../c/"
import pslib as ps
LEFT_BORDER = 50
EXAMPLE_BOX_HEIGHT = 190
EXAMPLE_BOX_WIDTH = 150
EXAMPLE_BOX_TITLE_HEIGHT = 40
def begin_example_box(p, llx, lly, title, font):
ps.PS_save(p)
ps.PS_translate(p, llx, lly)
ps.PS_setcolor(p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0)
ps.PS_rect(p, 0, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT,
EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_TITLE_HEIGHT)
ps.PS_fill(p)
ps.PS_setcolor(p, "stroke", "gray", 1.0, 0.0, 0.0, 0.0)
ps.PS_setfont(p, font, 12.0)
ps.PS_show_xy(p, title, 10, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT+5)
ps.PS_setlinewidth(p, 1.0)
ps.PS_setcolor(p, "stroke", "gray", 0.0, 0.0, 0.0, 0.0)
ps.PS_setcolor(p, "stroke", "gray", 0.0, 0.0, 0.0, 0.0)
ps.PS_rect(p, 0, 0, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT)
ps.PS_stroke(p)
ps.PS_moveto(p, 0, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT)
ps.PS_lineto(p, EXAMPLE_BOX_WIDTH, EXAMPLE_BOX_HEIGHT-EXAMPLE_BOX_TITLE_HEIGHT)
ps.PS_stroke(p)
def end_example_box(p):
ps.PS_restore(p)
p1=ps.PS_new()
ps.PS_set_info(p1, "Creator", "Python");
ps.PS_set_info(p1, "Author", "Uwe Steinmann & Stefan Schroeder");
ps.PS_set_info(p1, "Title", "Drawing Examples");
ps.PS_open_file(p1, 'image.ps')
print "Creating image.ps ... ",
ps.PS_begin_page(p1, 596, 842)
ps.PS_set_parameter(p1, "transition", "wipe")
ps.PS_set_value(p1, "duration", 0.5)
psfont = ps.PS_findfont(p1, "Helvetica", "", 0)
ps.PS_setfont(p1, psfont, 8.0);
x = 0
y = 675
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Indexed image without alpha channel", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "indexed.png", "", 0)
ps.PS_place_image(p1, psimage, 10, 30, 1.0)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "RGB image without alpha channel", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "rgb.png", "", 0)
ps.PS_place_image(p1, psimage, 10, 30, 1.0)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Indexed image with alpha channel", psfont)
x+=1
#psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "indexed-alpha.png", "", 0)
#ps.PS_place_image(p1, psimage, 10, 30, 1.0)
#ps.PS_close_image(p1, psimage)
end_example_box(p1)
x = 0
y = 405
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "RGB image with alpha channel", psfont)
x+=1
#psimage = ps.PS_open_image_file(p1, "png", IMAGEPATH + "rgb-alpha.png", "", 0)
#ps.PS_place_image(p1, psimage, 10, 30, 1.0)
#ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Jpeg gray scale image", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "jpeg", IMAGEPATH + "gnu-head.jpg", "", 0)
ps.PS_place_image(p1, psimage, 10, 10, 0.45)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
## BOX
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Exiftest", psfont)
x+=1
psimage = ps.PS_open_image_file(p1, "jpeg", IMAGEPATH + "exiftest.jpg", "", 0)
ps.PS_place_image(p1, psimage, 30, 10, 0.30)
ps.PS_close_image(p1, psimage)
end_example_box(p1)
x = 0
y = 185
begin_example_box(p1, LEFT_BORDER+(EXAMPLE_BOX_WIDTH+30)*(x), y, "Images created in memory", psfont)
x+=1
# RGB */
#psimage = ps.PS_open_image(p1, "memory", "memory", imagedata, 12, 2, 2, 3, 8, "")
#ps.PS_place_image(p1, psimage, 20, 20, 20.0)
#ps.close_image(p1, psimage)
# Gray */
#memset(imagedata, 0, 16)
#imagedata[0] = 192
#imagedata[1] = 128
#imagedata[2] = 64
#imagedata[3] = 0
##imagedata = "aaaaaaaaaaaaaaaa"
##psimage = ps.PS_open_image(p1, "memory", "memory", imagedata, 4, 2, 2, 1, 8, "")
##ps.PS_place_image(p1, psimage, 90, 20, 20.0)
# CMYK */
#memset(imagedata, 0, 16)
#imagedata[0] = 255
#imagedata[5] = 255
#imagedata[10] = 255
#imagedata[15] = 255
#imagedata = "aaaaaaaaaaaaaaaa"
#psimage = ps.PS_open_image(p1, "memory", "memory", imagedata, 16, 2, 2, 4, 8, "")
#ps.PS_place_image(p1, psimage, 20, 90, 20.0)
#ps.PS_setfont(p1, psfont, 8.0)
#ps.PS_show_xy(p1, "CMYK", 20, 80)
#ps.PS_show_xy(p1, "RGB", 20, 10)
#ps.PS_show_xy(p1, "Gray", 90, 10)
end_example_box(p1)
# TRAILER
ps.PS_end_page(p1)
ps.PS_close(p1)
ps.PS_delete(p1)
print "Finished."