Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
7f1898a0
Commit
7f1898a0
authored
13 years ago
by
cramakri
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2472 refactored image generation script
SVN: 22629
parent
8ab2528a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test-data/source/python/screening/canvas.py
+66
-0
66 additions, 0 deletions
test-data/source/python/screening/canvas.py
test-data/source/python/screening/generate-test-images.py
+13
-44
13 additions, 44 deletions
test-data/source/python/screening/generate-test-images.py
with
79 additions
and
44 deletions
test-data/source/python/screening/canvas.py
0 → 100644
+
66
−
0
View file @
7f1898a0
from
Quartz
import
*
from
Cocoa
import
*
from
LaunchServices
import
*
# for kUTTypePNG
class
PlateWellCanvas
:
"""
A canvas with utility methods for drawing images for plate wells.
The utility methods support drawing source images and overlays and
allow the resulting images to be written to files.
The canvas uses an underlying CoreGraphics bitmap context with with
device RGB color space.
"""
def
__init__
(
self
,
width
=
512
,
height
=
512
):
"""
Constructor that takes the size of the canvas.
"""
self
.
width
=
width
self
.
height
=
height
self
.
ctx
=
self
.
_create_rgba_bitmap_context
()
def
draw_inset_rect
(
self
,
r
,
g
,
b
,
start
,
isUnfilled
=
0
):
ctx
=
self
.
ctx
with
CGSavedGState
(
ctx
):
CGContextSetRGBStrokeColor
(
ctx
,
r
,
g
,
b
,
1
)
if
isUnfilled
:
CGContextSetRGBFillColor
(
ctx
,
0
,
0
,
0
,
0
)
# transparent
else
:
CGContextSetRGBFillColor
(
ctx
,
r
,
g
,
b
,
1
)
CGContextSetLineWidth
(
ctx
,
40
)
CGContextAddRect
(
ctx
,
CGRectMake
(
start
,
start
,
self
.
width
-
2
*
start
,
self
.
height
-
2
*
start
))
CGContextDrawPath
(
ctx
,
kCGPathFillStroke
)
def
draw_text
(
self
,
x
,
y
,
text
):
ctx
=
self
.
ctx
with
CGSavedGState
(
ctx
):
CGContextSetRGBStrokeColor
(
ctx
,
0
,
0
,
0
,
1
)
# black
CGContextSetRGBFillColor
(
ctx
,
1
,
1
,
1
,
1
)
# white
CGContextSetTextMatrix
(
ctx
,
CGAffineTransformIdentity
)
CGContextSelectFont
(
ctx
,
"
Helvetica Neue
"
,
70
,
kCGEncodingMacRoman
)
CGContextSetTextDrawingMode
(
ctx
,
kCGTextFillStroke
)
CGContextShowTextAtPoint
(
ctx
,
x
,
y
,
text
,
len
(
text
))
def
write_png_file
(
self
,
filename
):
"""
Write the graphics context to a PNG file
"""
ctx
=
self
.
ctx
image
=
CGBitmapContextCreateImage
(
ctx
)
fileUrl
=
NSURL
.
fileURLWithPath_
(
filename
)
dest
=
CGImageDestinationCreateWithURL
(
fileUrl
,
kUTTypePNG
,
1
,
None
)
CGImageDestinationAddImage
(
dest
,
image
,
None
)
CGImageDestinationFinalize
(
dest
)
# Private Methods
def
_create_rgba_bitmap_context
(
self
):
"""
Create a new CG Graphics Context.
"""
color_space
=
CGColorSpaceCreateDeviceRGB
()
pixels_wide
=
self
.
width
pixels_high
=
self
.
height
bits_per_component
=
8
number_of_components
=
4
# r,g,b,a
# Convert bits per component to bytes per pixel, rounding up to the next int if necessary
bytes_per_pixel
=
(
bits_per_component
*
number_of_components
+
7
)
/
8
bitmap_bytes_per_row
=
(
pixels_wide
*
bytes_per_pixel
);
# Create an RGB bitmap, let CoreGraphics deal with allocating and managing memory
ctx
=
CGBitmapContextCreate
(
None
,
pixels_wide
,
pixels_high
,
bits_per_component
,
bitmap_bytes_per_row
,
color_space
,
kCGImageAlphaPremultipliedLast
)
return
ctx
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test-data/source/python/screening/generate-test-images.py
+
13
−
44
View file @
7f1898a0
#!/usr/bin/python
#!/usr/bin/python
from
Quartz
import
*
import
canvas
from
Cocoa
import
*
from
LaunchServices
import
*
# for kUTTypePNG
import
math
import
math
import
os
import
os
import
shutil
import
shutil
...
@@ -11,51 +9,22 @@ size = 512
...
@@ -11,51 +9,22 @@ size = 512
well
=
"
A1
"
well
=
"
A1
"
tileNum
=
6
tileNum
=
6
def
createContext
():
def
create_canvas
():
cs
=
CGColorSpaceCreateDeviceRGB
()
return
canvas
.
PlateWellCanvas
(
size
,
size
)
pixelsWide
=
size
pixelsHigh
=
size
def
write_to_png_file
(
canvas
,
filename
):
bits_per_component
=
8
canvas
.
write_png_file
(
filename
)
number_of_components
=
4
# r,g,b,a
# Convert bits per component to bytes per pixel, rounding up to the next int if necessary
def
drawRect
(
canvas
,
r
,
g
,
b
,
start
,
isUnfilled
=
0
):
bytes_per_pixel
=
(
bits_per_component
*
number_of_components
+
7
)
/
8
canvas
.
draw_inset_rect
(
r
,
g
,
b
,
start
,
isUnfilled
)
bitmapBytesPerRow
=
(
pixelsWide
*
bytes_per_pixel
);
bitmapByteCount
=
(
bitmapBytesPerRow
*
pixelsHigh
);
# Create an RGB bitmap, let CoreGraphics deal with allocating and managing memory
ctx
=
CGBitmapContextCreate
(
None
,
pixelsWide
,
pixelsHigh
,
bits_per_component
,
bitmapBytesPerRow
,
cs
,
kCGImageAlphaPremultipliedLast
)
return
ctx
def
write_to_png_file
(
ctx
,
filename
):
image
=
CGBitmapContextCreateImage
(
ctx
)
fileUrl
=
NSURL
.
fileURLWithPath_
(
filename
)
dest
=
CGImageDestinationCreateWithURL
(
fileUrl
,
kUTTypePNG
,
1
,
None
);
CGImageDestinationAddImage
(
dest
,
image
,
None
);
CGImageDestinationFinalize
(
dest
);
def
drawRect
(
ctx
,
r
,
g
,
b
,
start
,
isUnfilled
=
0
):
with
CGSavedGState
(
ctx
):
CGContextSetRGBStrokeColor
(
ctx
,
r
,
g
,
b
,
1
)
if
isUnfilled
:
CGContextSetRGBFillColor
(
ctx
,
0
,
0
,
0
,
0
)
# transparent
else
:
CGContextSetRGBFillColor
(
ctx
,
r
,
g
,
b
,
1
)
CGContextSetLineWidth
(
ctx
,
40
)
CGContextAddRect
(
ctx
,
CGRectMake
(
start
,
start
,
size
-
2
*
start
,
size
-
2
*
start
))
CGContextDrawPath
(
ctx
,
kCGPathFillStroke
)
def
drawText
(
ctx
,
x
,
y
,
text
):
def
drawText
(
canvas
,
x
,
y
,
text
):
with
CGSavedGState
(
ctx
):
canvas
.
draw_text
(
x
,
y
,
text
)
CGContextSetRGBStrokeColor
(
ctx
,
0
,
0
,
0
,
1
)
# black
CGContextSetRGBFillColor
(
ctx
,
1
,
1
,
1
,
1
)
# white
CGContextSetTextMatrix
(
ctx
,
CGAffineTransformIdentity
)
CGContextSelectFont
(
ctx
,
"
Helvetica Neue
"
,
70
,
kCGEncodingMacRoman
)
CGContextSetTextDrawingMode
(
ctx
,
kCGTextFillStroke
)
CGContextShowTextAtPoint
(
ctx
,
x
,
y
,
text
,
len
(
text
))
def
drawMatrix
(
coordsList
,
dir
,
channel
,
isOverlay
):
def
drawMatrix
(
coordsList
,
dir
,
channel
,
isOverlay
):
nonemptyTiles
=
set
([
calcTile
(
coords
)
for
coords
in
coordsList
])
nonemptyTiles
=
set
([
calcTile
(
coords
)
for
coords
in
coordsList
])
for
tile
in
range
(
1
,
10
):
for
tile
in
range
(
1
,
10
):
c
=
create
Context
()
c
=
create
_canvas
()
if
tile
in
nonemptyTiles
:
if
tile
in
nonemptyTiles
:
if
not
isOverlay
:
if
not
isOverlay
:
drawRect
(
c
,
0
,
0
,
0
,
0
)
drawRect
(
c
,
0
,
0
,
0
,
0
)
...
@@ -96,7 +65,7 @@ def overlayTests(sampleCode):
...
@@ -96,7 +65,7 @@ def overlayTests(sampleCode):
def
save
(
dir
,
filename
,
text
,
r
,
g
,
b
,
merged
=
0
):
def
save
(
dir
,
filename
,
text
,
r
,
g
,
b
,
merged
=
0
):
c
=
create
Context
()
c
=
create
_canvas
()
drawRect
(
c
,
0
,
0
,
0
,
0
)
# fill with black
drawRect
(
c
,
0
,
0
,
0
,
0
)
# fill with black
zero
=
0
zero
=
0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment