Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends
nsSanePluginInstance Class Reference

#include <nsSanePlugin.h>

Inheritance diagram for nsSanePluginInstance:
Inheritance graph
[legend]
Collaboration diagram for nsSanePluginInstance:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsSanePluginInstance (void)
virtual ~nsSanePluginInstance (void)
NS_IMETHOD Initialize (nsIPluginInstancePeer *peer)
NS_IMETHOD GetPeer (nsIPluginInstancePeer **result)
NS_IMETHOD Start (void)
NS_IMETHOD Stop (void)
NS_IMETHOD Destroy (void)
NS_IMETHOD SetWindow (nsPluginWindow *window)
NS_IMETHOD NewStream (nsIPluginStreamListener **listener)
NS_IMETHOD Print (nsPluginPrint *platformPrint)
NS_IMETHOD GetValue (nsPluginInstanceVariable variable, void *value)
NS_IMETHOD HandleEvent (nsPluginEvent *event, PRBool *handled)
NS_IMETHOD DoScanCompleteCallback ()
NS_IMETHOD DoInitCompleteCallback ()
void SetMode (nsPluginMode mode)
void SetState (PRInt32 aState)
NS_IMETHOD PaintImage (void)
char * GetImageFilename ()
GtkWidget * GetFileSelection ()
PRBool IsUIThread ()
nsresult OpenSaneDeviceIF (void)
void initialize (in nsIPluginInstancePeer aPeer)
 Initializes a newly created plugin instance, passing to it the plugin instance peer which it should use for all communication back to the browser.
void start ()
 Called to instruct the plugin instance to start.
void stop ()
 Called to instruct the plugin instance to stop, thereby suspending its state.
void destroy ()
 Called to instruct the plugin instance to destroy itself.
void setWindow (in nsPluginWindowPtr aWindow)
 Called when the window containing the plugin instance changes.
void newStream (out nsIPluginStreamListener aListener)
 Called to tell the plugin that the initial src/data stream is ready.
void print (in nsPluginPrintPtr aPlatformPrint)
 Called to instruct the plugin instance to print itself to a printer.
void getValue (in nsPluginInstanceVariable aVariable, in voidPtr aValue)
 Returns the value of a variable associated with the plugin instance.
void handleEvent (in nsPluginEventPtr aEvent, out boolean aHandled)
 Handles an event.
void ZoomImage (in unsigned short x, in unsigned short y, in unsigned short width, in unsigned short height)
void ZoomImageWithAttributes (in unsigned short x, in unsigned short y, in unsigned short width, in unsigned short height, in long req_line_width, in string req_line_style, in string req_cap_style, in string req_join_style)
void Restore ()
void Crop (in unsigned short x, in unsigned short y, in unsigned short width, in unsigned short height)
void ScanImage ()
void SetOption (in string name, in string value)
void SaveImage ()

Public Attributes

 NS_DECL_ISUPPORTS
readonly attribute
nsIPluginInstancePeer 
peer
 Returns a reference back to the plugin instance peer.
attribute boolean Success
attribute string State
attribute unsigned short ZoomX
attribute unsigned short ZoomY
attribute unsigned short ZoomWidth
attribute unsigned short ZoomHeight
attribute long ZoomLineWidth
attribute string ZoomLineStyle
attribute string ZoomCapStyle
attribute string ZoomJoinStyle
attribute float ZoomBR_XChange
attribute float ZoomBR_YChange
attribute float ZoomTL_XChange
attribute float ZoomTL_YChange
attribute long Quality
attribute string Method
attribute string DeviceOptions
attribute string ActiveDevice
attribute string ImageParameters
attribute string AvailableDevices

Private Member Functions

int WritePNMHeader (int fd, SANE_Frame format, int width, int height, int depth)
void PlatformNew (void)
nsresult PlatformDestroy (void)
PRInt16 PlatformHandleEvent (nsPluginEvent *event)
nsresult PlatformSetWindow (nsPluginWindow *window)

Private Attributes

GtkWidget * mDrawing_area
GtkWidget * mEvent_box
PlatformInstance fPlatform
char mImageFilename [255]
GtkWidget * mFileSelection
GdkRectangle mZoom_box
unsigned char * mRGBData
int mRGBWidth
int mRGBHeight
PRInt32 mLineWidth
GdkLineStyle mLineStyle
GdkCapStyle mCapStyle
GdkJoinStyle mJoinStyle
float mTopLeftXChange
float mTopLeftYChange
float mBottomRightXChange
float mBottomRightYChange
int mCompQuality

Friends

void PR_CALLBACK scanimage_thread_routine (void *)

Detailed Description

Definition at line 96 of file nsSanePlugin.h.


Constructor & Destructor Documentation

Definition at line 104 of file nsSanePlugin.cpp.

    : fPeer( NULL ), fWindow( NULL ), fMode( nsPluginMode_Embedded )
{
#ifdef DEBUG
    printf("nsSanePluginInstance::nsSanePluginInstance()\n");
#endif

    PR_AtomicIncrement(&gPluginObjectCount);

    // set default jpeg compression attributes
    mCompQuality = 10;
    mCompMethod = JDCT_FASTEST;

    // Initialize sane interface
    mSaneDevice = nsnull;
    mSaneOpen = SANE_FALSE;
    mRGBData = nsnull;
    mBottomRightXChange = mBottomRightYChange = 
        mTopLeftXChange = mTopLeftYChange = 0;

    // initialize JavaScript callback members
    mOnScanCompleteScript = nsnull;
    mOnInitCompleteScript = nsnull;
    mScanThread = nsnull;
    mUIThread = PR_GetCurrentThread();

    mState = 0; // idle
    mSuccess = 1; // success
    mFileSelection = nsnull;

    // initialize gtk widgets
    fPlatform.widget = nsnull;
    mEvent_box = nsnull;
    mDrawing_area = nsnull;

    if (NS_FAILED(CallCreateInstance(kCPluginManagerCID, &mPluginManager))) {
        NS_ERROR("Error trying to create plugin manager!");
        return;
    }
}

Here is the call graph for this function:

Definition at line 145 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::~nsSanePluginInstance(%i)\n", 
           gPluginObjectCount );
#endif 

    PR_AtomicDecrement(&gPluginObjectCount);
    PlatformDestroy(); // Perform platform specific cleanup

    if (mPluginManager) {
        mPluginManager->Release();
        mPluginManager = nsnull;
    }

    sane_exit();

    // cleanup old widgets
    if (fPlatform.widget)
        gtk_widget_destroy(fPlatform.widget);
    if (mEvent_box)
        gtk_widget_destroy(mEvent_box);
    if (mDrawing_area)
        gtk_widget_destroy(mDrawing_area);

    NS_IF_RELEASE(fPeer); 
    PR_FREEIF(mSaneDevice);
    PR_FREEIF(mOnScanCompleteScript);
    PR_FREEIF(mOnInitCompleteScript);

}

Here is the call graph for this function:


Member Function Documentation

void nsISanePluginInstance::Crop ( in unsigned short  x,
in unsigned short  y,
in unsigned short  width,
in unsigned short  height 
) [inherited]

Definition at line 439 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::Destroy()\n");
#endif

    return NS_OK;
}

Called to instruct the plugin instance to destroy itself.

This is called when it become no longer possible to return to the plugin instance, either because the browser window's history list of pages is being trimmed, or because the window containing this page in the history is being closed.

Returns:
- NS_OK if this operation was successful

Definition at line 350 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::DoInitCompleteCallback()\n");
#endif

    char *url;

    if (mOnInitCompleteScript && mPluginManager) {
        url = (char *)PR_Malloc(PL_strlen(mOnInitCompleteScript) + 13);
        if (!url)
            return NS_ERROR_OUT_OF_MEMORY;

        sprintf(url, "javascript:%s", mOnInitCompleteScript);   
        mPluginManager->GetURL((nsIPluginInstance *)this, url, "_self");

        PR_FREEIF(url);
    }

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 328 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::DoScanCompleteCallback()\n");
#endif

    char *url;

    if (mOnScanCompleteScript && mPluginManager) {
        url = (char *)PR_Malloc(PL_strlen(mOnScanCompleteScript) + 13);
        if (!url)
            return NS_ERROR_OUT_OF_MEMORY;

        sprintf(url, "javascript:%s", mOnScanCompleteScript);   
        mPluginManager->GetURL((nsIPluginInstance *)this, url, "_self");

        PR_FREEIF(url);
    }
    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 685 of file nsSanePlugin.cpp.

{
    if (!mFileSelection)
        return (GtkWidget *)NULL;

    return mFileSelection;
}

Here is the caller graph for this function:

Definition at line 675 of file nsSanePlugin.cpp.

{
    if (!mImageFilename)
        return (char *)NULL;
    
    // Caller is responsible for freeing string
    return PL_strdup(mImageFilename);
}

Here is the caller graph for this function:

Definition at line 373 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::GetPeer()\n");
#endif

    fPeer->AddRef();
    *result = fPeer;
    return NS_OK;
}

Definition at line 506 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::GetValue()\n");
#endif

    //Needs to be implemented
    return NS_ERROR_NOT_IMPLEMENTED;
}
void nsIPluginInstance::getValue ( in nsPluginInstanceVariable  aVariable,
in voidPtr  aValue 
) [inherited]

Returns the value of a variable associated with the plugin instance.

Parameters:
aVariable- the plugin instance variable to get
aValue- the address of where to store the resulting value
Returns:
- NS_OK if this operation was successful

Definition at line 493 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::HandleEvent()\n");
#endif

    // Not used on unix platform.  Only here for potential
    // future porting efforts
    *handled = (PRBool)PlatformHandleEvent(event);
    return NS_OK;
}

Here is the call graph for this function:

void nsIPluginInstance::handleEvent ( in nsPluginEventPtr  aEvent,
out boolean  aHandled 
) [inherited]

Handles an event.

An nsIEventHandler can also get registered with with nsIPluginManager2::RegisterWindow and will be called whenever an event comes in for that window.

Note that for Unix and Mac the nsPluginEvent structure is different from the old NPEvent structure -- it's no longer the native event record, but is instead a struct. This was done for future extensibility, and so that the Mac could receive the window argument too. For Windows and OS2, it's always been a struct, so there's no change for them.

(Corresponds to NPP_HandleEvent.)

Parameters:
aEvent- the event to be handled
aHandled- set to PR_TRUE if event was handled
Returns:
- NS_OK if this operation was successful

Initializes a newly created plugin instance, passing to it the plugin instance peer which it should use for all communication back to the browser.

Parameters:
aPeer- the corresponding plugin instance peer
Returns:
- NS_OK if this operation was successful

Definition at line 694 of file nsSanePlugin.cpp.

{
    if (!mUIThread)
        return PR_FALSE;

    return (mUIThread == PR_GetCurrentThread());
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 466 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::NewStream()\n");
#endif

    if ( listener != NULL )
        *listener = new nsSanePluginStreamListener( this );
    
    return NS_OK;
}

Called to tell the plugin that the initial src/data stream is ready.

Expects the plugin to return a nsIPluginStreamListener.

(Corresponds to NPP_NewStream.)

Parameters:
aListener- listener the browser will use to give the plugin the data
Returns:
- NS_OK if this operation was successful

Definition at line 1644 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::OpenSaneDeviceIF()\n");
#endif

    if (mSaneOpen) {
        return NS_OK;
    }

    if (!mSaneDevice) {
        NS_ERROR("Device name not set!");
        return NS_ERROR_FAILURE;
    }

    SANE_Status status = sane_open(mSaneDevice, &mSaneHandle);
    if (status != SANE_STATUS_GOOD) {
        NS_ERROR ("sane_open returned error code");
        return NS_ERROR_FAILURE;
    }

    mSaneOpen = SANE_TRUE;
    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 611 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::PaintImage(%p)\n", this);
#endif

    if (mDrawing_area && fPlatform.widget) {
        if (mImageFilename) {

            if (!mRGBData) {

                if (mState)
                    // we are currently scanning, so the jpeg file
                    // is not valid yet
                    return NS_OK;
                
                FILE * f = fopen(mImageFilename, "rb");
                if (!f) 
                    // it's possible that an image hasn't been scanned yet
                    return NS_OK;

                mRGBData = jpeg_file_to_rgb(f, &mRGBWidth, &mRGBHeight);
                if (!mRGBData) {
                    NS_ERROR("Error converting jpeg to rgb data!");
                    return NS_ERROR_FAILURE;
                }

                fclose(f);

                // scale down to window size
                unsigned char * tmp = scale_image( mRGBData, 
                                                   mRGBWidth, mRGBHeight,
                                                   fPlatform.width,
                                                   fPlatform.height);
                if (!tmp) {
                    NS_ERROR("Error trying to scale image!");
                    return NS_ERROR_FAILURE;
                }

                // move to new data
                PR_FREEIF(mRGBData);
                mRGBData = tmp;
            }

            // render the image
            gdk_draw_rgb_image (mDrawing_area->window, 
                                mDrawing_area->style->fg_gc[GTK_STATE_NORMAL],
                                0, 0, fPlatform.width, fPlatform.height,
                                GDK_RGB_DITHER_MAX, mRGBData, 
                                fPlatform.width * 3);

            gdk_draw_rectangle (mDrawing_area->window,
                                mDrawing_area->style->fg_gc[mDrawing_area->state],
                                FALSE, mZoom_box.x, mZoom_box.y, 
                                mZoom_box.width, mZoom_box.height);        
            
            gdk_flush();
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 527 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::PlatformDestroy()\n");
#endif

       return NS_OK;
}

Here is the caller graph for this function:

Definition at line 599 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::PlatformHandleEvent()\n");
#endif

    /* UNIX Plugins do not use HandleEvent */
    return 0;
}

Here is the caller graph for this function:

Definition at line 517 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::PlatformNew\n");
#endif

    fPlatform.window = 0;
}

Here is the caller graph for this function:

Definition at line 537 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::PlatformSetWindow()\n");
#endif


    if ( window == NULL || window->window == NULL )
        return NS_ERROR_NULL_POINTER;
    
    if ( fPlatform.superwin == (GdkSuperWin *)window->window )
        return NS_OK;

    // Record windowing info
    fPlatform.superwin = (GdkSuperWin *)window->window;
    fPlatform.height = window->height;
    fPlatform.width = window->width;

    // cleanup old widgets
    if (fPlatform.widget)
        gtk_widget_destroy(fPlatform.widget);
    if (mEvent_box)
        gtk_widget_destroy(mEvent_box);
    if (mDrawing_area)
        gtk_widget_destroy(mDrawing_area);

    fPlatform.widget = gtk_mozbox_new(fPlatform.superwin->bin_window);

    // Initialize the zoom box to outline the entire image
    mZoom_box.x = 0;
    mZoom_box.y = 0;
    mZoom_box.width = fPlatform.width;
    mZoom_box.height = fPlatform.height;

    // Setup an event box to contain the drawable
    mEvent_box = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(fPlatform.widget), mEvent_box);
    gtk_widget_show(mEvent_box);

    // Setup the drawable
    mDrawing_area = ( GtkWidget * )gtk_drawing_area_new();
    gtk_drawing_area_size( GTK_DRAWING_AREA( mDrawing_area ),
                           window->width, window->height);
    gtk_container_add(GTK_CONTAINER(mEvent_box), mDrawing_area);
    gtk_widget_show(mDrawing_area);

    // Initialize line attributes for GC
    GdkGC * da_gc = mDrawing_area->style->fg_gc[mDrawing_area->state];
    gdk_gc_set_line_attributes ( da_gc, mLineWidth, mLineStyle, 
                                 mCapStyle, mJoinStyle);

    // Register signals
    gtk_signal_connect (GTK_OBJECT(mDrawing_area), "expose_event",
                        GTK_SIGNAL_FUNC(draw), this);

    // Now make everything visable
    gtk_widget_show( fPlatform.widget );

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 479 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::Print()\n");
#endif

    if ( printInfo == NULL )
        return NS_ERROR_FAILURE;

    // needs to be implemented
    return NS_ERROR_NOT_IMPLEMENTED;
}
void nsIPluginInstance::print ( in nsPluginPrintPtr  aPlatformPrint) [inherited]

Called to instruct the plugin instance to print itself to a printer.

(Corresponds to NPP_Print.)

Parameters:
aPlatformPrint- platform-specific printing information
Returns:
- NS_OK if this operation was successful

Here is the caller graph for this function:

Definition at line 132 of file nsSanePlugin.h.

{ fMode = mode; }
void nsISanePluginInstance::SetOption ( in string  name,
in string  value 
) [inherited]

Definition at line 133 of file nsSanePlugin.h.

{ mState = aState; };

Here is the caller graph for this function:

Definition at line 449 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::SetWindow()\n");
#endif

    nsresult result;

    // The real work is handled in PlatformSetWindow
    // (as if this plug-in was multiplatform)
    result = PlatformSetWindow( window );
    fWindow = window;

    return result;
}

Here is the call graph for this function:

Called when the window containing the plugin instance changes.

(Corresponds to NPP_SetWindow.)

Parameters:
aWindow- the plugin window structure
Returns:
- NS_OK if this operation was successful
void nsIPluginInstance::start ( ) [inherited]

Called to instruct the plugin instance to start.

This will be called after the plugin is first created and initialized, and may be called after the plugin is stopped (via the Stop method) if the plugin instance is returned to in the browser window's history.

Returns:
- NS_OK if this operation was successful

Definition at line 385 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::Start()\n");
#endif

    PR_FREEIF(mRGBData);
    mRGBData = nsnull;

    sane_init(0,0);
    mSaneOpen = SANE_FALSE;
    nsresult rv = OpenSaneDeviceIF();
    if (rv != NS_OK) {
        NS_ERROR("Failed to open device in Start()\n");
        return rv;
    }

    PlatformNew();

    // call onInitComplete callback
    DoInitCompleteCallback();
    return NS_OK;
}

Here is the call graph for this function:

Definition at line 410 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSanePluginInstance::Stop()\n");
#endif

    // Wait for scanner operation to complete.
    // TODO: Warn user that they are still scanning
    //       and send abort command to scanner if 
    //       the user wishes.
    if (mScanThread)
        PR_JoinThread(mScanThread);

    PR_FREEIF(mRGBData);

    // close sane
    if (mSaneOpen) {
        sane_close(mSaneHandle);
        sane_exit();
        mSaneOpen = SANE_FALSE;
    }

    if (remove ( mImageFilename ) == -1)
        perror(mImageFilename);

    return NS_OK;
}

Here is the call graph for this function:

void nsIPluginInstance::stop ( ) [inherited]

Called to instruct the plugin instance to stop, thereby suspending its state.

This method will be called whenever the browser window goes on to display another page and the page containing the plugin goes into the window's history list.

Returns:
- NS_OK if this operation was successful
int nsSanePluginInstance::WritePNMHeader ( int  fd,
SANE_Frame  format,
int  width,
int  height,
int  depth 
) [abstract, private]

Definition at line 1898 of file nsSanePlugin.cpp.

{
#ifdef DEBUG
    printf("nsSaneInstance::WritePNMHeader()\n");
#endif

    char b[32];

    switch (format) {
    case SANE_FRAME_RED:
    case SANE_FRAME_GREEN:
    case SANE_FRAME_BLUE:
    case SANE_FRAME_RGB:
        sprintf (b, "P6\n%d %d\n255\n", width, height);
        break;

    default:
        if (depth == 1)
            sprintf (b, "P4\n%d %d\n", width, height);
        else
            sprintf (b, "P5\n%d %d\n255\n", width, height);
        break;
    }

    return write(fd, b, PL_strlen(b));
}
void nsISanePluginInstance::ZoomImage ( in unsigned short  x,
in unsigned short  y,
in unsigned short  width,
in unsigned short  height 
) [inherited]
void nsISanePluginInstance::ZoomImageWithAttributes ( in unsigned short  x,
in unsigned short  y,
in unsigned short  width,
in unsigned short  height,
in long  req_line_width,
in string  req_line_style,
in string  req_cap_style,
in string  req_join_style 
) [inherited]

Friends And Related Function Documentation

Definition at line 2397 of file nsSanePlugin.cpp.

{
    nsSanePluginInstance * pthis = (nsSanePluginInstance *)arg;

    nsresult rv;
    SANE_Status status;
    SANE_Parameters param;
    int len;
    FILE * out;
    SANE_Byte * buf;
    JSAMPROW row_pointer[1];
    char *fname;

    // JPEG stuff
    struct jpeg_compress_struct cinfo;
       struct jpeg_error_mgr jerr;

       // Error handling
    jerr.error_exit = my_jpeg_error_exit; // fatal errors
       cinfo.err = jpeg_std_error(&jerr);

       jpeg_create_compress(&cinfo);

    rv = pthis->OpenSaneDeviceIF();
    if (rv != NS_OK)
        goto error_exit;

    // open image file
    fname = pthis->GetImageFilename();
    if (!fname)
        goto error_exit;
    out = fopen(fname, "wb");
    PR_FREEIF(fname);
    if (out == NULL) {
        NS_ERROR("Unable to open mImageFilename!\n");
        sane_cancel(pthis->mSaneHandle);
        goto error_exit;       
    }
    jpeg_stdio_dest(&cinfo, out);

    status = sane_start(pthis->mSaneHandle);
    if (status != SANE_STATUS_GOOD) {
        NS_ERROR("Error trying to start sane device!");
        goto error_exit;
    }

    status = sane_get_parameters(pthis->mSaneHandle, &param);
    if (status != SANE_STATUS_GOOD) {
        NS_ERROR("Error trying to get image parameters!\n");
        sane_cancel(pthis->mSaneHandle);
        goto error_exit;
    }
    cinfo.image_width = param.pixels_per_line;
    cinfo.image_height = param.lines;

    switch (param.format) {
    case SANE_FRAME_RED:
    case SANE_FRAME_GREEN:
    case SANE_FRAME_BLUE:
        // NOT Supported!
        NS_ERROR("Multiframe devices not supported!\n");
        sane_cancel(pthis->mSaneHandle);
        goto error_exit;
        break;
                
    case SANE_FRAME_RGB:
        cinfo.input_components = 3;
        cinfo.in_color_space = JCS_RGB;
        break;

    case SANE_FRAME_GRAY:
        cinfo.input_components = 1;
        cinfo.in_color_space = JCS_GRAYSCALE;
        break;
    }
    jpeg_set_defaults(&cinfo); 
    cinfo.dct_method = pthis->mCompMethod; 
    jpeg_set_quality(&cinfo, pthis->mCompQuality, FALSE);
    jpeg_start_compress(&cinfo, TRUE);

    buf = (SANE_Byte *)PR_MALLOC(param.bytes_per_line);
    if (!buf) {
        NS_ERROR("Error trying to allocate buffer!\n");
        jpeg_destroy_compress(&cinfo);
        fclose(out);
        sane_cancel(pthis->mSaneHandle);
        goto error_exit;
    }

    int total;
    while(1) {
        total = 0;
        while (total < param.bytes_per_line) {
            // Read in data from sane device
            status = sane_read(pthis->mSaneHandle, buf + total, 
                               param.bytes_per_line - total, 
                               &len);
            if (status != SANE_STATUS_GOOD) {
                if (status == SANE_STATUS_EOF)
                    // done with this frame
                    goto finished_scan;
                else {
                    NS_ERROR("Error trying to read from sane device!\n");
                    PR_FREEIF(buf);
                    jpeg_destroy_compress(&cinfo);
                    fclose(out);
                    sane_cancel(pthis->mSaneHandle);
                    goto error_exit;
                }
            }
            total += len;
        }

        row_pointer[0] = (JSAMPLE *) buf;
        jpeg_write_scanlines(&cinfo, row_pointer, 1); 

    } // end while

    // cleanup
 finished_scan:
    jpeg_finish_compress(&cinfo);
    jpeg_destroy_compress(&cinfo);
    PR_FREEIF(buf);
    sane_cancel(pthis->mSaneHandle);
    fclose(out);
    pthis->SetSuccess(PR_TRUE); // allow caller to check for success

 error_exit:

    // Call onScanComplete callback in the UI thread

    nsCOMPtr<nsIEventQueue> eventQ;

    // Get the event queue of the current thread...
    nsCOMPtr<nsIEventQueueService> eventQService = 
             do_GetService(kEventQueueService, &rv);
    if (NS_FAILED(rv)) {
        NS_ERROR("Unable to get event queue service!\n");
        return;
    }

    rv = eventQService->GetThreadEventQueue(pthis->mUIThread,
                                            getter_AddRefs(eventQ));
    if (NS_FAILED(rv)) {
        NS_ERROR("Unable to get thread queue!\n");
        return;
    }

    PLEvent *event = new PLEvent;
    if (!event) {
        NS_ERROR("Unable to create new event!\n");
        return;
    }

    // ThreadHandleEvent will now execute in the UI thread.
    PL_InitEvent(event, 
                 pthis,
                 (PLHandleEventProc)  ThreadedHandleEvent,
                 (PLDestroyEventProc) ThreadedDestroyEvent);

    if (NS_FAILED(eventQ->PostEvent(event))) {
        NS_ERROR("Error trying to post event!\n");
        PL_DestroyEvent(event);
        return;
    }
}

Member Data Documentation

Definition at line 147 of file nsSanePluginControl.idl.

Definition at line 153 of file nsSanePluginControl.idl.

Definition at line 144 of file nsSanePluginControl.idl.

Definition at line 147 of file nsSanePlugin.h.

Definition at line 150 of file nsSanePluginControl.idl.

Definition at line 163 of file nsSanePlugin.h.

Definition at line 164 of file nsSanePlugin.h.

GdkCapStyle nsSanePluginInstance::mCapStyle [private]

Definition at line 157 of file nsSanePlugin.h.

Definition at line 167 of file nsSanePlugin.h.

Definition at line 145 of file nsSanePlugin.h.

Definition at line 136 of file nsSanePluginControl.idl.

GtkWidget* nsSanePluginInstance::mEvent_box [private]

Definition at line 146 of file nsSanePlugin.h.

Definition at line 149 of file nsSanePlugin.h.

Definition at line 148 of file nsSanePlugin.h.

GdkJoinStyle nsSanePluginInstance::mJoinStyle [private]

Definition at line 158 of file nsSanePlugin.h.

GdkLineStyle nsSanePluginInstance::mLineStyle [private]

Definition at line 156 of file nsSanePlugin.h.

Definition at line 155 of file nsSanePlugin.h.

unsigned char* nsSanePluginInstance::mRGBData [private]

Definition at line 151 of file nsSanePlugin.h.

Definition at line 152 of file nsSanePlugin.h.

Definition at line 152 of file nsSanePlugin.h.

Definition at line 161 of file nsSanePlugin.h.

Definition at line 162 of file nsSanePlugin.h.

GdkRectangle nsSanePluginInstance::mZoom_box [private]

Definition at line 150 of file nsSanePlugin.h.

Definition at line 126 of file nsSanePlugin.h.

Returns a reference back to the plugin instance peer.

This method is used whenever the browser needs to obtain the peer back from a plugin instance. The implementation of this method should be sure to increment the reference count on the peer by calling AddRef.

Parameters:
aPeer- the resulting plugin instance peer
Returns:
- NS_OK if this operation was successful

Definition at line 96 of file nsIPluginInstance.idl.

Definition at line 135 of file nsSanePluginControl.idl.

Definition at line 86 of file nsSanePluginControl.idl.

Definition at line 83 of file nsSanePluginControl.idl.

Definition at line 129 of file nsSanePluginControl.idl.

Definition at line 130 of file nsSanePluginControl.idl.

Definition at line 122 of file nsSanePluginControl.idl.

attribute unsigned short nsISanePluginInstance::ZoomHeight [inherited]

Definition at line 116 of file nsSanePluginControl.idl.

Definition at line 123 of file nsSanePluginControl.idl.

Definition at line 121 of file nsSanePluginControl.idl.

Definition at line 120 of file nsSanePluginControl.idl.

Definition at line 131 of file nsSanePluginControl.idl.

Definition at line 132 of file nsSanePluginControl.idl.

attribute unsigned short nsISanePluginInstance::ZoomWidth [inherited]

Definition at line 115 of file nsSanePluginControl.idl.

attribute unsigned short nsISanePluginInstance::ZoomX [inherited]

Definition at line 113 of file nsSanePluginControl.idl.

attribute unsigned short nsISanePluginInstance::ZoomY [inherited]

Definition at line 114 of file nsSanePluginControl.idl.


The documentation for this class was generated from the following files: