home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include "title.h"
- #include <bstring.h>
- #include <malloc.h>
- #include "convertImageFormat.h"
- #ifdef DEBUG
- #define dprintf printf
- #else
- #define dprintf 0&&
- #endif
-
- extern "C" {
- // The following are external pswrap-generated routines
- // PSWforwardTransfer resets the color transfer
- void PSWforwardTransfer(DPSContext);
- // PSWreverseTransfer sets the color transfer to be negative
- // this is only used for erase so it erases to black and not white
- void PSWreverseTransfer(DPSContext);
- // PSWDisplayText adds the string at the pointsize indicated
- // for a NTSC size window, ptsize = 32 will hold ~35 chars across
- void PSWDisplayText(char *, int);
- }
-
- void *
- flipImage(void *inVoid, int width, int height)
- {
- unsigned char *inImage, *outImage;
- inImage = (unsigned char *)inVoid;
- outImage = new unsigned char [width * height * sizeof(long)];
- for(int y = 0; y < height; y++){
- bcopy(&inImage[width * (height - 1 - y) * sizeof(long)],
- &outImage[width * y * sizeof(long)], width * sizeof(long));
- }
- return (void *)outImage;
- }
-
- Title::Title(Widget d, int w, int h)
- {
- XGCValues values;
- _hasDPS = FALSE;
- _dpy = XtDisplay(d);
- _width = w;
- _height = h;
- _depth = DefaultDepth(_dpy, 0);
- _pixmap = NULL;
- _gc = NULL;
- _img = NULL;
- _ctxt = NULL;
- if(!XDPSExtensionPresent(_dpy)){
- // fprintf(stderr,"No DPS extension to the X server\n");
- return;
- }
- _pixmap = XCreatePixmap(_dpy, XtWindow(d),_width, _height, _depth);
- _gc = XCreateGC(_dpy, _pixmap, NULL, &values);
- _img = XGetImage(_dpy,_pixmap,0,0,_width, _height,0xffffffff, ZPixmap);
- _ctxt = XDPSCreateSimpleContext(_dpy, _pixmap, _gc, 0, 0,
- (DPSTextProc)DPSDefaultTextBackstop,
- (DPSErrorProc)DPSDefaultErrorProc, NULL );
- if(!_ctxt){
- fprintf(stderr,"Cannot creat context\n");
- return;
- }
- DPSSetContext(_ctxt);
- PSinitmatrix();
- PSinitclip();
- PSinitviewclip();
- erase();
- _hasDPS = TRUE;
- }
-
- Title::~Title()
- {
- if(_gc)XFreeGC(_dpy, _gc);
- if(_pixmap)XFreePixmap(_dpy, _pixmap);
- if(_img)XDestroyImage(_img);
- if(_ctxt)DPSDestroySpace(DPSSpaceFromContext(_ctxt));
- }
-
- void Title::setOffset(int x, int y)
- {
- // offset to point indicated
- dprintf("Calling setOffset\n");
- if(!_hasDPS) return;
- PSsetXoffset(x,y);
- }
-
- void Title::setColor(float r, float g, float b)
- {
- // set the current working RGB color
- dprintf("Calling setColor\n");
- if(!_hasDPS) return;
- PSsetrgbcolor(r,g,b);
- }
-
- void Title::erase()
- {
- // erase the screen. To do this, reverse the color transfer function, erase, and reset
- dprintf("Calling erase\n");
- if(!_hasDPS) return;
- PSWreverseTransfer(_ctxt);
- PSerasepage();
- PSWforwardTransfer(_ctxt);
- }
-
- void Title::text(char *str, int ptsize)
- {
- // draw string with pointsize
- dprintf("Calling text\n");
- if(!_hasDPS) return;
- PSWDisplayText(str, ptsize);
- }
-
- void *
- Title::getImage()
- {
- // return a ABGR char array of the pixmap
- XImage *img;
- void *flippedImage;
- unsigned char *charImage;
- dprintf("Calling getImage\n");
- if(!_hasDPS) return NULL;
- DPSWaitContext(_ctxt);
- img = XGetImage(_dpy,_pixmap,0,0,_width, _height,0xffffffff, ZPixmap);
- if(img->depth == 8){
- charImage = new unsigned char [_width * _height * sizeof(long)];
- flippedImage = (void *)charImage;
- csFlipVertically(TRUE);
- RGB332ToRGBX(_width, _height, 0, (void *)img->data, 0, flippedImage);
- }else{
- flippedImage = flipImage((void *)img->data, _width, _height);
- }
- XDestroyImage(img);
- return flippedImage;
- }
-
- void Title::putImage(void *image)
- {
- // Really backwards and slow way to put an image into the pixmap.
- void *flippedImage;
- unsigned char *charImage;
- dprintf("Calling putImage\n");
- if(!_hasDPS) return;
- if(_depth == 8){
- charImage = new unsigned char [_width*_height];
- flippedImage = (void *)charImage;
- csFlipVertically(TRUE);
- RGBXToRGB332(_width, _height, 0, image, 0, flippedImage);
- }else{
- flippedImage = flipImage(image, _width, _height);
- }
- free(_img->data);
- _img->data = (char *)flippedImage;
- XPutImage(_dpy, _pixmap, _gc, _img, 0,0,0,0,_width, _height);
- }
-
-