Max 5 API Reference
00001 /* 00002 jit.gworld.c 00003 00004 Copyright 2001-2005 - Cycling '74 00005 Joshua Kit Clayton jkc@cycling74.com 00006 00007 */ 00008 #include "jit.common.h" 00009 00010 //static CTabHandle _g_clut = 0; //probably not needed. 00011 00012 /** 00013 * Set all pixels in a QuickDraw GWorld to a specified 32-bit value 00014 * 00015 * @ingroup qtutilsmod 00016 * 00017 * @param gp QuickDraw GWorldPtr 00018 * @param c clear color 00019 * 00020 */ 00021 void jit_gworld_clear(GWorldPtr gp, long c) 00022 { 00023 PixMapHandle pmh; 00024 uchar *addr; 00025 long width,height,rowstride,i,j; 00026 long *p; 00027 Rect r; 00028 long widfactor; 00029 long v = BE_I32(c); 00030 00031 if (gp) { 00032 pmh = GetGWorldPixMap(gp); 00033 if (!pmh) { 00034 return; 00035 } 00036 00037 LockPixels(pmh); 00038 00039 #ifdef WIN_VERSION 00040 #ifndef USE_QTML 00041 ASI_SetCurrentPixMapType(*pmh, PMTYPE_SetMacCurrent); 00042 ASI_UnfoldPixMap((BitMapPtr)*pmh,(BitMapPtr)*pmh,&(*pmh)->bounds,&(*pmh)->bounds,0); 00043 #endif //USE_QTML 00044 #endif //WIN_VERSION 00045 00046 addr = (uchar *)GetPixBaseAddr(pmh); 00047 if (!addr) { 00048 UnlockPixels(pmh); 00049 return; 00050 } 00051 GetPortBounds(gp,&r); 00052 if ((**pmh).pixelSize == 16) // uyvy 00053 widfactor = 1L; 00054 else 00055 widfactor = 0L; 00056 width = (r.right-r.left) >> widfactor; 00057 height = (r.bottom-r.top); 00058 rowstride = GetPixRowBytes(pmh); 00059 if (rowstride<(width*4)) { 00060 //assuming one of the various uyvy packed types 00061 //could be better, perhaps convert argb value to 00062 //whatever colorspace? 00063 width /= 2; 00064 } 00065 for(i=0;i<height;i++) { 00066 p = (long *)(addr + (i * rowstride)); 00067 00068 --p; 00069 for(j=0;j<width;j++) { *++p = v; } 00070 } 00071 UnlockPixels(pmh); 00072 } 00073 } 00074 00075 /** 00076 * Determine whether a Jitter matrix can be wrapped in a QuickDraw GWorld (without a copy) 00077 * 00078 * @ingroup qtutilsmod 00079 * 00080 * @param gc optional pointer to a t_gworld_conv_info struct 00081 * @param m input t_jit_matrix pointer 00082 * 00083 * @return long success code (1 = can coerce, 0 = cannot coerce) 00084 */ 00085 long jit_gworld_can_coerce_matrix(t_gworld_conv_info *gc, void *m) 00086 { 00087 t_jit_matrix_info minfo; 00088 long rv=0,savelock; 00089 00090 if (m) { 00091 savelock = (long)jit_object_method(m,_jit_sym_lock,1); 00092 jit_object_method(m,_jit_sym_getinfo,&minfo); 00093 if (minfo.type!=_jit_sym_char) goto out; 00094 if (minfo.planecount!=4) goto out; 00095 if (minfo.dimstride[1]>16382) goto out; //QD maximum 00096 if (gc) { 00097 if (gc->planemap[0]!=0) goto out; 00098 if (gc->planemap[1]!=1) goto out; 00099 if (gc->planemap[2]!=2) goto out; 00100 if (gc->planemap[3]!=3) goto out; 00101 if (gc->flags&JIT_MATRIX_CONVERT_INTERP) goto out; 00102 if (gc->flags&JIT_MATRIX_CONVERT_SRCDIM) goto out; 00103 if (gc->flags&JIT_MATRIX_CONVERT_DSTDIM) goto out; 00104 } 00105 jit_object_method(m,_jit_sym_lock,savelock); 00106 rv = 1; 00107 } 00108 out: 00109 return rv; 00110 } 00111 00112 /** 00113 * Test for equality of dimensions between a QuickDraw GWorld and a Jitter matrix 00114 * Note: supports UYVY matrices 00115 * 00116 * @ingroup qtutilsmod 00117 * 00118 * @param gp input GWorldPtr 00119 * @param m input t_jit_matrix pointer 00120 * 00121 * @return long success code (1 = dims are equal, 0 = dims are not equal) 00122 */ 00123 long jit_gworld_matrix_equal_dim(GWorldPtr gp, void *m) 00124 { 00125 t_jit_matrix_info minfo; 00126 long rv=0,savelock; 00127 Rect r; 00128 PixMapHandle pmh; 00129 long widfactor; 00130 00131 if (gp&&m) { 00132 savelock = (long)jit_object_method(m,_jit_sym_lock,1); 00133 jit_object_method(m,_jit_sym_getinfo,&minfo); 00134 GetPortBounds(gp,&r); 00135 pmh = GetGWorldPixMap(gp); 00136 if ((**pmh).pixelSize == 16) // uyvy 00137 widfactor = 1L; 00138 else 00139 widfactor = 0L; 00140 if (minfo.dim[0] != (ABS(r.right-r.left) >> widfactor)) 00141 goto out; 00142 if (minfo.dim[1] != ABS(r.bottom-r.top)) 00143 goto out; 00144 jit_object_method(m,_jit_sym_lock,savelock); 00145 rv = 1; 00146 } 00147 out: 00148 return rv; 00149 } 00150 00151 00152 /** 00153 * Generate a QuickDraw PixMap for a given Jitter matrix 00154 * 00155 * @ingroup qtutilsmod 00156 * 00157 * @param m input t_jit_matrix pointer 00158 * @param pm on output, a pointer to the generated PixMap 00159 * 00160 * @return t_jit_err error code 00161 * 00162 * @warning The matrix should be locked previous to this call, and unlocked afterward. 00163 */ 00164 //no call to save lock since this should be called outside 00165 t_jit_err jit_coerce_matrix_pixmap(void *m, PixMap *pm) 00166 { 00167 t_jit_matrix_info minfo; 00168 long rv=JIT_ERR_GENERIC; 00169 00170 if (m&&pm) { 00171 jit_object_method(m,_jit_sym_getinfo,&minfo); 00172 //if (!_g_clut) _g_clut = GetCTable(72); //don't know if we really need this 00173 pm->baseAddr = NULL; 00174 jit_object_method(m,_jit_sym_getdata,&pm->baseAddr); 00175 if (!pm->baseAddr) goto out; 00176 00177 if (minfo.dimstride[1]>16382) goto out; //QD maximum 00178 else if (minfo.dim[1]==1) { 00179 // on windows, we need a nonzero dimstride 00180 minfo.dimstride[1] = 4*minfo.dim[0]; 00181 } 00182 pm->rowBytes = minfo.dimstride[1] | 0x8000; //pixmap vs. bitmap 00183 MacSetRect(&pm->bounds,0,0,minfo.dim[0],minfo.dim[1]); 00184 pm->pmVersion = 0; // nothing in reserved 00185 pm->packType = 0; 00186 pm->packSize = 0; 00187 pm->hRes = 0x00480000; // 72 dpi 00188 pm->vRes = 0x00480000; 00189 pm->pixelType = 16; // RGBDirect 00190 pm->pixelSize = 32; 00191 pm->cmpCount = 3; 00192 pm->cmpSize = 8; 00193 #if OLDPIXMAPSTRUCT 00194 pm->planeBytes = 0; 00195 pm->pmTable = NULL; //may need to call GetCTable(), but shouldn't 00196 //pm->pmTable = _g_clut; 00197 pm->pmReserved = 0; 00198 #else 00199 pm->pixelFormat = k32ARGBPixelFormat; 00200 pm->pmTable = NULL; //may need to call GetCTable(), but shouldn't 00201 pm->pmExt = NULL; /*Handle to pixMap extension*/ 00202 #endif 00203 00204 rv = JIT_ERR_NONE; 00205 } 00206 out: 00207 return rv; 00208 }
Copyright © 2008, Cycling '74