LCOV - code coverage report
Current view: top level - src/components/hdr - HdrViewerContent.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 73.1 % 26 19
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1            2 : <template>
       2              :   <div class="flex size-full bg-background">
       3              :     <div class="relative flex-1">
       4              :       <div
       5              :         ref="containerRef"
       6              :         class="absolute size-full"
       7              :         data-testid="hdr-viewer-canvas"
       8              :       />
       9              : 
      10              :       <div
      11              :         v-if="viewer.loading.value"
      12              :         class="absolute inset-0 flex items-center justify-center"
      13              :       >
      14              :         {{ $t('g.loading') }}...
      15              :       </div>
      16              :       <div
      17              :         v-else-if="viewer.error.value"
      18              :         role="alert"
      19              :         class="absolute inset-0 flex flex-col items-center justify-center gap-2"
      20              :       >
      21              :         <i class="icon-[lucide--image-off] size-12" />
      22              :         <p class="text-sm">{{ $t('hdrViewer.failedToLoad') }}</p>
      23              :       </div>
      24              : 
      25              :       <div
      26              :         v-if="viewer.pixel.value"
      27              :         class="absolute top-2 left-2 rounded-sm bg-background/80 px-2 py-1 font-mono text-xs"
      28              :         data-testid="hdr-pixel-readout"
      29              :       >
      30              :         <div>{{ viewer.pixel.value.x }}, {{ viewer.pixel.value.y }}</div>
      31              :         <div>
      32              :           {{ formatNum(viewer.pixel.value.r) }}
      33              :           {{ formatNum(viewer.pixel.value.g) }}
      34              :           {{ formatNum(viewer.pixel.value.b) }}
      35              :           <template v-if="viewer.pixel.value.a !== null">
      36              :             {{ formatNum(viewer.pixel.value.a) }}
      37              :           </template>
      38              :         </div>
      39              :       </div>
      40              :     </div>
      41              : 
      42              :     <div class="flex w-72 flex-col" data-testid="hdr-viewer-sidebar">
      43              :       <div class="flex-1 overflow-y-auto p-4">
      44              :         <div class="space-y-2">
      45              :           <div class="space-y-4 p-2">
      46              :             <div class="flex flex-col gap-2">
      47              :               <label>{{ $t('hdrViewer.exposure') }}: {{ exposureLabel }}</label>
      48              :               <input
      49              :                 v-model.number="viewer.exposureStops.value"
      50              :                 type="range"
      51              :                 min="-10"
      52              :                 max="10"
      53              :                 step="0.1"
      54              :                 class="w-full"
      55              :                 :aria-label="$t('hdrViewer.exposure')"
      56              :               />
      57              :             </div>
      58              :             <Button
      59              :               variant="secondary"
      60              :               class="w-full"
      61              :               @click="viewer.normalizeExposure"
      62              :             >
      63              :               {{ $t('hdrViewer.normalizeExposure') }}
      64              :             </Button>
      65              :           </div>
      66              : 
      67              :           <div class="space-y-4 p-2">
      68              :             <div class="flex flex-col gap-2">
      69              :               <label>{{ $t('hdrViewer.channel') }}</label>
      70              :               <select
      71              :                 v-model="viewer.channel.value"
      72              :                 class="w-full rounded-sm bg-secondary px-2 py-1"
      73              :                 :aria-label="$t('hdrViewer.channel')"
      74              :               >
      75           24 :                 <option v-for="mode in channelModes" :key="mode" :value="mode">
      76              :                   {{ channelLabels[mode] }}
      77              :                 </option>
      78              :               </select>
      79              :             </div>
      80              : 
      81              :             <div class="flex flex-col gap-2">
      82              :               <label>{{ $t('hdrViewer.sourceGamut') }}</label>
      83              :               <select
      84              :                 v-model="viewer.gamut.value"
      85              :                 class="w-full rounded-sm bg-secondary px-2 py-1"
      86              :                 :aria-label="$t('hdrViewer.sourceGamut')"
      87              :               >
      88            8 :                 <option v-for="name in gamutNames" :key="name" :value="name">
      89              :                   {{ name }}
      90              :                 </option>
      91              :               </select>
      92              :             </div>
      93              :           </div>
      94              : 
      95              :           <div class="space-y-4 p-2">
      96              :             <div class="flex items-center gap-2">
      97              :               <input
      98              :                 id="hdr-dither"
      99              :                 v-model="viewer.dither.value"
     100              :                 type="checkbox"
     101              :                 class="size-4 cursor-pointer accent-muted-foreground"
     102              :               />
     103              :               <label for="hdr-dither" class="cursor-pointer">
     104              :                 {{ $t('hdrViewer.dither') }}
     105              :               </label>
     106              :             </div>
     107              :             <div class="flex items-center gap-2">
     108              :               <input
     109              :                 id="hdr-clip"
     110              :                 v-model="viewer.clipWarnings.value"
     111              :                 type="checkbox"
     112              :                 class="size-4 cursor-pointer accent-muted-foreground"
     113              :               />
     114              :               <label for="hdr-clip" class="cursor-pointer">
     115              :                 {{ $t('hdrViewer.clipWarnings') }}
     116              :               </label>
     117              :             </div>
     118              :             <div class="flex items-center gap-2">
     119              :               <input
     120              :                 id="hdr-checkerboard"
     121              :                 v-model="viewer.checkerboard.value"
     122              :                 type="checkbox"
     123              :                 class="size-4 cursor-pointer accent-muted-foreground"
     124              :               />
     125              :               <label for="hdr-checkerboard" class="cursor-pointer">
     126              :                 {{ $t('hdrViewer.checkerboard') }}
     127              :               </label>
     128              :             </div>
     129              :           </div>
     130              : 
     131              :           <div v-if="histogramPath" class="space-y-2 p-2">
     132              :             <label>{{ $t('hdrViewer.histogram') }}</label>
     133              :             <svg
     134              :               viewBox="0 0 1 1"
     135              :               preserveAspectRatio="none"
     136              :               class="aspect-3/2 w-full rounded-sm bg-secondary"
     137              :             >
     138              :               <path
     139              :                 :d="histogramPath"
     140              :                 :class="histogramColorClass"
     141              :                 fill="currentColor"
     142              :                 fill-opacity="0.5"
     143              :                 stroke="none"
     144              :               />
     145              :             </svg>
     146              :           </div>
     147              : 
     148              :           <div
     149              :             v-if="viewer.stats.value"
     150              :             class="space-y-1 p-2 text-xs tabular-nums"
     151              :           >
     152              :             <div v-if="viewer.dimensions.value" class="flex justify-between">
     153              :               <span>{{ $t('hdrViewer.resolution') }}</span>
     154              :               <span>{{ viewer.dimensions.value }}</span>
     155              :             </div>
     156              :             <div class="flex justify-between">
     157              :               <span>{{ $t('hdrViewer.min') }}</span>
     158              :               <span>{{ formatNum(viewer.stats.value.min) }}</span>
     159              :             </div>
     160              :             <div class="flex justify-between">
     161              :               <span>{{ $t('hdrViewer.max') }}</span>
     162              :               <span>{{ formatNum(viewer.stats.value.max) }}</span>
     163              :             </div>
     164              :             <div class="flex justify-between">
     165              :               <span>{{ $t('hdrViewer.mean') }}</span>
     166              :               <span>{{ formatNum(viewer.stats.value.mean) }}</span>
     167              :             </div>
     168              :             <div class="flex justify-between">
     169              :               <span>{{ $t('hdrViewer.stdDev') }}</span>
     170              :               <span>{{ formatNum(viewer.stats.value.stdDev) }}</span>
     171              :             </div>
     172              :             <div
     173              :               v-if="viewer.stats.value.nanCount"
     174              :               class="flex justify-between text-destructive"
     175              :             >
     176              :               <span>{{ $t('hdrViewer.nan') }}</span>
     177              :               <span>{{ viewer.stats.value.nanCount }}</span>
     178              :             </div>
     179              :             <div
     180              :               v-if="viewer.stats.value.infCount"
     181              :               class="flex justify-between text-destructive"
     182              :             >
     183              :               <span>{{ $t('hdrViewer.inf') }}</span>
     184              :               <span>{{ viewer.stats.value.infCount }}</span>
     185              :             </div>
     186              :           </div>
     187              :         </div>
     188              :       </div>
     189              : 
     190              :       <div class="p-4">
     191              :         <div class="flex gap-2">
     192              :           <Button variant="secondary" class="flex-1" @click="viewer.fitView">
     193              :             {{ $t('hdrViewer.fitView') }}
     194              :           </Button>
     195              :           <Button variant="secondary" class="flex-1" @click="handleDownload">
     196              :             {{ $t('g.downloadImage') }}
     197              :           </Button>
     198              :         </div>
     199              :       </div>
     200              :     </div>
     201              :   </div>
     202              : </template>
     203              : 
     204              : <script setup lang="ts">
     205              : import { computed, onMounted, useTemplateRef } from 'vue'
     206              : import { useI18n } from 'vue-i18n'
     207              : 
     208              : import { downloadFile } from '@/base/common/downloadUtil'
     209              : import Button from '@comfyorg/design-system/button/Button'
     210              : import type { ChannelMode } from '@/composables/useHdrViewer'
     211              : import { CHANNEL_MODES, useHdrViewer } from '@/composables/useHdrViewer'
     212              : import { GAMUT_NAMES } from '@/renderer/hdr/colorGamut'
     213              : import { toFullResolutionUrl } from '@/utils/hdrFormatUtil'
     214              : import { histogramToPath } from '@/utils/histogramUtil'
     215              : 
     216              : const { imageUrl } = defineProps<{ imageUrl: string }>()
     217              : 
     218            2 : const { t } = useI18n()
     219            2 : const viewer = useHdrViewer()
     220            2 : const gamutNames = GAMUT_NAMES
     221            2 : const channelModes = CHANNEL_MODES
     222            2 : const containerRef = useTemplateRef<HTMLDivElement>('containerRef')
     223              : 
     224            2 : const exposureLabel = computed(() => {
     225            2 :   const value = viewer.exposureStops.value
     226            2 :   return `${value > 0 ? '+' : ''}${value.toFixed(1)}`
     227              : })
     228              : 
     229            2 : const histogramPath = computed(() =>
     230              :   viewer.histogram.value ? histogramToPath(viewer.histogram.value) : ''
     231              : )
     232              : 
     233            2 : const histogramColorClass = computed(() => {
     234            0 :   switch (viewer.channel.value) {
     235              :     case 'r':
     236            0 :       return 'text-red-500'
     237              :     case 'g':
     238            0 :       return 'text-green-500'
     239              :     case 'b':
     240            0 :       return 'text-blue-500'
     241              :     default:
     242            0 :       return 'text-foreground'
     243              :   }
     244              : })
     245              : 
     246            2 : const channelLabels = computed<Record<ChannelMode, string>>(() => ({
     247              :   rgb: t('hdrViewer.channels.rgb'),
     248              :   r: t('hdrViewer.channels.r'),
     249              :   g: t('hdrViewer.channels.g'),
     250              :   b: t('hdrViewer.channels.b'),
     251              :   a: t('hdrViewer.channels.a'),
     252              :   luminance: t('hdrViewer.channels.luminance')
     253              : }))
     254              : 
     255            8 : function formatNum(value: number): string {
     256            8 :   if (!Number.isFinite(value)) return String(value)
     257            8 :   return Math.abs(value) >= 1000 || (value !== 0 && Math.abs(value) < 0.001)
     258              :     ? value.toExponential(3)
     259              :     : value.toFixed(4)
     260              : }
     261              : 
     262            0 : function handleDownload() {
     263            0 :   downloadFile(toFullResolutionUrl(imageUrl))
     264              : }
     265              : 
     266            2 : onMounted(() => {
     267            2 :   if (containerRef.value) void viewer.mount(containerRef.value, imageUrl)
     268              : })
     269              : </script>
        

Generated by: LCOV version 2.0-1