Skip to content

Commit

Permalink
minor fixes (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc authored Dec 21, 2023
1 parent ef91525 commit 97b8f53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions apps/frontend/src/app/Snow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { range } from '@genshin-optimizer/util'
export default function Snow() {
return (
<div id="snowflake-container">
{range(1, 200).map(() => (
<div className="snowflake" />
{range(1, 200).map((i) => (
<div key={i} className="snowflake" />
))}
</div>
)
Expand Down
4 changes: 3 additions & 1 deletion libs/gi-art-scanner/src/lib/processImg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function processEntry(

const titleHistogram = findTitle(artifactCardImageData)
const [titleTop, titleBot] = titleHistogram
? findHistogramRange(titleHistogram)
? findHistogramRange(titleHistogram, 0.7, 1) // smaller threshold
: [0, 0]

const whiteCardHistogram = histogramContAnalysis(
Expand Down Expand Up @@ -261,6 +261,8 @@ export async function processEntry(
)
if (debugImgs) {
debugImgs['bwHeader'] = imageDataToCanvas(bwHeader).toDataURL()
debugImgs['greenTextCropped'] =
imageDataToCanvas(greenTextCropped).toDataURL()
debugImgs['bwGreenText'] = imageDataToCanvas(bwGreenText).toDataURL()
if (bwEquipped)
debugImgs['bwEquipped'] = imageDataToCanvas(bwEquipped).toDataURL()
Expand Down
10 changes: 8 additions & 2 deletions libs/img-util/src/imageData.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { clamp } from '@genshin-optimizer/util'

export function cropCanvas(
srcCanvas: HTMLCanvasElement,
x: number,
Expand All @@ -23,14 +25,18 @@ export function crop(srcCanvas: HTMLCanvasElement, options: CropOptions) {
const width = srcCanvas.width
const height = srcCanvas.height
let { x1 = 0, x2 = width, y1 = 0, y2 = height } = options
if (y1 > y2 || y1 > height) {
x1 = clamp(x1, 0, width)
x2 = clamp(x2, 0, width)
y1 = clamp(y1, 0, height)
y2 = clamp(y2, 0, height)
if (y1 >= y2) {
console.warn(
`trying to crop with y1:${y1} y2:${y2}, with src height ${height}.`
)
y1 = 0
y2 = height
}
if (x1 > x2 || x1 > width) {
if (x1 >= x2) {
console.warn(
`trying to crop with x1:${x1} x2:${x2}, with src width ${width}.`
)
Expand Down

0 comments on commit 97b8f53

Please sign in to comment.