{"id":26060895,"url":"https://github.com/swnb/dct-ts","last_synced_at":"2026-05-26T20:31:27.460Z","repository":{"id":57163997,"uuid":"452187073","full_name":"swnb/dct-ts","owner":"swnb","description":"dct and idct algorithm implement with typescript","archived":false,"fork":false,"pushed_at":"2022-01-27T15:22:19.000Z","size":992,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T03:23:07.024Z","etag":null,"topics":["algorithm","dct","idct","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/swnb/dct-ts#readme","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swnb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-26T07:55:34.000Z","updated_at":"2022-11-03T05:22:56.000Z","dependencies_parsed_at":"2022-09-01T09:11:48.732Z","dependency_job_id":null,"html_url":"https://github.com/swnb/dct-ts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/swnb/dct-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swnb%2Fdct-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swnb%2Fdct-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swnb%2Fdct-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swnb%2Fdct-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swnb","download_url":"https://codeload.github.com/swnb/dct-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swnb%2Fdct-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33538659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","dct","idct","typescript"],"created_at":"2025-03-08T14:47:34.171Z","updated_at":"2026-05-26T20:31:27.444Z","avatar_url":"https://github.com/swnb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @swnb/dct\n\n\u003e dct and idct algorithm implement in typescript\n\n## for example\n\nluma image before dct\n\n![luma](./assets/luma.jpeg)\n\nafter dct, you can use idct to recovery origin image\n\n![dct](./assets/dct.jpeg)\n\n\n\n## install\n\nuse pnpm\n\n```shell\n  pnpm i @swnb/dct\n```\n\nuse npm\n\n```shell\n  npm i @swnb/dct\n```\n\n## usage\n\nprepare example data\n\n```typescript\n  const example = [\n    [65, 76, 82, 66, 18, 32],\n    [12, 87, 9, 2, 54, 78],\n    [74, 45, 18, 48, 60, 72],\n    [65, 2, 54, 404, 800, 905],\n  ]\n```\n\ndiscrete cosine transform\n\n```typescript\n  import { dct } from '@swnb/dct'\n\n  const result = dct(example)\n\n  console.log(result) \n  // [\n  //   [\n  //     638.5003262854817, -416.9193200063309, 154.99999999999983, 42.4578222082416, -43.01259505462728,\n  //     -17.244243642209376,\n  //   ],\n  //   [\n  //     -512.6170218697843, 578.6135814300578, -184.03403633138637, -109.98075816639899,\n  //     29.645534009728465, -12.201804240974509,\n  //   ],\n  //   [\n  //     410.2895319161823, -385.13955429855645, 75.4999999999998, 66.54447134560958, 8.660254037844224,\n  //     12.49428061324591,\n  //   ],\n  //   [\n  //     -188.89844420398651, 249.46420106733234, -75.84671035435811, 2.2508146252807193,\n  //     52.71203828296457, 1.9283180367658657,\n  //   ],\n  // ]\n```\n\ninverse discrete cosine transform\n\n```typescript\n  import { idct } from '@swnb/dct'\n\n  const result = dct(example)\n\n  const originData = idct(result)\n\n  console.log(originData)\n  // [\n  //   [\n  //     64.99999999999993,\n  //     75.99999999999999,\n  //     81.99999999999997,\n  //     65.99999999999996,\n  //     17.999999999999897,\n  //     31.999999999999893\n  //   ],\n  //   [\n  //     11.99999999999998,\n  //     87.00000000000003,\n  //     8.999999999999943,\n  //     1.9999999999999762,\n  //     53.99999999999998,\n  //     78.00000000000009\n  //   ],\n  //   [\n  //     73.99999999999994,\n  //     45.000000000000036,\n  //     17.999999999999922,\n  //     47.99999999999986,\n  //     59.99999999999982,\n  //     71.99999999999982\n  //   ],\n  //   [\n  //     64.99999999999974,\n  //     2.00000000000048,\n  //     53.99999999999999,\n  //     404.0000000000001,\n  //     799.9999999999999,\n  //     904.9999999999995\n  //   ]\n  // ]\n```\n\n## use interface\n\n```typescript\n// if you implement Matrix or MatrixPromise\n\ninterface Matrix {\n  getValue: (x: number, y: number) =\u003e number\n}\n\ninterface MatrixPromise {\n  getValue: (x: number, y: number) =\u003e Promise\u003cnumber\u003e\n}\n\n```\n\nyou can use dctMatrix, dctMatrixPromise, idctMatrix, idctMatrixPromise to process matrix\n\n```typescript\n  import { dctMatrix, idctMatrix, dctMatrixPromise, idctMatrixPromise, Matrix, MatrixPromise } from '@swnb/dct'\n\n  declare const m: number // matrix's width\n  declare const n: number // matrix's height\n  declare const matrix: Matrix // matrix implement { getValue: ( x, y ) =\u003e number }  0 \u003c= x \u003c m , 0 \u003c= y \u003c n\n\n  declare const matrixPromise: MatrixPromise\n\n  const result1 = dctMatrix(matrix, m, n)\n\n  const result2 = await dctMatrixPromise(matrixPromise, m, n)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswnb%2Fdct-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswnb%2Fdct-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswnb%2Fdct-ts/lists"}