DoujinSoft icon indicating copy to clipboard operation
DoujinSoft copied to clipboard

Port Python HD thumbnail generator to Java for server integration

Open Copilot opened this issue 6 months ago • 0 comments

This PR ports the functionality from tools/mio_hd_thumbnail.py to Java, enabling the main server to generate high-quality game thumbnails without external Python dependencies.

Problem

The existing Python script mio_hd_thumbnail.py generates high-quality 192×128px previews of .mio game files, but requires external execution and cannot be integrated with the main Java server. This creates a dependency on Python and PIL, making deployment more complex.

Solution

Complete Java port with server integration:

New Components

  • BitField.java: Utility class for bit field manipulation (equivalent to Python's bf class)
  • MioUtils.getHDGamePreview(): Core method that generates 192×128px HD thumbnails from .mio files
  • Enhanced DownloadServlet: Added &hd parameter to request HD previews via HTTP

Key Features Ported

  • Validates .mio file format (magic "DSMIO_S" and 65536 byte size)
  • Parses background data using the same 16-color palette
  • Processes up to 15 sprite objects with proper positioning logic
  • Handles object attachments and area-based placement with randomization
  • Combines all elements with correct layering

Server Integration

Users can now request HD thumbnails directly from the server:

/download?type=game&id=HASH&preview&hd

The implementation maintains full backward compatibility - standard 95×63px previews remain the default, and HD generation only occurs when explicitly requested.

Testing

Comprehensive test suite validates:

  • Error handling for invalid files
  • Correct image dimensions (192×128px)
  • Fallback behavior when HD generation fails
  • Integration with existing preview functionality

The Java implementation produces the same high-quality output as the Python script while integrating seamlessly with the existing server architecture.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Aug 23 '25 16:08 Copilot