electron
This commit is contained in:
@@ -185,10 +185,7 @@ function createPaarrotExtension(color: string): Uint8Array {
|
||||
export function extractColorFromGIF(imageData: ArrayBuffer | Uint8Array): string | undefined {
|
||||
const data = imageData instanceof Uint8Array ? imageData : new Uint8Array(imageData);
|
||||
|
||||
console.log('[extractColorFromGIF] Input size:', data.length, 'bytes');
|
||||
|
||||
if (!isGIF(data)) {
|
||||
console.error('[extractColorFromGIF] Not a GIF file');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -196,19 +193,16 @@ export function extractColorFromGIF(imageData: ArrayBuffer | Uint8Array): string
|
||||
const startOffset = 13 + gctSize; // Header(6) + LSD(7) + GCT
|
||||
|
||||
const extensions = findAppExtensions(data, startOffset);
|
||||
console.log('[extractColorFromGIF] Found', extensions.length, 'application extensions');
|
||||
|
||||
for (const ext of extensions) {
|
||||
if (ext.appId.startsWith('PAARROT')) {
|
||||
if (ext.dataBlocks.length > 0) {
|
||||
const color = new TextDecoder().decode(ext.dataBlocks[0]);
|
||||
console.log('[extractColorFromGIF] Found color:', color);
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[extractColorFromGIF] No color found');
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -218,10 +212,7 @@ export function extractColorFromGIF(imageData: ArrayBuffer | Uint8Array): string
|
||||
export function embedColorInGIF(imageData: ArrayBuffer | Uint8Array, color: string): Uint8Array | null {
|
||||
const data = imageData instanceof Uint8Array ? imageData : new Uint8Array(imageData);
|
||||
|
||||
console.log('[embedColorInGIF] Input size:', data.length, 'bytes');
|
||||
|
||||
if (!isGIF(data)) {
|
||||
console.error('[embedColorInGIF] Not a GIF file');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -229,7 +220,6 @@ export function embedColorInGIF(imageData: ArrayBuffer | Uint8Array, color: stri
|
||||
const insertOffset = 13 + gctSize; // After Header + LSD + GCT
|
||||
|
||||
const extensions = findAppExtensions(data, insertOffset);
|
||||
console.log('[embedColorInGIF] Found', extensions.length, 'application extensions');
|
||||
|
||||
// Find existing PAARROT extension
|
||||
let existingExt: { offset: number; length: number } | null = null;
|
||||
@@ -243,14 +233,10 @@ export function embedColorInGIF(imageData: ArrayBuffer | Uint8Array, color: stri
|
||||
// Create new extension
|
||||
const newExtension = createPaarrotExtension(color);
|
||||
|
||||
console.log('[embedColorInGIF] Created extension, size:', newExtension.length, 'bytes');
|
||||
console.log('[embedColorInGIF] Color being embedded:', color);
|
||||
|
||||
let newData: Uint8Array;
|
||||
|
||||
if (existingExt) {
|
||||
// Replace existing extension
|
||||
console.log('[embedColorInGIF] Replacing existing extension at offset', existingExt.offset);
|
||||
newData = new Uint8Array(data.length - existingExt.length + newExtension.length);
|
||||
newData.set(data.slice(0, existingExt.offset), 0);
|
||||
newData.set(newExtension, existingExt.offset);
|
||||
@@ -260,15 +246,12 @@ export function embedColorInGIF(imageData: ArrayBuffer | Uint8Array, color: stri
|
||||
);
|
||||
} else {
|
||||
// Insert after GCT (before any other blocks)
|
||||
console.log('[embedColorInGIF] Inserting new extension at offset', insertOffset);
|
||||
newData = new Uint8Array(data.length + newExtension.length);
|
||||
newData.set(data.slice(0, insertOffset), 0);
|
||||
newData.set(newExtension, insertOffset);
|
||||
newData.set(data.slice(insertOffset), insertOffset + newExtension.length);
|
||||
}
|
||||
|
||||
console.log('[embedColorInGIF] Output size:', newData.length, 'bytes');
|
||||
|
||||
return newData;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user