discoverpixy
Functions
pixy_frame.c File Reference
#include "pixy_frame.h"
#include "pixy.h"
#include "tft.h"
#include <stdlib.h>
Include dependency graph for pixy_frame.c:

Go to the source code of this file.

Functions

static int renderBA81 (uint16_t xpos, uint16_t ypos, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame)
 
static int saveBA81 (FILE_HANDLE *handle, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame)
 
int pixy_render_full_frame (uint16_t x, uint16_t y)
 
int pixy_render_cropped_frame (uint16_t x, uint16_t y, uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height)
 
int pixy_save_full_frame (FILE_HANDLE *handle)
 
int pixy_save_cropped_frame (FILE_HANDLE *handle, uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height)
 
static void interpolateBayer (uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t *r, uint8_t *g, uint8_t *b)
 
int pixy_cc_set_region (uint8_t signum, uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height)
 

Function Documentation

static void interpolateBayer ( uint16_t  width,
uint16_t  x,
uint16_t  y,
uint8_t *  pixel,
uint8_t *  r,
uint8_t *  g,
uint8_t *  b 
)
static

Definition at line 108 of file pixy_frame.c.

109 {
110  if (y & 1) {
111  if (x & 1) {
112  *r = *pixel;
113  *g = (*(pixel - 1) + * (pixel + 1) + * (pixel + width) + * (pixel - width)) >> 2;
114  *b = (*(pixel - width - 1) + * (pixel - width + 1) + * (pixel + width - 1) + * (pixel + width + 1)) >> 2;
115  } else {
116  *r = (*(pixel - 1) + * (pixel + 1)) >> 1;
117  *g = *pixel;
118  *b = (*(pixel - width) + * (pixel + width)) >> 1;
119  }
120  } else {
121  if (x & 1) {
122  *r = (*(pixel - width) + * (pixel + width)) >> 1;
123  *g = *pixel;
124  *b = (*(pixel - 1) + * (pixel + 1)) >> 1;
125  } else {
126  *r = (*(pixel - width - 1) + * (pixel - width + 1) + * (pixel + width - 1) + * (pixel + width + 1)) >> 2;
127  *g = (*(pixel - 1) + * (pixel + 1) + * (pixel + width) + * (pixel - width)) >> 2;
128  *b = *pixel;
129  }
130  }
131 
132 }

Here is the caller graph for this function:

static int renderBA81 ( uint16_t  xpos,
uint16_t  ypos,
uint16_t  width,
uint16_t  height,
uint32_t  frameLen,
uint8_t *  frame 
)
static

Definition at line 139 of file pixy_frame.c.

140 {
141  uint16_t x, y;
142  uint8_t r, g, b;
143 
144 
145  // skip first line
146  frame += width;
147 
148  // don't render top and bottom rows, and left and rightmost columns because of color
149  // interpolation
150  //uint32_t decodedimage[(width-2)*(height-2)];
151  uint16_t* decodedimage = malloc(sizeof(uint16_t) * (width - 2) * (height - 2));
152 
153  if (decodedimage == NULL) { //not enough free space to decode image in memory
154  //decode & render image pixel by pixel
155  for (y = 1; y < height - 1; y++) {
156  frame++;
157 
158  for (x = 1; x < width - 1; x++, frame++) {
159  interpolateBayer(width, x, y, frame, &r, &g, &b);
160  tft_draw_pixel(xpos + x - 1, ypos + y - 1, RGB(r, g, b));
161  }
162 
163  frame++;
164  }
165  } else { //enough space
166  uint16_t* line = decodedimage;
167 
168  for (y = 1; y < height - 1; y++) {
169  //line = (unsigned int *)img.scanLine(y-1);
170  frame++;
171 
172  for (x = 1; x < width - 1; x++, frame++) {
173  interpolateBayer(width, x, y, frame, &r, &g, &b);
174  //*line++ = (0xff<<24) | (r<<16) | (g<<8) | (b<<0);
175  *line++ = RGB(r, g, b);
176  }
177 
178  frame++;
179  }
180 
181  tft_draw_bitmap_unscaled(xpos, ypos, width - 2, height - 2, decodedimage);
182 
183  free(decodedimage);
184  }
185 
186  return 0;
187 }
#define RGB(r, g, b)
Definition: tft.h:48
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat)
Definition: tft.c:72
static void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t *r, uint8_t *g, uint8_t *b)
Definition: pixy_frame.c:108
void tft_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
Definition: tft.c:56

Here is the call graph for this function:

Here is the caller graph for this function:

static int saveBA81 ( FILE_HANDLE handle,
uint16_t  width,
uint16_t  height,
uint32_t  frameLen,
uint8_t *  frame 
)
static

Definition at line 189 of file pixy_frame.c.

190 {
191  uint16_t x, y;
192  uint8_t r, g, b;
193 
194  uint32_t fpos = handle->fpos;
195  uint32_t row_size_padded = ((width - 2) * 3 + 3) & (~3); //row size aligned to 4 bytes
196  uint32_t fpos_end = fpos + row_size_padded * (height - 2);
197 
198 
199  // skip first line
200  frame += width;
201 
202  // don't render top and bottom rows, and left and rightmost columns because of color
203  // interpolation
204 
205  for (y = 1; y < height - 1; y++) {
206  frame++;
207  uint8_t rowbuf[row_size_padded];
208 
209  //Bitmaps are saved "bottom-up". Seek to the right row.
210  if (filesystem_file_seek(handle, fpos_end - row_size_padded * y) != F_OK) {
211  return -1;
212  }
213 
214  for (x = 1; x < width - 1; x++, frame++) {
215  interpolateBayer(width, x, y, frame, &r, &g, &b);
216  //bitmaps are saved in 24bit b,g,r format
217  rowbuf[(x - 1) * 3] = b;
218  rowbuf[(x - 1) * 3 + 1] = g;
219  rowbuf[(x - 1) * 3 + 2] = r;
220  }
221 
222  if (filesystem_file_write(handle, rowbuf, row_size_padded) != F_OK) {
223  return -1;
224  }
225 
226  frame++;
227  }
228 
229  return 0;
230 }
FILE_STATUS filesystem_file_seek(FILE_HANDLE *handle, uint32_t offset)
Definition: filesystem.c:43
static void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t *r, uint8_t *g, uint8_t *b)
Definition: pixy_frame.c:108
FILE_STATUS filesystem_file_write(FILE_HANDLE *handle, uint8_t *buf, uint32_t size)
Definition: filesystem.c:53
uint32_t fpos
The current byte-position in the file.
Definition: filesystem.h:83
Everything ok.
Definition: filesystem.h:91

Here is the call graph for this function:

Here is the caller graph for this function: