コード例 #1
0
ファイル: svg.c プロジェクト: Ever-Never/libaroma
LIBAROMA_CANVASP libaroma_svg_ex(
    LIBAROMA_STREAMP stream,
    byte freeStream,
    byte use_px) {

  LIBAROMA_CANVASP cv = NULL;
  if (!stream) {
    return NULL;
  }
  
  char * data = libaroma_stream_to_string(stream,0);
  if (data){
    NSVGimage *image = NULL;
    if (!use_px){
      image=nsvgParse(data, "dp", ((float) libaroma_fb()->dpi));
    }
    else{
      image=nsvgParse(data, "px", ((float) libaroma_fb()->dpi));
    }
    free(data);
    if (image == NULL) {
  		ALOGW("libaroma_svg: Could not open SVG image.");
  		goto exit;
  	}
  	
  	
  	NSVGrasterizer *rast =nsvgCreateRasterizer();
  	if (rast == NULL) {
  		printf("libaroma_svg: Could not init rasterizer.");
  		nsvgDelete(image);
  		goto exit;
  	}
  	if (!use_px){
  	  cv = libaroma_canvas_ex(libaroma_dp(image->width),libaroma_dp(image->height),1);
  	}
  	else{
  	  cv = libaroma_canvas_ex(image->width,image->height,1);
  	}
  	libaroma_canvas_setcolor(cv,0,0);
  	nsvgRasterize(rast,image,0,0,1,cv);
  	nsvgDelete(image);
  	nsvgDeleteRasterizer(rast);
  }
  
exit:
  if (freeStream) {
    libaroma_stream_close(stream);
  }
  return cv;
}
コード例 #2
0
ファイル: blur.c プロジェクト: ProjectOpenCannibal/libaroma
/*
 * Function    : libaroma_blur_ex
 * Return Value: LIBAROMA_CANVASP
 * Descriptions: create new blur-ed canvas - extended
 */
LIBAROMA_CANVASP libaroma_blur_ex(
    LIBAROMA_CANVASP src,
    const int inRadius,
    byte isMask,
    word maskColor
) {
    if (inRadius < 1) {
        return NULL;
    }
    byte usealpha = (src->alpha ? 1 : 0);
    if (isMask && !usealpha) {
        return NULL;
    }
    float * kernel = _libaroma_blur_kernel(inRadius);
    int radius2 = inRadius * 2;
    int pixels_on_row = radius2 + 1;
    int height = src->h;
    int width = src->w;
    int x, y, o;
    int nwidth = width + radius2;
    int nheight = height + radius2;
    LIBAROMA_CANVASP t1 = libaroma_canvas_ex(nwidth, nheight, usealpha);
    if (!t1) {
        return NULL;
    }
    LIBAROMA_CANVASP t2 = libaroma_canvas_ex(nwidth, nheight, usealpha);
    if (!t2) {
        libaroma_canvas_free(t1);
        return NULL;
    }
    libaroma_canvas_setcolor(t1,0,0);
    if (isMask) {
        libaroma_canvas_setcolor(t2,maskColor,0);
    }
    else {
        libaroma_canvas_setcolor(t2,0,0);
    }

    int sz = nwidth * nheight;
    if (usealpha) {
        memset(t1->alpha, 0, sz);
        memset(t2->alpha, 0, sz);
    }
    int r, g, b, a;
    /* X PASS */
    for (y = 0; y < height; y++) {
        int row = y * src->l;
        int drw = (y + inRadius) * t1->l;
        for (x = 0; x < nwidth; x++) {
            r = g = b = a = 0;
            for (o = 0; o < pixels_on_row; o++) {
                int sx = (x - radius2) + o;
                if (!libaroma_draw_limited(sx, width)) {
                    int pos = row + sx;
                    if (!isMask) {
                        word c = src->data[pos];
                        r += libaroma_color_r(c) * kernel[o];
                        g += libaroma_color_g(c) * kernel[o];
                        b += libaroma_color_b(c) * kernel[o];
                    }
                    if (usealpha) {
                        a += src->alpha[pos] * kernel[o];
                    }
                }
            }
            int dpos = drw + x;
            if (!isMask) {
                r = MAX(MIN(r, 0xff), 0);
                g = MAX(MIN(g, 0xff), 0);
                b = MAX(MIN(b, 0xff), 0);
                t1->data[dpos] = libaroma_dither_rgb(x, y, r, g, b);
                if (usealpha) {
                    a = MAX(MIN(a, 0xff), 0);
                    t1->alpha[dpos] = a;
                }
            }
            else {
                a = MAX(MIN(a, 0xff), 0);
                t1->alpha[dpos] = a;
            }
        }
    }
    /* Y PASS */
    for (y = 0; y < nheight; y++) {
        int row = y * t1->l;
        for (x = 0; x < nwidth; x++) {
            r = g = b = a = 0;
            for (o = 0; o < pixels_on_row; o++) {
                int sy = (y - inRadius) + o;
                if (!libaroma_draw_limited(sy, nheight)) {
                    int pos = (sy * t1->l) + x;
                    if (!isMask) {
                        word c = t1->data[pos];
                        r += libaroma_color_r(c) * kernel[o];
                        g += libaroma_color_g(c) * kernel[o];
                        b += libaroma_color_b(c) * kernel[o];
                    }
                    if (usealpha) {
                        a += t1->alpha[pos] * kernel[o];
                    }
                }
            }
            int dpos = row + x;
            if (!isMask) {
                r = MAX(MIN(r, 0xff), 0);
                g = MAX(MIN(g, 0xff), 0);
                b = MAX(MIN(b, 0xff), 0);
                t2->data[dpos] = libaroma_dither_rgb(x, y, r, g, b);
                if (usealpha) {
                    a = MAX(MIN(a, 0xff), 0);
                    t2->alpha[dpos] = a;
                }
            }
            else {
                a = MAX(MIN(a, 0xff), 0);
                t2->alpha[dpos] = a;
            }
        }
    }
    free(kernel);
    libaroma_canvas_free(t1);
    return t2;
} /* End of libaroma_blur_ex */
コード例 #3
0
ファイル: text_public.c プロジェクト: Ever-Never/libaroma
/*
 * Function    : libaroma_text_draw_line_ex
 * Return Value: int
 * Descriptions: draw text line
 */
int libaroma_text_draw_line_ex(
  LIBAROMA_CANVASP dest,
  LIBAROMA_TEXT text,
  int dx,
  int dy,
  int line,
  byte isshadow,
  int radius,
  word shadow_color,
  byte shadow_opacity
) {
  if (!dest) {
    dest = libaroma_fb()->canvas;
  }
  if ((dy > dest->h) || (dx > dest->w)) {
    return 0;
  }
  if (text) {
    _LIBAROMA_TEXTP txt = (_LIBAROMA_TEXTP) text;
    if (line > txt->n - 1) {
      return 0;
    }
    else if (line < 0) {
      return 0;
    }
    _LIBAROMA_TEXTLINEP line_txt = txt->lines[line];
    _libaroma_pubtext_lock(1);
    if (line_txt->span) {
      if (!isshadow) {
        libaroma_textline_draw(
          dest,
          line_txt,
          dx,
          dy - line_txt->y, 0, 0);
      }
      else if (isshadow>=10) {
        libaroma_textline_draw(
          dest,
          line_txt,
          dx,
          dy - line_txt->y, 1, shadow_color);
      }
      else if (radius > 0) {
        byte light = (isshadow == 2) ? 1 : 0;
        int w = line_txt->maxx - line_txt->minx;
        int h = line_txt->lineheight * 1.5;
        int xx, yy;
        LIBAROMA_CANVASP cv = libaroma_canvas_ex(w, h, 0);
        word trans_color = (light) ? 0xffff : 0x0000;
        word fore_color = (light) ? 0x0000 : 0xffff;
        libaroma_canvas_setcolor(cv, trans_color, 0);
        libaroma_textline_draw(
          cv,
          line_txt,
          0 - line_txt->minx,
          0 - line_txt->y, 1, fore_color);
        cv->alpha = (bytep) calloc(cv->s,1);
        for (yy = 0; yy < cv->h; yy++) {
          int row = cv->l * yy;
          for (xx = 0; xx < cv->w; xx++) {
            int pos = row + xx;
            word c = cv->data[pos];
            if (trans_color == c) {
              cv->alpha[pos] = 0;
            }
            else {
              cv->alpha[pos] = shadow_opacity;
            }
          }
        }
        LIBAROMA_CANVASP gb = libaroma_blur_ex(cv, radius, 1, shadow_color);
        if (gb) {
          libaroma_draw(
            dest,
            gb,
            (dx - radius) + line_txt->minx,
            (dy) - radius,
            1);
          libaroma_canvas_free(gb);
        }
        libaroma_canvas_free(cv);
      }
    }
    _libaroma_pubtext_lock(0);
    return line_txt->lineheight;
  }
  return 0;
} /* End of libaroma_text_draw_line_ex */
コード例 #4
0
ファイル: artworker.c プロジェクト: Ever-Never/libaroma
/*
 * Function    : libaroma_art_busy_progress
 * Return Value: LIBAROMA_CANVASP
 * Descriptions: create busy progress sprite canvas
 */
LIBAROMA_CANVASP libaroma_art_busy_progress(
    word basecolor) {
  int i, j;
  
  /* calculate size */
  int dp1   = libaroma_dp(1);
  int dp36  = libaroma_dp(36);
  int dp72  = libaroma_dp(72);
  int dp144 = dp72 * 2;
  int dp288 = dp144 * 2;
  int dp28  = libaroma_dp(28);
  int dp56  = dp28 * 2;
  int dp116 = dp144 - dp28;
  
  /* main + temp canvas */
  LIBAROMA_CANVASP load  = libaroma_canvas_ex(dp72 * 13, dp72, 1);
  if (!load){
    return NULL;
  }
  LIBAROMA_CANVASP load1 = libaroma_canvas_ex(dp288, dp288, 1);
  if (!load1){
    libaroma_canvas_free(load);
    return NULL;
  }
  LIBAROMA_CANVASP load2 = libaroma_canvas_ex(dp56, dp56, 1);
  if (!load2){
    libaroma_canvas_free(load1);
    libaroma_canvas_free(load);
    return NULL;
  }
  
  /* cleanup */
  libaroma_canvas_setcolor(load, 0x0000, 0);
  
  /* frame loop */
  for (j = 0; j < 13; j++) {
    /* angle per frame */
    double added = ((27.69230769230769 * j) / 360);
    
    /* cleanup load1 */
    libaroma_canvas_setcolor(load1, 0x0000, 0);
    
    /* circle draw */
    for (i = 0; i < 12; i++) {
      /* position */
      double angle = 2 * __PI * ((((double) i) / 12.0) + added);
      int xpos     = round(dp116 * cos(angle));
      int ypos     = round(dp116 * sin(angle));
      
      /* cleanup load2 */
      libaroma_canvas_setcolor(load2, 0x0000, 0);
      int b = 2;
      
      /* draw */
      libaroma_gradient_ex(
        load2,
        b * dp1,
        b * dp1,
        dp56 - (b * dp1 * 2),
        dp56 - (b * dp1 * 2),
        basecolor,
        basecolor,
        dp28,
        0x1111,
        MIN(0xff, ((i + 1) * 18) + 39),
        MIN(0xff, ((i + 1) * 18))
      );
      
      /* Stretch Copy to load1 */
      libaroma_draw_scale_smooth(
        load1,
        load2,
        dp144 + xpos - dp28,
        dp144 + ypos - dp28,
        dp56,
        dp56,
        0,
        0,
        dp56,
        dp56
      );
    }
    
    /* Stretch Copy to load canvas */
    libaroma_draw_scale_smooth(
      load,
      load1,
      j * dp72,
      0,
      dp72,
      dp72,
      0,
      0,
      dp288,
      dp288
    );
  }
  
  /* free temp canvases */
  libaroma_canvas_free(load1);
  libaroma_canvas_free(load2);
  
  /* return canvas */
  LIBAROMA_CANVASP load_out =
    libaroma_canvas_ex(dp36 * 13, dp36, 1);
  if (!load_out){
    libaroma_canvas_free(load);
    return NULL;
  }
  libaroma_canvas_setcolor(load_out, 0x0000, 0);
  
  /* draw */
  libaroma_draw_scale_smooth(
    load_out, load,
    0, 0, dp36 * 13, dp36,
    0, 0, dp72 * 13, dp72
  );
  libaroma_canvas_free(load);
  return load_out;
} /* End of libaroma_art_busy_progress */