Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Jan 22, 2026

This change converts ARGB Radar pixel colors into the correct format before writing them into the DirectX surface.

I have not been able to figure out how to get the game to use a non A8R8B8G8 surface on my machine, so I was not able to really confirm that this is a useful change.

But it seems like this is the correct thing to do.

The ARGB_Color_To_WW3D_Color function was mostly generated by Chad Gippi.

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Rendering Is Rendering related Fix Is fixing something, but is not user facing labels Jan 22, 2026
@greptile-apps
Copy link

greptile-apps bot commented Jan 22, 2026

Greptile Overview

Greptile Summary

This PR adds proper pixel format conversion for radar rendering on non-A8R8G8B8 DirectX surfaces, following up on #2138.

Key Changes:

  • Implemented ARGB_Color_To_WW3D_Color() function supporting 13 pixel formats (RGB variants, luminance formats, and fixed-point color formats)
  • Modified radar rendering to convert ARGB colors to surface-specific formats before writing pixels
  • Added m_shroudSurfaceFormat member to cache format for efficient repeated conversions during shroud updates
  • Updated three rendering paths: radar objects (renderObjectList), terrain texture (buildTerrainTexture), and shroud overlay (setShroudLevel)

Technical Details:

  • Luminance conversion uses ITU-R BT.601 coefficients: L = (R*77 + G*150 + B*29) >> 8
  • Handles bit depth reduction correctly (e.g., 8-bit to 5-bit for R5G6B5 format)
  • Returns 0 for unsupported formats (palettized, bump-map, and compressed formats)

The implementation is thorough and mathematically sound. While the author couldn't test with non-A8R8G8B8 surfaces, the logic correctly handles format conversion according to DirectX conventions.

Confidence Score: 5/5

  • This PR is safe to merge with no blocking issues
  • The changes are well-structured and follow best practices. The new color conversion function is comprehensive, handles edge cases properly, and the integration into existing code is clean. All three rendering paths are consistently updated. The code is defensive with proper initialization and assertions.
  • No files require special attention

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WW3D2/ww3dformat.cpp Implemented ARGB_Color_To_WW3D_Color function with format conversion logic for 13 different pixel formats including RGB, luminance, and fixed-point color formats
Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp Converted ARGB colors to surface-specific formats before pixel writes in radar rendering, terrain building, and shroud updating functions

Sequence Diagram

sequenceDiagram
    participant Radar as W3DRadar
    participant Surface as SurfaceClass
    participant Convert as ARGB_Color_To_WW3D_Color
    participant Draw as Draw_Pixel

    Note over Radar: Rendering radar objects/terrain/shroud
    Radar->>Surface: Get_Description(surfaceDesc)
    Surface-->>Radar: Returns surface format (e.g. R5G6B5)
    Radar->>Surface: Lock(&pitch)
    Surface-->>Radar: Returns pixel buffer pointer
    
    Note over Radar: For each pixel to draw
    Radar->>Radar: Create ARGB color (GameMakeColor)
    Radar->>Convert: ARGB_Color_To_WW3D_Color(format, argb)
    Note over Convert: Convert ARGB to surface-specific format<br/>(e.g. A8R8G8B8, R5G6B5, L8, etc.)
    Convert-->>Radar: Returns format-specific pixel value
    Radar->>Draw: Draw_Pixel(x, y, pixelColor, bytesPerPixel, pBits, pitch)
    Draw->>Surface: Write pixel to buffer
    
    Note over Radar: After all pixels drawn
    Radar->>Surface: Unlock()

Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (1)

  1. Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp, line 1431 (link)

    style: m_shroudSurfaceFormat should be reset to WW3D_FORMAT_UNKNOWN here for consistency with other cleanup

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@JohnsterID
Copy link

I've reviewed the implementation and verified the bit manipulation logic mathematically - the RGB565/ARGB4444 conversions are correct, and the luminance calculation properly follows ITU-R BT.601 standard (77R + 150G + 29B = 256). The function is applied consistently across all radar rendering paths (renderObjectList, buildTerrainTexture, setShroudLevel) and handles edge cases safely by returning 0 for unsupported formats. While the code path may rarely execute on modern hardware (which typically uses A8R8G8B8), this is solid defensive programming that ensures correctness for legacy systems and alternative DirectX configurations with zero performance penalty.


}

color = ARGB_Color_To_WW3D_Color(surfaceDesc.Format, color);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what C++ convention is, but in c# you would distinguish the colors by variable name, so rgbColor and ww3dColor, rather than using 1 variable for both color types.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Introduced argbColor and pixelColor for clarity.

@xezon xezon force-pushed the xezon/fix-radar-drawpixel-color-2 branch from 0ba1ef5 to 64d1bf0 Compare January 28, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Rendering Is Rendering related ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants