{"record":{"id":"b2b16fdc846baff9","repo":"stride3d/stride","slug":"format-is-already-an-srgb-pixel-format","errorCode":null,"errorMessage":"'{format}' is already an sRGB pixel format","messagePattern":"'(.+?)' is already an sRGB pixel format","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"warning","filePath":"sources/engine/Stride.Foundation/Graphics/PixelFormatExtensions.cs","lineNumber":273,"sourceCode":"        ///   They are often used in scenarios where the same data may be interpreted\n        ///   as different types depending on the context, such as when creating\n        ///   a resource that can be viewed in multiple ways.\n        /// </remarks>\n        public bool IsTypeless => typelessFormats[GetIndex(format)];\n\n        /// <summary>\n        ///   Gets a value indicating if the <see cref=\"PixelFormat\"/> has an equivalent sRGB format.\n        /// </summary>\n        /// <returns>\n        ///   <see langword=\"true\"/> if the pixel format has an sRGB equivalent;\n        ///   <see langword=\"false\"/> otherwise.\n        /// </returns>\n        /// <exception cref=\"ArgumentException\">\n        ///   The provided pixel format is already an sRGB format.\n        /// </exception>\n        public bool HasSRgbEquivalent\n            => format.IsSRgb\n                ? throw new ArgumentException($\"'{format}' is already an sRGB pixel format\", nameof(format))\n                : sRgbConversion.ContainsKey(format);\n\n        /// <summary>\n        ///   Gets a value indicating if the <see cref=\"PixelFormat\"/> has an equivalent non-sRGB format.\n        /// </summary>\n        /// <returns>\n        ///   <see langword=\"true\"/> if the pixel format has an non-sRGB equivalent;\n        ///   <see langword=\"false\"/> otherwise.\n        /// </returns>\n        /// <exception cref=\"ArgumentException\">\n        ///   The provided pixel format is not an sRGB format.\n        /// </exception>\n        public bool HasNonSRgbEquivalent\n            => !format.IsSRgb\n                ? throw new ArgumentException($\"'{format}' is not a sRGB format\", nameof(format))\n                : sRgbConversion.ContainsKey(format);\n\n        /// <summary>","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/PixelFormatExtensions.cs#L255-L291","documentation":"The HasSRgbEquivalent property accessor on the PixelFormat helper throws ArgumentException when the wrapped format IsSRgb, because asking for an sRGB equivalent of a format that is already sRGB is meaningless. The property is intended for non-sRGB formats; for sRGB formats it throws instead of returning a value.","triggerScenarios":"Evaluating helper.HasSRgbEquivalent on a PixelFormatExtensions instance whose format is already an sRGB format (e.g. R8G8B8A8_UNorm_SRgb), typically inside generic format-handling code that does not branch on IsSRgb first.","commonSituations":"Generic texture-format migration code adding _SRgb variants that double-applies to already-sRGB formats; asset pipelines iterating formats where sRGB inputs slip through; debugging code that probes all formats indiscriminately.","solutions":["Check format.IsSRgb first and skip/short-circuit for already-sRGB formats.","Return the format itself when IsSRgb is true instead of querying HasSRgbEquivalent.","Filter the format list to non-sRGB entries before calling this property."],"exampleFix":"// before\nvar srgbFmt = helper.HasSRgbEquivalent ? helper.GetSRgbEquivalent() : helper.Format;\n// after\nvar srgbFmt = helper.Format.IsSRgb ? helper.Format\n    : helper.HasSRgbEquivalent ? helper.GetSRgbEquivalent() : helper.Format;","handlingStrategy":"type-guard","validationCode":"if (!format.IsSRgb)\n{\n    // safe to query\n    var has = helper.HasSRgbEquivalent;\n}","typeGuard":"bool CanQuerySRgbEquivalent(PixelFormat fmt) => !fmt.IsSRgb;","tryCatchPattern":"try { return helper.HasSRgbEquivalent ? helper.GetSRgbEquivalent() : helper.Format; }\ncatch (ArgumentException) { return helper.Format; /* already sRGB */ }","preventionTips":["Gate all sRGB-conversion queries behind an IsSRgb check.","Write a pure helper that returns fmt when fmt.IsSRgb instead of touching the throwing property.","Add asset-pipeline assertions that sRGB formats are not re-converted."],"tags":["graphics","pixel-format","srgb","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}