fix: logo cores e tamanho
Some checks failed
Deploy QR Rapido / test (push) Successful in 3m39s
Deploy QR Rapido / build-and-push (push) Failing after 5s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Has been skipped

This commit is contained in:
Ricardo Carneiro 2025-08-04 01:22:29 -03:00
parent 9b094ed712
commit 5f0d3dbf66
3 changed files with 51 additions and 17 deletions

View File

@ -301,6 +301,10 @@ namespace QRRapidoApp.Controllers
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
var isAuthenticated = User?.Identity?.IsAuthenticated ?? false;
// DEBUG: Log detalhado dos parâmetros recebidos
_logger.LogInformation("🔍 [DEBUG] GenerateRapidWithLogo called - RequestId: {RequestId}, ApplyLogoColorization: {ApplyLogoColorization}, LogoSizePercent: {LogoSizePercent}, HasLogo: {HasLogo}",
requestId, request.ApplyLogoColorization, request.LogoSizePercent, request.HasLogo);
using (_logger.BeginScope(new Dictionary<string, object>
{
["RequestId"] = requestId,

View File

@ -265,7 +265,12 @@ namespace QRRapidoApp.Services
}));
using var outputStream = new MemoryStream();
resizedImage.Save(outputStream, new PngEncoder());
// Preservar formato e cores originais ao redimensionar
resizedImage.Save(outputStream, new PngEncoder
{
ColorType = PngColorType.RgbWithAlpha,
CompressionLevel = PngCompressionLevel.DefaultCompression
});
var resizedBytes = outputStream.ToArray();
_logger.LogInformation("Logo redimensionado: {OriginalSize} -> {NewSize} bytes",
@ -491,13 +496,16 @@ namespace QRRapidoApp.Services
var backgroundY = (qrImage.Height - backgroundSize) / 2;
// MELHORIA: Aplicar colorização se solicitado
_logger.LogDebug("Processing logo - Apply colorization: {ApplyColorization}",
request.ApplyLogoColorization);
_logger.LogInformation("🎨 [LOGO DEBUG] Processing logo - ApplyColorization: {ApplyColorization}, PrimaryColor: {PrimaryColor}",
request.ApplyLogoColorization, request.PrimaryColor);
using Image finalLogo = request.ApplyLogoColorization
? ApplyLogoColorization(logoImage, request.PrimaryColor)
: logoImage.Clone(ctx => { }); // Create a copy to avoid disposing the original
_logger.LogInformation("🎨 [LOGO DEBUG] Logo processing path: {Path}",
request.ApplyLogoColorization ? "COLORIZED" : "ORIGINAL_COLORS");
if (finalLogo == null)
{
_logger.LogError("Final logo is null after processing, cannot apply logo overlay");
@ -531,7 +539,11 @@ namespace QRRapidoApp.Services
// Convert back to byte array
_logger.LogDebug("Saving final image with logo overlay");
using var outputStream = new MemoryStream();
finalImage.Save(outputStream, new PngEncoder());
finalImage.Save(outputStream, new PngEncoder
{
ColorType = PngColorType.RgbWithAlpha,
CompressionLevel = PngCompressionLevel.DefaultCompression
});
var result = outputStream.ToArray();
_logger.LogInformation("Logo overlay completed successfully - Final image size: {FinalSize} bytes",
@ -570,7 +582,7 @@ namespace QRRapidoApp.Services
_logger.LogDebug("Creating colorized image with dimensions {Width}x{Height}",
originalLogo.Width, originalLogo.Height);
// Apply colorization by processing each pixel
// Apply intelligent colorization: preserve light backgrounds, colorize dark elements
var colorizedLogo = originalLogo.Clone(ctx =>
{
ctx.ProcessPixelRowsAsVector4((span, point) =>
@ -578,19 +590,36 @@ namespace QRRapidoApp.Services
for (int x = 0; x < span.Length; x++)
{
var pixel = span[x];
// Preserve alpha, but colorize RGB channels based on luminance
// Calculate luminance (brightness) of the pixel
var luminance = (pixel.X * 0.299f + pixel.Y * 0.587f + pixel.Z * 0.114f);
span[x] = new Vector4(
rgba.R / 255f * luminance,
rgba.G / 255f * luminance,
rgba.B / 255f * luminance,
pixel.W // Preserve alpha
);
// Define threshold for "background" vs "content"
// Values above 0.8 (bright) are considered background and preserved
var brightnessThreshold = 0.8f;
if (luminance > brightnessThreshold)
{
// Preserve bright pixels (background) - keep original colors
span[x] = pixel;
}
else
{
// Colorize dark pixels (content/drawings) with QR color
// Use inverse luminance for intensity (darker pixels get more color)
var intensity = Math.Max(0.1f, 1.0f - luminance);
span[x] = new Vector4(
rgba.R / 255f * intensity,
rgba.G / 255f * intensity,
rgba.B / 255f * intensity,
pixel.W // Preserve alpha
);
}
}
});
});
_logger.LogDebug("Logo colorization completed successfully");
_logger.LogInformation("✨ Smart logo colorization completed - Preserving bright pixels (>0.8), colorizing dark content with {Color}", targetColor);
return colorizedLogo;
}
catch (Exception ex)

View File

@ -573,8 +573,8 @@ class QRRapidoGenerator {
// NOVOS PARÂMETROS DE LOGO APRIMORADO
const logoSettings = this.getLogoSettings();
formData.append('logoSizePercent', logoSettings.logoSizePercent.toString());
formData.append('applyLogoColorization', logoSettings.applyColorization.toString());
formData.append('LogoSizePercent', logoSettings.logoSizePercent.toString());
formData.append('ApplyLogoColorization', logoSettings.applyColorization.toString());
// Add logo file
formData.append('logo', logoUpload.files[0]);
@ -586,8 +586,9 @@ class QRRapidoGenerator {
console.log('🎨 Preparando FormData com logo:', {
logoFile: logoUpload.files[0].name,
logoSize: logoUpload.files[0].size + ' bytes',
logoSizePercent: logoSizeSlider?.value || logoSettings.logoSizePercent || '20',
colorization: logoColorizeToggle?.checked || logoSettings.applyColorization || false,
LogoSizePercent: logoSettings.logoSizePercent,
ApplyLogoColorization: logoSettings.applyColorization,
checkboxChecked: logoColorizeToggle?.checked,
endpoint: '/api/QR/GenerateRapidWithLogo'
});