fix: logo cores e tamanho
This commit is contained in:
parent
9b094ed712
commit
5f0d3dbf66
@ -301,6 +301,10 @@ namespace QRRapidoApp.Controllers
|
|||||||
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
var userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||||
var isAuthenticated = User?.Identity?.IsAuthenticated ?? false;
|
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>
|
using (_logger.BeginScope(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["RequestId"] = requestId,
|
["RequestId"] = requestId,
|
||||||
|
|||||||
@ -265,7 +265,12 @@ namespace QRRapidoApp.Services
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
using var outputStream = new MemoryStream();
|
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();
|
var resizedBytes = outputStream.ToArray();
|
||||||
|
|
||||||
_logger.LogInformation("Logo redimensionado: {OriginalSize} -> {NewSize} bytes",
|
_logger.LogInformation("Logo redimensionado: {OriginalSize} -> {NewSize} bytes",
|
||||||
@ -491,13 +496,16 @@ namespace QRRapidoApp.Services
|
|||||||
var backgroundY = (qrImage.Height - backgroundSize) / 2;
|
var backgroundY = (qrImage.Height - backgroundSize) / 2;
|
||||||
|
|
||||||
// MELHORIA: Aplicar colorização se solicitado
|
// MELHORIA: Aplicar colorização se solicitado
|
||||||
_logger.LogDebug("Processing logo - Apply colorization: {ApplyColorization}",
|
_logger.LogInformation("🎨 [LOGO DEBUG] Processing logo - ApplyColorization: {ApplyColorization}, PrimaryColor: {PrimaryColor}",
|
||||||
request.ApplyLogoColorization);
|
request.ApplyLogoColorization, request.PrimaryColor);
|
||||||
|
|
||||||
using Image finalLogo = request.ApplyLogoColorization
|
using Image finalLogo = request.ApplyLogoColorization
|
||||||
? ApplyLogoColorization(logoImage, request.PrimaryColor)
|
? ApplyLogoColorization(logoImage, request.PrimaryColor)
|
||||||
: logoImage.Clone(ctx => { }); // Create a copy to avoid disposing the original
|
: 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)
|
if (finalLogo == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("Final logo is null after processing, cannot apply logo overlay");
|
_logger.LogError("Final logo is null after processing, cannot apply logo overlay");
|
||||||
@ -531,7 +539,11 @@ namespace QRRapidoApp.Services
|
|||||||
// Convert back to byte array
|
// Convert back to byte array
|
||||||
_logger.LogDebug("Saving final image with logo overlay");
|
_logger.LogDebug("Saving final image with logo overlay");
|
||||||
using var outputStream = new MemoryStream();
|
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();
|
var result = outputStream.ToArray();
|
||||||
|
|
||||||
_logger.LogInformation("Logo overlay completed successfully - Final image size: {FinalSize} bytes",
|
_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}",
|
_logger.LogDebug("Creating colorized image with dimensions {Width}x{Height}",
|
||||||
originalLogo.Width, originalLogo.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 =>
|
var colorizedLogo = originalLogo.Clone(ctx =>
|
||||||
{
|
{
|
||||||
ctx.ProcessPixelRowsAsVector4((span, point) =>
|
ctx.ProcessPixelRowsAsVector4((span, point) =>
|
||||||
@ -578,19 +590,36 @@ namespace QRRapidoApp.Services
|
|||||||
for (int x = 0; x < span.Length; x++)
|
for (int x = 0; x < span.Length; x++)
|
||||||
{
|
{
|
||||||
var pixel = span[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);
|
var luminance = (pixel.X * 0.299f + pixel.Y * 0.587f + pixel.Z * 0.114f);
|
||||||
span[x] = new Vector4(
|
|
||||||
rgba.R / 255f * luminance,
|
// Define threshold for "background" vs "content"
|
||||||
rgba.G / 255f * luminance,
|
// Values above 0.8 (bright) are considered background and preserved
|
||||||
rgba.B / 255f * luminance,
|
var brightnessThreshold = 0.8f;
|
||||||
pixel.W // Preserve alpha
|
|
||||||
);
|
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;
|
return colorizedLogo;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@ -573,8 +573,8 @@ class QRRapidoGenerator {
|
|||||||
|
|
||||||
// NOVOS PARÂMETROS DE LOGO APRIMORADO
|
// NOVOS PARÂMETROS DE LOGO APRIMORADO
|
||||||
const logoSettings = this.getLogoSettings();
|
const logoSettings = this.getLogoSettings();
|
||||||
formData.append('logoSizePercent', logoSettings.logoSizePercent.toString());
|
formData.append('LogoSizePercent', logoSettings.logoSizePercent.toString());
|
||||||
formData.append('applyLogoColorization', logoSettings.applyColorization.toString());
|
formData.append('ApplyLogoColorization', logoSettings.applyColorization.toString());
|
||||||
|
|
||||||
// Add logo file
|
// Add logo file
|
||||||
formData.append('logo', logoUpload.files[0]);
|
formData.append('logo', logoUpload.files[0]);
|
||||||
@ -586,8 +586,9 @@ class QRRapidoGenerator {
|
|||||||
console.log('🎨 Preparando FormData com logo:', {
|
console.log('🎨 Preparando FormData com logo:', {
|
||||||
logoFile: logoUpload.files[0].name,
|
logoFile: logoUpload.files[0].name,
|
||||||
logoSize: logoUpload.files[0].size + ' bytes',
|
logoSize: logoUpload.files[0].size + ' bytes',
|
||||||
logoSizePercent: logoSizeSlider?.value || logoSettings.logoSizePercent || '20',
|
LogoSizePercent: logoSettings.logoSizePercent,
|
||||||
colorization: logoColorizeToggle?.checked || logoSettings.applyColorization || false,
|
ApplyLogoColorization: logoSettings.applyColorization,
|
||||||
|
checkboxChecked: logoColorizeToggle?.checked,
|
||||||
endpoint: '/api/QR/GenerateRapidWithLogo'
|
endpoint: '/api/QR/GenerateRapidWithLogo'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user