📄 batcolor.mx
字号:
@' The contents of this file are subject to the MonetDB Public License@' Version 1.1 (the "License"); you may not use this file except in@' compliance with the License. You may obtain a copy of the License at@' http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html@'@' Software distributed under the License is distributed on an "AS IS"@' basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the@' License for the specific language governing rights and limitations@' under the License.@'@' The Original Code is the MonetDB Database System.@'@' The Initial Developer of the Original Code is CWI.@' Portions created by CWI are Copyright (C) 1997-2007 CWI.@' All Rights Reserved.@f batcolor@a M.L. Kersten@+ Color multiplexes[TODO: property propagations and general testing]The collection of routines provided here are map operationsfor the color string primitives. In line with the batcalc module, we assume thatif two bat operands are provided that they are alreadyaligned on the head. Moreover, the head of the BATsare limited to :oid, which can be cheaply realized usingthe GRPsplit operation.@{@malmodule batcolor;command str(b:bat[:oid,:color]):bat[:oid,:str]address CLRbatStrcomment "Identity mapping for string bats";command color(s:bat[:oid,:str]):bat[:oid,:color]address CLRbatColorcomment "Converts string to color";command rgb(r:bat[:oid,:int], g:bat[:oid,:int], b:bat[:oid,:int]):bat[:oid,:color] address CLRbatRgbcomment "Converts an RGB triplets to a color atom";command red(c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatRedcomment "Extracts red component from a color atom";command green(c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatGreencomment "Extracts green component from a color atom";command blue (c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatBluecomment "Extracts blue component from a color atom";command hue(c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatHueIntcomment "Extracts hue component from a color atom";command saturation(c:bat[:oid,:color]) :bat[:oid,:int]address CLRbatSaturationIntcomment "Extracts saturation component from a color atom";command value(c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatValueIntcomment "Extracts value component from a color atom";command hsv(h:bat[:oid,:flt],s:bat[:oid,:flt], v:bat[:oid,:flt]) :bat[:oid,:color] address CLRbatHsvcomment "Converts an HSV triplets to a color atom";command hue(c:bat[:oid,:color]) :bat[:oid,:flt] address CLRbatHuecomment "Extracts hue component from a color atom";command saturation(c:bat[:oid,:color]) :bat[:oid,:flt] address CLRbatSaturationcomment "Extracts saturation component from a color atom";command value(c:bat[:oid,:color]) :bat[:oid,:flt] address CLRbatValuecomment "Extracts value component from a color atom";#command ycc(y:bat[:oid,:int],cr:bat[:oid,:int],cb:bat[:oid,:int]) :bat[:oid,:color] #address CLRbatycc#comment "Converts an YCC triplets to a color atom";command luminance (c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatLuminancecomment "Extracts Y(luminance) component from a color atom";command cr(c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatCrcomment "Extracts Cr(red color) component from a color atom";command cb(c:bat[:oid,:color]) :bat[:oid,:int] address CLRbatCbcomment "Extracts Cb(blue color) component from a color atom";@+ Implementation@c#include "mal_config.h"#include <gdk.h>#include <string.h>#include <mal.h>#include <color.h>#include "mal_exception.h"#ifdef WIN32#ifndef LIBBATCOLOR#define batcolor_export extern __declspec(dllimport)#else#define batcolor_export extern __declspec(dllexport)#endif#else#define batcolor_export extern#endif#ifdef HAVE_LANGINFO_H#include <langinfo.h>#endif#ifdef HAVE_ICONV_H#include <iconv.h>#endif#define prepareOperand(X,Y,Z) \ if( (X= BATdescriptor(*Y)) == NULL ) \ throw(MAL, "batstr." Z, "Cannot access descriptor");#define prepareOperand2(X,Y,A,B,Z) \ if( (X= BATdescriptor(*Y)) == NULL ) \ throw(MAL, "batstr." Z, "Cannot access descriptor"); \ if( (A= BATdescriptor(*B)) == NULL ){\ BBPreleaseref(X->batCacheid); \ throw(MAL, "batstr."Z, "Cannot access descriptor"); \ }#define prepareResult(X,Y,T,Z) \ X= BATnew(Y->htype,T,BATcount(Y)); \ if( Y->htype== TYPE_void) \ BATseqbase(X, Y->hseqbase); \ if( X == NULL){ \ BBPreleaseref(Y->batCacheid); \ throw(MAL, "batstr." Z, "no space available "); \ } \ X->hsorted=Y->hsorted; \ X->tsorted=0; #define finalizeResult(X,Y,Z) \ if (!((Y)->batDirty&2)) (Y) = BATsetaccess((Y), BAT_READ); \ *X = (Y)->batCacheid; \ BBPkeepref(*(X));\ BBPreleaseref(Z->batCacheid);@= BATwalkbatcolor_export str CLRbat@1(int *ret, int *l);str CLRbat@1(int *ret, int *l){ BAT *bn, *b; BUN p,q; int xx; @3 *x; @4 y, *yp = &y; prepareOperand(b,l,"@1"); prepareResult(bn,b,getTypeIndex("@4",-1,TYPE_int),"@1"); BATloopFast(b, p, q, xx) { ptr h = BUNhead(b,p); x= (@3 *) BUNtail(b,p); if(x== 0 || *x == @3_nil) y = (@4)@4_nil; else @2(yp,x); bunfastins(bn, h, yp); } finalizeResult(ret,bn,b); return MAL_SUCCEED;bunins_failed: BBPreleaseref(b->batCacheid); BBPreleaseref(bn->batCacheid); throw(MAL, "batstr.==", "bunins failed");}@c@:BATwalk(Color,CLRcolor,str,color)@@:BATwalk(Str,CLRstr,color,str)@@:BATwalk(Red,CLRred,color,int)@@:BATwalk(Green,CLRgreen,color,int)@@:BATwalk(Blue,CLRblue,color,int)@@:BATwalk(Hue,CLRhue,color,flt)@@:BATwalk(Saturation,CLRsaturation,color,flt)@@:BATwalk(Value,CLRvalue,color,flt)@@:BATwalk(HueInt,CLRhueInt,color,int)@@:BATwalk(SaturationInt,CLRsaturationInt,color,int)@@:BATwalk(ValueInt,CLRvalueInt,color,int)@@:BATwalk(Luminance,CLRluminance,color,int)@@:BATwalk(Cr,CLRcr,color,int)@@:BATwalk(Cb,CLRcb,color,int)@@-A few triple versions.@= BATwalk3batcolor_export str CLRbat@1(int *ret, int *l, int *bid2, int *bid3);str CLRbat@1(int *ret, int *l, int *bid2, int *bid3){ BAT *bn, *b2,*b3, *b; BUN p,q,p2,p3; int xx; @3 *x, *x2, *x3; @4 y, *yp = &y; prepareOperand(b,l,"@1"); b2= BATdescriptor(*bid2); if(b2== NULL) throw(MAL, "batcolor.@1","can not access BAT"); b3= BATdescriptor(*bid3); if(b3== NULL) throw(MAL, "batcolor.@1","can not access BAT"); prepareResult(bn,b,getTypeIndex("@4",-1,TYPE_int),"@1"); p2= BUNfirst(b2); p3= BUNfirst(b3); BATloopFast(b, p, q, xx) { ptr h = BUNhead(b,p); x= (@3 *) BUNtail(b,p); x2= (@3 *) BUNtail(b2,p); x3= (@3 *) BUNtail(b3,p); if(x== 0 || *x == @3_nil || x2== 0 || *x2 == @3_nil || x3== 0 || *x3 == @3_nil) y= @4_nil; else @2(yp,x,x2,x3); bunfastins(bn, h, yp); p2+= BUNsize(b2); p3+= BUNsize(b3); } finalizeResult(ret,bn,b); return MAL_SUCCEED;bunins_failed: BBPreleaseref(b->batCacheid); BBPreleaseref(bn->batCacheid); throw(MAL, "batstr.==", "bunins failed");}@c@:BATwalk3(Hsv,CLRhsv,flt,color)@@:BATwalk3(Rgb,CLRrgb,int,color)@@:BATwalk3(ycc,CLRycc,int,color)@@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -