Print file number of stored image
This commit is contained in:
parent
dc61ac7f85
commit
59b2022e48
|
@ -1 +1 @@
|
|||
615
|
||||
641
|
||||
|
|
20
src/bmp.c
20
src/bmp.c
|
@ -64,7 +64,7 @@ void BMP_ConstructFilename(int number, char *buffer, unsigned int size)
|
|||
memcpy(buffer + size - 5, ".BMP", 5);
|
||||
}
|
||||
|
||||
void BMP_Save(uint8_t *data, int width, int height)
|
||||
int BMP_Save(uint8_t *data, int width, int height)
|
||||
{
|
||||
FATFS fs;
|
||||
FIL fp;
|
||||
|
@ -74,19 +74,19 @@ void BMP_Save(uint8_t *data, int width, int height)
|
|||
rc = f_mount(&fs, "", 0);
|
||||
if(rc)
|
||||
{
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int file_number = BMP_PickFileNumber();
|
||||
if(file_number == -1)
|
||||
return;
|
||||
return -2;
|
||||
char filename[13];
|
||||
BMP_ConstructFilename(file_number, filename, sizeof(filename));
|
||||
|
||||
rc = f_open(&fp, filename, FA_WRITE | FA_CREATE_NEW);
|
||||
if(rc)
|
||||
{
|
||||
return;
|
||||
return -3;
|
||||
}
|
||||
|
||||
// Rows must be padded to a multiple of 4 bytes
|
||||
|
@ -121,24 +121,26 @@ void BMP_Save(uint8_t *data, int width, int height)
|
|||
};
|
||||
|
||||
if(f_write(&fp, &file_header, sizeof(file_header), &bw) != FR_OK)
|
||||
return;
|
||||
return -4;
|
||||
if(f_write(&fp, &core_header, sizeof(core_header), &bw) != FR_OK)
|
||||
return;
|
||||
return -4;
|
||||
if(f_write(&fp, &colour_table, sizeof(colour_table), &bw) != FR_OK)
|
||||
return;
|
||||
return -4;
|
||||
|
||||
// BMPs are stored with their rows from the bottom upwards
|
||||
for(int y = height - 1; y >= 0; y--)
|
||||
{
|
||||
uint8_t *row = data + y * (width / 8);
|
||||
if(f_write(&fp, row, width / 8, &bw) != FR_OK)
|
||||
return;
|
||||
return -4;
|
||||
if(padding_length != 0)
|
||||
{
|
||||
if(f_write(&fp, padding_bytes, padding_length, &bw) != FR_OK)
|
||||
return;
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
|
||||
f_close(&fp);
|
||||
|
||||
return file_number;
|
||||
}
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void BMP_Save(uint8_t *data, int width, int height);
|
||||
int BMP_Save(uint8_t *data, int width, int height);
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
#define CONFIG_MAX_FRAMES 15
|
||||
|
||||
// Print number of black pixels per captured frame
|
||||
// #define CONFIG_PRINT_EXPOSURE_DEBUG_INFORMATION
|
||||
// #define CONFIG_PRINT_EXPOSURE_DEBUG_INFORMATION
|
||||
|
||||
// Print file number if a file was saved to SD card
|
||||
#define CONFIG_PRINT_FILE_NUMBER
|
26
src/main.c
26
src/main.c
|
@ -14,8 +14,7 @@ int main(void)
|
|||
Camera_Init();
|
||||
LTP1245_Init();
|
||||
|
||||
LTP1245_FeedPaper(100);
|
||||
LTP1245_FeedPaper(10);
|
||||
LTP1245_FeedPaper(50);
|
||||
|
||||
while(!Camera_Captured);
|
||||
|
||||
|
@ -26,8 +25,9 @@ int main(void)
|
|||
char buffer[32] = "Finished after lines: ";
|
||||
itoa(Camera_FinalFrameCount, buffer + strlen(buffer), 10);
|
||||
|
||||
Print_Text(buffer, &Arpegius_32);
|
||||
Print_Text("Black pixel counts:", &Arpegius_32);
|
||||
Print_Text(buffer, &Hannover_Messe_Serif_26, Print_LeftAligned);
|
||||
Print_Text("Black pixel counts:", &Hannover_Messe_Serif_26,
|
||||
Print_LeftAligned);
|
||||
for(int i = 0; i < Camera_FinalFrameCount; i++)
|
||||
{
|
||||
if(i >= (int)(sizeof(Camera_BlackPixelCounts)
|
||||
|
@ -36,14 +36,26 @@ int main(void)
|
|||
break;
|
||||
}
|
||||
itoa(Camera_BlackPixelCounts[i], buffer, 10);
|
||||
Print_Text(buffer, &Arpegius_32);
|
||||
Print_Text(buffer, &Hannover_Messe_Serif_26, Print_LeftAligned);
|
||||
}
|
||||
#endif
|
||||
|
||||
LTP1245_FeedPaper(100);
|
||||
int file_number = BMP_Save(ImageBuffer, CAMERA_IMAGE_WIDTH,
|
||||
CAMERA_IMAGE_HEIGHT);
|
||||
(void)file_number;
|
||||
|
||||
BMP_Save(ImageBuffer, CAMERA_IMAGE_WIDTH, CAMERA_IMAGE_HEIGHT);
|
||||
#ifdef CONFIG_PRINT_FILE_NUMBER
|
||||
LTP1245_FeedPaper(10);
|
||||
char buffer[32] = "- ";
|
||||
if(file_number >= 0)
|
||||
{
|
||||
itoa(file_number, buffer + strlen(buffer), 10);
|
||||
strcpy(buffer + strlen(buffer), " -");
|
||||
Print_Text(buffer, &Hannover_Messe_Serif_26, Print_Centred);
|
||||
}
|
||||
#endif
|
||||
|
||||
LTP1245_FeedPaper(80);
|
||||
LTP1245_FeedPaper(10);
|
||||
|
||||
GPIOC->BRR = (1 << PIN_SUPPLY);
|
||||
|
|
35
src/print.c
35
src/print.c
|
@ -3,12 +3,45 @@
|
|||
|
||||
static uint8_t Print_Buffer[PRINT_BUFFER_LINES * LTP1245_LINE_BYTES];
|
||||
|
||||
void Print_Text(const char *text, const Font_t *font)
|
||||
int Print_MeasureTextWidth(const char *text, const Font_t *font)
|
||||
{
|
||||
char c;
|
||||
int width = 0;
|
||||
while((c = *text++) != 0)
|
||||
{
|
||||
if(c > font->glyphcount + font->charoffset
|
||||
|| c < font->charoffset)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
width += font->glyphs[c - font->charoffset].width;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
void Print_Text(const char *text, const Font_t *font,
|
||||
Print_TextAlignment_t alignment)
|
||||
{
|
||||
int height = font->height;
|
||||
memset(Print_Buffer, 0, LTP1245_LINE_BYTES * height);
|
||||
char c;
|
||||
int xpos = 0;
|
||||
if(alignment != Print_LeftAligned)
|
||||
{
|
||||
int width = Print_MeasureTextWidth(text, font);
|
||||
if(width < LTP1245_LINEWIDTH)
|
||||
{
|
||||
if(alignment == Print_Centred)
|
||||
{
|
||||
xpos = LTP1245_LINEWIDTH / 2 - width / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
xpos = LTP1245_LINEWIDTH - width;
|
||||
}
|
||||
}
|
||||
}
|
||||
while((c = *text++) != 0)
|
||||
{
|
||||
if(c > font->glyphcount + font->charoffset
|
||||
|
|
10
src/print.h
10
src/print.h
|
@ -7,5 +7,13 @@
|
|||
|
||||
#define PRINT_BUFFER_LINES 64
|
||||
|
||||
void Print_Text(const char *text, const Font_t *font);
|
||||
typedef enum
|
||||
{
|
||||
Print_LeftAligned,
|
||||
Print_Centred,
|
||||
Print_RightAligned,
|
||||
} Print_TextAlignment_t;
|
||||
|
||||
void Print_Text(const char *text, const Font_t *font,
|
||||
Print_TextAlignment_t alignment);
|
||||
void Print_Image(const uint8_t *data, int width, int height, int scale);
|
Loading…
Reference in a new issue