LCOV - code coverage report
Current view: top level - monetdb5/modules/kernel - batcolor.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 19 15.8 %
Date: 2021-10-13 02:24:04 Functions: 2 18 11.1 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * M.L. Kersten
      11             :  * Color multiplexes
      12             :  * [TODO: property propagations and general testing]
      13             :  * The collection of routines provided here are map operations
      14             :  * for the color string primitives.
      15             :  *
      16             :  * In line with the batcalc module, we assume that if two bat operands
      17             :  * are provided that they are aligned.
      18             :  */
      19             : 
      20             : #include "monetdb_config.h"
      21             : #include "gdk.h"
      22             : #include <string.h>
      23             : #include "mal.h"
      24             : #include "color.h"
      25             : #include "mal_exception.h"
      26             : 
      27             : #include "mel.h"
      28             : 
      29             : #define BATwalk(NAME,FUNC,TYPE1,ISNIL,TYPE2,TPE,APP)                                    \
      30             : static str CLRbat##NAME(bat *ret, const bat *l)                                                 \
      31             : {                                                                                                                                               \
      32             :         BATiter bi;                                                                                                                     \
      33             :         BAT *bn, *b;                                                                                                            \
      34             :         BUN p,q;                                                                                                                        \
      35             :         const TYPE1 *x;                                                                                                         \
      36             :         TYPE2 y;                                                                                                                        \
      37             :         char *msg = MAL_SUCCEED;                                                                                        \
      38             :                                                                                                                                                 \
      39             :         if( (b= BATdescriptor(*l)) == NULL )                                                            \
      40             :                 throw(MAL, "batcolor." #NAME, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \
      41             :         bn= COLnew(b->hseqbase,TPE,BATcount(b), TRANSIENT);                                  \
      42             :         if( bn == NULL){                                                                                                        \
      43             :                 BBPunfix(b->batCacheid);                                                                             \
      44             :                 throw(MAL, "batcolor." #NAME, SQLSTATE(HY013) MAL_MALLOC_FAIL);       \
      45             :         }                                                                                                                                       \
      46             :         bn->tsorted=false;                                                                                                   \
      47             :         bn->trevsorted=false;                                                                                                \
      48             :         bn->tnil = false;                                                                                                    \
      49             :         bn->tnonil = true;                                                                                                   \
      50             :                                                                                                                                                 \
      51             :         bi = bat_iterator(b);                                                                                           \
      52             :                                                                                                                                                 \
      53             :         BATloop(b, p, q) {                                                                                                      \
      54             :                 x= (const TYPE1 *) BUNtail(bi,p);                                                               \
      55             :                 if (x== 0 || ISNIL(*x)) {                                                                               \
      56             :                         y = (TYPE2) TYPE2##_nil;                                                                        \
      57             :                         bn->tnonil = false;                                                                                  \
      58             :                         bn->tnil = true;                                                                                     \
      59             :                 } else if ((msg = FUNC(&y,x)) != MAL_SUCCEED)                                       \
      60             :                         goto bunins_failed;                                                                                     \
      61             :                 if ((APP) != GDK_SUCCEED)                                                                               \
      62             :                         goto bunins_failed;                                                                                     \
      63             :         }                                                                                                                                       \
      64             :         bat_iterator_end(&bi);                                                                                              \
      65             :         bn->theap->dirty |= BATcount(bn) > 0;                                                          \
      66             :         *ret = bn->batCacheid;                                                                                               \
      67             :         BBPkeepref(*ret);                                                                                                       \
      68             :         BBPunfix(b->batCacheid);                                                                                     \
      69             :         return MAL_SUCCEED;                                                                                                     \
      70             : bunins_failed:                                                                                                                  \
      71             :         bat_iterator_end(&bi);                                                                                              \
      72             :         BBPunfix(b->batCacheid);                                                                                     \
      73             :         BBPunfix(bn->batCacheid);                                                                                    \
      74             :         if (msg)                                                                                                                        \
      75             :                 return msg;                                                                                                             \
      76             :         throw(MAL, "batcolor." #NAME, OPERATION_FAILED " During bulk operation"); \
      77             : }
      78             : 
      79           0 : BATwalk(Color,CLRcolor,char *,strNil,color,getAtomIndex("color",5,TYPE_int),bunfastappTYPE(color, bn, &y))
      80           0 : BATwalk(Str,CLRstr,color,is_color_nil,str,TYPE_str,bunfastapp_nocheckVAR(bn, &y))
      81             : 
      82           4 : BATwalk(Red,CLRred,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      83           0 : BATwalk(Green,CLRgreen,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      84           0 : BATwalk(Blue,CLRblue,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      85             : 
      86           0 : BATwalk(Hue,CLRhue,color,is_color_nil,flt,TYPE_flt,bunfastappTYPE(flt, bn, &y))
      87           0 : BATwalk(Saturation,CLRsaturation,color,is_color_nil,flt,TYPE_flt,bunfastappTYPE(flt, bn, &y))
      88           0 : BATwalk(Value,CLRvalue,color,is_color_nil,flt,TYPE_flt,bunfastappTYPE(flt, bn, &y))
      89             : 
      90           0 : BATwalk(HueInt,CLRhueInt,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      91           0 : BATwalk(SaturationInt,CLRsaturationInt,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      92           0 : BATwalk(ValueInt,CLRvalueInt,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      93             : 
      94           0 : BATwalk(Luminance,CLRluminance,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      95           0 : BATwalk(Cr,CLRcr,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      96           0 : BATwalk(Cb,CLRcb,color,is_color_nil,int,TYPE_int,bunfastappTYPE(int, bn, &y))
      97             : 
      98             : #define BATwalk3(NAME,FUNC,TYPE)                                                                                \
      99             : static str CLRbat##NAME(bat *ret, const bat *l, const bat *bid2, const bat *bid3) \
     100             : {                                                                                                                                               \
     101             :         BATiter bi, b2i, b3i;                                                                                           \
     102             :         BAT *bn, *b2,*b3, *b;                                                                                           \
     103             :         BUN p,q;                                                                                                                        \
     104             :         const TYPE *x, *x2, *x3;                                                                                        \
     105             :         color y;                                                                                                                        \
     106             :         char *msg = MAL_SUCCEED;                                                                                        \
     107             :                                                                                                                                                 \
     108             :         b= BATdescriptor(*l);                                                                                           \
     109             :         b2= BATdescriptor(*bid2);                                                                                       \
     110             :         b3= BATdescriptor(*bid3);                                                                                       \
     111             :         if (b == NULL || b2 == NULL || b3 == NULL) {                                            \
     112             :                 if (b)                                                                                                                  \
     113             :                         BBPunfix(b->batCacheid);                                                                     \
     114             :                 if (b2)                                                                                                                 \
     115             :                         BBPunfix(b2->batCacheid);                                                                    \
     116             :                 if (b3)                                                                                                                 \
     117             :                         BBPunfix(b3->batCacheid);                                                                    \
     118             :                 throw(MAL, "batcolor." #NAME, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING); \
     119             :         }                                                                                                                                       \
     120             :         bn= COLnew(b->hseqbase,getAtomIndex("color",5,TYPE_int),BATcount(b), TRANSIENT); \
     121             :         if( bn == NULL){                                                                                                        \
     122             :                 BBPunfix(b->batCacheid);                                                                             \
     123             :                 BBPunfix(b2->batCacheid);                                                                            \
     124             :                 BBPunfix(b3->batCacheid);                                                                            \
     125             :                 throw(MAL, "batcolor." #NAME, SQLSTATE(HY013) MAL_MALLOC_FAIL);       \
     126             :         }                                                                                                                                       \
     127             :         bn->tsorted=false;                                                                                                   \
     128             :         bn->trevsorted=false;                                                                                                \
     129             :         bn->tnil = false;                                                                                                    \
     130             :         bn->tnonil = true;                                                                                                   \
     131             :                                                                                                                                                 \
     132             :         bi = bat_iterator(b);                                                                                           \
     133             :         b2i = bat_iterator(b2);                                                                                         \
     134             :         b3i = bat_iterator(b3);                                                                                         \
     135             :                                                                                                                                                 \
     136             :         BATloop(b, p, q) {                                                                                                      \
     137             :                 x= (const TYPE *) BUNtail(bi,p);                                                                \
     138             :                 x2= (const TYPE *) BUNtail(b2i,p);                                                              \
     139             :                 x3= (const TYPE *) BUNtail(b3i,p);                                                              \
     140             :                 if (x== 0 || is_##TYPE##_nil(*x) ||                                                             \
     141             :                         x2== 0 || is_##TYPE##_nil(*x2) ||                                                       \
     142             :                         x3== 0 || is_##TYPE##_nil(*x3)) {                                                       \
     143             :                         y = color_nil;                                                                                          \
     144             :                         bn->tnonil = false;                                                                                  \
     145             :                         bn->tnil = true;                                                                                     \
     146             :                 } else if ((msg = FUNC(&y,x,x2,x3)) != MAL_SUCCEED)                         \
     147             :                         goto bunins_failed;                                                                                     \
     148             :                 if (bunfastappTYPE(color, bn, &y) != GDK_SUCCEED)                           \
     149             :                         goto bunins_failed;                                                                                     \
     150             :         }                                                                                                                                       \
     151             :         bat_iterator_end(&bi);                                                                                              \
     152             :         bat_iterator_end(&b2i);                                                                                             \
     153             :         bat_iterator_end(&b3i);                                                                                             \
     154             :         bn->theap->dirty |= BATcount(bn) > 0;                                                          \
     155             :         *ret = bn->batCacheid;                                                                                               \
     156             :         BBPkeepref(*ret);                                                                                                       \
     157             :         BBPunfix(b->batCacheid);                                                                                     \
     158             :         BBPunfix(b2->batCacheid);                                                                                    \
     159             :         BBPunfix(b3->batCacheid);                                                                                    \
     160             :         return MAL_SUCCEED;                                                                                                     \
     161             : bunins_failed:                                                                                                                  \
     162             :         bat_iterator_end(&bi);                                                                                              \
     163             :         bat_iterator_end(&b2i);                                                                                             \
     164             :         bat_iterator_end(&b3i);                                                                                             \
     165             :         BBPunfix(b->batCacheid);                                                                                     \
     166             :         BBPunfix(b2->batCacheid);                                                                                    \
     167             :         BBPunfix(b3->batCacheid);                                                                                    \
     168             :         BBPunfix(bn->batCacheid);                                                                                    \
     169             :         if (msg)                                                                                                                        \
     170             :                 return msg;                                                                                                             \
     171             :         throw(MAL, "batcolor." #NAME, OPERATION_FAILED " During bulk operation"); \
     172             : }
     173             : 
     174           0 : BATwalk3(Hsv,CLRhsv,flt)
     175           0 : BATwalk3(Rgb,CLRrgb,int)
     176           0 : BATwalk3(ycc,CLRycc,int)
     177             : 
     178             : #include "mel.h"
     179             : mel_func batcolor_init_funcs[] = {
     180             :  command("batcolor", "str", CLRbatStr, false, "Identity mapping for string bats", args(1,2, batarg("",str),batarg("b",color))),
     181             :  command("batcolor", "color", CLRbatColor, false, "Converts string to color", args(1,2, batarg("",color),batarg("s",str))),
     182             :  command("batcolor", "rgb", CLRbatRgb, false, "Converts an RGB triplets to a color atom", args(1,4, batarg("",color),batarg("r",int),batarg("g",int),batarg("b",int))),
     183             :  command("batcolor", "red", CLRbatRed, false, "Extracts red component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     184             :  command("batcolor", "green", CLRbatGreen, false, "Extracts green component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     185             :  command("batcolor", "blue", CLRbatBlue, false, "Extracts blue component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     186             :  command("batcolor", "hue", CLRbatHueInt, false, "Extracts hue component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     187             :  command("batcolor", "saturation", CLRbatSaturationInt, false, "Extracts saturation component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     188             :  command("batcolor", "value", CLRbatValueInt, false, "Extracts value component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     189             :  command("batcolor", "hsv", CLRbatHsv, false, "Converts an HSV triplets to a color atom", args(1,4, batarg("",color),batarg("h",flt),batarg("s",flt),batarg("v",flt))),
     190             :  command("batcolor", "hue", CLRbatHue, false, "Extracts hue component from a color atom", args(1,2, batarg("",flt),batarg("c",color))),
     191             :  command("batcolor", "saturation", CLRbatSaturation, false, "Extracts saturation component from a color atom", args(1,2, batarg("",flt),batarg("c",color))),
     192             :  command("batcolor", "value", CLRbatValue, false, "Extracts value component from a color atom", args(1,2, batarg("",flt),batarg("c",color))),
     193             :  command("batcolor", "ycc", CLRbatycc, false, "Converts an YCC triplets to a color atom", args(1,4, batarg("",color),batarg("y",flt),batarg("cr",flt),batarg("cb",flt))),
     194             :  command("batcolor", "luminance", CLRbatLuminance, false, "Extracts Y(luminance) component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     195             :  command("batcolor", "cr", CLRbatCr, false, "Extracts Cr(red color) component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     196             :  command("batcolor", "cb", CLRbatCb, false, "Extracts Cb(blue color) component from a color atom", args(1,2, batarg("",int),batarg("c",color))),
     197             :  { .imp=NULL }
     198             : };
     199             : #include "mal_import.h"
     200             : #ifdef _MSC_VER
     201             : #undef read
     202             : #pragma section(".CRT$XCU",read)
     203             : #endif
     204         259 : LIB_STARTUP_FUNC(init_batcolor_mal)
     205         259 : { mal_module("batcolor", NULL, batcolor_init_funcs); }

Generated by: LCOV version 1.14