Back to index

lightning-sunbird  0.9+nobinonly
XIE.c
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  * vim:ts=2:et:sw=2:
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 2001
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Stuart Parmenter <pavlov@netscape.com>
00026  *   Syd Logan <syd@netscape.com>
00027  *   Xlibified by tim copperfield <timecop@japan.co.jp>
00028  *
00029  * Alternatively, the contents of this file may be used under the terms of
00030  * either of the GNU General Public License Version 2 or later (the "GPL"),
00031  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00032  * in which case the provisions of the GPL or the LGPL are applicable instead
00033  * of those above. If you wish to allow use of your version of this file only
00034  * under the terms of either the GPL or the LGPL, and not to allow others to
00035  * use your version of this file under the terms of the MPL, indicate your
00036  * decision by deleting the provisions above and replace them with the notice
00037  * and other provisions required by the GPL or the LGPL. If you do not delete
00038  * the provisions above, a recipient may use your version of this file under
00039  * the terms of any one of the MPL, the GPL or the LGPL.
00040  *
00041  * ***** END LICENSE BLOCK ***** */
00042 
00043 #include "drawers.h"
00044 
00045 #ifdef HAVE_XIE
00046 
00047 #include <stdio.h>
00048 #include <string.h>
00049 #include "prenv.h"
00050 #include "xlibrgb.h"
00051 #include <X11/extensions/XIElib.h>
00052 
00053 /* #define DEBUG_XIE 1 */
00054 static PRBool useXIE = PR_TRUE;
00055 static PRBool inited = PR_FALSE;
00056 static XiePhotospace gPhotospace;
00057 static XiePhotoElement *photoElement;
00058 
00059 static void
00060 DoFlo(Display *display,
00061       Drawable aDest,
00062       GC aGC,
00063       Drawable aSrc,
00064       PRInt32 aSrcWidth,
00065       PRInt32 aSrcHeight,
00066       PRInt32 aSX,
00067       PRInt32 aSY,
00068       PRInt32 aSWidth,
00069       PRInt32 aSHeight,
00070       PRInt32 aDX,
00071       PRInt32 aDY,
00072       PRInt32 aDWidth,
00073       PRInt32 aDHeight)
00074 {
00075   XieExtensionInfo *info;
00076   float coeffs[6];
00077   XieConstant constant;
00078   XiePhototag idx = 0, src;
00079 
00080   /* create the pretty flo graph */
00081 
00082 
00083   /* import */
00084   XieFloImportDrawable(&photoElement[idx], aSrc,
00085                        aSX, aSY, aSWidth, aSHeight,
00086                        0, PR_FALSE);
00087   ++idx;
00088   src = idx;
00089 
00090   /* do the scaling stuff */
00091   coeffs[0] = (float)aSrcWidth / (float)aDWidth;
00092   coeffs[1] = 0.0;
00093   coeffs[2] = 0.0;
00094   coeffs[3] = (float)aSrcHeight / (float)aDHeight;
00095   coeffs[4] = 0.0;
00096   coeffs[5] = 0.0;
00097 
00098   constant[0] = 128.0;
00099   constant[1] = 128.0;
00100   constant[2] = 128.0;
00101 
00102   XieFloGeometry(&photoElement[idx], src, aDWidth, aDHeight,
00103                  coeffs,
00104                  constant,
00105                  0x07,
00106                  xieValGeomNearestNeighbor,
00107                  NULL);
00108   ++idx;
00109 
00110   /* export */
00111   XieFloExportDrawable(&photoElement[idx], idx, aDest, aGC,
00112                        (aDX - aSX),
00113                        (aDY - aSY));
00114 #ifdef DEBUG_XIE
00115   printf("export to %d, %d (%dx%d)\n", (aDX - aSX), (aDY - aSY),
00116       aDWidth, aDHeight);
00117 #endif
00118   ++idx;
00119 
00120   /* do the scale thing baby */
00121   XieExecuteImmediate(display, gPhotospace, 1, PR_FALSE, photoElement, idx);
00122 
00123   /*
00124     XieFreePhotofloGraph(photoElement, 3);
00125   */
00126 }
00127 
00128 PRBool 
00129 DrawScaledImageXIE(Display *display,
00130                    Drawable aDest,
00131                    GC aGC,
00132                    Drawable aSrc,
00133                    PRInt32 aSrcWidth,
00134                    PRInt32 aSrcHeight,
00135                    PRInt32 aSX,
00136                    PRInt32 aSY,
00137                    PRInt32 aSWidth,
00138                    PRInt32 aSHeight,
00139                    PRInt32 aDX,
00140                    PRInt32 aDY,
00141                    PRInt32 aDWidth,
00142                    PRInt32 aDHeight)
00143 {
00144 #ifdef DEBUG_XIE
00145   printf("DrawScaledImageXIE\n");
00146 #endif
00147 
00148   if (!useXIE) {
00149 #ifdef DEBUG_XIE
00150     fprintf(stderr, "useXIE is false.\n");
00151 #endif
00152     return PR_FALSE;
00153   }
00154 
00155   if (!inited) {
00156     XieExtensionInfo *info;
00157 
00158     if (useXIE) {
00159       char *text = PR_GetEnv("MOZ_DISABLE_XIE");
00160       if (text) {
00161 #ifdef DEBUG_XIE
00162         fprintf(stderr, "MOZ_DISABLE_XIE set, disabling use of XIE.\n");
00163 #endif
00164         useXIE = PR_FALSE;
00165         return PR_FALSE;
00166       }
00167     }
00168 
00169     if (!XieInitialize(display, &info)) {
00170       useXIE = PR_FALSE;
00171       return PR_FALSE;
00172     }
00173 
00174     inited = PR_TRUE;
00175 
00176     /* create the photospace (we only need to do this once) */
00177     gPhotospace = XieCreatePhotospace(display);
00178 
00179     photoElement = XieAllocatePhotofloGraph(3);
00180 
00181     /* XXX we want to destroy this at shutdown
00182        XieDestroyPhotospace(display, photospace);
00183     */
00184   }
00185 
00186   /* run the flo on the image to get a the scaled image */
00187   DoFlo(display, aDest, aGC, aSrc,
00188         aSrcWidth, aSrcHeight,
00189         aSX, aSY, aSWidth, aSHeight,
00190         aDX, aDY, aDWidth, aDHeight);
00191 
00192   return PR_TRUE;
00193 }
00194 #endif