codewario / PocketLibraryImages

This tool will prepare an image library for use with cartridges (and openFPGA cores if Analogue ever supports them) on Analogue OS
MIT License
104 stars 1 forks source link

Images generation for Analogue Duo #18

Open ChatMin opened 8 months ago

ChatMin commented 8 months ago

By using the tool to generate the full PCE library .bin files for the Analogue Duo, images are displayed but not correctly rendered .

Steps to reproduce the behavior:

  1. Generate the .bin files thanks to the script : step 2 (select "NEC - PC Engine - TurboGrafx 16"), step 5 (with "NEC - PC Engine - TurboGrafx 16" .dat file from DAT-o-MATIC)
  2. Copy the generated .bin files from "[WorkingDirectory]\conv\BoxArts" to the Analogue Duo SD card ("System\Library\Images\PCE")
  3. Start the Analogue Duo with a HuCard game inserted inside and go to the first menu to start the game
  4. The correct BoxArt image is displayed but image pixels are not rendered in the correct order (the image is recognizable but tilted and sheared). There is a similar issue on Titles images but with a different pixels mix.

The images are expected to be displayed correctly

ChatMin commented 8 months ago

About BoxArts display, the image top left pixel position is displayed at the bottom left hand corner and the top right pixel position is rendered at the top right hand corner, resulting on an image oriented by -45° and splited along the diagonal (bottom left/top right).

codewario commented 8 months ago

Currently, the scope of this project is for Pocket library images, which display fine on the Pocket. I don't own a Duo, so this isn't something I can easily test.

It does look like the image format is slightly different according to the recently updated developer docs on library images (8 bytes vs. the previous 4, expecting width and height information), so I'm wondering if this is something that will break when the Pocket gets its 2.0 update. The current image format used was never properly documented for library images on the developer docs and was instead reverse engineered from the original spiritualized1997 title screen pack.

For now, I will keep this open, though I may not be able to work on it until I knock out some other issues first. I'm open to PRs as well, if someone wants to contribute a fix before I can get to it. Unless this starts affecting the Pocket in a future firmware update, I won't be able to validate a fix on my own.

siffland commented 8 months ago

@ChatMin

If you are not adverse to using python i created a script that works and displays the images properly, will convert the entire thumbnails directory pretty quickly for the analogue duo.

https://github.com/siffland/analogue_duo_convert_images

the issue you are facing is the 90 degree rotation, i know it is in the official docs, but it distorts the image. It does not work for the cd's, i am unsure what they are using for CRC. I am unsure what the lift is for this project to work for the Duo since i know nothing about powershell scripts and .net

codewario commented 8 months ago

@siffland It wouldn't be that hard for me to add it in, as long as I:

The new/Duo format doesn't appear to be much different than the current format used for the Pocket, the main difference is the new file header now expects additional bytes with width and height information which this tool currently doesn't support. That may mean it's as simple as adding those values to the header once calculated.

I have a feeling that the Analogue OS 2.0 update is going to expect this new image format so the fact that I don't own a Duo might not be a problem. I plan on starting to look at this likely after Christmas but before the New Year.

ChatMin commented 8 months ago

@siffland I am a little bit surprised the issue could only be based on the -90° rotation, as it corresponds to my first attempt to fix the powershell script. But I will test and analyse more deeply your python script.

@codewario Maybe I am missing something but, from your tool, it seems the width + height information is already present in the header, as expected:

# Dimensions as bytes, reverse order for little endian
$h_bytes = [BitConverter]::GetBytes(( [int16]( $convertedBitmap.PixelHeight ) ))
$w_bytes = [BitConverter]::GetBytes(( [int16]( $convertedBitmap.PixelWidth ) ))
if ( !( [BitConverter]::IsLittleEndian ) ) {
    [array]::Reverse($h_bytes)
    [array]::Reverse($w_bytes)
}

# Write image dimensions in bytes
$imageStream2.Write($h_bytes, 0, $h_bytes.Length)
$bytesWritten += $h_bytes.Length
$imageStream2.Write($w_bytes, 0, $w_bytes.Length)
$bytesWritten += $w_bytes.Length

If it can help, I could test any fix from you on my own Duo. I have some free days just before the New Year so let me know.

codewario commented 8 months ago

I was mistaken, it does look like I am already putting the H/W info in the header as you pointed out. Misread that part of the code the other night, I wrote most of this tool over a year ago, lol. I will still take a look at this after the holiday and compare what I'm doing to @siffland and the Python sample that Analogue has provided. It looks like others have joined in the effort to figure out the Duo image format (with some obvious success), so the Duo format should be something I am able to add to this tool as well.

ChatMin commented 8 months ago

@codewario For your information, the Analogue Pocket OS 2.0 is available since Xmas : https://www.analogue.co/support/pocket/firmware/2.0. I have not tested yet.