Print file number of stored image

This commit is contained in:
fruchti 2024-12-18 22:01:04 +01:00
parent dc61ac7f85
commit 59b2022e48
7 changed files with 79 additions and 21 deletions

View file

@ -1 +1 @@
615 641

View file

@ -64,7 +64,7 @@ void BMP_ConstructFilename(int number, char *buffer, unsigned int size)
memcpy(buffer + size - 5, ".BMP", 5); 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; FATFS fs;
FIL fp; FIL fp;
@ -74,19 +74,19 @@ void BMP_Save(uint8_t *data, int width, int height)
rc = f_mount(&fs, "", 0); rc = f_mount(&fs, "", 0);
if(rc) if(rc)
{ {
return; return -1;
} }
int file_number = BMP_PickFileNumber(); int file_number = BMP_PickFileNumber();
if(file_number == -1) if(file_number == -1)
return; return -2;
char filename[13]; char filename[13];
BMP_ConstructFilename(file_number, filename, sizeof(filename)); BMP_ConstructFilename(file_number, filename, sizeof(filename));
rc = f_open(&fp, filename, FA_WRITE | FA_CREATE_NEW); rc = f_open(&fp, filename, FA_WRITE | FA_CREATE_NEW);
if(rc) if(rc)
{ {
return; return -3;
} }
// Rows must be padded to a multiple of 4 bytes // 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) 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) 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) 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 // BMPs are stored with their rows from the bottom upwards
for(int y = height - 1; y >= 0; y--) for(int y = height - 1; y >= 0; y--)
{ {
uint8_t *row = data + y * (width / 8); uint8_t *row = data + y * (width / 8);
if(f_write(&fp, row, width / 8, &bw) != FR_OK) if(f_write(&fp, row, width / 8, &bw) != FR_OK)
return; return -4;
if(padding_length != 0) if(padding_length != 0)
{ {
if(f_write(&fp, padding_bytes, padding_length, &bw) != FR_OK) if(f_write(&fp, padding_bytes, padding_length, &bw) != FR_OK)
return; return -4;
} }
} }
f_close(&fp); f_close(&fp);
return file_number;
} }

View file

@ -4,4 +4,4 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
void BMP_Save(uint8_t *data, int width, int height); int BMP_Save(uint8_t *data, int width, int height);

View file

@ -18,4 +18,7 @@
#define CONFIG_MAX_FRAMES 15 #define CONFIG_MAX_FRAMES 15
// Print number of black pixels per captured frame // 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

View file

@ -14,8 +14,7 @@ int main(void)
Camera_Init(); Camera_Init();
LTP1245_Init(); LTP1245_Init();
LTP1245_FeedPaper(100); LTP1245_FeedPaper(50);
LTP1245_FeedPaper(10);
while(!Camera_Captured); while(!Camera_Captured);
@ -26,8 +25,9 @@ int main(void)
char buffer[32] = "Finished after lines: "; char buffer[32] = "Finished after lines: ";
itoa(Camera_FinalFrameCount, buffer + strlen(buffer), 10); itoa(Camera_FinalFrameCount, buffer + strlen(buffer), 10);
Print_Text(buffer, &Arpegius_32); Print_Text(buffer, &Hannover_Messe_Serif_26, Print_LeftAligned);
Print_Text("Black pixel counts:", &Arpegius_32); Print_Text("Black pixel counts:", &Hannover_Messe_Serif_26,
Print_LeftAligned);
for(int i = 0; i < Camera_FinalFrameCount; i++) for(int i = 0; i < Camera_FinalFrameCount; i++)
{ {
if(i >= (int)(sizeof(Camera_BlackPixelCounts) if(i >= (int)(sizeof(Camera_BlackPixelCounts)
@ -36,14 +36,26 @@ int main(void)
break; break;
} }
itoa(Camera_BlackPixelCounts[i], buffer, 10); itoa(Camera_BlackPixelCounts[i], buffer, 10);
Print_Text(buffer, &Arpegius_32); Print_Text(buffer, &Hannover_Messe_Serif_26, Print_LeftAligned);
} }
#endif #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); LTP1245_FeedPaper(10);
GPIOC->BRR = (1 << PIN_SUPPLY); GPIOC->BRR = (1 << PIN_SUPPLY);

View file

@ -3,12 +3,45 @@
static uint8_t Print_Buffer[PRINT_BUFFER_LINES * LTP1245_LINE_BYTES]; 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; int height = font->height;
memset(Print_Buffer, 0, LTP1245_LINE_BYTES * height); memset(Print_Buffer, 0, LTP1245_LINE_BYTES * height);
char c; char c;
int xpos = 0; 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) while((c = *text++) != 0)
{ {
if(c > font->glyphcount + font->charoffset if(c > font->glyphcount + font->charoffset

View file

@ -7,5 +7,13 @@
#define PRINT_BUFFER_LINES 64 #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); void Print_Image(const uint8_t *data, int width, int height, int scale);