File: string_io.py

package info (click to toggle)
gamera 1%3A3.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,912 kB
  • sloc: xml: 122,324; cpp: 50,730; python: 35,044; ansic: 258; makefile: 114; sh: 101
file content (67 lines) | stat: -rw-r--r-- 2,375 bytes parent folder | download | duplicates (4)
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
#
# Copyright (C) 2005 Alex Cobb
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

"""Transfer of Gamera image data in Python strings. 
"""

from gamera.plugin import *

class _to_raw_string(PluginFunction):
    """
    Returns the image's binary data as a Python string.

    Requires a copying operation;  may fail for very large images.

    This function is not intended to be used directly.  To move data
    to/from Numeric/numarray/PIL, use the functions in numeric_io.py,
    numarray_io.py and pil_io.py respectively.
    """
    self_type = ImageType(ALL)
    return_type = Class("string_from_image")

class _from_raw_string(PluginFunction):
    """
    Instantiates an image from binary data in a Python string.

    Requires a copying operation;  may fail for very large images.
    
    This function is not intended to be used directly.  To move data
    to/from Numeric/numarray/PIL, use the functions in numeric_io.py,
    numarray_io.py and pil_io.py respectively.
    """
    self_type = None
    ## Image constructor uses:
    ##   page_offset_y, page_offset_x,
    ##   nrows, ncols, pixel_format=0, storage_type=0,
    ## so we'll do something similar:
    args = Args([Point("offset"), Dim("dim"),
                 Int("pixel_type"), Int("storage_type"),
                 Class("data_string")])
    return_type = ImageType(ALL)

class StringIOModule(PluginModule):
    category = "ExternalLibraries"
    cpp_headers=["string_io.hpp"]
    functions = [_to_raw_string,
                 _from_raw_string]
    author = "Alex Cobb"
    url = ('http://www.oeb.harvard.edu/faculty/holbrook/'
           'people/alex/Website/alex.htm')
module = StringIOModule()

_from_raw_string = _from_raw_string()