Version 3.1.0 now with experimental DCT support.
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Stegasoo Web Frontend
|
||||
Stegasoo Web Frontend (v3.0.1)
|
||||
|
||||
Flask-based web UI for steganography operations.
|
||||
Supports both text messages and file embedding.
|
||||
NEW in v3.0: LSB and DCT embedding modes with advanced options.
|
||||
NEW in v3.0.1: DCT output format selection (PNG or JPEG).
|
||||
"""
|
||||
|
||||
import io
|
||||
@@ -35,6 +37,13 @@ from stegasoo import (
|
||||
StegasooError, DecryptionError, CapacityError,
|
||||
has_argon2,
|
||||
FilePayload,
|
||||
# NEW in v3.0 - Embedding modes
|
||||
EMBED_MODE_LSB,
|
||||
EMBED_MODE_DCT,
|
||||
EMBED_MODE_AUTO,
|
||||
has_dct_support,
|
||||
compare_modes,
|
||||
will_fit_by_mode,
|
||||
)
|
||||
from stegasoo.constants import (
|
||||
__version__,
|
||||
@@ -102,6 +111,8 @@ def inject_globals():
|
||||
'temp_file_expiry_minutes': TEMP_FILE_EXPIRY_MINUTES,
|
||||
'min_pin_length': MIN_PIN_LENGTH,
|
||||
'max_pin_length': MAX_PIN_LENGTH,
|
||||
# NEW in v3.0
|
||||
'has_dct': has_dct_support(),
|
||||
}
|
||||
|
||||
|
||||
@@ -114,6 +125,7 @@ try:
|
||||
# Check current limits
|
||||
print(f"Current MAX_FILE_SIZE from constants: {MAX_FILE_SIZE}")
|
||||
print(f"Current MAX_FILE_PAYLOAD_SIZE: {MAX_FILE_PAYLOAD_SIZE}")
|
||||
print(f"DCT support available: {has_dct_support()}")
|
||||
|
||||
DESIRED_PAYLOAD_SIZE = 2 * 1024 * 1024 # 2MB
|
||||
|
||||
@@ -131,7 +143,7 @@ def generate_thumbnail(image_data: bytes, size: tuple = THUMBNAIL_SIZE) -> bytes
|
||||
"""Generate thumbnail from image data."""
|
||||
try:
|
||||
with Image.open(io.BytesIO(image_data)) as img:
|
||||
# Convert to RGB if necessary
|
||||
# Convert to RGB if necessary (handle grayscale too)
|
||||
if img.mode in ('RGBA', 'LA', 'P'):
|
||||
# Create white background for transparent images
|
||||
background = Image.new('RGB', img.size, (255, 255, 255))
|
||||
@@ -139,6 +151,9 @@ def generate_thumbnail(image_data: bytes, size: tuple = THUMBNAIL_SIZE) -> bytes
|
||||
img = img.convert('RGBA')
|
||||
background.paste(img, mask=img.split()[-1] if img.mode == 'RGBA' else None)
|
||||
img = background
|
||||
elif img.mode == 'L':
|
||||
# Convert grayscale to RGB for thumbnail
|
||||
img = img.convert('RGB')
|
||||
elif img.mode != 'RGB':
|
||||
img = img.convert('RGB')
|
||||
|
||||
@@ -401,6 +416,85 @@ def extract_key_from_qr_route():
|
||||
}), 500
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# NEW in v3.0 - CAPACITY COMPARISON API
|
||||
# ============================================================================
|
||||
|
||||
@app.route('/api/compare-capacity', methods=['POST'])
|
||||
def api_compare_capacity():
|
||||
"""
|
||||
Compare LSB and DCT capacity for an uploaded carrier image.
|
||||
Returns JSON with capacity info for both modes.
|
||||
"""
|
||||
carrier = request.files.get('carrier')
|
||||
if not carrier:
|
||||
return jsonify({'error': 'No carrier image provided'}), 400
|
||||
|
||||
try:
|
||||
carrier_data = carrier.read()
|
||||
comparison = compare_modes(carrier_data)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'width': comparison['width'],
|
||||
'height': comparison['height'],
|
||||
'lsb': {
|
||||
'capacity_bytes': comparison['lsb']['capacity_bytes'],
|
||||
'capacity_kb': round(comparison['lsb']['capacity_kb'], 1),
|
||||
'output': comparison['lsb']['output'],
|
||||
},
|
||||
'dct': {
|
||||
'capacity_bytes': comparison['dct']['capacity_bytes'],
|
||||
'capacity_kb': round(comparison['dct']['capacity_kb'], 1),
|
||||
'output': comparison['dct']['output'],
|
||||
'available': comparison['dct']['available'],
|
||||
'ratio': round(comparison['dct']['ratio_vs_lsb'], 1),
|
||||
}
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/check-fit', methods=['POST'])
|
||||
def api_check_fit():
|
||||
"""
|
||||
Check if a payload will fit in the carrier with selected mode.
|
||||
Returns JSON with fit status and details.
|
||||
"""
|
||||
carrier = request.files.get('carrier')
|
||||
payload_size = request.form.get('payload_size', type=int)
|
||||
embed_mode = request.form.get('embed_mode', 'lsb')
|
||||
|
||||
if not carrier or payload_size is None:
|
||||
return jsonify({'error': 'Missing carrier or payload_size'}), 400
|
||||
|
||||
if embed_mode not in ('lsb', 'dct'):
|
||||
return jsonify({'error': 'Invalid embed_mode'}), 400
|
||||
|
||||
if embed_mode == 'dct' and not has_dct_support():
|
||||
return jsonify({'error': 'DCT mode requires scipy'}), 400
|
||||
|
||||
try:
|
||||
carrier_data = carrier.read()
|
||||
result = will_fit_by_mode(payload_size, carrier_data, embed_mode=embed_mode)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'fits': result['fits'],
|
||||
'payload_size': result['payload_size'],
|
||||
'capacity': result['capacity'],
|
||||
'usage_percent': round(result['usage_percent'], 1),
|
||||
'headroom': result['headroom'],
|
||||
'mode': embed_mode,
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# ENCODE
|
||||
# ============================================================================
|
||||
|
||||
@app.route('/encode', methods=['GET', 'POST'])
|
||||
def encode_page():
|
||||
day_of_week = get_today_day()
|
||||
@@ -428,6 +522,21 @@ def encode_page():
|
||||
rsa_password = request.form.get('rsa_password', '')
|
||||
payload_type = request.form.get('payload_type', 'text')
|
||||
|
||||
# NEW in v3.0 - Embedding mode
|
||||
embed_mode = request.form.get('embed_mode', 'lsb')
|
||||
if embed_mode not in ('lsb', 'dct'):
|
||||
embed_mode = 'lsb'
|
||||
|
||||
# NEW in v3.0.1 - DCT output format
|
||||
dct_output_format = request.form.get('dct_output_format', 'png')
|
||||
if dct_output_format not in ('png', 'jpeg'):
|
||||
dct_output_format = 'png'
|
||||
|
||||
# Check DCT availability
|
||||
if embed_mode == 'dct' and not has_dct_support():
|
||||
flash('DCT mode requires scipy. Install with: pip install scipy', 'error')
|
||||
return render_template('encode.html', day_of_week=day_of_week, has_qrcode_read=HAS_QRCODE_READ)
|
||||
|
||||
# Determine payload
|
||||
if payload_type == 'file' and payload_file and payload_file.filename:
|
||||
# File payload
|
||||
@@ -515,7 +624,7 @@ def encode_page():
|
||||
else:
|
||||
date_str = datetime.now().strftime('%Y-%m-%d')
|
||||
|
||||
# Encode
|
||||
# Encode with selected mode and output format
|
||||
encode_result = encode(
|
||||
message=payload,
|
||||
reference_photo=ref_data,
|
||||
@@ -524,16 +633,34 @@ def encode_page():
|
||||
pin=pin,
|
||||
rsa_key_data=rsa_key_data,
|
||||
rsa_password=key_password,
|
||||
date_str=date_str
|
||||
date_str=date_str,
|
||||
embed_mode=embed_mode, # NEW in v3.0
|
||||
dct_output_format=dct_output_format if embed_mode == 'dct' else None, # NEW in v3.0.1
|
||||
)
|
||||
|
||||
# Determine actual output format for filename and storage
|
||||
if embed_mode == 'dct' and dct_output_format == 'jpeg':
|
||||
output_ext = '.jpg'
|
||||
output_mime = 'image/jpeg'
|
||||
# Modify filename extension if needed
|
||||
filename = encode_result.filename
|
||||
if filename.endswith('.png'):
|
||||
filename = filename[:-4] + '.jpg'
|
||||
else:
|
||||
output_ext = '.png'
|
||||
output_mime = 'image/png'
|
||||
filename = encode_result.filename
|
||||
|
||||
# Store temporarily
|
||||
file_id = secrets.token_urlsafe(16)
|
||||
cleanup_temp_files()
|
||||
TEMP_FILES[file_id] = {
|
||||
'data': encode_result.stego_image,
|
||||
'filename': encode_result.filename,
|
||||
'timestamp': time.time()
|
||||
'filename': filename,
|
||||
'timestamp': time.time(),
|
||||
'embed_mode': embed_mode,
|
||||
'output_format': dct_output_format if embed_mode == 'dct' else 'png',
|
||||
'mime_type': output_mime,
|
||||
}
|
||||
|
||||
return redirect(url_for('encode_result', file_id=file_id))
|
||||
@@ -570,7 +697,9 @@ def encode_result(file_id):
|
||||
return render_template('encode_result.html',
|
||||
file_id=file_id,
|
||||
filename=file_info['filename'],
|
||||
thumbnail_url=url_for('encode_thumbnail', thumb_id=thumbnail_id) if thumbnail_id else None
|
||||
thumbnail_url=url_for('encode_thumbnail', thumb_id=thumbnail_id) if thumbnail_id else None,
|
||||
embed_mode=file_info.get('embed_mode', 'lsb'),
|
||||
output_format=file_info.get('output_format', 'png'), # NEW in v3.0.1
|
||||
)
|
||||
|
||||
|
||||
@@ -594,9 +723,11 @@ def encode_download(file_id):
|
||||
return redirect(url_for('encode_page'))
|
||||
|
||||
file_info = TEMP_FILES[file_id]
|
||||
mime_type = file_info.get('mime_type', 'image/png')
|
||||
|
||||
return send_file(
|
||||
io.BytesIO(file_info['data']),
|
||||
mimetype='image/png',
|
||||
mimetype=mime_type,
|
||||
as_attachment=True,
|
||||
download_name=file_info['filename']
|
||||
)
|
||||
@@ -609,9 +740,11 @@ def encode_file_route(file_id):
|
||||
return "Not found", 404
|
||||
|
||||
file_info = TEMP_FILES[file_id]
|
||||
mime_type = file_info.get('mime_type', 'image/png')
|
||||
|
||||
return send_file(
|
||||
io.BytesIO(file_info['data']),
|
||||
mimetype='image/png',
|
||||
mimetype=mime_type,
|
||||
as_attachment=False,
|
||||
download_name=file_info['filename']
|
||||
)
|
||||
@@ -629,6 +762,10 @@ def encode_cleanup(file_id):
|
||||
return jsonify({'status': 'ok'})
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# DECODE
|
||||
# ============================================================================
|
||||
|
||||
@app.route('/decode', methods=['GET', 'POST'])
|
||||
def decode_page():
|
||||
if request.method == 'POST':
|
||||
@@ -647,6 +784,16 @@ def decode_page():
|
||||
pin = request.form.get('pin', '').strip()
|
||||
rsa_password = request.form.get('rsa_password', '')
|
||||
|
||||
# NEW in v3.0 - Extraction mode
|
||||
embed_mode = request.form.get('embed_mode', 'auto')
|
||||
if embed_mode not in ('auto', 'lsb', 'dct'):
|
||||
embed_mode = 'auto'
|
||||
|
||||
# Check DCT availability
|
||||
if embed_mode == 'dct' and not has_dct_support():
|
||||
flash('DCT mode requires scipy. Install with: pip install scipy', 'error')
|
||||
return render_template('decode.html', has_qrcode_read=HAS_QRCODE_READ)
|
||||
|
||||
# Get encoding date from form (detected from filename in JS)
|
||||
stego_date = request.form.get('stego_date', '').strip()
|
||||
|
||||
@@ -700,7 +847,7 @@ def decode_page():
|
||||
flash(result.error_message, 'error')
|
||||
return render_template('decode.html', has_qrcode_read=HAS_QRCODE_READ)
|
||||
|
||||
# Decode
|
||||
# Decode with selected mode
|
||||
decode_result = decode(
|
||||
stego_image=stego_data,
|
||||
reference_photo=ref_data,
|
||||
@@ -708,7 +855,8 @@ def decode_page():
|
||||
pin=pin,
|
||||
rsa_key_data=rsa_key_data,
|
||||
rsa_password=key_password,
|
||||
date_str=stego_date if stego_date else None
|
||||
date_str=stego_date if stego_date else None,
|
||||
embed_mode=embed_mode, # NEW in v3.0
|
||||
)
|
||||
|
||||
if decode_result.is_file:
|
||||
|
||||
@@ -181,6 +181,78 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================================================================
|
||||
ADVANCED OPTIONS (v3.0) - Extraction Mode
|
||||
================================================================ -->
|
||||
<div class="mb-4">
|
||||
<a class="btn btn-sm btn-outline-secondary w-100" data-bs-toggle="collapse" href="#advancedOptionsDec" role="button" aria-expanded="false">
|
||||
<i class="bi bi-gear me-1"></i> Advanced Options
|
||||
<i class="bi bi-chevron-down ms-1" id="advancedChevronDec"></i>
|
||||
</a>
|
||||
|
||||
<div class="collapse" id="advancedOptionsDec">
|
||||
<div class="card card-body mt-2 bg-dark border-secondary">
|
||||
|
||||
<!-- Extraction Mode Selection -->
|
||||
<div class="mb-0">
|
||||
<label class="form-label">
|
||||
<i class="bi bi-cpu me-1"></i> Extraction Mode
|
||||
<span class="badge bg-info ms-1">v3.0</span>
|
||||
</label>
|
||||
|
||||
<div class="row g-2">
|
||||
<!-- Auto Mode -->
|
||||
<div class="col-4">
|
||||
<div class="form-check card p-2 text-center h-100" id="autoModeCard">
|
||||
<input class="form-check-input mx-auto" type="radio" name="embed_mode" id="modeAuto" value="auto" checked>
|
||||
<label class="form-check-label w-100" for="modeAuto">
|
||||
<i class="bi bi-magic text-success fs-4 d-block mb-1"></i>
|
||||
<strong>Auto</strong>
|
||||
<div class="small text-muted">Try both</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- LSB Mode -->
|
||||
<div class="col-4">
|
||||
<div class="form-check card p-2 text-center h-100" id="lsbModeCardDec">
|
||||
<input class="form-check-input mx-auto" type="radio" name="embed_mode" id="modeLsbDec" value="lsb">
|
||||
<label class="form-check-label w-100" for="modeLsbDec">
|
||||
<i class="bi bi-grid-3x3-gap text-primary fs-4 d-block mb-1"></i>
|
||||
<strong>LSB</strong>
|
||||
<div class="small text-muted">Spatial only</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DCT Mode -->
|
||||
<div class="col-4">
|
||||
<div class="form-check card p-2 text-center h-100 {% if not has_dct %}opacity-50{% endif %}" id="dctModeCardDec">
|
||||
<input class="form-check-input mx-auto" type="radio" name="embed_mode" id="modeDctDec" value="dct" {% if not has_dct %}disabled{% endif %}>
|
||||
<label class="form-check-label w-100" for="modeDctDec">
|
||||
<i class="bi bi-soundwave text-info fs-4 d-block mb-1"></i>
|
||||
<strong>DCT</strong>
|
||||
<div class="small text-muted">
|
||||
{% if has_dct %}Frequency only{% else %}N/A{% endif %}
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-text mt-2">
|
||||
<i class="bi bi-lightbulb me-1"></i>
|
||||
<strong>Auto</strong> tries LSB first, then DCT. Use specific mode if you know how it was encoded.
|
||||
{% if not has_dct %}
|
||||
<br><span class="text-warning"><i class="bi bi-exclamation-triangle me-1"></i>DCT requires scipy: <code>pip install scipy</code></span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-lg w-100" id="decodeBtn">
|
||||
<i class="bi bi-unlock me-2"></i>Decode
|
||||
</button>
|
||||
@@ -211,10 +283,14 @@
|
||||
<i class="bi bi-dot"></i>
|
||||
Ensure the stego image hasn't been <strong>resized or recompressed</strong>
|
||||
</li>
|
||||
<li class="mb-0">
|
||||
<li class="mb-2">
|
||||
<i class="bi bi-dot"></i>
|
||||
If using an RSA key, make sure the <strong>password is correct</strong>
|
||||
</li>
|
||||
<li class="mb-0">
|
||||
<i class="bi bi-dot"></i>
|
||||
<strong>v3.0:</strong> If auto-detection fails, try specifying <strong>LSB or DCT mode</strong> in Advanced Options
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -228,7 +304,8 @@
|
||||
// Form submit loading state
|
||||
document.getElementById('decodeForm')?.addEventListener('submit', function() {
|
||||
const btn = document.getElementById('decodeBtn');
|
||||
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Decoding...';
|
||||
const selectedMode = document.querySelector('input[name="embed_mode"]:checked')?.value || 'auto';
|
||||
btn.innerHTML = `<span class="spinner-border spinner-border-sm me-2"></span>Decoding (${selectedMode.toUpperCase()})...`;
|
||||
btn.disabled = true;
|
||||
});
|
||||
|
||||
@@ -323,6 +400,38 @@ document.getElementById('togglePin')?.addEventListener('click', function() {
|
||||
}
|
||||
});
|
||||
|
||||
// Mode card highlighting
|
||||
const autoModeCard = document.getElementById('autoModeCard');
|
||||
const lsbModeCardDec = document.getElementById('lsbModeCardDec');
|
||||
const dctModeCardDec = document.getElementById('dctModeCardDec');
|
||||
const modeAuto = document.getElementById('modeAuto');
|
||||
const modeLsbDec = document.getElementById('modeLsbDec');
|
||||
const modeDctDec = document.getElementById('modeDctDec');
|
||||
|
||||
function updateModeCardHighlightDec() {
|
||||
autoModeCard?.classList.toggle('border-success', modeAuto?.checked);
|
||||
autoModeCard?.classList.toggle('border-2', modeAuto?.checked);
|
||||
lsbModeCardDec?.classList.toggle('border-primary', modeLsbDec?.checked);
|
||||
lsbModeCardDec?.classList.toggle('border-2', modeLsbDec?.checked);
|
||||
dctModeCardDec?.classList.toggle('border-info', modeDctDec?.checked);
|
||||
dctModeCardDec?.classList.toggle('border-2', modeDctDec?.checked);
|
||||
}
|
||||
|
||||
modeAuto?.addEventListener('change', updateModeCardHighlightDec);
|
||||
modeLsbDec?.addEventListener('change', updateModeCardHighlightDec);
|
||||
modeDctDec?.addEventListener('change', updateModeCardHighlightDec);
|
||||
updateModeCardHighlightDec(); // Initial state
|
||||
|
||||
// Advanced options chevron rotation
|
||||
document.getElementById('advancedOptionsDec')?.addEventListener('show.bs.collapse', function() {
|
||||
document.getElementById('advancedChevronDec').classList.add('bi-chevron-up');
|
||||
document.getElementById('advancedChevronDec').classList.remove('bi-chevron-down');
|
||||
});
|
||||
document.getElementById('advancedOptionsDec')?.addEventListener('hide.bs.collapse', function() {
|
||||
document.getElementById('advancedChevronDec').classList.remove('bi-chevron-up');
|
||||
document.getElementById('advancedChevronDec').classList.add('bi-chevron-down');
|
||||
});
|
||||
|
||||
// Paste from Clipboard
|
||||
document.addEventListener('paste', function(e) {
|
||||
if (!document.getElementById('decodeForm')) return;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<i class="bi bi-file-image me-1"></i> Carrier Image
|
||||
</label>
|
||||
<div class="drop-zone" id="carrierDropZone">
|
||||
<input type="file" name="carrier" accept="image/*" required>
|
||||
<input type="file" name="carrier" accept="image/*" required id="carrierInput">
|
||||
<div class="drop-zone-label">
|
||||
<i class="bi bi-cloud-arrow-up fs-3 d-block mb-2 text-muted"></i>
|
||||
<span class="text-muted">Drop image or click to browse</span>
|
||||
@@ -49,6 +49,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Capacity Info Panel (shown when carrier loaded) -->
|
||||
<div class="alert alert-info small d-none" id="capacityPanel">
|
||||
<div class="row align-items-center">
|
||||
<div class="col">
|
||||
<i class="bi bi-rulers me-1"></i>
|
||||
<strong>Carrier:</strong> <span id="carrierDimensions">-</span>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<span class="badge bg-primary me-1" id="lsbCapacityBadge">LSB: -</span>
|
||||
<span class="badge bg-secondary" id="dctCapacityBadge">DCT: -</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Payload Type Selector -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">
|
||||
@@ -179,6 +193,141 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ================================================================
|
||||
ADVANCED OPTIONS (v3.0) - Collapsible Section
|
||||
================================================================ -->
|
||||
<div class="mb-4">
|
||||
<a class="btn btn-sm btn-outline-secondary w-100" data-bs-toggle="collapse" href="#advancedOptions" role="button" aria-expanded="false">
|
||||
<i class="bi bi-gear me-1"></i> Advanced Options
|
||||
<i class="bi bi-chevron-down ms-1" id="advancedChevron"></i>
|
||||
</a>
|
||||
|
||||
<div class="collapse" id="advancedOptions">
|
||||
<div class="card card-body mt-2 bg-dark border-secondary">
|
||||
|
||||
<!-- Embedding Mode Selection -->
|
||||
<div class="mb-3">
|
||||
<label class="form-label">
|
||||
<i class="bi bi-cpu me-1"></i> Embedding Mode
|
||||
<span class="badge bg-info ms-1">v3.0</span>
|
||||
</label>
|
||||
|
||||
<div class="row g-2">
|
||||
<!-- LSB Mode Card -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-check card p-3 h-100 border-primary border-2" id="lsbModeCard">
|
||||
<input class="form-check-input" type="radio" name="embed_mode" id="modeLsb" value="lsb" checked>
|
||||
<label class="form-check-label w-100" for="modeLsb">
|
||||
<div class="d-flex align-items-center mb-2">
|
||||
<i class="bi bi-grid-3x3-gap text-primary fs-4 me-2"></i>
|
||||
<strong>LSB Mode</strong>
|
||||
<span class="badge bg-success ms-auto">Default</span>
|
||||
</div>
|
||||
<ul class="small text-muted mb-0 ps-3">
|
||||
<li>Full color PNG output</li>
|
||||
<li>Higher capacity (~375 KB/MP)</li>
|
||||
<li>Faster processing</li>
|
||||
</ul>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DCT Mode Card -->
|
||||
<div class="col-md-6">
|
||||
<div class="form-check card p-3 h-100 {% if not has_dct %}opacity-50{% endif %}" id="dctModeCard">
|
||||
<input class="form-check-input" type="radio" name="embed_mode" id="modeDct" value="dct" {% if not has_dct %}disabled{% endif %}>
|
||||
<label class="form-check-label w-100" for="modeDct">
|
||||
<div class="d-flex align-items-center mb-2">
|
||||
<i class="bi bi-soundwave text-info fs-4 me-2"></i>
|
||||
<strong>DCT Mode</strong>
|
||||
{% if has_dct %}
|
||||
<span class="badge bg-info ms-auto">Stealth</span>
|
||||
{% else %}
|
||||
<span class="badge bg-secondary ms-auto">Unavailable</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
<ul class="small text-muted mb-0 ps-3">
|
||||
<li>Grayscale output (PNG/JPEG)</li>
|
||||
<li>Lower capacity (~75 KB/MP)</li>
|
||||
<li>Better detection resistance</li>
|
||||
</ul>
|
||||
{% if not has_dct %}
|
||||
<div class="alert alert-warning small mt-2 mb-0 py-1 px-2">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>
|
||||
Requires scipy: <code>pip install scipy</code>
|
||||
</div>
|
||||
{% endif %}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mode comparison hint -->
|
||||
<div class="form-text mt-2" id="modeHint">
|
||||
<i class="bi bi-lightbulb me-1"></i>
|
||||
<strong>LSB</strong> is best for most uses.
|
||||
<strong>DCT</strong> provides better stealth but smaller capacity and grayscale output.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DCT Output Format (shown only when DCT selected) -->
|
||||
<div class="mb-3 d-none" id="dctOutputFormatGroup">
|
||||
<label class="form-label">
|
||||
<i class="bi bi-file-image me-1"></i> DCT Output Format
|
||||
</label>
|
||||
|
||||
<div class="row g-2">
|
||||
<div class="col-6">
|
||||
<div class="form-check card p-2 text-center" id="dctPngCard">
|
||||
<input class="form-check-input mx-auto" type="radio" name="dct_output_format" id="dctFormatPng" value="png" checked>
|
||||
<label class="form-check-label w-100" for="dctFormatPng">
|
||||
<i class="bi bi-file-earmark-image text-success fs-5 d-block"></i>
|
||||
<strong>PNG</strong>
|
||||
<div class="small text-muted">Lossless, larger</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-check card p-2 text-center" id="dctJpegCard">
|
||||
<input class="form-check-input mx-auto" type="radio" name="dct_output_format" id="dctFormatJpeg" value="jpeg">
|
||||
<label class="form-check-label w-100" for="dctFormatJpeg">
|
||||
<i class="bi bi-file-earmark-richtext text-warning fs-5 d-block"></i>
|
||||
<strong>JPEG</strong>
|
||||
<div class="small text-muted">Smaller, natural</div>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-text mt-2">
|
||||
<i class="bi bi-info-circle me-1"></i>
|
||||
<strong>PNG</strong> is 100% reliable. <strong>JPEG</strong> produces smaller, more natural-looking files but uses lossy compression (Q=95).
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Capacity Comparison (populated by JS) -->
|
||||
<div class="d-none" id="modeCapacityComparison">
|
||||
<div class="alert alert-secondary small mb-0">
|
||||
<div class="row text-center">
|
||||
<div class="col-6 border-end">
|
||||
<div class="text-muted">LSB Capacity</div>
|
||||
<div class="fs-5 text-primary" id="lsbCapacityDetail">-</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="text-muted">DCT Capacity</div>
|
||||
<div class="fs-5 text-info" id="dctCapacityDetail">-</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center mt-2 small text-muted" id="capacityRatio">
|
||||
DCT is ~20% of LSB capacity
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-lg w-100" id="encodeBtn">
|
||||
<i class="bi bi-lock me-2"></i>Encode
|
||||
</button>
|
||||
@@ -317,7 +466,15 @@ if (rsaKeyQrInput) {
|
||||
// Form submit loading state
|
||||
document.getElementById('encodeForm').addEventListener('submit', function(e) {
|
||||
const btn = document.getElementById('encodeBtn');
|
||||
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2"></span>Encoding...';
|
||||
const selectedMode = document.querySelector('input[name="embed_mode"]:checked').value;
|
||||
let modeLabel = selectedMode.toUpperCase();
|
||||
|
||||
if (selectedMode === 'dct') {
|
||||
const outputFormat = document.querySelector('input[name="dct_output_format"]:checked')?.value || 'png';
|
||||
modeLabel += ` → ${outputFormat.toUpperCase()}`;
|
||||
}
|
||||
|
||||
btn.innerHTML = `<span class="spinner-border spinner-border-sm me-2"></span>Encoding (${modeLabel})...`;
|
||||
btn.disabled = true;
|
||||
});
|
||||
|
||||
@@ -338,12 +495,147 @@ messageInput.addEventListener('input', function() {
|
||||
charCount.classList.toggle('text-danger', len > maxChars * 0.95);
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// v3.0 - Capacity Comparison API
|
||||
// ============================================================================
|
||||
|
||||
const carrierInput = document.getElementById('carrierInput');
|
||||
const capacityPanel = document.getElementById('capacityPanel');
|
||||
const carrierDimensions = document.getElementById('carrierDimensions');
|
||||
const lsbCapacityBadge = document.getElementById('lsbCapacityBadge');
|
||||
const dctCapacityBadge = document.getElementById('dctCapacityBadge');
|
||||
const lsbCapacityDetail = document.getElementById('lsbCapacityDetail');
|
||||
const dctCapacityDetail = document.getElementById('dctCapacityDetail');
|
||||
const modeCapacityComparison = document.getElementById('modeCapacityComparison');
|
||||
const capacityRatio = document.getElementById('capacityRatio');
|
||||
|
||||
let currentCapacity = null;
|
||||
|
||||
async function fetchCapacityComparison(file) {
|
||||
const formData = new FormData();
|
||||
formData.append('carrier', file);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/compare-capacity', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.success) {
|
||||
currentCapacity = data;
|
||||
updateCapacityDisplay(data);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Capacity comparison failed:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function updateCapacityDisplay(data) {
|
||||
// Update top panel
|
||||
carrierDimensions.textContent = `${data.width} × ${data.height}`;
|
||||
lsbCapacityBadge.textContent = `LSB: ${data.lsb.capacity_kb} KB`;
|
||||
|
||||
if (data.dct.available) {
|
||||
dctCapacityBadge.textContent = `DCT: ${data.dct.capacity_kb} KB`;
|
||||
dctCapacityBadge.classList.remove('bg-secondary');
|
||||
dctCapacityBadge.classList.add('bg-info');
|
||||
} else {
|
||||
dctCapacityBadge.textContent = `DCT: N/A`;
|
||||
dctCapacityBadge.classList.remove('bg-info');
|
||||
dctCapacityBadge.classList.add('bg-secondary');
|
||||
}
|
||||
|
||||
capacityPanel.classList.remove('d-none');
|
||||
|
||||
// Update advanced options panel
|
||||
lsbCapacityDetail.textContent = `${data.lsb.capacity_kb} KB`;
|
||||
dctCapacityDetail.textContent = data.dct.available ? `${data.dct.capacity_kb} KB` : 'N/A';
|
||||
capacityRatio.textContent = data.dct.available
|
||||
? `DCT is ${data.dct.ratio}% of LSB capacity`
|
||||
: 'DCT mode not available';
|
||||
modeCapacityComparison.classList.remove('d-none');
|
||||
}
|
||||
|
||||
// Listen for carrier file selection
|
||||
if (carrierInput) {
|
||||
carrierInput.addEventListener('change', function() {
|
||||
if (this.files && this.files[0]) {
|
||||
fetchCapacityComparison(this.files[0]);
|
||||
} else {
|
||||
capacityPanel.classList.add('d-none');
|
||||
modeCapacityComparison.classList.add('d-none');
|
||||
currentCapacity = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Mode card highlighting & DCT output format visibility
|
||||
// ============================================================================
|
||||
|
||||
const lsbModeCard = document.getElementById('lsbModeCard');
|
||||
const dctModeCard = document.getElementById('dctModeCard');
|
||||
const modeLsb = document.getElementById('modeLsb');
|
||||
const modeDct = document.getElementById('modeDct');
|
||||
const dctOutputFormatGroup = document.getElementById('dctOutputFormatGroup');
|
||||
const dctPngCard = document.getElementById('dctPngCard');
|
||||
const dctJpegCard = document.getElementById('dctJpegCard');
|
||||
const dctFormatPng = document.getElementById('dctFormatPng');
|
||||
const dctFormatJpeg = document.getElementById('dctFormatJpeg');
|
||||
|
||||
function updateModeCardHighlight() {
|
||||
// Mode cards
|
||||
lsbModeCard.classList.toggle('border-primary', modeLsb.checked);
|
||||
lsbModeCard.classList.toggle('border-2', modeLsb.checked);
|
||||
dctModeCard.classList.toggle('border-info', modeDct.checked);
|
||||
dctModeCard.classList.toggle('border-2', modeDct.checked);
|
||||
|
||||
// Show/hide DCT output format selector
|
||||
if (dctOutputFormatGroup) {
|
||||
dctOutputFormatGroup.classList.toggle('d-none', !modeDct.checked);
|
||||
}
|
||||
}
|
||||
|
||||
function updateDctFormatCardHighlight() {
|
||||
if (dctPngCard && dctJpegCard) {
|
||||
dctPngCard.classList.toggle('border-success', dctFormatPng.checked);
|
||||
dctPngCard.classList.toggle('border-2', dctFormatPng.checked);
|
||||
dctJpegCard.classList.toggle('border-warning', dctFormatJpeg.checked);
|
||||
dctJpegCard.classList.toggle('border-2', dctFormatJpeg.checked);
|
||||
}
|
||||
}
|
||||
|
||||
modeLsb.addEventListener('change', updateModeCardHighlight);
|
||||
modeDct.addEventListener('change', updateModeCardHighlight);
|
||||
dctFormatPng?.addEventListener('change', updateDctFormatCardHighlight);
|
||||
dctFormatJpeg?.addEventListener('change', updateDctFormatCardHighlight);
|
||||
|
||||
updateModeCardHighlight(); // Initial state
|
||||
updateDctFormatCardHighlight(); // Initial state
|
||||
|
||||
// Advanced options chevron rotation
|
||||
document.getElementById('advancedOptions').addEventListener('show.bs.collapse', function() {
|
||||
document.getElementById('advancedChevron').classList.add('bi-chevron-up');
|
||||
document.getElementById('advancedChevron').classList.remove('bi-chevron-down');
|
||||
});
|
||||
document.getElementById('advancedOptions').addEventListener('hide.bs.collapse', function() {
|
||||
document.getElementById('advancedChevron').classList.remove('bi-chevron-up');
|
||||
document.getElementById('advancedChevron').classList.add('bi-chevron-down');
|
||||
});
|
||||
|
||||
// ============================================================================
|
||||
// Drag & drop with preview for images
|
||||
// ============================================================================
|
||||
|
||||
document.querySelectorAll('.drop-zone').forEach(zone => {
|
||||
const input = zone.querySelector('input[type="file"]');
|
||||
const label = zone.querySelector('.drop-zone-label');
|
||||
const preview = zone.querySelector('.drop-zone-preview');
|
||||
const isPayloadZone = zone.id === 'payloadDropZone';
|
||||
const isCarrierZone = zone.id === 'carrierDropZone';
|
||||
|
||||
['dragenter', 'dragover'].forEach(evt => {
|
||||
zone.addEventListener(evt, e => {
|
||||
@@ -367,6 +659,11 @@ document.querySelectorAll('.drop-zone').forEach(zone => {
|
||||
if (!isPayloadZone) {
|
||||
showPreview(e.dataTransfer.files[0]);
|
||||
}
|
||||
|
||||
// Trigger capacity check for carrier
|
||||
if (isCarrierZone && e.dataTransfer.files[0]) {
|
||||
fetchCapacityComparison(e.dataTransfer.files[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -420,6 +717,7 @@ function checkDuplicateFiles() {
|
||||
document.querySelector('#carrierDropZone .drop-zone-label').innerHTML =
|
||||
'<i class="bi bi-cloud-arrow-up fs-3 d-block mb-2 text-muted"></i>' +
|
||||
'<span class="text-muted">Drop image or click to browse</span>';
|
||||
capacityPanel.classList.add('d-none');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,6 +741,11 @@ document.addEventListener('paste', function(e) {
|
||||
targetInput.files = container.files;
|
||||
|
||||
targetInput.dispatchEvent(new Event('change'));
|
||||
|
||||
// Trigger capacity check if pasted to carrier
|
||||
if (targetInput === carrierInput) {
|
||||
fetchCapacityComparison(blob);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,34 @@
|
||||
<code class="fs-5">{{ filename }}</code>
|
||||
</div>
|
||||
|
||||
<!-- Mode and format badges (v3.0) -->
|
||||
<div class="mb-4">
|
||||
{% if embed_mode == 'dct' %}
|
||||
<span class="badge bg-info fs-6">
|
||||
<i class="bi bi-soundwave me-1"></i>DCT Mode
|
||||
</span>
|
||||
{% if output_format == 'jpeg' %}
|
||||
<span class="badge bg-warning text-dark fs-6 ms-1">
|
||||
<i class="bi bi-file-earmark-richtext me-1"></i>JPEG
|
||||
</span>
|
||||
<div class="small text-muted mt-1">Grayscale JPEG, frequency domain embedding (Q=95)</div>
|
||||
{% else %}
|
||||
<span class="badge bg-success fs-6 ms-1">
|
||||
<i class="bi bi-file-earmark-image me-1"></i>PNG
|
||||
</span>
|
||||
<div class="small text-muted mt-1">Grayscale PNG, frequency domain embedding (lossless)</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class="badge bg-primary fs-6">
|
||||
<i class="bi bi-grid-3x3-gap me-1"></i>LSB Mode
|
||||
</span>
|
||||
<span class="badge bg-success fs-6 ms-1">
|
||||
<i class="bi bi-file-earmark-image me-1"></i>PNG
|
||||
</span>
|
||||
<div class="small text-muted mt-1">Full color PNG, spatial LSB embedding</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2">
|
||||
<a href="{{ url_for('encode_download', file_id=file_id) }}"
|
||||
class="btn btn-primary btn-lg" id="downloadBtn">
|
||||
@@ -53,7 +81,14 @@
|
||||
<ul class="mb-0 mt-2">
|
||||
<li>This file expires in <strong>5 minutes</strong></li>
|
||||
<li>Do <strong>not</strong> resize or recompress the image</li>
|
||||
{% if embed_mode == 'dct' and output_format == 'jpeg' %}
|
||||
<li>JPEG format is lossy - avoid re-saving or editing</li>
|
||||
{% else %}
|
||||
<li>PNG format preserves your hidden data</li>
|
||||
{% endif %}
|
||||
{% if embed_mode == 'dct' %}
|
||||
<li>Recipient needs <strong>DCT mode</strong> or <strong>Auto</strong> detection to decode</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -72,13 +107,14 @@
|
||||
const shareBtn = document.getElementById('shareBtn');
|
||||
const fileUrl = "{{ url_for('encode_file_route', file_id=file_id, _external=True) }}";
|
||||
const fileName = "{{ filename }}";
|
||||
const mimeType = "{{ 'image/jpeg' if embed_mode == 'dct' and output_format == 'jpeg' else 'image/png' }}";
|
||||
|
||||
if (navigator.share && navigator.canShare) {
|
||||
// Check if we can share files
|
||||
fetch(fileUrl)
|
||||
.then(response => response.blob())
|
||||
.then(blob => {
|
||||
const file = new File([blob], fileName, { type: 'image/png' });
|
||||
const file = new File([blob], fileName, { type: mimeType });
|
||||
if (navigator.canShare({ files: [file] })) {
|
||||
shareBtn.style.display = 'block';
|
||||
shareBtn.addEventListener('click', async () => {
|
||||
@@ -106,4 +142,4 @@ document.getElementById('downloadBtn').addEventListener('click', function() {
|
||||
}, 2000);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user