Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-2015 committed Dec 31, 2022
2 parents d2a296a + 9240d11 commit c6310c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions 2D/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ cairo_surface_t* cairo_image_surface_create_from_jpg(const char* filename);


//draw a png file to surface
//draw_image <channel>,<file_name>,<dst_x>,<dst_y>,<src_x>,<src_y>,<dst_width>,<dst_height>,<src_width>,<src_height>,<speed>,<max_loops>
//draw_image <channel>,<file_name>,<dst_x>,<dst_y>,<src_x>,<src_y>,<dst_width>,<dst_height>,<src_width>,<src_height>,<speed>,<max_loops>,<gif_trans>
void draw_image(thread_context* context, char* args) {
char filename[MAX_VAL_LEN] = { 0 };
char fileext[MAX_VAL_LEN] = { 0 };
int channel = 0, max_loops = 0, src_x = 0, src_y = 0, src_width = 0, src_height = 0, i;
double dst_x = 0.0, dst_y = 0.0, dst_width = 0.0, dst_height = 0.0;
int gif_trans = 1;
double speed = 1.0;
bool is_gif = false;
gd_GIF* gif = NULL;
Expand Down Expand Up @@ -75,8 +76,9 @@ void draw_image(thread_context* context, char* args) {
args = read_int(args, &src_height);
args = read_double(args, &speed);
args = read_int(args, &max_loops);
args = read_int(args, &gif_trans);

if (debug) printf("draw_image %d,%s,%s,%f,%f,%d,%d,%f,%f,%d,%d,%f,%d\n", channel, filename, fileext, dst_x, dst_y, src_x, src_y, dst_width, dst_height, src_width, src_height, speed, max_loops);
if (debug) printf("draw_image %d,%s,%s,%f,%f,%d,%d,%f,%f,%d,%d,%f,%d,%d\n", channel, filename, fileext, dst_x, dst_y, src_x, src_y, dst_width, dst_height, src_width, src_height, speed, max_loops, gif_trans);


double xScale = dst_width / (float)src_width;
Expand Down Expand Up @@ -108,7 +110,7 @@ void draw_image(thread_context* context, char* args) {
unsigned char* color = gif_buffer;
for (unsigned int y = 0; y < gif->height; y++) {
for (unsigned int x = 0; x < gif->width; x++) {
if (gd_is_bgcolor(gif, color)) {
if ((gif_trans!=0) && (gd_is_bgcolor(gif, color))) {
pixels[y * cairo_stride + x] = 0; //full transparent
}else{
pixels[y * cairo_stride + x] = convert_cairo_color((*((unsigned int*)color)) & 0xFFFFFF);
Expand Down Expand Up @@ -216,4 +218,4 @@ cairo_surface_t * cairo_image_surface_create_from_jpg(const char * filename) {
fclose(infile);

return surface;
}
}
3 changes: 2 additions & 1 deletion COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ draw_circle <channel>,<x>,<y>,<radius>,<color>,<border_width>,<border_color>,<st
* `draw_image` draws an image file

```
draw_image <channel>,<file_name>,<dst_x>,<dst_y>,<src_x>,<src_y>,<dst_width>,<dst_height>,<src_width>,<src_height>,<speed>,<max_loops>
draw_image <channel>,<file_name>,<dst_x>,<dst_y>,<src_x>,<src_y>,<dst_width>,<dst_height>,<src_width>,<src_height>,<speed>,<max_loops>,<gif_trans>
This will paint a JPG, PNG or (animated) GIF to the LED matrix.
# <channel> Channel number
Expand All @@ -590,6 +590,7 @@ This will paint a JPG, PNG or (animated) GIF to the LED matrix.
# <src_height> Source height, change together with src_width
# <speed> If the file is an animated gif, specify here a speed multiplier, for example 2 will play at twice the speed. default is 1
# <max_loops> for animated gif only stop repeating the animation after max_loops, default 0 = inifite loops or loops defined in the GIF
# <gif_trans> Draws GIF background when the value is 0, and transparaent when the value is 1 (default 1)
```

* `draw_line` draws an image file
Expand Down

0 comments on commit c6310c0

Please sign in to comment.