Public Vars

Back

unchecked-byte (clj)

(source)

function

(unchecked-byte x)
Coerce to byte. Subject to rounding or truncation.

Examples

pjstadig/utf8
;;;; Copyright © 2013 Paul Stadig. All rights reserved.
;;;;
;;;; This Source Code Form is subject to the terms of the Mozilla Public
;;;; License, v. 2.0. If a copy of the MPL was not distributed with this file,
;;;; You can obtain one at http://mozilla.org/MPL/2.0/.
;;;;
;;;; This Source Code Form is "Incompatible With Secondary Licenses", as defined
;;;; by the Mozilla Public License, v. 2.0.
(ns pjstadig.test.utf8
  (:require [clojure.core :as clj]
            [clojure.java.io :as io]
            [clojure.test :refer :all]
            [pjstadig.utf8 :refer :all]))

(deftest test-byte-seq
  (is (= (map unchecked-byte [2r11110000 2r10100100 2r10101101 2r10100010
                              2r11000010 2r10100010
                              2r11100010 2r10000010 2r10101100])
         (byte-seq (seq "\ud852\udf62¢€")))))
originrose/think.image
(ns think.image.byte-color-test
  (:require [clojure.test :refer :all]
            [clojure.core.matrix.macros :refer [c-for]])
  (:import [think.image ByteColor]
           [java.awt.image BufferedImage]))


(deftest gray-scale
  (let [test-color (ByteColor. 255 128 64)
        gray-color (ByteColor/grayScale test-color)]
    (is (= gray-color (unchecked-byte
                       (+ (* 255.0 0.2989)
                          (* 128.0 0.5870)
                          (* 64.0 0.1140)
                          0.5))))))


(deftest convert-gray-scale
  (let [test-color (ByteColor. 255 128 64)
        color-array (into-array ByteColor (repeat 16 test-color))
        gray-color (ByteColor. (unchecked-byte
                                (+ (* 255.0 0.2989)
                                   (* 128.0 0.5870)
                                   (* 64.0 0.1140)
                                   0.5)))
        answer (into-array ByteColor (repeat 16 gray-color))
        byte-result
        (ByteColor/convertAllocate color-array BufferedImage/TYPE_INT_ARGB Byte/TYPE BufferedImage/TYPE_BYTE_GRAY ByteColor/Black)
        int-result
        (ByteColor/convertAllocate color-array BufferedImage/TYPE_INT_ARGB Integer/TYPE BufferedImage/TYPE_BYTE_GRAY ByteColor/Black)
        byte-color-result
        (ByteColor/convertAllocate color-array BufferedImage/TYPE_INT_ARGB ByteColor BufferedImage/TYPE_BYTE_GRAY ByteColor/Black)
        int-result-color
        (ByteColor/convertAllocate int-result BufferedImage/TYPE_BYTE_GRAY ByteColor BufferedImage/TYPE_BYTE_GRAY ByteColor/Black)
        byte-result-color
        (ByteColor/convertAllocate byte-result BufferedImage/TYPE_BYTE_GRAY ByteColor BufferedImage/TYPE_BYTE_GRAY ByteColor/Black)]