Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Clipboard Quicker than MathLink?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20563] Clipboard Quicker than MathLink?
  • From: simon shannon <sshannon at taz.dra.hmg.gb>
  • Date: Sat, 30 Oct 1999 00:14:10 -0400
  • Organization: dera
  • Sender: owner-wri-mathgroup at wolfram.com

Dear All,

    I am trying to find a way of squirting data between Mathematica and an
external process quicker than mathlink under Windows NT4 on a pc.  My
data is a simple greyscale image, typically it is just 700 by 300 and
each pixel is 0-255, so a single byte per pixel would do.

Even using the PackedArray format, one still needs two bytes per pixel.
Storage is not really the issue here, doing lots of array access at the
pixel level is still unusably slow (assume the problem cannot be
reformulated to take advantage of fast internal functions like
ListCovolve), so I thought I'd go for C/mathlink solution.

Now, whether I squirt the image data down the mathlink pixel by pixel,
ie doing MLGetInteger() for every pixel, or one big
MLGetIntegerArray() it still takes about 3 seconds to transfer an image
to or from the mathlink process.

But....I observe that very large complicated display cells can be copied
very quickly to and from the clipboard from the Mathematica frontend, so can we
sidestep the slow mathlink?

The Mathematica fragment that I would like is something like:

---------------------------------------------------------------------
(* install my external C process *)
mylink = Install["cprog.exe"];         

(* invent an image *)
data = ToPackedArray[Table[Random[Integer,{0,128}],{700},{200}]];

(* copy it to the clipboard somehow *)
copyToClipboard[data];

(* call a function in the extenal C process to invert the image
   and assume that it is pasted to the clipboard *)
myInvert[];

(* grab the result from the clipboard *)
result = pasteFromClipboard[];
---------------------------------------------------------------------

The important part of the cprog.tm used to build cprog.exe might look
something like:

:Begin:
:Function:       myinvert
:Pattern:        myInvert[ ]
:Arguments:      { }
:ArgumentTypes:  { }
:ReturnType:     Manual
:End:

void myinvert()
{
    int i,j,nr,nc;
    char *data;

    (1) openclipboard()

    (2) check format of data (eg image size nr rows by nc columns)

    (3) malloc storage

    (4) read the data from the clip board

    for (i=0; i<nr; i++)
        for (j=0; j<nc; j++)
            data[i*nc+j] = read a pixel;

    (5) delete the data from the clipbaord

    (6) do some manipulation

    for (i=0; i<nr; i++)
        for (j=0; j<nc; j++)
            data[i*nc+j] = 255-data[i*nc+j];

    (7) put it back to the clipboard

    (8) closeclipboard

    (9) free malloced memory

    return;
}

Apart from (3), (6) and (9), any ideas on the other steps
would be welcome.


   - Simon Shannon


  • Prev by Date: Re: Re: Preventing NotebookWrite From Wrapping
  • Next by Date: Mac OS-X server
  • Previous by thread: Re: A Graphics Import problem
  • Next by thread: Mac OS-X server