feat: refactor album art handling, implement progress bar display, and update application version to dev63
Some checks failed
Build (3DS) / build (push) Failing after 2m6s
Some checks failed
Build (3DS) / build (push) Failing after 2m6s
This commit is contained in:
@@ -83,16 +83,7 @@ void clearMetadata(struct metadata_t* metadata)
|
||||
memset(metadata->artist, 0, METADATA_ARTIST_MAX);
|
||||
memset(metadata->album, 0, METADATA_ALBUM_MAX);
|
||||
|
||||
if(metadata->albumArt)
|
||||
{
|
||||
free(metadata->albumArt);
|
||||
metadata->albumArt = NULL;
|
||||
}
|
||||
|
||||
metadata->albumArtSize = 0;
|
||||
metadata->albumArtWidth = 0;
|
||||
metadata->albumArtHeight = 0;
|
||||
metadata->hasAlbumArt = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,19 +95,6 @@ void displayMetadata(struct metadata_t* metadata, const char* filename)
|
||||
guiDisplayMetadata(metadata, filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display album art on top screen if available
|
||||
*/
|
||||
void displayAlbumArt(struct metadata_t* metadata)
|
||||
{
|
||||
if(!metadata || !metadata->hasAlbumArt || !metadata->albumArt)
|
||||
return;
|
||||
|
||||
/* For now, just indicate that album art is available */
|
||||
/* Full implementation would require image decoding and display */
|
||||
printf("🖼️ Album Art: %dx%d\n", metadata->albumArtWidth, metadata->albumArtHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract ID3v2 metadata from MP3 file
|
||||
*/
|
||||
@@ -278,51 +256,8 @@ static int extractId3v2Metadata(FILE* fp, struct metadata_t* metadata)
|
||||
}
|
||||
else if(strncmp(frameId, "APIC", 4) == 0) /* Attached Picture */
|
||||
{
|
||||
/* Extract album art data */
|
||||
if(frameSize > 10 && !metadata->hasAlbumArt)
|
||||
{
|
||||
uint8_t* frameData = malloc(frameSize);
|
||||
if(frameData && fread(frameData, 1, frameSize, fp) == frameSize)
|
||||
{
|
||||
/* ID3v2 APIC frame format:
|
||||
* - Text encoding (1 byte)
|
||||
* - MIME type (null-terminated string)
|
||||
* - Picture type (1 byte)
|
||||
* - Description (null-terminated string)
|
||||
* - Picture data
|
||||
*/
|
||||
uint8_t* ptr = frameData;
|
||||
ptr++; /* Skip text encoding */
|
||||
|
||||
/* Skip MIME type */
|
||||
while(*ptr != 0 && (ptr - frameData) < (int)frameSize) ptr++;
|
||||
ptr++; /* Skip null terminator */
|
||||
|
||||
ptr++; /* Skip picture type */
|
||||
|
||||
/* Skip description */
|
||||
while(*ptr != 0 && (ptr - frameData) < (int)frameSize) ptr++;
|
||||
ptr++; /* Skip null terminator */
|
||||
|
||||
/* Remaining data is the image */
|
||||
size_t imageSize = frameSize - (ptr - frameData);
|
||||
if(imageSize > 0)
|
||||
{
|
||||
metadata->albumArt = malloc(imageSize);
|
||||
if(metadata->albumArt)
|
||||
{
|
||||
memcpy(metadata->albumArt, ptr, imageSize);
|
||||
metadata->albumArtSize = imageSize;
|
||||
metadata->hasAlbumArt = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(frameData) free(frameData);
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek(fp, frameSize, SEEK_CUR);
|
||||
}
|
||||
/* Skip album art data */
|
||||
fseek(fp, frameSize, SEEK_CUR);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -496,68 +431,8 @@ static int extractFlacMetadata(FILE* fp, struct metadata_t* metadata)
|
||||
|
||||
if(blockType == 6) /* PICTURE */
|
||||
{
|
||||
/* Extract album art from FLAC picture block */
|
||||
if(!metadata->hasAlbumArt && blockSize > 32)
|
||||
{
|
||||
uint8_t* pictureData = malloc(blockSize);
|
||||
if(pictureData && fread(pictureData, 1, blockSize, fp) == blockSize)
|
||||
{
|
||||
/* FLAC picture block format:
|
||||
* - Picture type (4 bytes BE)
|
||||
* - MIME type length (4 bytes BE)
|
||||
* - MIME type string
|
||||
* - Description length (4 bytes BE)
|
||||
* - Description string
|
||||
* - Width (4 bytes BE)
|
||||
* - Height (4 bytes BE)
|
||||
* - Depth (4 bytes BE)
|
||||
* - Colors (4 bytes BE)
|
||||
* - Picture data length (4 bytes BE)
|
||||
* - Picture data
|
||||
*/
|
||||
uint32_t offset = 4; /* Skip picture type */
|
||||
|
||||
/* Skip MIME type */
|
||||
uint32_t mimeLen = (pictureData[offset] << 24) | (pictureData[offset+1] << 16) |
|
||||
(pictureData[offset+2] << 8) | pictureData[offset+3];
|
||||
offset += 4 + mimeLen;
|
||||
|
||||
/* Skip description */
|
||||
if(offset + 4 <= blockSize)
|
||||
{
|
||||
uint32_t descLen = (pictureData[offset] << 24) | (pictureData[offset+1] << 16) |
|
||||
(pictureData[offset+2] << 8) | pictureData[offset+3];
|
||||
offset += 4 + descLen;
|
||||
}
|
||||
|
||||
/* Skip width, height, depth, colors (16 bytes) */
|
||||
offset += 16;
|
||||
|
||||
/* Get picture data length */
|
||||
if(offset + 4 <= blockSize)
|
||||
{
|
||||
uint32_t picLen = (pictureData[offset] << 24) | (pictureData[offset+1] << 16) |
|
||||
(pictureData[offset+2] << 8) | pictureData[offset+3];
|
||||
offset += 4;
|
||||
|
||||
if(offset + picLen <= blockSize && picLen > 0)
|
||||
{
|
||||
metadata->albumArt = malloc(picLen);
|
||||
if(metadata->albumArt)
|
||||
{
|
||||
memcpy(metadata->albumArt, pictureData + offset, picLen);
|
||||
metadata->albumArtSize = picLen;
|
||||
metadata->hasAlbumArt = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(pictureData) free(pictureData);
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek(fp, blockSize, SEEK_CUR);
|
||||
}
|
||||
/* Skip picture block */
|
||||
fseek(fp, blockSize, SEEK_CUR);
|
||||
}
|
||||
else if(blockType == 4) /* VORBIS_COMMENT */
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user