repo_id stringlengths 6 101 | file_path stringlengths 2 269 | content stringlengths 367 5.14M | size int64 367 5.14M | filename stringlengths 1 248 | ext stringlengths 0 87 | lang stringclasses 88 values | program_lang stringclasses 232 values | doc_type stringclasses 5 values | quality_signal stringlengths 2 1.9k | effective stringclasses 2 values | hit_map stringlengths 2 1.4k |
|---|---|---|---|---|---|---|---|---|---|---|---|
00-Evan/shattered-pixel-dungeon-gdx | PD-classes/src/com/watabou/utils/BitmapCache.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import java.util.HashMap;
public class BitmapCache {
private static final String DEFAULT = "__default";
private static HashMap<String,Layer> layers = new HashMap<>();
public static Pixmap get( String assetName ) {
return get( DEFAULT, assetName );
}
public static Pixmap get(String layerName, String assetName ) {
Layer layer;
if (!layers.containsKey( layerName )) {
layer = new Layer();
layers.put( layerName, layer );
} else {
layer = layers.get( layerName );
}
if (layer.containsKey( assetName )) {
return layer.get( assetName );
} else {
Pixmap bmp = new Pixmap( Gdx.files.internal(assetName) );
layer.put( assetName, bmp );
return bmp;
}
}
public static void clear( String layerName ) {
if (layers.containsKey( layerName )) {
layers.get( layerName ).clear();
layers.remove(layerName);
}
}
public static void clear() {
for (Layer layer:layers.values()) {
layer.clear();
}
layers.clear();
}
@SuppressWarnings("serial")
private static class Layer extends HashMap<Object,Pixmap> {
@Override
public void clear() {
for (Pixmap bmp:values()) {
bmp.dispose();
}
super.clear();
}
}
}
| 2,114 | BitmapCache | java | en | java | code | {"qsc_code_num_words": 274, "qsc_code_num_chars": 2114.0, "qsc_code_mean_word_length": 5.34306569, "qsc_code_frac_words_unique": 0.44525547, "qsc_code_frac_chars_top_2grams": 0.03005464, "qsc_code_frac_chars_top_3grams": 0.02663934, "qsc_code_frac_chars_top_4grams": 0.03893443, "qsc_code_frac_chars_dupe_5grams": 0.13114754, "qsc_code_frac_chars_dupe_6grams": 0.03825137, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01007109, "qsc_code_frac_chars_whitespace": 0.20151372, "qsc_code_size_file_byte": 2114.0, "qsc_code_num_lines": 84.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 25.16666667, "qsc_code_frac_chars_alphabet": 0.85722749, "qsc_code_frac_chars_comments": 0.36944182, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01125281, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.12, "qsc_codejava_score_lines_no_logic": 0.26, "qsc_codejava_frac_words_no_modifier": 0.71428571, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | PD-classes/src/com/watabou/utils/Reflection.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.utils;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.badlogic.gdx.utils.reflect.ReflectionException;
import com.watabou.noosa.Game;
//wrapper for LibGDX reflection
public class Reflection {
public static boolean isMemberClass( Class cls ){
return ClassReflection.isMemberClass(cls);
}
public static boolean isStatic( Class cls ){
return ClassReflection.isStaticClass(cls);
}
public static <T> T newInstance( Class<T> cls ){
try {
return ClassReflection.newInstance(cls);
} catch (ReflectionException e) {
Game.reportException(e);
return null;
}
}
public static <T> T newInstanceUnhandled( Class<T> cls ) throws Exception {
return ClassReflection.newInstance(cls);
}
public static Class forName( String name ){
try {
return ClassReflection.forName( name );
} catch (ReflectionException e) {
Game.reportException(e);
return null;
}
}
public static Class forNameUnhandled( String name ) throws Exception {
return ClassReflection.forName( name );
}
}
| 1,835 | Reflection | java | en | java | code | {"qsc_code_num_words": 237, "qsc_code_num_chars": 1835.0, "qsc_code_mean_word_length": 5.70042194, "qsc_code_frac_words_unique": 0.48523207, "qsc_code_frac_chars_top_2grams": 0.05329386, "qsc_code_frac_chars_top_3grams": 0.02886751, "qsc_code_frac_chars_top_4grams": 0.04219097, "qsc_code_frac_chars_dupe_5grams": 0.20725389, "qsc_code_frac_chars_dupe_6grams": 0.18800888, "qsc_code_frac_chars_dupe_7grams": 0.09918579, "qsc_code_frac_chars_dupe_8grams": 0.09918579, "qsc_code_frac_chars_dupe_9grams": 0.09918579, "qsc_code_frac_chars_dupe_10grams": 0.09918579, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01131824, "qsc_code_frac_chars_whitespace": 0.18147139, "qsc_code_size_file_byte": 1835.0, "qsc_code_num_lines": 65.0, "qsc_code_num_chars_line_max": 77.0, "qsc_code_num_chars_line_mean": 28.23076923, "qsc_code_frac_chars_alphabet": 0.88814913, "qsc_code_frac_chars_comments": 0.44196185, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.35294118, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.17647059, "qsc_codejava_score_lines_no_logic": 0.35294118, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | PD-classes/src/com/watabou/utils/Graph.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class Graph {
public static <T extends Node> void setPrice( List<T> nodes, int value ) {
for (T node : nodes) {
node.price( value );
}
}
public static <T extends Node> void buildDistanceMap( Collection<T> nodes, Node focus ) {
for (T node : nodes) {
node.distance( Integer.MAX_VALUE );
}
LinkedList<Node> queue = new LinkedList<>();
focus.distance( 0 );
queue.add( focus );
while (!queue.isEmpty()) {
Node node = queue.poll();
int distance = node.distance();
int price = node.price();
for (Node edge : node.edges()) {
if (edge.distance() > distance + price) {
queue.add( edge );
edge.distance( distance + price );
}
}
}
}
@SuppressWarnings("unchecked")
public static <T extends Node> List<T> buildPath( Collection<T> nodes, T from, T to ) {
List<T> path = new ArrayList<>();
T room = from;
while (room != to) {
int min = room.distance();
T next = null;
Collection<? extends Node> edges = room.edges();
for (Node edge : edges) {
int distance = edge.distance();
if (distance < min) {
min = distance;
next = (T)edge;
}
}
if (next == null) {
return null;
}
path.add( next );
room = next;
}
return path;
}
public interface Node {
int distance();
void distance( int value );
int price();
void price( int value );
Collection<? extends Node> edges();
}
}
| 2,387 | Graph | java | en | java | code | {"qsc_code_num_words": 315, "qsc_code_num_chars": 2387.0, "qsc_code_mean_word_length": 4.83174603, "qsc_code_frac_words_unique": 0.4031746, "qsc_code_frac_chars_top_2grams": 0.03613666, "qsc_code_frac_chars_top_3grams": 0.03679369, "qsc_code_frac_chars_top_4grams": 0.03745072, "qsc_code_frac_chars_dupe_5grams": 0.12877792, "qsc_code_frac_chars_dupe_6grams": 0.07358739, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01002786, "qsc_code_frac_chars_whitespace": 0.24801005, "qsc_code_size_file_byte": 2387.0, "qsc_code_num_lines": 107.0, "qsc_code_num_chars_line_max": 91.0, "qsc_code_num_chars_line_mean": 22.30841121, "qsc_code_frac_chars_alphabet": 0.83788301, "qsc_code_frac_chars_comments": 0.32718894, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.03278689, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00560399, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06557377, "qsc_codejava_score_lines_no_logic": 0.18032787, "qsc_codejava_frac_words_no_modifier": 0.0, "qsc_codejava_frac_words_legal_var_name": 0.77777778, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | PD-classes/src/com/watabou/utils/PathFinder.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.watabou.utils;
import java.util.Arrays;
import java.util.LinkedList;
public class PathFinder {
public static int[] distance;
private static int[] maxVal;
private static boolean[] goals;
private static int[] queue;
private static int size = 0;
private static int width = 0;
private static int[] dir;
private static int[] dirLR;
//performance-light shortcuts for some common pathfinder cases
//they are in array-access order for increased memory performance
public static int[] NEIGHBOURS4;
public static int[] NEIGHBOURS8;
public static int[] NEIGHBOURS9;
//similar to their equivalent neighbour arrays, but the order is clockwise.
//Useful for some logic functions, but is slower due to lack of array-access order.
public static int[] CIRCLE4;
public static int[] CIRCLE8;
public static void setMapSize( int width, int height ) {
PathFinder.width = width;
PathFinder.size = width * height;
distance = new int[size];
goals = new boolean[size];
queue = new int[size];
maxVal = new int[size];
Arrays.fill(maxVal, Integer.MAX_VALUE);
dir = new int[]{-1, +1, -width, +width, -width-1, -width+1, +width-1, +width+1};
dirLR = new int[]{-1-width, -1, -1+width, -width, +width, +1-width, +1, +1+width};
NEIGHBOURS4 = new int[]{-width, -1, +1, +width};
NEIGHBOURS8 = new int[]{-width-1, -width, -width+1, -1, +1, +width-1, +width, +width+1};
NEIGHBOURS9 = new int[]{-width-1, -width, -width+1, -1, 0, +1, +width-1, +width, +width+1};
CIRCLE4 = new int[]{-width, +1, +width, -1};
CIRCLE8 = new int[]{-width-1, -width, -width+1, +1, +width+1, +width, +width-1, -1};
}
public static Path find( int from, int to, boolean[] passable ) {
if (!buildDistanceMap( from, to, passable )) {
return null;
}
Path result = new Path();
int s = from;
// From the starting position we are moving downwards,
// until we reach the ending point
do {
int minD = distance[s];
int mins = s;
for (int i=0; i < dir.length; i++) {
int n = s + dir[i];
int thisD = distance[n];
if (thisD < minD) {
minD = thisD;
mins = n;
}
}
s = mins;
result.add( s );
} while (s != to);
return result;
}
public static int getStep( int from, int to, boolean[] passable ) {
if (!buildDistanceMap( from, to, passable )) {
return -1;
}
// From the starting position we are making one step downwards
int minD = distance[from];
int best = from;
int step, stepD;
for (int i=0; i < dir.length; i++) {
if ((stepD = distance[step = from + dir[i]]) < minD) {
minD = stepD;
best = step;
}
}
return best;
}
public static int getStepBack( int cur, int from, boolean[] passable ) {
int d = buildEscapeDistanceMap( cur, from, 2f, passable );
for (int i=0; i < size; i++) {
goals[i] = distance[i] == d;
}
if (!buildDistanceMap( cur, goals, passable )) {
return -1;
}
int s = cur;
// From the starting position we are making one step downwards
int minD = distance[s];
int mins = s;
for (int i=0; i < dir.length; i++) {
int n = s + dir[i];
int thisD = distance[n];
if (thisD < minD) {
minD = thisD;
mins = n;
}
}
return mins;
}
private static boolean buildDistanceMap( int from, int to, boolean[] passable ) {
if (from == to) {
return false;
}
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
boolean pathFound = false;
int head = 0;
int tail = 0;
// Add to queue
queue[tail++] = to;
distance[to] = 0;
while (head < tail) {
// Remove from queue
int step = queue[head++];
if (step == from) {
pathFound = true;
break;
}
int nextDistance = distance[step] + 1;
int start = (step % width == 0 ? 3 : 0);
int end = ((step+1) % width == 0 ? 3 : 0);
for (int i = start; i < dirLR.length - end; i++) {
int n = step + dirLR[i];
if (n == from || (n >= 0 && n < size && passable[n] && (distance[n] > nextDistance))) {
// Add to queue
queue[tail++] = n;
distance[n] = nextDistance;
}
}
}
return pathFound;
}
public static void buildDistanceMap( int to, boolean[] passable, int limit ) {
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
int head = 0;
int tail = 0;
// Add to queue
queue[tail++] = to;
distance[to] = 0;
while (head < tail) {
// Remove from queue
int step = queue[head++];
int nextDistance = distance[step] + 1;
if (nextDistance > limit) {
return;
}
int start = (step % width == 0 ? 3 : 0);
int end = ((step+1) % width == 0 ? 3 : 0);
for (int i = start; i < dirLR.length - end; i++) {
int n = step + dirLR[i];
if (n >= 0 && n < size && passable[n] && (distance[n] > nextDistance)) {
// Add to queue
queue[tail++] = n;
distance[n] = nextDistance;
}
}
}
}
private static boolean buildDistanceMap( int from, boolean[] to, boolean[] passable ) {
if (to[from]) {
return false;
}
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
boolean pathFound = false;
int head = 0;
int tail = 0;
// Add to queue
for (int i=0; i < size; i++) {
if (to[i]) {
queue[tail++] = i;
distance[i] = 0;
}
}
while (head < tail) {
// Remove from queue
int step = queue[head++];
if (step == from) {
pathFound = true;
break;
}
int nextDistance = distance[step] + 1;
int start = (step % width == 0 ? 3 : 0);
int end = ((step+1) % width == 0 ? 3 : 0);
for (int i = start; i < dirLR.length - end; i++) {
int n = step + dirLR[i];
if (n == from || (n >= 0 && n < size && passable[n] && (distance[n] > nextDistance))) {
// Add to queue
queue[tail++] = n;
distance[n] = nextDistance;
}
}
}
return pathFound;
}
private static int buildEscapeDistanceMap( int cur, int from, float factor, boolean[] passable ) {
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
int destDist = Integer.MAX_VALUE;
int head = 0;
int tail = 0;
// Add to queue
queue[tail++] = from;
distance[from] = 0;
int dist = 0;
while (head < tail) {
// Remove from queue
int step = queue[head++];
dist = distance[step];
if (dist > destDist) {
return destDist;
}
if (step == cur) {
destDist = (int)(dist * factor) + 1;
}
int nextDistance = dist + 1;
int start = (step % width == 0 ? 3 : 0);
int end = ((step+1) % width == 0 ? 3 : 0);
for (int i = start; i < dirLR.length - end; i++) {
int n = step + dirLR[i];
if (n >= 0 && n < size && passable[n] && distance[n] > nextDistance) {
// Add to queue
queue[tail++] = n;
distance[n] = nextDistance;
}
}
}
return dist;
}
public static void buildDistanceMap( int to, boolean[] passable ) {
System.arraycopy(maxVal, 0, distance, 0, maxVal.length);
int head = 0;
int tail = 0;
// Add to queue
queue[tail++] = to;
distance[to] = 0;
while (head < tail) {
// Remove from queue
int step = queue[head++];
int nextDistance = distance[step] + 1;
int start = (step % width == 0 ? 3 : 0);
int end = ((step+1) % width == 0 ? 3 : 0);
for (int i = start; i < dirLR.length - end; i++) {
int n = step + dirLR[i];
if (n >= 0 && n < size && passable[n] && (distance[n] > nextDistance)) {
// Add to queue
queue[tail++] = n;
distance[n] = nextDistance;
}
}
}
}
@SuppressWarnings("serial")
public static class Path extends LinkedList<Integer> {
}
}
| 8,463 | PathFinder | java | en | java | code | {"qsc_code_num_words": 1146, "qsc_code_num_chars": 8463.0, "qsc_code_mean_word_length": 4.29319372, "qsc_code_frac_words_unique": 0.17277487, "qsc_code_frac_chars_top_2grams": 0.02926829, "qsc_code_frac_chars_top_3grams": 0.0245935, "qsc_code_frac_chars_top_4grams": 0.01626016, "qsc_code_frac_chars_dupe_5grams": 0.56117886, "qsc_code_frac_chars_dupe_6grams": 0.55, "qsc_code_frac_chars_dupe_7grams": 0.51056911, "qsc_code_frac_chars_dupe_8grams": 0.49186992, "qsc_code_frac_chars_dupe_9grams": 0.44552846, "qsc_code_frac_chars_dupe_10grams": 0.44552846, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02339181, "qsc_code_frac_chars_whitespace": 0.27259837, "qsc_code_size_file_byte": 8463.0, "qsc_code_num_lines": 371.0, "qsc_code_num_chars_line_max": 100.0, "qsc_code_num_chars_line_mean": 22.81132075, "qsc_code_frac_chars_alphabet": 0.77582846, "qsc_code_frac_chars_comments": 0.18055063, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.45217391, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00086518, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03913043, "qsc_codejava_score_lines_no_logic": 0.1, "qsc_codejava_frac_words_no_modifier": 0.9, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/hal/intrin_avx512.hpp | // This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef OPENCV_HAL_INTRIN_AVX512_HPP
#define OPENCV_HAL_INTRIN_AVX512_HPP
#if defined(_MSC_VER) && (_MSC_VER < 1920/*MSVS2019*/)
# pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned
# pragma warning(disable:4309) // 'argument': truncation of constant value
# pragma warning(disable:4310) // cast truncates constant value
#endif
#define CVT_ROUND_MODES_IMPLEMENTED 0
#define CV_SIMD512 1
#define CV_SIMD512_64F 1
#define CV_SIMD512_FP16 0 // no native operations with FP16 type. Only load/store from float32x8 are available (if CV_FP16 == 1)
#define _v512_set_epu64(a7, a6, a5, a4, a3, a2, a1, a0) _mm512_set_epi64((int64)(a7),(int64)(a6),(int64)(a5),(int64)(a4),(int64)(a3),(int64)(a2),(int64)(a1),(int64)(a0))
#define _v512_set_epu32(a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \
_mm512_set_epi64(((int64)(a15)<<32)|(int64)(a14), ((int64)(a13)<<32)|(int64)(a12), ((int64)(a11)<<32)|(int64)(a10), ((int64)( a9)<<32)|(int64)( a8), \
((int64)( a7)<<32)|(int64)( a6), ((int64)( a5)<<32)|(int64)( a4), ((int64)( a3)<<32)|(int64)( a2), ((int64)( a1)<<32)|(int64)( a0))
#define _v512_set_epu16(a31, a30, a29, a28, a27, a26, a25, a24, a23, a22, a21, a20, a19, a18, a17, a16, \
a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \
_v512_set_epu32(((unsigned)(a31)<<16)|(unsigned)(a30), ((unsigned)(a29)<<16)|(unsigned)(a28), ((unsigned)(a27)<<16)|(unsigned)(a26), ((unsigned)(a25)<<16)|(unsigned)(a24), \
((unsigned)(a23)<<16)|(unsigned)(a22), ((unsigned)(a21)<<16)|(unsigned)(a20), ((unsigned)(a19)<<16)|(unsigned)(a18), ((unsigned)(a17)<<16)|(unsigned)(a16), \
((unsigned)(a15)<<16)|(unsigned)(a14), ((unsigned)(a13)<<16)|(unsigned)(a12), ((unsigned)(a11)<<16)|(unsigned)(a10), ((unsigned)( a9)<<16)|(unsigned)( a8), \
((unsigned)( a7)<<16)|(unsigned)( a6), ((unsigned)( a5)<<16)|(unsigned)( a4), ((unsigned)( a3)<<16)|(unsigned)( a2), ((unsigned)( a1)<<16)|(unsigned)( a0))
#define _v512_set_epu8(a63, a62, a61, a60, a59, a58, a57, a56, a55, a54, a53, a52, a51, a50, a49, a48, \
a47, a46, a45, a44, a43, a42, a41, a40, a39, a38, a37, a36, a35, a34, a33, a32, \
a31, a30, a29, a28, a27, a26, a25, a24, a23, a22, a21, a20, a19, a18, a17, a16, \
a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \
_v512_set_epu32(((unsigned)(a63)<<24)|((unsigned)(a62)<<16)|((unsigned)(a61)<<8)|(unsigned)(a60),((unsigned)(a59)<<24)|((unsigned)(a58)<<16)|((unsigned)(a57)<<8)|(unsigned)(a56), \
((unsigned)(a55)<<24)|((unsigned)(a54)<<16)|((unsigned)(a53)<<8)|(unsigned)(a52),((unsigned)(a51)<<24)|((unsigned)(a50)<<16)|((unsigned)(a49)<<8)|(unsigned)(a48), \
((unsigned)(a47)<<24)|((unsigned)(a46)<<16)|((unsigned)(a45)<<8)|(unsigned)(a44),((unsigned)(a43)<<24)|((unsigned)(a42)<<16)|((unsigned)(a41)<<8)|(unsigned)(a40), \
((unsigned)(a39)<<24)|((unsigned)(a38)<<16)|((unsigned)(a37)<<8)|(unsigned)(a36),((unsigned)(a35)<<24)|((unsigned)(a34)<<16)|((unsigned)(a33)<<8)|(unsigned)(a32), \
((unsigned)(a31)<<24)|((unsigned)(a30)<<16)|((unsigned)(a29)<<8)|(unsigned)(a28),((unsigned)(a27)<<24)|((unsigned)(a26)<<16)|((unsigned)(a25)<<8)|(unsigned)(a24), \
((unsigned)(a23)<<24)|((unsigned)(a22)<<16)|((unsigned)(a21)<<8)|(unsigned)(a20),((unsigned)(a19)<<24)|((unsigned)(a18)<<16)|((unsigned)(a17)<<8)|(unsigned)(a16), \
((unsigned)(a15)<<24)|((unsigned)(a14)<<16)|((unsigned)(a13)<<8)|(unsigned)(a12),((unsigned)(a11)<<24)|((unsigned)(a10)<<16)|((unsigned)( a9)<<8)|(unsigned)( a8), \
((unsigned)( a7)<<24)|((unsigned)( a6)<<16)|((unsigned)( a5)<<8)|(unsigned)( a4),((unsigned)( a3)<<24)|((unsigned)( a2)<<16)|((unsigned)( a1)<<8)|(unsigned)( a0))
#define _v512_set_epi8(a63, a62, a61, a60, a59, a58, a57, a56, a55, a54, a53, a52, a51, a50, a49, a48, \
a47, a46, a45, a44, a43, a42, a41, a40, a39, a38, a37, a36, a35, a34, a33, a32, \
a31, a30, a29, a28, a27, a26, a25, a24, a23, a22, a21, a20, a19, a18, a17, a16, \
a15, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3, a2, a1, a0) \
_v512_set_epu8((uchar)(a63), (uchar)(a62), (uchar)(a61), (uchar)(a60), (uchar)(a59), (uchar)(a58), (uchar)(a57), (uchar)(a56), \
(uchar)(a55), (uchar)(a54), (uchar)(a53), (uchar)(a52), (uchar)(a51), (uchar)(a50), (uchar)(a49), (uchar)(a48), \
(uchar)(a47), (uchar)(a46), (uchar)(a45), (uchar)(a44), (uchar)(a43), (uchar)(a42), (uchar)(a41), (uchar)(a40), \
(uchar)(a39), (uchar)(a38), (uchar)(a37), (uchar)(a36), (uchar)(a35), (uchar)(a34), (uchar)(a33), (uchar)(a32), \
(uchar)(a31), (uchar)(a30), (uchar)(a29), (uchar)(a28), (uchar)(a27), (uchar)(a26), (uchar)(a25), (uchar)(a24), \
(uchar)(a23), (uchar)(a22), (uchar)(a21), (uchar)(a20), (uchar)(a19), (uchar)(a18), (uchar)(a17), (uchar)(a16), \
(uchar)(a15), (uchar)(a14), (uchar)(a13), (uchar)(a12), (uchar)(a11), (uchar)(a10), (uchar)( a9), (uchar)( a8), \
(uchar)( a7), (uchar)( a6), (uchar)( a5), (uchar)( a4), (uchar)( a3), (uchar)( a2), (uchar)( a1), (uchar)( a0))
#ifndef _mm512_cvtpd_pslo
#ifdef _mm512_zextsi256_si512
#define _mm512_cvtpd_pslo(a) _mm512_zextps256_ps512(_mm512_cvtpd_ps(a))
#else
//if preferred way to extend with zeros is unavailable
#define _mm512_cvtpd_pslo(a) _mm512_castps256_ps512(_mm512_cvtpd_ps(a))
#endif
#endif
///////// Utils ////////////
namespace
{
inline __m512i _v512_combine(const __m256i& lo, const __m256i& hi)
{ return _mm512_inserti32x8(_mm512_castsi256_si512(lo), hi, 1); }
inline __m512 _v512_combine(const __m256& lo, const __m256& hi)
{ return _mm512_insertf32x8(_mm512_castps256_ps512(lo), hi, 1); }
inline __m512d _v512_combine(const __m256d& lo, const __m256d& hi)
{ return _mm512_insertf64x4(_mm512_castpd256_pd512(lo), hi, 1); }
inline int _v_cvtsi512_si32(const __m512i& a)
{ return _mm_cvtsi128_si32(_mm512_castsi512_si128(a)); }
inline __m256i _v512_extract_high(const __m512i& v)
{ return _mm512_extracti32x8_epi32(v, 1); }
inline __m256 _v512_extract_high(const __m512& v)
{ return _mm512_extractf32x8_ps(v, 1); }
inline __m256d _v512_extract_high(const __m512d& v)
{ return _mm512_extractf64x4_pd(v, 1); }
inline __m256i _v512_extract_low(const __m512i& v)
{ return _mm512_castsi512_si256(v); }
inline __m256 _v512_extract_low(const __m512& v)
{ return _mm512_castps512_ps256(v); }
inline __m256d _v512_extract_low(const __m512d& v)
{ return _mm512_castpd512_pd256(v); }
inline __m512i _v512_insert(const __m512i& a, const __m256i& b)
{ return _mm512_inserti32x8(a, b, 0); }
inline __m512 _v512_insert(const __m512& a, const __m256& b)
{ return _mm512_insertf32x8(a, b, 0); }
inline __m512d _v512_insert(const __m512d& a, const __m256d& b)
{ return _mm512_insertf64x4(a, b, 0); }
}
namespace cv
{
//! @cond IGNORED
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
///////// Types ////////////
struct v_uint8x64
{
typedef uchar lane_type;
enum { nlanes = 64 };
__m512i val;
explicit v_uint8x64(__m512i v) : val(v) {}
v_uint8x64(uchar v0, uchar v1, uchar v2, uchar v3,
uchar v4, uchar v5, uchar v6, uchar v7,
uchar v8, uchar v9, uchar v10, uchar v11,
uchar v12, uchar v13, uchar v14, uchar v15,
uchar v16, uchar v17, uchar v18, uchar v19,
uchar v20, uchar v21, uchar v22, uchar v23,
uchar v24, uchar v25, uchar v26, uchar v27,
uchar v28, uchar v29, uchar v30, uchar v31,
uchar v32, uchar v33, uchar v34, uchar v35,
uchar v36, uchar v37, uchar v38, uchar v39,
uchar v40, uchar v41, uchar v42, uchar v43,
uchar v44, uchar v45, uchar v46, uchar v47,
uchar v48, uchar v49, uchar v50, uchar v51,
uchar v52, uchar v53, uchar v54, uchar v55,
uchar v56, uchar v57, uchar v58, uchar v59,
uchar v60, uchar v61, uchar v62, uchar v63)
{
val = _v512_set_epu8(v63, v62, v61, v60, v59, v58, v57, v56, v55, v54, v53, v52, v51, v50, v49, v48,
v47, v46, v45, v44, v43, v42, v41, v40, v39, v38, v37, v36, v35, v34, v33, v32,
v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16,
v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1, v0);
}
v_uint8x64() : val(_mm512_setzero_si512()) {}
uchar get0() const { return (uchar)_v_cvtsi512_si32(val); }
};
struct v_int8x64
{
typedef schar lane_type;
enum { nlanes = 64 };
__m512i val;
explicit v_int8x64(__m512i v) : val(v) {}
v_int8x64(schar v0, schar v1, schar v2, schar v3,
schar v4, schar v5, schar v6, schar v7,
schar v8, schar v9, schar v10, schar v11,
schar v12, schar v13, schar v14, schar v15,
schar v16, schar v17, schar v18, schar v19,
schar v20, schar v21, schar v22, schar v23,
schar v24, schar v25, schar v26, schar v27,
schar v28, schar v29, schar v30, schar v31,
schar v32, schar v33, schar v34, schar v35,
schar v36, schar v37, schar v38, schar v39,
schar v40, schar v41, schar v42, schar v43,
schar v44, schar v45, schar v46, schar v47,
schar v48, schar v49, schar v50, schar v51,
schar v52, schar v53, schar v54, schar v55,
schar v56, schar v57, schar v58, schar v59,
schar v60, schar v61, schar v62, schar v63)
{
val = _v512_set_epi8(v63, v62, v61, v60, v59, v58, v57, v56, v55, v54, v53, v52, v51, v50, v49, v48,
v47, v46, v45, v44, v43, v42, v41, v40, v39, v38, v37, v36, v35, v34, v33, v32,
v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16,
v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1, v0);
}
v_int8x64() : val(_mm512_setzero_si512()) {}
schar get0() const { return (schar)_v_cvtsi512_si32(val); }
};
struct v_uint16x32
{
typedef ushort lane_type;
enum { nlanes = 32 };
__m512i val;
explicit v_uint16x32(__m512i v) : val(v) {}
v_uint16x32(ushort v0, ushort v1, ushort v2, ushort v3,
ushort v4, ushort v5, ushort v6, ushort v7,
ushort v8, ushort v9, ushort v10, ushort v11,
ushort v12, ushort v13, ushort v14, ushort v15,
ushort v16, ushort v17, ushort v18, ushort v19,
ushort v20, ushort v21, ushort v22, ushort v23,
ushort v24, ushort v25, ushort v26, ushort v27,
ushort v28, ushort v29, ushort v30, ushort v31)
{
val = _v512_set_epu16(v31, v30, v29, v28, v27, v26, v25, v24, v23, v22, v21, v20, v19, v18, v17, v16,
v15, v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1, v0);
}
v_uint16x32() : val(_mm512_setzero_si512()) {}
ushort get0() const { return (ushort)_v_cvtsi512_si32(val); }
};
struct v_int16x32
{
typedef short lane_type;
enum { nlanes = 32 };
__m512i val;
explicit v_int16x32(__m512i v) : val(v) {}
v_int16x32(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7,
short v8, short v9, short v10, short v11, short v12, short v13, short v14, short v15,
short v16, short v17, short v18, short v19, short v20, short v21, short v22, short v23,
short v24, short v25, short v26, short v27, short v28, short v29, short v30, short v31)
{
val = _v512_set_epu16((ushort)v31, (ushort)v30, (ushort)v29, (ushort)v28, (ushort)v27, (ushort)v26, (ushort)v25, (ushort)v24,
(ushort)v23, (ushort)v22, (ushort)v21, (ushort)v20, (ushort)v19, (ushort)v18, (ushort)v17, (ushort)v16,
(ushort)v15, (ushort)v14, (ushort)v13, (ushort)v12, (ushort)v11, (ushort)v10, (ushort)v9 , (ushort)v8,
(ushort)v7 , (ushort)v6 , (ushort)v5 , (ushort)v4 , (ushort)v3 , (ushort)v2 , (ushort)v1 , (ushort)v0);
}
v_int16x32() : val(_mm512_setzero_si512()) {}
short get0() const { return (short)_v_cvtsi512_si32(val); }
};
struct v_uint32x16
{
typedef unsigned lane_type;
enum { nlanes = 16 };
__m512i val;
explicit v_uint32x16(__m512i v) : val(v) {}
v_uint32x16(unsigned v0, unsigned v1, unsigned v2, unsigned v3,
unsigned v4, unsigned v5, unsigned v6, unsigned v7,
unsigned v8, unsigned v9, unsigned v10, unsigned v11,
unsigned v12, unsigned v13, unsigned v14, unsigned v15)
{
val = _mm512_setr_epi32((int)v0, (int)v1, (int)v2, (int)v3, (int)v4, (int)v5, (int)v6, (int)v7,
(int)v8, (int)v9, (int)v10, (int)v11, (int)v12, (int)v13, (int)v14, (int)v15);
}
v_uint32x16() : val(_mm512_setzero_si512()) {}
unsigned get0() const { return (unsigned)_v_cvtsi512_si32(val); }
};
struct v_int32x16
{
typedef int lane_type;
enum { nlanes = 16 };
__m512i val;
explicit v_int32x16(__m512i v) : val(v) {}
v_int32x16(int v0, int v1, int v2, int v3, int v4, int v5, int v6, int v7,
int v8, int v9, int v10, int v11, int v12, int v13, int v14, int v15)
{
val = _mm512_setr_epi32(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);
}
v_int32x16() : val(_mm512_setzero_si512()) {}
int get0() const { return _v_cvtsi512_si32(val); }
};
struct v_float32x16
{
typedef float lane_type;
enum { nlanes = 16 };
__m512 val;
explicit v_float32x16(__m512 v) : val(v) {}
v_float32x16(float v0, float v1, float v2, float v3, float v4, float v5, float v6, float v7,
float v8, float v9, float v10, float v11, float v12, float v13, float v14, float v15)
{
val = _mm512_setr_ps(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);
}
v_float32x16() : val(_mm512_setzero_ps()) {}
float get0() const { return _mm_cvtss_f32(_mm512_castps512_ps128(val)); }
};
struct v_uint64x8
{
typedef uint64 lane_type;
enum { nlanes = 8 };
__m512i val;
explicit v_uint64x8(__m512i v) : val(v) {}
v_uint64x8(uint64 v0, uint64 v1, uint64 v2, uint64 v3, uint64 v4, uint64 v5, uint64 v6, uint64 v7)
{ val = _mm512_setr_epi64((int64)v0, (int64)v1, (int64)v2, (int64)v3, (int64)v4, (int64)v5, (int64)v6, (int64)v7); }
v_uint64x8() : val(_mm512_setzero_si512()) {}
uint64 get0() const
{
#if defined __x86_64__ || defined _M_X64
return (uint64)_mm_cvtsi128_si64(_mm512_castsi512_si128(val));
#else
int a = _mm_cvtsi128_si32(_mm512_castsi512_si128(val));
int b = _mm_cvtsi128_si32(_mm512_castsi512_si128(_mm512_srli_epi64(val, 32)));
return (unsigned)a | ((uint64)(unsigned)b << 32);
#endif
}
};
struct v_int64x8
{
typedef int64 lane_type;
enum { nlanes = 8 };
__m512i val;
explicit v_int64x8(__m512i v) : val(v) {}
v_int64x8(int64 v0, int64 v1, int64 v2, int64 v3, int64 v4, int64 v5, int64 v6, int64 v7)
{ val = _mm512_setr_epi64(v0, v1, v2, v3, v4, v5, v6, v7); }
v_int64x8() : val(_mm512_setzero_si512()) {}
int64 get0() const
{
#if defined __x86_64__ || defined _M_X64
return (int64)_mm_cvtsi128_si64(_mm512_castsi512_si128(val));
#else
int a = _mm_cvtsi128_si32(_mm512_castsi512_si128(val));
int b = _mm_cvtsi128_si32(_mm512_castsi512_si128(_mm512_srli_epi64(val, 32)));
return (int64)((unsigned)a | ((uint64)(unsigned)b << 32));
#endif
}
};
struct v_float64x8
{
typedef double lane_type;
enum { nlanes = 8 };
__m512d val;
explicit v_float64x8(__m512d v) : val(v) {}
v_float64x8(double v0, double v1, double v2, double v3, double v4, double v5, double v6, double v7)
{ val = _mm512_setr_pd(v0, v1, v2, v3, v4, v5, v6, v7); }
v_float64x8() : val(_mm512_setzero_pd()) {}
double get0() const { return _mm_cvtsd_f64(_mm512_castpd512_pd128(val)); }
};
//////////////// Load and store operations ///////////////
#define OPENCV_HAL_IMPL_AVX512_LOADSTORE(_Tpvec, _Tp) \
inline _Tpvec v512_load(const _Tp* ptr) \
{ return _Tpvec(_mm512_loadu_si512((const __m512i*)ptr)); } \
inline _Tpvec v512_load_aligned(const _Tp* ptr) \
{ return _Tpvec(_mm512_load_si512((const __m512i*)ptr)); } \
inline _Tpvec v512_load_low(const _Tp* ptr) \
{ \
__m256i v256 = _mm256_loadu_si256((const __m256i*)ptr); \
return _Tpvec(_mm512_castsi256_si512(v256)); \
} \
inline _Tpvec v512_load_halves(const _Tp* ptr0, const _Tp* ptr1) \
{ \
__m256i vlo = _mm256_loadu_si256((const __m256i*)ptr0); \
__m256i vhi = _mm256_loadu_si256((const __m256i*)ptr1); \
return _Tpvec(_v512_combine(vlo, vhi)); \
} \
inline void v_store(_Tp* ptr, const _Tpvec& a) \
{ _mm512_storeu_si512((__m512i*)ptr, a.val); } \
inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \
{ _mm512_store_si512((__m512i*)ptr, a.val); } \
inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \
{ _mm512_stream_si512((__m512i*)ptr, a.val); } \
inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \
{ \
if( mode == hal::STORE_UNALIGNED ) \
_mm512_storeu_si512((__m512i*)ptr, a.val); \
else if( mode == hal::STORE_ALIGNED_NOCACHE ) \
_mm512_stream_si512((__m512i*)ptr, a.val); \
else \
_mm512_store_si512((__m512i*)ptr, a.val); \
} \
inline void v_store_low(_Tp* ptr, const _Tpvec& a) \
{ _mm256_storeu_si256((__m256i*)ptr, _v512_extract_low(a.val)); } \
inline void v_store_high(_Tp* ptr, const _Tpvec& a) \
{ _mm256_storeu_si256((__m256i*)ptr, _v512_extract_high(a.val)); }
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint8x64, uchar)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int8x64, schar)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint16x32, ushort)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int16x32, short)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint32x16, unsigned)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int32x16, int)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_uint64x8, uint64)
OPENCV_HAL_IMPL_AVX512_LOADSTORE(v_int64x8, int64)
#define OPENCV_HAL_IMPL_AVX512_LOADSTORE_FLT(_Tpvec, _Tp, suffix, halfreg) \
inline _Tpvec v512_load(const _Tp* ptr) \
{ return _Tpvec(_mm512_loadu_##suffix(ptr)); } \
inline _Tpvec v512_load_aligned(const _Tp* ptr) \
{ return _Tpvec(_mm512_load_##suffix(ptr)); } \
inline _Tpvec v512_load_low(const _Tp* ptr) \
{ \
return _Tpvec(_mm512_cast##suffix##256_##suffix##512 \
(_mm256_loadu_##suffix(ptr))); \
} \
inline _Tpvec v512_load_halves(const _Tp* ptr0, const _Tp* ptr1) \
{ \
halfreg vlo = _mm256_loadu_##suffix(ptr0); \
halfreg vhi = _mm256_loadu_##suffix(ptr1); \
return _Tpvec(_v512_combine(vlo, vhi)); \
} \
inline void v_store(_Tp* ptr, const _Tpvec& a) \
{ _mm512_storeu_##suffix(ptr, a.val); } \
inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \
{ _mm512_store_##suffix(ptr, a.val); } \
inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \
{ _mm512_stream_##suffix(ptr, a.val); } \
inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \
{ \
if( mode == hal::STORE_UNALIGNED ) \
_mm512_storeu_##suffix(ptr, a.val); \
else if( mode == hal::STORE_ALIGNED_NOCACHE ) \
_mm512_stream_##suffix(ptr, a.val); \
else \
_mm512_store_##suffix(ptr, a.val); \
} \
inline void v_store_low(_Tp* ptr, const _Tpvec& a) \
{ _mm256_storeu_##suffix(ptr, _v512_extract_low(a.val)); } \
inline void v_store_high(_Tp* ptr, const _Tpvec& a) \
{ _mm256_storeu_##suffix(ptr, _v512_extract_high(a.val)); }
OPENCV_HAL_IMPL_AVX512_LOADSTORE_FLT(v_float32x16, float, ps, __m256)
OPENCV_HAL_IMPL_AVX512_LOADSTORE_FLT(v_float64x8, double, pd, __m256d)
#define OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, _Tpvecf, suffix, cast) \
inline _Tpvec v_reinterpret_as_##suffix(const _Tpvecf& a) \
{ return _Tpvec(cast(a.val)); }
#define OPENCV_HAL_IMPL_AVX512_INIT(_Tpvec, _Tp, suffix, ssuffix, ctype_s) \
inline _Tpvec v512_setzero_##suffix() \
{ return _Tpvec(_mm512_setzero_si512()); } \
inline _Tpvec v512_setall_##suffix(_Tp v) \
{ return _Tpvec(_mm512_set1_##ssuffix((ctype_s)v)); } \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint8x64, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int8x64, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint16x32, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int16x32, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint32x16, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int32x16, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint64x8, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int64x8, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_float32x16, suffix, _mm512_castps_si512) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_float64x8, suffix, _mm512_castpd_si512)
OPENCV_HAL_IMPL_AVX512_INIT(v_uint8x64, uchar, u8, epi8, char)
OPENCV_HAL_IMPL_AVX512_INIT(v_int8x64, schar, s8, epi8, char)
OPENCV_HAL_IMPL_AVX512_INIT(v_uint16x32, ushort, u16, epi16, short)
OPENCV_HAL_IMPL_AVX512_INIT(v_int16x32, short, s16, epi16, short)
OPENCV_HAL_IMPL_AVX512_INIT(v_uint32x16, unsigned, u32, epi32, int)
OPENCV_HAL_IMPL_AVX512_INIT(v_int32x16, int, s32, epi32, int)
OPENCV_HAL_IMPL_AVX512_INIT(v_uint64x8, uint64, u64, epi64, int64)
OPENCV_HAL_IMPL_AVX512_INIT(v_int64x8, int64, s64, epi64, int64)
#define OPENCV_HAL_IMPL_AVX512_INIT_FLT(_Tpvec, _Tp, suffix, zsuffix, cast) \
inline _Tpvec v512_setzero_##suffix() \
{ return _Tpvec(_mm512_setzero_##zsuffix()); } \
inline _Tpvec v512_setall_##suffix(_Tp v) \
{ return _Tpvec(_mm512_set1_##zsuffix(v)); } \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint8x64, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int8x64, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint16x32, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int16x32, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint32x16, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int32x16, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_uint64x8, suffix, cast) \
OPENCV_HAL_IMPL_AVX512_CAST(_Tpvec, v_int64x8, suffix, cast)
OPENCV_HAL_IMPL_AVX512_INIT_FLT(v_float32x16, float, f32, ps, _mm512_castsi512_ps)
OPENCV_HAL_IMPL_AVX512_INIT_FLT(v_float64x8, double, f64, pd, _mm512_castsi512_pd)
inline v_float32x16 v_reinterpret_as_f32(const v_float32x16& a)
{ return a; }
inline v_float32x16 v_reinterpret_as_f32(const v_float64x8& a)
{ return v_float32x16(_mm512_castpd_ps(a.val)); }
inline v_float64x8 v_reinterpret_as_f64(const v_float64x8& a)
{ return a; }
inline v_float64x8 v_reinterpret_as_f64(const v_float32x16& a)
{ return v_float64x8(_mm512_castps_pd(a.val)); }
// FP16
inline v_float32x16 v512_load_expand(const float16_t* ptr)
{
return v_float32x16(_mm512_cvtph_ps(_mm256_loadu_si256((const __m256i*)ptr)));
}
inline void v_pack_store(float16_t* ptr, const v_float32x16& a)
{
__m256i ah = _mm512_cvtps_ph(a.val, 0);
_mm256_storeu_si256((__m256i*)ptr, ah);
}
/* Recombine & ZIP */
inline void v_zip(const v_int8x64& a, const v_int8x64& b, v_int8x64& ab0, v_int8x64& ab1)
{
#if CV_AVX_512VBMI
__m512i mask0 = _v512_set_epu8( 95, 31, 94, 30, 93, 29, 92, 28, 91, 27, 90, 26, 89, 25, 88, 24,
87, 23, 86, 22, 85, 21, 84, 20, 83, 19, 82, 18, 81, 17, 80, 16,
79, 15, 78, 14, 77, 13, 76, 12, 75, 11, 74, 10, 73, 9, 72, 8,
71, 7, 70, 6, 69, 5, 68, 4, 67, 3, 66, 2, 65, 1, 64, 0);
ab0 = v_int8x64(_mm512_permutex2var_epi8(a.val, mask0, b.val));
__m512i mask1 = _v512_set_epu8(127, 63, 126, 62, 125, 61, 124, 60, 123, 59, 122, 58, 121, 57, 120, 56,
119, 55, 118, 54, 117, 53, 116, 52, 115, 51, 114, 50, 113, 49, 112, 48,
111, 47, 110, 46, 109, 45, 108, 44, 107, 43, 106, 42, 105, 41, 104, 40,
103, 39, 102, 38, 101, 37, 100, 36, 99, 35, 98, 34, 97, 33, 96, 32);
ab1 = v_int8x64(_mm512_permutex2var_epi8(a.val, mask1, b.val));
#else
__m512i low = _mm512_unpacklo_epi8(a.val, b.val);
__m512i high = _mm512_unpackhi_epi8(a.val, b.val);
ab0 = v_int8x64(_mm512_permutex2var_epi64(low, _v512_set_epu64(11, 10, 3, 2, 9, 8, 1, 0), high));
ab1 = v_int8x64(_mm512_permutex2var_epi64(low, _v512_set_epu64(15, 14, 7, 6, 13, 12, 5, 4), high));
#endif
}
inline void v_zip(const v_int16x32& a, const v_int16x32& b, v_int16x32& ab0, v_int16x32& ab1)
{
__m512i mask0 = _v512_set_epu16(47, 15, 46, 14, 45, 13, 44, 12, 43, 11, 42, 10, 41, 9, 40, 8,
39, 7, 38, 6, 37, 5, 36, 4, 35, 3, 34, 2, 33, 1, 32, 0);
ab0 = v_int16x32(_mm512_permutex2var_epi16(a.val, mask0, b.val));
__m512i mask1 = _v512_set_epu16(63, 31, 62, 30, 61, 29, 60, 28, 59, 27, 58, 26, 57, 25, 56, 24,
55, 23, 54, 22, 53, 21, 52, 20, 51, 19, 50, 18, 49, 17, 48, 16);
ab1 = v_int16x32(_mm512_permutex2var_epi16(a.val, mask1, b.val));
}
inline void v_zip(const v_int32x16& a, const v_int32x16& b, v_int32x16& ab0, v_int32x16& ab1)
{
__m512i mask0 = _v512_set_epu32(23, 7, 22, 6, 21, 5, 20, 4, 19, 3, 18, 2, 17, 1, 16, 0);
ab0 = v_int32x16(_mm512_permutex2var_epi32(a.val, mask0, b.val));
__m512i mask1 = _v512_set_epu32(31, 15, 30, 14, 29, 13, 28, 12, 27, 11, 26, 10, 25, 9, 24, 8);
ab1 = v_int32x16(_mm512_permutex2var_epi32(a.val, mask1, b.val));
}
inline void v_zip(const v_int64x8& a, const v_int64x8& b, v_int64x8& ab0, v_int64x8& ab1)
{
__m512i mask0 = _v512_set_epu64(11, 3, 10, 2, 9, 1, 8, 0);
ab0 = v_int64x8(_mm512_permutex2var_epi64(a.val, mask0, b.val));
__m512i mask1 = _v512_set_epu64(15, 7, 14, 6, 13, 5, 12, 4);
ab1 = v_int64x8(_mm512_permutex2var_epi64(a.val, mask1, b.val));
}
inline void v_zip(const v_uint8x64& a, const v_uint8x64& b, v_uint8x64& ab0, v_uint8x64& ab1)
{
v_int8x64 i0, i1;
v_zip(v_reinterpret_as_s8(a), v_reinterpret_as_s8(b), i0, i1);
ab0 = v_reinterpret_as_u8(i0);
ab1 = v_reinterpret_as_u8(i1);
}
inline void v_zip(const v_uint16x32& a, const v_uint16x32& b, v_uint16x32& ab0, v_uint16x32& ab1)
{
v_int16x32 i0, i1;
v_zip(v_reinterpret_as_s16(a), v_reinterpret_as_s16(b), i0, i1);
ab0 = v_reinterpret_as_u16(i0);
ab1 = v_reinterpret_as_u16(i1);
}
inline void v_zip(const v_uint32x16& a, const v_uint32x16& b, v_uint32x16& ab0, v_uint32x16& ab1)
{
v_int32x16 i0, i1;
v_zip(v_reinterpret_as_s32(a), v_reinterpret_as_s32(b), i0, i1);
ab0 = v_reinterpret_as_u32(i0);
ab1 = v_reinterpret_as_u32(i1);
}
inline void v_zip(const v_uint64x8& a, const v_uint64x8& b, v_uint64x8& ab0, v_uint64x8& ab1)
{
v_int64x8 i0, i1;
v_zip(v_reinterpret_as_s64(a), v_reinterpret_as_s64(b), i0, i1);
ab0 = v_reinterpret_as_u64(i0);
ab1 = v_reinterpret_as_u64(i1);
}
inline void v_zip(const v_float32x16& a, const v_float32x16& b, v_float32x16& ab0, v_float32x16& ab1)
{
v_int32x16 i0, i1;
v_zip(v_reinterpret_as_s32(a), v_reinterpret_as_s32(b), i0, i1);
ab0 = v_reinterpret_as_f32(i0);
ab1 = v_reinterpret_as_f32(i1);
}
inline void v_zip(const v_float64x8& a, const v_float64x8& b, v_float64x8& ab0, v_float64x8& ab1)
{
v_int64x8 i0, i1;
v_zip(v_reinterpret_as_s64(a), v_reinterpret_as_s64(b), i0, i1);
ab0 = v_reinterpret_as_f64(i0);
ab1 = v_reinterpret_as_f64(i1);
}
#define OPENCV_HAL_IMPL_AVX512_COMBINE(_Tpvec, suffix) \
inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_v512_combine(_v512_extract_low(a.val), _v512_extract_low(b.val))); } \
inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_v512_insert(b.val, _v512_extract_high(a.val))); } \
inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \
_Tpvec& c, _Tpvec& d) \
{ \
c.val = _v512_combine(_v512_extract_low(a.val),_v512_extract_low(b.val)); \
d.val = _v512_insert(b.val,_v512_extract_high(a.val)); \
}
OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint8x64, epi8)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_int8x64, epi8)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint16x32, epi16)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_int16x32, epi16)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint32x16, epi32)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_int32x16, epi32)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_uint64x8, epi64)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_int64x8, epi64)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_float32x16, ps)
OPENCV_HAL_IMPL_AVX512_COMBINE(v_float64x8, pd)
////////// Arithmetic, bitwise and comparison operations /////////
/* Element-wise binary and unary operations */
/** Non-saturating arithmetics **/
#define OPENCV_HAL_IMPL_AVX512_BIN_FUNC(func, _Tpvec, intrin) \
inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(intrin(a.val, b.val)); }
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_uint8x64, _mm512_add_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_int8x64, _mm512_add_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_uint16x32, _mm512_add_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_add_wrap, v_int16x32, _mm512_add_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_uint8x64, _mm512_sub_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_int8x64, _mm512_sub_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_uint16x32, _mm512_sub_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_sub_wrap, v_int16x32, _mm512_sub_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_mul_wrap, v_uint16x32, _mm512_mullo_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_mul_wrap, v_int16x32, _mm512_mullo_epi16)
inline v_uint8x64 v_mul_wrap(const v_uint8x64& a, const v_uint8x64& b)
{
__m512i ad = _mm512_srai_epi16(a.val, 8);
__m512i bd = _mm512_srai_epi16(b.val, 8);
__m512i p0 = _mm512_mullo_epi16(a.val, b.val); // even
__m512i p1 = _mm512_slli_epi16(_mm512_mullo_epi16(ad, bd), 8); // odd
return v_uint8x64(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, p0, p1));
}
inline v_int8x64 v_mul_wrap(const v_int8x64& a, const v_int8x64& b)
{
return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b)));
}
#define OPENCV_HAL_IMPL_AVX512_BIN_OP(bin_op, _Tpvec, intrin) \
inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(intrin(a.val, b.val)); } \
inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \
{ a.val = intrin(a.val, b.val); return a; }
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint32x16, _mm512_add_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint32x16, _mm512_sub_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int32x16, _mm512_add_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int32x16, _mm512_sub_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint64x8, _mm512_add_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint64x8, _mm512_sub_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int64x8, _mm512_add_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int64x8, _mm512_sub_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_uint32x16, _mm512_mullo_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_int32x16, _mm512_mullo_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_uint64x8, _mm512_mullo_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_int64x8, _mm512_mullo_epi64)
/** Saturating arithmetics **/
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint8x64, _mm512_adds_epu8)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint8x64, _mm512_subs_epu8)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int8x64, _mm512_adds_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int8x64, _mm512_subs_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_uint16x32, _mm512_adds_epu16)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_uint16x32, _mm512_subs_epu16)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_int16x32, _mm512_adds_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_int16x32, _mm512_subs_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_float32x16, _mm512_add_ps)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_float32x16, _mm512_sub_ps)
OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_float32x16, _mm512_mul_ps)
OPENCV_HAL_IMPL_AVX512_BIN_OP(/, v_float32x16, _mm512_div_ps)
OPENCV_HAL_IMPL_AVX512_BIN_OP(+, v_float64x8, _mm512_add_pd)
OPENCV_HAL_IMPL_AVX512_BIN_OP(-, v_float64x8, _mm512_sub_pd)
OPENCV_HAL_IMPL_AVX512_BIN_OP(*, v_float64x8, _mm512_mul_pd)
OPENCV_HAL_IMPL_AVX512_BIN_OP(/, v_float64x8, _mm512_div_pd)
// saturating multiply
inline v_uint8x64 operator * (const v_uint8x64& a, const v_uint8x64& b)
{
v_uint16x32 c, d;
v_mul_expand(a, b, c, d);
return v_pack(c, d);
}
inline v_int8x64 operator * (const v_int8x64& a, const v_int8x64& b)
{
v_int16x32 c, d;
v_mul_expand(a, b, c, d);
return v_pack(c, d);
}
inline v_uint16x32 operator * (const v_uint16x32& a, const v_uint16x32& b)
{
__m512i pl = _mm512_mullo_epi16(a.val, b.val);
__m512i ph = _mm512_mulhi_epu16(a.val, b.val);
__m512i p0 = _mm512_unpacklo_epi16(pl, ph);
__m512i p1 = _mm512_unpackhi_epi16(pl, ph);
const __m512i m = _mm512_set1_epi32(65535);
return v_uint16x32(_mm512_packus_epi32(_mm512_min_epu32(p0, m), _mm512_min_epu32(p1, m)));
}
inline v_int16x32 operator * (const v_int16x32& a, const v_int16x32& b)
{
__m512i pl = _mm512_mullo_epi16(a.val, b.val);
__m512i ph = _mm512_mulhi_epi16(a.val, b.val);
__m512i p0 = _mm512_unpacklo_epi16(pl, ph);
__m512i p1 = _mm512_unpackhi_epi16(pl, ph);
return v_int16x32(_mm512_packs_epi32(p0, p1));
}
inline v_uint8x64& operator *= (v_uint8x64& a, const v_uint8x64& b)
{ a = a * b; return a; }
inline v_int8x64& operator *= (v_int8x64& a, const v_int8x64& b)
{ a = a * b; return a; }
inline v_uint16x32& operator *= (v_uint16x32& a, const v_uint16x32& b)
{ a = a * b; return a; }
inline v_int16x32& operator *= (v_int16x32& a, const v_int16x32& b)
{ a = a * b; return a; }
inline v_int16x32 v_mul_hi(const v_int16x32& a, const v_int16x32& b) { return v_int16x32(_mm512_mulhi_epi16(a.val, b.val)); }
inline v_uint16x32 v_mul_hi(const v_uint16x32& a, const v_uint16x32& b) { return v_uint16x32(_mm512_mulhi_epu16(a.val, b.val)); }
// Multiply and expand
inline void v_mul_expand(const v_uint8x64& a, const v_uint8x64& b,
v_uint16x32& c, v_uint16x32& d)
{
v_uint16x32 a0, a1, b0, b1;
v_expand(a, a0, a1);
v_expand(b, b0, b1);
c = v_mul_wrap(a0, b0);
d = v_mul_wrap(a1, b1);
}
inline void v_mul_expand(const v_int8x64& a, const v_int8x64& b,
v_int16x32& c, v_int16x32& d)
{
v_int16x32 a0, a1, b0, b1;
v_expand(a, a0, a1);
v_expand(b, b0, b1);
c = v_mul_wrap(a0, b0);
d = v_mul_wrap(a1, b1);
}
inline void v_mul_expand(const v_int16x32& a, const v_int16x32& b,
v_int32x16& c, v_int32x16& d)
{
v_int16x32 v0, v1;
v_zip(v_mul_wrap(a, b), v_mul_hi(a, b), v0, v1);
c = v_reinterpret_as_s32(v0);
d = v_reinterpret_as_s32(v1);
}
inline void v_mul_expand(const v_uint16x32& a, const v_uint16x32& b,
v_uint32x16& c, v_uint32x16& d)
{
v_uint16x32 v0, v1;
v_zip(v_mul_wrap(a, b), v_mul_hi(a, b), v0, v1);
c = v_reinterpret_as_u32(v0);
d = v_reinterpret_as_u32(v1);
}
inline void v_mul_expand(const v_uint32x16& a, const v_uint32x16& b,
v_uint64x8& c, v_uint64x8& d)
{
v_zip(v_uint64x8(_mm512_mul_epu32(a.val, b.val)),
v_uint64x8(_mm512_mul_epu32(_mm512_srli_epi64(a.val, 32), _mm512_srli_epi64(b.val, 32))), c, d);
}
inline void v_mul_expand(const v_int32x16& a, const v_int32x16& b,
v_int64x8& c, v_int64x8& d)
{
v_zip(v_int64x8(_mm512_mul_epi32(a.val, b.val)),
v_int64x8(_mm512_mul_epi32(_mm512_srli_epi64(a.val, 32), _mm512_srli_epi64(b.val, 32))), c, d);
}
/** Bitwise shifts **/
#define OPENCV_HAL_IMPL_AVX512_SHIFT_OP(_Tpuvec, _Tpsvec, suffix) \
inline _Tpuvec operator << (const _Tpuvec& a, int imm) \
{ return _Tpuvec(_mm512_slli_##suffix(a.val, imm)); } \
inline _Tpsvec operator << (const _Tpsvec& a, int imm) \
{ return _Tpsvec(_mm512_slli_##suffix(a.val, imm)); } \
inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \
{ return _Tpuvec(_mm512_srli_##suffix(a.val, imm)); } \
inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \
{ return _Tpsvec(_mm512_srai_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpuvec v_shl(const _Tpuvec& a) \
{ return _Tpuvec(_mm512_slli_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpsvec v_shl(const _Tpsvec& a) \
{ return _Tpsvec(_mm512_slli_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpuvec v_shr(const _Tpuvec& a) \
{ return _Tpuvec(_mm512_srli_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpsvec v_shr(const _Tpsvec& a) \
{ return _Tpsvec(_mm512_srai_##suffix(a.val, imm)); }
OPENCV_HAL_IMPL_AVX512_SHIFT_OP(v_uint16x32, v_int16x32, epi16)
OPENCV_HAL_IMPL_AVX512_SHIFT_OP(v_uint32x16, v_int32x16, epi32)
OPENCV_HAL_IMPL_AVX512_SHIFT_OP(v_uint64x8, v_int64x8, epi64)
/** Bitwise logic **/
#define OPENCV_HAL_IMPL_AVX512_LOGIC_OP(_Tpvec, suffix, not_const) \
OPENCV_HAL_IMPL_AVX512_BIN_OP(&, _Tpvec, _mm512_and_##suffix) \
OPENCV_HAL_IMPL_AVX512_BIN_OP(|, _Tpvec, _mm512_or_##suffix) \
OPENCV_HAL_IMPL_AVX512_BIN_OP(^, _Tpvec, _mm512_xor_##suffix) \
inline _Tpvec operator ~ (const _Tpvec& a) \
{ return _Tpvec(_mm512_xor_##suffix(a.val, not_const)); }
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint8x64, si512, _mm512_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int8x64, si512, _mm512_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint16x32, si512, _mm512_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int16x32, si512, _mm512_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint32x16, si512, _mm512_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int32x16, si512, _mm512_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_uint64x8, si512, _mm512_set1_epi64(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_int64x8, si512, _mm512_set1_epi64(-1))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_float32x16, ps, _mm512_castsi512_ps(_mm512_set1_epi32(-1)))
OPENCV_HAL_IMPL_AVX512_LOGIC_OP(v_float64x8, pd, _mm512_castsi512_pd(_mm512_set1_epi32(-1)))
/** Select **/
#define OPENCV_HAL_IMPL_AVX512_SELECT(_Tpvec, suffix, zsuf) \
inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm512_mask_blend_##suffix(_mm512_cmp_##suffix##_mask(mask.val, _mm512_setzero_##zsuf(), _MM_CMPINT_EQ), a.val, b.val)); }
OPENCV_HAL_IMPL_AVX512_SELECT(v_uint8x64, epi8, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_int8x64, epi8, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_uint16x32, epi16, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_int16x32, epi16, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_uint32x16, epi32, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_int32x16, epi32, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_uint64x8, epi64, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_int64x8, epi64, si512)
OPENCV_HAL_IMPL_AVX512_SELECT(v_float32x16, ps, ps)
OPENCV_HAL_IMPL_AVX512_SELECT(v_float64x8, pd, pd)
/** Comparison **/
#define OPENCV_HAL_IMPL_AVX512_CMP_INT(bin_op, imm8, _Tpvec, sufcmp, sufset, tval) \
inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm512_maskz_set1_##sufset(_mm512_cmp_##sufcmp##_mask(a.val, b.val, imm8), tval)); }
#define OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(_Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_INT(==, _MM_CMPINT_EQ, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_INT(!=, _MM_CMPINT_NE, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_INT(<, _MM_CMPINT_LT, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_INT(>, _MM_CMPINT_NLE, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_INT(<=, _MM_CMPINT_LE, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_INT(>=, _MM_CMPINT_NLT, _Tpvec, sufcmp, sufset, tval)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint8x64, epu8, epi8, (char)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int8x64, epi8, epi8, (char)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint16x32, epu16, epi16, (short)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int16x32, epi16, epi16, (short)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint32x16, epu32, epi32, (int)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int32x16, epi32, epi32, (int)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_uint64x8, epu64, epi64, (int64)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_INT(v_int64x8, epi64, epi64, (int64)-1)
#define OPENCV_HAL_IMPL_AVX512_CMP_FLT(bin_op, imm8, _Tpvec, sufcmp, sufset, tval) \
inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm512_castsi512_##sufcmp(_mm512_maskz_set1_##sufset(_mm512_cmp_##sufcmp##_mask(a.val, b.val, imm8), tval))); }
#define OPENCV_HAL_IMPL_AVX512_CMP_OP_FLT(_Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_FLT(==, _CMP_EQ_OQ, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_FLT(!=, _CMP_NEQ_OQ, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_FLT(<, _CMP_LT_OQ, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_FLT(>, _CMP_GT_OQ, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_FLT(<=, _CMP_LE_OQ, _Tpvec, sufcmp, sufset, tval) \
OPENCV_HAL_IMPL_AVX512_CMP_FLT(>=, _CMP_GE_OQ, _Tpvec, sufcmp, sufset, tval)
OPENCV_HAL_IMPL_AVX512_CMP_OP_FLT(v_float32x16, ps, epi32, (int)-1)
OPENCV_HAL_IMPL_AVX512_CMP_OP_FLT(v_float64x8, pd, epi64, (int64)-1)
inline v_float32x16 v_not_nan(const v_float32x16& a)
{ return v_float32x16(_mm512_castsi512_ps(_mm512_maskz_set1_epi32(_mm512_cmp_ps_mask(a.val, a.val, _CMP_ORD_Q), (int)-1))); }
inline v_float64x8 v_not_nan(const v_float64x8& a)
{ return v_float64x8(_mm512_castsi512_pd(_mm512_maskz_set1_epi64(_mm512_cmp_pd_mask(a.val, a.val, _CMP_ORD_Q), (int64)-1))); }
/** min/max **/
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint8x64, _mm512_min_epu8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint8x64, _mm512_max_epu8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int8x64, _mm512_min_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int8x64, _mm512_max_epi8)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint16x32, _mm512_min_epu16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint16x32, _mm512_max_epu16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int16x32, _mm512_min_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int16x32, _mm512_max_epi16)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint32x16, _mm512_min_epu32)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint32x16, _mm512_max_epu32)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int32x16, _mm512_min_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int32x16, _mm512_max_epi32)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_uint64x8, _mm512_min_epu64)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_uint64x8, _mm512_max_epu64)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_int64x8, _mm512_min_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_int64x8, _mm512_max_epi64)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_float32x16, _mm512_min_ps)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_float32x16, _mm512_max_ps)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_min, v_float64x8, _mm512_min_pd)
OPENCV_HAL_IMPL_AVX512_BIN_FUNC(v_max, v_float64x8, _mm512_max_pd)
/** Rotate **/
namespace {
template<bool prec, int imm4, bool part, int imm32>
struct _v_rotate_right { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64&) { return v_int8x64(); }};
template<int imm4, int imm32>
struct _v_rotate_right<true, imm4, false, imm32> { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64& b)
{
return v_int8x64(_mm512_or_si512(_mm512_srli_epi32(_mm512_alignr_epi32(b.val, a.val, imm32 ), imm4 *8),
_mm512_slli_epi32(_mm512_alignr_epi32(b.val, a.val, imm32 + 1), (4-imm4)*8)));
}};
template<int imm4>
struct _v_rotate_right<true, imm4, false, 15> { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64& b)
{
return v_int8x64(_mm512_or_si512(_mm512_srli_epi32(_mm512_alignr_epi32(b.val, a.val, 15), imm4 *8),
_mm512_slli_epi32( b.val, (4-imm4)*8)));
}};
template<int imm4, int imm32>
struct _v_rotate_right<true, imm4, true, imm32> { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b)
{
return v_int8x64(_mm512_or_si512(_mm512_srli_epi32(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, imm32 - 16), imm4 *8),
_mm512_slli_epi32(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, imm32 - 15), (4-imm4)*8)));
}};
template<int imm4>
struct _v_rotate_right<true, imm4, true, 31> { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b)
{ return v_int8x64(_mm512_srli_epi32(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, 15), imm4*8)); }};
template<int imm32>
struct _v_rotate_right<false, 0, false, imm32> { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64& b)
{ return v_int8x64(_mm512_alignr_epi32(b.val, a.val, imm32)); }};
template<>
struct _v_rotate_right<false, 0, false, 0> { static inline v_int8x64 eval(const v_int8x64& a, const v_int8x64&) { return a; }};
template<int imm32>
struct _v_rotate_right<false, 0, true, imm32> { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b)
{ return v_int8x64(_mm512_alignr_epi32(_mm512_setzero_si512(), b.val, imm32 - 16)); }};
template<>
struct _v_rotate_right<false, 0, true, 16> { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64& b) { return b; }};
template<>
struct _v_rotate_right<false, 0, true, 32> { static inline v_int8x64 eval(const v_int8x64&, const v_int8x64&) { return v_int8x64(); }};
}
template<int imm> inline v_int8x64 v_rotate_right(const v_int8x64& a, const v_int8x64& b)
{
return imm >= 128 ? v_int8x64() :
#if CV_AVX_512VBMI
v_int8x64(_mm512_permutex2var_epi8(a.val,
_v512_set_epu8(0x3f + imm, 0x3e + imm, 0x3d + imm, 0x3c + imm, 0x3b + imm, 0x3a + imm, 0x39 + imm, 0x38 + imm,
0x37 + imm, 0x36 + imm, 0x35 + imm, 0x34 + imm, 0x33 + imm, 0x32 + imm, 0x31 + imm, 0x30 + imm,
0x2f + imm, 0x2e + imm, 0x2d + imm, 0x2c + imm, 0x2b + imm, 0x2a + imm, 0x29 + imm, 0x28 + imm,
0x27 + imm, 0x26 + imm, 0x25 + imm, 0x24 + imm, 0x23 + imm, 0x22 + imm, 0x21 + imm, 0x20 + imm,
0x1f + imm, 0x1e + imm, 0x1d + imm, 0x1c + imm, 0x1b + imm, 0x1a + imm, 0x19 + imm, 0x18 + imm,
0x17 + imm, 0x16 + imm, 0x15 + imm, 0x14 + imm, 0x13 + imm, 0x12 + imm, 0x11 + imm, 0x10 + imm,
0x0f + imm, 0x0e + imm, 0x0d + imm, 0x0c + imm, 0x0b + imm, 0x0a + imm, 0x09 + imm, 0x08 + imm,
0x07 + imm, 0x06 + imm, 0x05 + imm, 0x04 + imm, 0x03 + imm, 0x02 + imm, 0x01 + imm, 0x00 + imm), b.val));
#else
_v_rotate_right<imm%4!=0, imm%4, (imm/4 > 15), imm/4>::eval(a, b);
#endif
}
template<int imm>
inline v_int8x64 v_rotate_left(const v_int8x64& a, const v_int8x64& b)
{
if (imm == 0) return a;
if (imm == 64) return b;
if (imm >= 128) return v_int8x64();
#if CV_AVX_512VBMI
return v_int8x64(_mm512_permutex2var_epi8(b.val,
_v512_set_epi8(0x7f - imm,0x7e - imm,0x7d - imm,0x7c - imm,0x7b - imm,0x7a - imm,0x79 - imm,0x78 - imm,
0x77 - imm,0x76 - imm,0x75 - imm,0x74 - imm,0x73 - imm,0x72 - imm,0x71 - imm,0x70 - imm,
0x6f - imm,0x6e - imm,0x6d - imm,0x6c - imm,0x6b - imm,0x6a - imm,0x69 - imm,0x68 - imm,
0x67 - imm,0x66 - imm,0x65 - imm,0x64 - imm,0x63 - imm,0x62 - imm,0x61 - imm,0x60 - imm,
0x5f - imm,0x5e - imm,0x5d - imm,0x5c - imm,0x5b - imm,0x5a - imm,0x59 - imm,0x58 - imm,
0x57 - imm,0x56 - imm,0x55 - imm,0x54 - imm,0x53 - imm,0x52 - imm,0x51 - imm,0x50 - imm,
0x4f - imm,0x4e - imm,0x4d - imm,0x4c - imm,0x4b - imm,0x4a - imm,0x49 - imm,0x48 - imm,
0x47 - imm,0x46 - imm,0x45 - imm,0x44 - imm,0x43 - imm,0x42 - imm,0x41 - imm,0x40 - imm), a.val));
#else
return imm < 64 ? v_rotate_right<64 - imm>(b, a) : v_rotate_right<128 - imm>(v512_setzero_s8(), b);
#endif
}
template<int imm>
inline v_int8x64 v_rotate_right(const v_int8x64& a)
{
if (imm == 0) return a;
if (imm >= 64) return v_int8x64();
#if CV_AVX_512VBMI
return v_int8x64(_mm512_maskz_permutexvar_epi8(0xFFFFFFFFFFFFFFFF >> imm,
_v512_set_epu8(0x3f + imm,0x3e + imm,0x3d + imm,0x3c + imm,0x3b + imm,0x3a + imm,0x39 + imm,0x38 + imm,
0x37 + imm,0x36 + imm,0x35 + imm,0x34 + imm,0x33 + imm,0x32 + imm,0x31 + imm,0x30 + imm,
0x2f + imm,0x2e + imm,0x2d + imm,0x2c + imm,0x2b + imm,0x2a + imm,0x29 + imm,0x28 + imm,
0x27 + imm,0x26 + imm,0x25 + imm,0x24 + imm,0x23 + imm,0x22 + imm,0x21 + imm,0x20 + imm,
0x1f + imm,0x1e + imm,0x1d + imm,0x1c + imm,0x1b + imm,0x1a + imm,0x19 + imm,0x18 + imm,
0x17 + imm,0x16 + imm,0x15 + imm,0x14 + imm,0x13 + imm,0x12 + imm,0x11 + imm,0x10 + imm,
0x0f + imm,0x0e + imm,0x0d + imm,0x0c + imm,0x0b + imm,0x0a + imm,0x09 + imm,0x08 + imm,
0x07 + imm,0x06 + imm,0x05 + imm,0x04 + imm,0x03 + imm,0x02 + imm,0x01 + imm,0x00 + imm), a.val));
#else
return v_rotate_right<imm>(a, v512_setzero_s8());
#endif
}
template<int imm>
inline v_int8x64 v_rotate_left(const v_int8x64& a)
{
if (imm == 0) return a;
if (imm >= 64) return v_int8x64();
#if CV_AVX_512VBMI
return v_int8x64(_mm512_maskz_permutexvar_epi8(0xFFFFFFFFFFFFFFFF << imm,
_v512_set_epi8(0x3f - imm,0x3e - imm,0x3d - imm,0x3c - imm,0x3b - imm,0x3a - imm,0x39 - imm,0x38 - imm,
0x37 - imm,0x36 - imm,0x35 - imm,0x34 - imm,0x33 - imm,0x32 - imm,0x31 - imm,0x30 - imm,
0x2f - imm,0x2e - imm,0x2d - imm,0x2c - imm,0x2b - imm,0x2a - imm,0x29 - imm,0x28 - imm,
0x27 - imm,0x26 - imm,0x25 - imm,0x24 - imm,0x23 - imm,0x22 - imm,0x21 - imm,0x20 - imm,
0x1f - imm,0x1e - imm,0x1d - imm,0x1c - imm,0x1b - imm,0x1a - imm,0x19 - imm,0x18 - imm,
0x17 - imm,0x16 - imm,0x15 - imm,0x14 - imm,0x13 - imm,0x12 - imm,0x11 - imm,0x10 - imm,
0x0f - imm,0x0e - imm,0x0d - imm,0x0c - imm,0x0b - imm,0x0a - imm,0x09 - imm,0x08 - imm,
0x07 - imm,0x06 - imm,0x05 - imm,0x04 - imm,0x03 - imm,0x02 - imm,0x01 - imm,0x00 - imm), a.val));
#else
return v_rotate_right<64 - imm>(v512_setzero_s8(), a);
#endif
}
#define OPENCV_HAL_IMPL_AVX512_ROTATE_PM(_Tpvec, suffix) \
template<int imm> inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \
{ return v_reinterpret_as_##suffix(v_rotate_left<imm * sizeof(_Tpvec::lane_type)>(v_reinterpret_as_s8(a), v_reinterpret_as_s8(b))); } \
template<int imm> inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \
{ return v_reinterpret_as_##suffix(v_rotate_right<imm * sizeof(_Tpvec::lane_type)>(v_reinterpret_as_s8(a), v_reinterpret_as_s8(b))); } \
template<int imm> inline _Tpvec v_rotate_left(const _Tpvec& a) \
{ return v_reinterpret_as_##suffix(v_rotate_left<imm * sizeof(_Tpvec::lane_type)>(v_reinterpret_as_s8(a))); } \
template<int imm> inline _Tpvec v_rotate_right(const _Tpvec& a) \
{ return v_reinterpret_as_##suffix(v_rotate_right<imm * sizeof(_Tpvec::lane_type)>(v_reinterpret_as_s8(a))); }
#define OPENCV_HAL_IMPL_AVX512_ROTATE_EC(_Tpvec, suffix) \
template<int imm> \
inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \
{ \
enum { SHIFT2 = (_Tpvec::nlanes - imm) }; \
enum { MASK = ((1 << _Tpvec::nlanes) - 1) }; \
if (imm == 0) return a; \
if (imm == _Tpvec::nlanes) return b; \
if (imm >= 2*_Tpvec::nlanes) return _Tpvec(); \
return _Tpvec(_mm512_mask_expand_##suffix(_mm512_maskz_compress_##suffix((MASK << SHIFT2)&MASK, b.val), (MASK << (imm))&MASK, a.val)); \
} \
template<int imm> \
inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \
{ \
enum { SHIFT2 = (_Tpvec::nlanes - imm) }; \
enum { MASK = ((1 << _Tpvec::nlanes) - 1) }; \
if (imm == 0) return a; \
if (imm == _Tpvec::nlanes) return b; \
if (imm >= 2*_Tpvec::nlanes) return _Tpvec(); \
return _Tpvec(_mm512_mask_expand_##suffix(_mm512_maskz_compress_##suffix((MASK << (imm))&MASK, a.val), (MASK << SHIFT2)&MASK, b.val)); \
} \
template<int imm> \
inline _Tpvec v_rotate_left(const _Tpvec& a) \
{ \
if (imm == 0) return a; \
if (imm >= _Tpvec::nlanes) return _Tpvec(); \
return _Tpvec(_mm512_maskz_expand_##suffix((1 << _Tpvec::nlanes) - (1 << (imm)), a.val)); \
} \
template<int imm> \
inline _Tpvec v_rotate_right(const _Tpvec& a) \
{ \
if (imm == 0) return a; \
if (imm >= _Tpvec::nlanes) return _Tpvec(); \
return _Tpvec(_mm512_maskz_compress_##suffix((1 << _Tpvec::nlanes) - (1 << (imm)), a.val)); \
}
OPENCV_HAL_IMPL_AVX512_ROTATE_PM(v_uint8x64, u8)
OPENCV_HAL_IMPL_AVX512_ROTATE_PM(v_uint16x32, u16)
OPENCV_HAL_IMPL_AVX512_ROTATE_PM(v_int16x32, s16)
OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_uint32x16, epi32)
OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_int32x16, epi32)
OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_uint64x8, epi64)
OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_int64x8, epi64)
OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_float32x16, ps)
OPENCV_HAL_IMPL_AVX512_ROTATE_EC(v_float64x8, pd)
/** Reverse **/
inline v_uint8x64 v_reverse(const v_uint8x64 &a)
{
#if CV_AVX_512VBMI
static const __m512i perm = _mm512_set_epi32(
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617, 0x18191a1b, 0x1c1d1e1f,
0x20212223, 0x24252627, 0x28292a2b, 0x2c2d2e2f,
0x30313233, 0x34353637, 0x38393a3b, 0x3c3d3e3f);
return v_uint8x64(_mm512_permutexvar_epi8(perm, a.val));
#else
static const __m512i shuf = _mm512_set_epi32(
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f);
static const __m512i perm = _mm512_set_epi64(1, 0, 3, 2, 5, 4, 7, 6);
__m512i vec = _mm512_shuffle_epi8(a.val, shuf);
return v_uint8x64(_mm512_permutexvar_epi64(perm, vec));
#endif
}
inline v_int8x64 v_reverse(const v_int8x64 &a)
{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); }
inline v_uint16x32 v_reverse(const v_uint16x32 &a)
{
#if CV_AVX_512VBMI
static const __m512i perm = _mm512_set_epi32(
0x00000001, 0x00020003, 0x00040005, 0x00060007,
0x00080009, 0x000a000b, 0x000c000d, 0x000e000f,
0x00100011, 0x00120013, 0x00140015, 0x00160017,
0x00180019, 0x001a001b, 0x001c001d, 0x001e001f);
return v_uint16x32(_mm512_permutexvar_epi16(perm, a.val));
#else
static const __m512i shuf = _mm512_set_epi32(
0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e,
0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e,
0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e,
0x01000302, 0x05040706, 0x09080b0a, 0x0d0c0f0e);
static const __m512i perm = _mm512_set_epi64(1, 0, 3, 2, 5, 4, 7, 6);
__m512i vec = _mm512_shuffle_epi8(a.val, shuf);
return v_uint16x32(_mm512_permutexvar_epi64(perm, vec));
#endif
}
inline v_int16x32 v_reverse(const v_int16x32 &a)
{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); }
inline v_uint32x16 v_reverse(const v_uint32x16 &a)
{
static const __m512i perm = _mm512_set_epi32(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,14, 15);
return v_uint32x16(_mm512_permutexvar_epi32(perm, a.val));
}
inline v_int32x16 v_reverse(const v_int32x16 &a)
{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); }
inline v_float32x16 v_reverse(const v_float32x16 &a)
{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); }
inline v_uint64x8 v_reverse(const v_uint64x8 &a)
{
static const __m512i perm = _mm512_set_epi64(0, 1, 2, 3, 4, 5, 6, 7);
return v_uint64x8(_mm512_permutexvar_epi64(perm, a.val));
}
inline v_int64x8 v_reverse(const v_int64x8 &a)
{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); }
inline v_float64x8 v_reverse(const v_float64x8 &a)
{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); }
////////// Reduce /////////
/** Reduce **/
#define OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64(a, b) a + b
#define OPENCV_HAL_IMPL_AVX512_REDUCE_8(sctype, func, _Tpvec, ifunc, scop) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \
sctype CV_DECL_ALIGNED(64) idx[2]; \
_mm_store_si128((__m128i*)idx, _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1))); \
return scop(idx[0], idx[1]); }
OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, min, v_uint64x8, min_epu64, min)
OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, max, v_uint64x8, max_epu64, max)
OPENCV_HAL_IMPL_AVX512_REDUCE_8(uint64, sum, v_uint64x8, add_epi64, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64)
OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, min, v_int64x8, min_epi64, min)
OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, max, v_int64x8, max_epi64, max)
OPENCV_HAL_IMPL_AVX512_REDUCE_8(int64, sum, v_int64x8, add_epi64, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64)
#define OPENCV_HAL_IMPL_AVX512_REDUCE_8F(func, ifunc, scop) \
inline double v_reduce_##func(const v_float64x8& a) \
{ __m256d half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \
double CV_DECL_ALIGNED(64) idx[2]; \
_mm_store_pd(idx, _mm_##ifunc(_mm256_castpd256_pd128(half), _mm256_extractf128_pd(half, 1))); \
return scop(idx[0], idx[1]); }
OPENCV_HAL_IMPL_AVX512_REDUCE_8F(min, min_pd, min)
OPENCV_HAL_IMPL_AVX512_REDUCE_8F(max, max_pd, max)
OPENCV_HAL_IMPL_AVX512_REDUCE_8F(sum, add_pd, OPENCV_HAL_IMPL_AVX512_REDUCE_ADD64)
#define OPENCV_HAL_IMPL_AVX512_REDUCE_16(sctype, func, _Tpvec, ifunc) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \
__m128i quarter = _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 8)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 4)); \
return (sctype)_mm_cvtsi128_si32(quarter); }
OPENCV_HAL_IMPL_AVX512_REDUCE_16(uint, min, v_uint32x16, min_epu32)
OPENCV_HAL_IMPL_AVX512_REDUCE_16(uint, max, v_uint32x16, max_epu32)
OPENCV_HAL_IMPL_AVX512_REDUCE_16(int, min, v_int32x16, min_epi32)
OPENCV_HAL_IMPL_AVX512_REDUCE_16(int, max, v_int32x16, max_epi32)
#define OPENCV_HAL_IMPL_AVX512_REDUCE_16F(func, ifunc) \
inline float v_reduce_##func(const v_float32x16& a) \
{ __m256 half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \
__m128 quarter = _mm_##ifunc(_mm256_castps256_ps128(half), _mm256_extractf128_ps(half, 1)); \
quarter = _mm_##ifunc(quarter, _mm_permute_ps(quarter, _MM_SHUFFLE(0, 0, 3, 2))); \
quarter = _mm_##ifunc(quarter, _mm_permute_ps(quarter, _MM_SHUFFLE(0, 0, 0, 1))); \
return _mm_cvtss_f32(quarter); }
OPENCV_HAL_IMPL_AVX512_REDUCE_16F(min, min_ps)
OPENCV_HAL_IMPL_AVX512_REDUCE_16F(max, max_ps)
inline float v_reduce_sum(const v_float32x16& a)
{
__m256 half = _mm256_add_ps(_v512_extract_low(a.val), _v512_extract_high(a.val));
__m128 quarter = _mm_add_ps(_mm256_castps256_ps128(half), _mm256_extractf128_ps(half, 1));
quarter = _mm_hadd_ps(quarter, quarter);
return _mm_cvtss_f32(_mm_hadd_ps(quarter, quarter));
}
inline int v_reduce_sum(const v_int32x16& a)
{
__m256i half = _mm256_add_epi32(_v512_extract_low(a.val), _v512_extract_high(a.val));
__m128i quarter = _mm_add_epi32(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1));
quarter = _mm_hadd_epi32(quarter, quarter);
return _mm_cvtsi128_si32(_mm_hadd_epi32(quarter, quarter));
}
inline uint v_reduce_sum(const v_uint32x16& a)
{ return (uint)v_reduce_sum(v_reinterpret_as_s32(a)); }
#define OPENCV_HAL_IMPL_AVX512_REDUCE_32(sctype, func, _Tpvec, ifunc) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \
__m128i quarter = _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 8)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 4)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 2)); \
return (sctype)_mm_cvtsi128_si32(quarter); }
OPENCV_HAL_IMPL_AVX512_REDUCE_32(ushort, min, v_uint16x32, min_epu16)
OPENCV_HAL_IMPL_AVX512_REDUCE_32(ushort, max, v_uint16x32, max_epu16)
OPENCV_HAL_IMPL_AVX512_REDUCE_32(short, min, v_int16x32, min_epi16)
OPENCV_HAL_IMPL_AVX512_REDUCE_32(short, max, v_int16x32, max_epi16)
inline int v_reduce_sum(const v_int16x32& a)
{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); }
inline uint v_reduce_sum(const v_uint16x32& a)
{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); }
#define OPENCV_HAL_IMPL_AVX512_REDUCE_64(sctype, func, _Tpvec, ifunc) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ __m256i half = _mm256_##ifunc(_v512_extract_low(a.val), _v512_extract_high(a.val)); \
__m128i quarter = _mm_##ifunc(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 8)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 4)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 2)); \
quarter = _mm_##ifunc(quarter, _mm_srli_si128(quarter, 1)); \
return (sctype)_mm_cvtsi128_si32(quarter); }
OPENCV_HAL_IMPL_AVX512_REDUCE_64(uchar, min, v_uint8x64, min_epu8)
OPENCV_HAL_IMPL_AVX512_REDUCE_64(uchar, max, v_uint8x64, max_epu8)
OPENCV_HAL_IMPL_AVX512_REDUCE_64(schar, min, v_int8x64, min_epi8)
OPENCV_HAL_IMPL_AVX512_REDUCE_64(schar, max, v_int8x64, max_epi8)
#define OPENCV_HAL_IMPL_AVX512_REDUCE_64_SUM(sctype, _Tpvec, suffix) \
inline sctype v_reduce_sum(const _Tpvec& a) \
{ __m512i a16 = _mm512_add_epi16(_mm512_cvt##suffix##_epi16(_v512_extract_low(a.val)), \
_mm512_cvt##suffix##_epi16(_v512_extract_high(a.val))); \
a16 = _mm512_cvtepi16_epi32(_mm256_add_epi16(_v512_extract_low(a16), _v512_extract_high(a16))); \
__m256i a8 = _mm256_add_epi32(_v512_extract_low(a16), _v512_extract_high(a16)); \
__m128i a4 = _mm_add_epi32(_mm256_castsi256_si128(a8), _mm256_extracti128_si256(a8, 1)); \
a4 = _mm_hadd_epi32(a4, a4); \
return (sctype)_mm_cvtsi128_si32(_mm_hadd_epi32(a4, a4)); }
OPENCV_HAL_IMPL_AVX512_REDUCE_64_SUM(uint, v_uint8x64, epu8)
OPENCV_HAL_IMPL_AVX512_REDUCE_64_SUM(int, v_int8x64, epi8)
inline v_float32x16 v_reduce_sum4(const v_float32x16& a, const v_float32x16& b,
const v_float32x16& c, const v_float32x16& d)
{
__m256 abl = _mm256_hadd_ps(_v512_extract_low(a.val), _v512_extract_low(b.val));
__m256 abh = _mm256_hadd_ps(_v512_extract_high(a.val), _v512_extract_high(b.val));
__m256 cdl = _mm256_hadd_ps(_v512_extract_low(c.val), _v512_extract_low(d.val));
__m256 cdh = _mm256_hadd_ps(_v512_extract_high(c.val), _v512_extract_high(d.val));
return v_float32x16(_v512_combine(_mm256_hadd_ps(abl, cdl), _mm256_hadd_ps(abh, cdh)));
}
inline unsigned v_reduce_sad(const v_uint8x64& a, const v_uint8x64& b)
{
__m512i val = _mm512_sad_epu8(a.val, b.val);
__m256i half = _mm256_add_epi32(_v512_extract_low(val), _v512_extract_high(val));
__m128i quarter = _mm_add_epi32(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1));
return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter)));
}
inline unsigned v_reduce_sad(const v_int8x64& a, const v_int8x64& b)
{
__m512i val = _mm512_set1_epi8(-128);
val = _mm512_sad_epu8(_mm512_add_epi8(a.val, val), _mm512_add_epi8(b.val, val));
__m256i half = _mm256_add_epi32(_v512_extract_low(val), _v512_extract_high(val));
__m128i quarter = _mm_add_epi32(_mm256_castsi256_si128(half), _mm256_extracti128_si256(half, 1));
return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter)));
}
inline unsigned v_reduce_sad(const v_uint16x32& a, const v_uint16x32& b)
{ return v_reduce_sum(v_add_wrap(a - b, b - a)); }
inline unsigned v_reduce_sad(const v_int16x32& a, const v_int16x32& b)
{ return v_reduce_sum(v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b)))); }
inline unsigned v_reduce_sad(const v_uint32x16& a, const v_uint32x16& b)
{ return v_reduce_sum(v_max(a, b) - v_min(a, b)); }
inline unsigned v_reduce_sad(const v_int32x16& a, const v_int32x16& b)
{ return v_reduce_sum(v_reinterpret_as_u32(v_max(a, b) - v_min(a, b))); }
inline float v_reduce_sad(const v_float32x16& a, const v_float32x16& b)
{ return v_reduce_sum((a - b) & v_float32x16(_mm512_castsi512_ps(_mm512_set1_epi32(0x7fffffff)))); }
inline double v_reduce_sad(const v_float64x8& a, const v_float64x8& b)
{ return v_reduce_sum((a - b) & v_float64x8(_mm512_castsi512_pd(_mm512_set1_epi64(0x7fffffffffffffff)))); }
/** Popcount **/
inline v_uint8x64 v_popcount(const v_int8x64& a)
{
#if CV_AVX_512BITALG
return v_uint8x64(_mm512_popcnt_epi8(a.val));
#elif CV_AVX_512VBMI
__m512i _popcnt_table0 = _v512_set_epu8(7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3,
5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1,
5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1,
4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0);
__m512i _popcnt_table1 = _v512_set_epu8(7, 6, 6, 5, 6, 5, 5, 4, 6, 5, 5, 4, 5, 4, 4, 3,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
6, 5, 5, 4, 5, 4, 4, 3, 5, 4, 4, 3, 4, 3, 3, 2,
5, 4, 4, 3, 4, 3, 3, 2, 4, 3, 3, 2, 3, 2, 2, 1);
return v_uint8x64(_mm512_sub_epi8(_mm512_permutex2var_epi8(_popcnt_table0, a.val, _popcnt_table1), _mm512_movm_epi8(_mm512_movepi8_mask(a.val))));
#else
__m512i _popcnt_table = _mm512_set4_epi32(0x04030302, 0x03020201, 0x03020201, 0x02010100);
__m512i _popcnt_mask = _mm512_set1_epi8(0x0F);
return v_uint8x64(_mm512_add_epi8(_mm512_shuffle_epi8(_popcnt_table, _mm512_and_si512( a.val, _popcnt_mask)),
_mm512_shuffle_epi8(_popcnt_table, _mm512_and_si512(_mm512_srli_epi16(a.val, 4), _popcnt_mask))));
#endif
}
inline v_uint16x32 v_popcount(const v_int16x32& a)
{
#if CV_AVX_512BITALG
return v_uint16x32(_mm512_popcnt_epi16(a.val));
#elif CV_AVX_512VPOPCNTDQ
__m512i zero = _mm512_setzero_si512();
return v_uint16x32(_mm512_packs_epi32(_mm512_popcnt_epi32(_mm512_unpacklo_epi16(a.val, zero)),
_mm512_popcnt_epi32(_mm512_unpackhi_epi16(a.val, zero))));
#else
v_uint8x64 p = v_popcount(v_reinterpret_as_s8(a));
p += v_rotate_right<1>(p);
return v_reinterpret_as_u16(p) & v512_setall_u16(0x00ff);
#endif
}
inline v_uint32x16 v_popcount(const v_int32x16& a)
{
#if CV_AVX_512VPOPCNTDQ
return v_uint32x16(_mm512_popcnt_epi32(a.val));
#else
v_uint8x64 p = v_popcount(v_reinterpret_as_s8(a));
p += v_rotate_right<1>(p);
p += v_rotate_right<2>(p);
return v_reinterpret_as_u32(p) & v512_setall_u32(0x000000ff);
#endif
}
inline v_uint64x8 v_popcount(const v_int64x8& a)
{
#if CV_AVX_512VPOPCNTDQ
return v_uint64x8(_mm512_popcnt_epi64(a.val));
#else
return v_uint64x8(_mm512_sad_epu8(v_popcount(v_reinterpret_as_s8(a)).val, _mm512_setzero_si512()));
#endif
}
inline v_uint8x64 v_popcount(const v_uint8x64& a) { return v_popcount(v_reinterpret_as_s8 (a)); }
inline v_uint16x32 v_popcount(const v_uint16x32& a) { return v_popcount(v_reinterpret_as_s16(a)); }
inline v_uint32x16 v_popcount(const v_uint32x16& a) { return v_popcount(v_reinterpret_as_s32(a)); }
inline v_uint64x8 v_popcount(const v_uint64x8& a) { return v_popcount(v_reinterpret_as_s64(a)); }
////////// Other math /////////
/** Some frequent operations **/
#define OPENCV_HAL_IMPL_AVX512_MULADD(_Tpvec, suffix) \
inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \
{ return _Tpvec(_mm512_fmadd_##suffix(a.val, b.val, c.val)); } \
inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \
{ return _Tpvec(_mm512_fmadd_##suffix(a.val, b.val, c.val)); } \
inline _Tpvec v_sqrt(const _Tpvec& x) \
{ return _Tpvec(_mm512_sqrt_##suffix(x.val)); } \
inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \
{ return v_fma(a, a, b * b); } \
inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \
{ return v_sqrt(v_fma(a, a, b * b)); }
OPENCV_HAL_IMPL_AVX512_MULADD(v_float32x16, ps)
OPENCV_HAL_IMPL_AVX512_MULADD(v_float64x8, pd)
inline v_int32x16 v_fma(const v_int32x16& a, const v_int32x16& b, const v_int32x16& c)
{ return a * b + c; }
inline v_int32x16 v_muladd(const v_int32x16& a, const v_int32x16& b, const v_int32x16& c)
{ return v_fma(a, b, c); }
inline v_float32x16 v_invsqrt(const v_float32x16& x)
{
#if CV_AVX_512ER
return v_float32x16(_mm512_rsqrt28_ps(x.val));
#else
v_float32x16 half = x * v512_setall_f32(0.5);
v_float32x16 t = v_float32x16(_mm512_rsqrt14_ps(x.val));
t *= v512_setall_f32(1.5) - ((t * t) * half);
return t;
#endif
}
inline v_float64x8 v_invsqrt(const v_float64x8& x)
{
#if CV_AVX_512ER
return v_float64x8(_mm512_rsqrt28_pd(x.val));
#else
return v512_setall_f64(1.) / v_sqrt(x);
// v_float64x8 half = x * v512_setall_f64(0.5);
// v_float64x8 t = v_float64x8(_mm512_rsqrt14_pd(x.val));
// t *= v512_setall_f64(1.5) - ((t * t) * half);
// t *= v512_setall_f64(1.5) - ((t * t) * half);
// return t;
#endif
}
/** Absolute values **/
#define OPENCV_HAL_IMPL_AVX512_ABS(_Tpvec, _Tpuvec, suffix) \
inline _Tpuvec v_abs(const _Tpvec& x) \
{ return _Tpuvec(_mm512_abs_##suffix(x.val)); }
OPENCV_HAL_IMPL_AVX512_ABS(v_int8x64, v_uint8x64, epi8)
OPENCV_HAL_IMPL_AVX512_ABS(v_int16x32, v_uint16x32, epi16)
OPENCV_HAL_IMPL_AVX512_ABS(v_int32x16, v_uint32x16, epi32)
OPENCV_HAL_IMPL_AVX512_ABS(v_int64x8, v_uint64x8, epi64)
inline v_float32x16 v_abs(const v_float32x16& x)
{
#ifdef _mm512_abs_pd
return v_float32x16(_mm512_abs_ps(x.val));
#else
return v_float32x16(_mm512_castsi512_ps(_mm512_and_si512(_mm512_castps_si512(x.val),
_v512_set_epu64(0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF,
0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF, 0x7FFFFFFF7FFFFFFF))));
#endif
}
inline v_float64x8 v_abs(const v_float64x8& x)
{
#ifdef _mm512_abs_pd
#if defined __GNUC__ && (__GNUC__ < 7 || (__GNUC__ == 7 && __GNUC_MINOR__ <= 3) || (__GNUC__ == 8 && __GNUC_MINOR__ <= 2))
// Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87476
return v_float64x8(_mm512_abs_pd(_mm512_castpd_ps(x.val)));
#else
return v_float64x8(_mm512_abs_pd(x.val));
#endif
#else
return v_float64x8(_mm512_castsi512_pd(_mm512_and_si512(_mm512_castpd_si512(x.val),
_v512_set_epu64(0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF,
0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF))));
#endif
}
/** Absolute difference **/
inline v_uint8x64 v_absdiff(const v_uint8x64& a, const v_uint8x64& b)
{ return v_add_wrap(a - b, b - a); }
inline v_uint16x32 v_absdiff(const v_uint16x32& a, const v_uint16x32& b)
{ return v_add_wrap(a - b, b - a); }
inline v_uint32x16 v_absdiff(const v_uint32x16& a, const v_uint32x16& b)
{ return v_max(a, b) - v_min(a, b); }
inline v_uint8x64 v_absdiff(const v_int8x64& a, const v_int8x64& b)
{
v_int8x64 d = v_sub_wrap(a, b);
v_int8x64 m = a < b;
return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m));
}
inline v_uint16x32 v_absdiff(const v_int16x32& a, const v_int16x32& b)
{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); }
inline v_uint32x16 v_absdiff(const v_int32x16& a, const v_int32x16& b)
{
v_int32x16 d = a - b;
v_int32x16 m = a < b;
return v_reinterpret_as_u32((d ^ m) - m);
}
inline v_float32x16 v_absdiff(const v_float32x16& a, const v_float32x16& b)
{ return v_abs(a - b); }
inline v_float64x8 v_absdiff(const v_float64x8& a, const v_float64x8& b)
{ return v_abs(a - b); }
/** Saturating absolute difference **/
inline v_int8x64 v_absdiffs(const v_int8x64& a, const v_int8x64& b)
{
v_int8x64 d = a - b;
v_int8x64 m = a < b;
return (d ^ m) - m;
}
inline v_int16x32 v_absdiffs(const v_int16x32& a, const v_int16x32& b)
{ return v_max(a, b) - v_min(a, b); }
////////// Conversions /////////
/** Rounding **/
inline v_int32x16 v_round(const v_float32x16& a)
{ return v_int32x16(_mm512_cvtps_epi32(a.val)); }
inline v_int32x16 v_round(const v_float64x8& a)
{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvtpd_epi32(a.val))); }
inline v_int32x16 v_round(const v_float64x8& a, const v_float64x8& b)
{ return v_int32x16(_v512_combine(_mm512_cvtpd_epi32(a.val), _mm512_cvtpd_epi32(b.val))); }
inline v_int32x16 v_trunc(const v_float32x16& a)
{ return v_int32x16(_mm512_cvttps_epi32(a.val)); }
inline v_int32x16 v_trunc(const v_float64x8& a)
{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvttpd_epi32(a.val))); }
#if CVT_ROUND_MODES_IMPLEMENTED
inline v_int32x16 v_floor(const v_float32x16& a)
{ return v_int32x16(_mm512_cvt_roundps_epi32(a.val, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC)); }
inline v_int32x16 v_floor(const v_float64x8& a)
{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvt_roundpd_epi32(a.val, _MM_FROUND_TO_NEG_INF | _MM_FROUND_NO_EXC))); }
inline v_int32x16 v_ceil(const v_float32x16& a)
{ return v_int32x16(_mm512_cvt_roundps_epi32(a.val, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC)); }
inline v_int32x16 v_ceil(const v_float64x8& a)
{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvt_roundpd_epi32(a.val, _MM_FROUND_TO_POS_INF | _MM_FROUND_NO_EXC))); }
#else
inline v_int32x16 v_floor(const v_float32x16& a)
{ return v_int32x16(_mm512_cvtps_epi32(_mm512_roundscale_ps(a.val, 1))); }
inline v_int32x16 v_floor(const v_float64x8& a)
{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvtpd_epi32(_mm512_roundscale_pd(a.val, 1)))); }
inline v_int32x16 v_ceil(const v_float32x16& a)
{ return v_int32x16(_mm512_cvtps_epi32(_mm512_roundscale_ps(a.val, 2))); }
inline v_int32x16 v_ceil(const v_float64x8& a)
{ return v_int32x16(_mm512_castsi256_si512(_mm512_cvtpd_epi32(_mm512_roundscale_pd(a.val, 2)))); }
#endif
/** To float **/
inline v_float32x16 v_cvt_f32(const v_int32x16& a)
{ return v_float32x16(_mm512_cvtepi32_ps(a.val)); }
inline v_float32x16 v_cvt_f32(const v_float64x8& a)
{ return v_float32x16(_mm512_cvtpd_pslo(a.val)); }
inline v_float32x16 v_cvt_f32(const v_float64x8& a, const v_float64x8& b)
{ return v_float32x16(_v512_combine(_mm512_cvtpd_ps(a.val), _mm512_cvtpd_ps(b.val))); }
inline v_float64x8 v_cvt_f64(const v_int32x16& a)
{ return v_float64x8(_mm512_cvtepi32_pd(_v512_extract_low(a.val))); }
inline v_float64x8 v_cvt_f64_high(const v_int32x16& a)
{ return v_float64x8(_mm512_cvtepi32_pd(_v512_extract_high(a.val))); }
inline v_float64x8 v_cvt_f64(const v_float32x16& a)
{ return v_float64x8(_mm512_cvtps_pd(_v512_extract_low(a.val))); }
inline v_float64x8 v_cvt_f64_high(const v_float32x16& a)
{ return v_float64x8(_mm512_cvtps_pd(_v512_extract_high(a.val))); }
// from (Mysticial and wim) https://stackoverflow.com/q/41144668
inline v_float64x8 v_cvt_f64(const v_int64x8& v)
{
#if CV_AVX_512DQ
return v_float64x8(_mm512_cvtepi64_pd(v.val));
#else
// constants encoded as floating-point
__m512i magic_i_lo = _mm512_set1_epi64(0x4330000000000000); // 2^52
__m512i magic_i_hi32 = _mm512_set1_epi64(0x4530000080000000); // 2^84 + 2^63
__m512i magic_i_all = _mm512_set1_epi64(0x4530000080100000); // 2^84 + 2^63 + 2^52
__m512d magic_d_all = _mm512_castsi512_pd(magic_i_all);
// Blend the 32 lowest significant bits of v with magic_int_lo
__m512i v_lo = _mm512_mask_blend_epi32(0x5555, magic_i_lo, v.val);
// Extract the 32 most significant bits of v
__m512i v_hi = _mm512_srli_epi64(v.val, 32);
// Flip the msb of v_hi and blend with 0x45300000
v_hi = _mm512_xor_si512(v_hi, magic_i_hi32);
// Compute in double precision
__m512d v_hi_dbl = _mm512_sub_pd(_mm512_castsi512_pd(v_hi), magic_d_all);
// (v_hi - magic_d_all) + v_lo Do not assume associativity of floating point addition
__m512d result = _mm512_add_pd(v_hi_dbl, _mm512_castsi512_pd(v_lo));
return v_float64x8(result);
#endif
}
////////////// Lookup table access ////////////////////
inline v_int8x64 v512_lut(const schar* tab, const int* idx)
{
__m128i p0 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx ), (const int *)tab, 1));
__m128i p1 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 1), (const int *)tab, 1));
__m128i p2 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 2), (const int *)tab, 1));
__m128i p3 = _mm512_cvtepi32_epi8(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 3), (const int *)tab, 1));
return v_int8x64(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512(p0), p1, 1), p2, 2), p3, 3));
}
inline v_int8x64 v512_lut_pairs(const schar* tab, const int* idx)
{
__m256i p0 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx ), (const int *)tab, 1));
__m256i p1 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 1), (const int *)tab, 1));
return v_int8x64(_v512_combine(p0, p1));
}
inline v_int8x64 v512_lut_quads(const schar* tab, const int* idx)
{
return v_int8x64(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx), (const int *)tab, 1));
}
inline v_uint8x64 v512_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v512_lut((const schar *)tab, idx)); }
inline v_uint8x64 v512_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v512_lut_pairs((const schar *)tab, idx)); }
inline v_uint8x64 v512_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v512_lut_quads((const schar *)tab, idx)); }
inline v_int16x32 v512_lut(const short* tab, const int* idx)
{
__m256i p0 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx ), (const int *)tab, 2));
__m256i p1 = _mm512_cvtepi32_epi16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx + 1), (const int *)tab, 2));
return v_int16x32(_v512_combine(p0, p1));
}
inline v_int16x32 v512_lut_pairs(const short* tab, const int* idx)
{
return v_int16x32(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx), (const int *)tab, 2));
}
inline v_int16x32 v512_lut_quads(const short* tab, const int* idx)
{
#if defined(__GNUC__)
return v_int16x32(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const long long int*)tab, 2));
#else
return v_int16x32(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const int64*)tab, 2));
#endif
}
inline v_uint16x32 v512_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v512_lut((const short *)tab, idx)); }
inline v_uint16x32 v512_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v512_lut_pairs((const short *)tab, idx)); }
inline v_uint16x32 v512_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v512_lut_quads((const short *)tab, idx)); }
inline v_int32x16 v512_lut(const int* tab, const int* idx)
{
return v_int32x16(_mm512_i32gather_epi32(_mm512_loadu_si512((const __m512i*)idx), tab, 4));
}
inline v_int32x16 v512_lut_pairs(const int* tab, const int* idx)
{
#if defined(__GNUC__)
return v_int32x16(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const long long int*)tab, 4));
#else
return v_int32x16(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const int64*)tab, 4));
#endif
}
inline v_int32x16 v512_lut_quads(const int* tab, const int* idx)
{
return v_int32x16(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512(
_mm_loadu_si128((const __m128i*)(tab + idx[0]))),
_mm_loadu_si128((const __m128i*)(tab + idx[1])), 1),
_mm_loadu_si128((const __m128i*)(tab + idx[2])), 2),
_mm_loadu_si128((const __m128i*)(tab + idx[3])), 3));
}
inline v_uint32x16 v512_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v512_lut((const int *)tab, idx)); }
inline v_uint32x16 v512_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v512_lut_pairs((const int *)tab, idx)); }
inline v_uint32x16 v512_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v512_lut_quads((const int *)tab, idx)); }
inline v_int64x8 v512_lut(const int64* tab, const int* idx)
{
#if defined(__GNUC__)
return v_int64x8(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), (const long long int*)tab, 8));
#else
return v_int64x8(_mm512_i32gather_epi64(_mm256_loadu_si256((const __m256i*)idx), tab , 8));
#endif
}
inline v_int64x8 v512_lut_pairs(const int64* tab, const int* idx)
{
return v_int64x8(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_inserti32x4(_mm512_castsi128_si512(
_mm_loadu_si128((const __m128i*)(tab + idx[0]))),
_mm_loadu_si128((const __m128i*)(tab + idx[1])), 1),
_mm_loadu_si128((const __m128i*)(tab + idx[2])), 2),
_mm_loadu_si128((const __m128i*)(tab + idx[3])), 3));
}
inline v_uint64x8 v512_lut(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v512_lut((const int64 *)tab, idx)); }
inline v_uint64x8 v512_lut_pairs(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v512_lut_pairs((const int64 *)tab, idx)); }
inline v_float32x16 v512_lut(const float* tab, const int* idx)
{
return v_float32x16(_mm512_i32gather_ps(_mm512_loadu_si512((const __m512i*)idx), tab, 4));
}
inline v_float32x16 v512_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v512_lut_pairs((const int *)tab, idx)); }
inline v_float32x16 v512_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v512_lut_quads((const int *)tab, idx)); }
inline v_float64x8 v512_lut(const double* tab, const int* idx)
{
return v_float64x8(_mm512_i32gather_pd(_mm256_loadu_si256((const __m256i*)idx), tab, 8));
}
inline v_float64x8 v512_lut_pairs(const double* tab, const int* idx)
{
return v_float64x8(_mm512_insertf64x2(_mm512_insertf64x2(_mm512_insertf64x2(_mm512_castpd128_pd512(
_mm_loadu_pd(tab + idx[0])),
_mm_loadu_pd(tab + idx[1]), 1),
_mm_loadu_pd(tab + idx[2]), 2),
_mm_loadu_pd(tab + idx[3]), 3));
}
inline v_int32x16 v_lut(const int* tab, const v_int32x16& idxvec)
{
return v_int32x16(_mm512_i32gather_epi32(idxvec.val, tab, 4));
}
inline v_uint32x16 v_lut(const unsigned* tab, const v_int32x16& idxvec)
{
return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec));
}
inline v_float32x16 v_lut(const float* tab, const v_int32x16& idxvec)
{
return v_float32x16(_mm512_i32gather_ps(idxvec.val, tab, 4));
}
inline v_float64x8 v_lut(const double* tab, const v_int32x16& idxvec)
{
return v_float64x8(_mm512_i32gather_pd(_v512_extract_low(idxvec.val), tab, 8));
}
inline void v_lut_deinterleave(const float* tab, const v_int32x16& idxvec, v_float32x16& x, v_float32x16& y)
{
x.val = _mm512_i32gather_ps(idxvec.val, tab, 4);
y.val = _mm512_i32gather_ps(idxvec.val, &tab[1], 4);
}
inline void v_lut_deinterleave(const double* tab, const v_int32x16& idxvec, v_float64x8& x, v_float64x8& y)
{
x.val = _mm512_i32gather_pd(_v512_extract_low(idxvec.val), tab, 8);
y.val = _mm512_i32gather_pd(_v512_extract_low(idxvec.val), &tab[1], 8);
}
inline v_int8x64 v_interleave_pairs(const v_int8x64& vec)
{
return v_int8x64(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0d0e0c, 0x0b090a08, 0x07050604, 0x03010200)));
}
inline v_uint8x64 v_interleave_pairs(const v_uint8x64& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); }
inline v_int8x64 v_interleave_quads(const v_int8x64& vec)
{
return v_int8x64(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0b0e0a, 0x0d090c08, 0x07030602, 0x05010400)));
}
inline v_uint8x64 v_interleave_quads(const v_uint8x64& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); }
inline v_int16x32 v_interleave_pairs(const v_int16x32& vec)
{
return v_int16x32(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0e0b0a, 0x0d0c0908, 0x07060302, 0x05040100)));
}
inline v_uint16x32 v_interleave_pairs(const v_uint16x32& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); }
inline v_int16x32 v_interleave_quads(const v_int16x32& vec)
{
return v_int16x32(_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0x0f0e0706, 0x0d0c0504, 0x0b0a0302, 0x09080100)));
}
inline v_uint16x32 v_interleave_quads(const v_uint16x32& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); }
inline v_int32x16 v_interleave_pairs(const v_int32x16& vec)
{
return v_int32x16(_mm512_shuffle_epi32(vec.val, _MM_PERM_ACBD));
}
inline v_uint32x16 v_interleave_pairs(const v_uint32x16& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
inline v_float32x16 v_interleave_pairs(const v_float32x16& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
inline v_int8x64 v_pack_triplets(const v_int8x64& vec)
{
return v_int8x64(_mm512_permutexvar_epi32(_v512_set_epu64(0x0000000f0000000f, 0x0000000f0000000f, 0x0000000e0000000d, 0x0000000c0000000a,
0x0000000900000008, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000),
_mm512_shuffle_epi8(vec.val, _mm512_set4_epi32(0xffffff0f, 0x0e0d0c0a, 0x09080605, 0x04020100))));
}
inline v_uint8x64 v_pack_triplets(const v_uint8x64& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); }
inline v_int16x32 v_pack_triplets(const v_int16x32& vec)
{
return v_int16x32(_mm512_permutexvar_epi16(_v512_set_epu64(0x001f001f001f001f, 0x001f001f001f001f, 0x001e001d001c001a, 0x0019001800160015,
0x0014001200110010, 0x000e000d000c000a, 0x0009000800060005, 0x0004000200010000), vec.val));
}
inline v_uint16x32 v_pack_triplets(const v_uint16x32& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); }
inline v_int32x16 v_pack_triplets(const v_int32x16& vec)
{
return v_int32x16(_mm512_permutexvar_epi32(_v512_set_epu64(0x0000000f0000000f, 0x0000000f0000000f, 0x0000000e0000000d, 0x0000000c0000000a,
0x0000000900000008, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000), vec.val));
}
inline v_uint32x16 v_pack_triplets(const v_uint32x16& vec) { return v_reinterpret_as_u32(v_pack_triplets(v_reinterpret_as_s32(vec))); }
inline v_float32x16 v_pack_triplets(const v_float32x16& vec)
{
return v_float32x16(_mm512_permutexvar_ps(_v512_set_epu64(0x0000000f0000000f, 0x0000000f0000000f, 0x0000000e0000000d, 0x0000000c0000000a,
0x0000000900000008, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000), vec.val));
}
////////// Matrix operations /////////
//////// Dot Product ////////
// 16 >> 32
inline v_int32x16 v_dotprod(const v_int16x32& a, const v_int16x32& b)
{ return v_int32x16(_mm512_madd_epi16(a.val, b.val)); }
inline v_int32x16 v_dotprod(const v_int16x32& a, const v_int16x32& b, const v_int32x16& c)
{ return v_dotprod(a, b) + c; }
// 32 >> 64
inline v_int64x8 v_dotprod(const v_int32x16& a, const v_int32x16& b)
{
__m512i even = _mm512_mul_epi32(a.val, b.val);
__m512i odd = _mm512_mul_epi32(_mm512_srli_epi64(a.val, 32), _mm512_srli_epi64(b.val, 32));
return v_int64x8(_mm512_add_epi64(even, odd));
}
inline v_int64x8 v_dotprod(const v_int32x16& a, const v_int32x16& b, const v_int64x8& c)
{ return v_dotprod(a, b) + c; }
// 8 >> 32
inline v_uint32x16 v_dotprod_expand(const v_uint8x64& a, const v_uint8x64& b)
{
__m512i even_a = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, a.val, _mm512_setzero_si512());
__m512i odd_a = _mm512_srli_epi16(a.val, 8);
__m512i even_b = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, b.val, _mm512_setzero_si512());
__m512i odd_b = _mm512_srli_epi16(b.val, 8);
__m512i prod0 = _mm512_madd_epi16(even_a, even_b);
__m512i prod1 = _mm512_madd_epi16(odd_a, odd_b);
return v_uint32x16(_mm512_add_epi32(prod0, prod1));
}
inline v_uint32x16 v_dotprod_expand(const v_uint8x64& a, const v_uint8x64& b, const v_uint32x16& c)
{ return v_dotprod_expand(a, b) + c; }
inline v_int32x16 v_dotprod_expand(const v_int8x64& a, const v_int8x64& b)
{
__m512i even_a = _mm512_srai_epi16(_mm512_bslli_epi128(a.val, 1), 8);
__m512i odd_a = _mm512_srai_epi16(a.val, 8);
__m512i even_b = _mm512_srai_epi16(_mm512_bslli_epi128(b.val, 1), 8);
__m512i odd_b = _mm512_srai_epi16(b.val, 8);
__m512i prod0 = _mm512_madd_epi16(even_a, even_b);
__m512i prod1 = _mm512_madd_epi16(odd_a, odd_b);
return v_int32x16(_mm512_add_epi32(prod0, prod1));
}
inline v_int32x16 v_dotprod_expand(const v_int8x64& a, const v_int8x64& b, const v_int32x16& c)
{ return v_dotprod_expand(a, b) + c; }
// 16 >> 64
inline v_uint64x8 v_dotprod_expand(const v_uint16x32& a, const v_uint16x32& b)
{
__m512i mullo = _mm512_mullo_epi16(a.val, b.val);
__m512i mulhi = _mm512_mulhi_epu16(a.val, b.val);
__m512i mul0 = _mm512_unpacklo_epi16(mullo, mulhi);
__m512i mul1 = _mm512_unpackhi_epi16(mullo, mulhi);
__m512i p02 = _mm512_mask_blend_epi32(0xAAAA, mul0, _mm512_setzero_si512());
__m512i p13 = _mm512_srli_epi64(mul0, 32);
__m512i p46 = _mm512_mask_blend_epi32(0xAAAA, mul1, _mm512_setzero_si512());
__m512i p57 = _mm512_srli_epi64(mul1, 32);
__m512i p15_ = _mm512_add_epi64(p02, p13);
__m512i p9d_ = _mm512_add_epi64(p46, p57);
return v_uint64x8(_mm512_add_epi64(
_mm512_unpacklo_epi64(p15_, p9d_),
_mm512_unpackhi_epi64(p15_, p9d_)
));
}
inline v_uint64x8 v_dotprod_expand(const v_uint16x32& a, const v_uint16x32& b, const v_uint64x8& c)
{ return v_dotprod_expand(a, b) + c; }
inline v_int64x8 v_dotprod_expand(const v_int16x32& a, const v_int16x32& b)
{
__m512i prod = _mm512_madd_epi16(a.val, b.val);
__m512i even = _mm512_srai_epi64(_mm512_bslli_epi128(prod, 4), 32);
__m512i odd = _mm512_srai_epi64(prod, 32);
return v_int64x8(_mm512_add_epi64(even, odd));
}
inline v_int64x8 v_dotprod_expand(const v_int16x32& a, const v_int16x32& b, const v_int64x8& c)
{ return v_dotprod_expand(a, b) + c; }
// 32 >> 64f
inline v_float64x8 v_dotprod_expand(const v_int32x16& a, const v_int32x16& b)
{ return v_cvt_f64(v_dotprod(a, b)); }
inline v_float64x8 v_dotprod_expand(const v_int32x16& a, const v_int32x16& b, const v_float64x8& c)
{ return v_dotprod_expand(a, b) + c; }
//////// Fast Dot Product ////////
// 16 >> 32
inline v_int32x16 v_dotprod_fast(const v_int16x32& a, const v_int16x32& b)
{ return v_dotprod(a, b); }
inline v_int32x16 v_dotprod_fast(const v_int16x32& a, const v_int16x32& b, const v_int32x16& c)
{ return v_dotprod(a, b, c); }
// 32 >> 64
inline v_int64x8 v_dotprod_fast(const v_int32x16& a, const v_int32x16& b)
{ return v_dotprod(a, b); }
inline v_int64x8 v_dotprod_fast(const v_int32x16& a, const v_int32x16& b, const v_int64x8& c)
{ return v_dotprod(a, b, c); }
// 8 >> 32
inline v_uint32x16 v_dotprod_expand_fast(const v_uint8x64& a, const v_uint8x64& b)
{ return v_dotprod_expand(a, b); }
inline v_uint32x16 v_dotprod_expand_fast(const v_uint8x64& a, const v_uint8x64& b, const v_uint32x16& c)
{ return v_dotprod_expand(a, b, c); }
inline v_int32x16 v_dotprod_expand_fast(const v_int8x64& a, const v_int8x64& b)
{ return v_dotprod_expand(a, b); }
inline v_int32x16 v_dotprod_expand_fast(const v_int8x64& a, const v_int8x64& b, const v_int32x16& c)
{ return v_dotprod_expand(a, b, c); }
// 16 >> 64
inline v_uint64x8 v_dotprod_expand_fast(const v_uint16x32& a, const v_uint16x32& b)
{
__m512i mullo = _mm512_mullo_epi16(a.val, b.val);
__m512i mulhi = _mm512_mulhi_epu16(a.val, b.val);
__m512i mul0 = _mm512_unpacklo_epi16(mullo, mulhi);
__m512i mul1 = _mm512_unpackhi_epi16(mullo, mulhi);
__m512i p02 = _mm512_mask_blend_epi32(0xAAAA, mul0, _mm512_setzero_si512());
__m512i p13 = _mm512_srli_epi64(mul0, 32);
__m512i p46 = _mm512_mask_blend_epi32(0xAAAA, mul1, _mm512_setzero_si512());
__m512i p57 = _mm512_srli_epi64(mul1, 32);
__m512i p15_ = _mm512_add_epi64(p02, p13);
__m512i p9d_ = _mm512_add_epi64(p46, p57);
return v_uint64x8(_mm512_add_epi64(p15_, p9d_));
}
inline v_uint64x8 v_dotprod_expand_fast(const v_uint16x32& a, const v_uint16x32& b, const v_uint64x8& c)
{ return v_dotprod_expand_fast(a, b) + c; }
inline v_int64x8 v_dotprod_expand_fast(const v_int16x32& a, const v_int16x32& b)
{ return v_dotprod_expand(a, b); }
inline v_int64x8 v_dotprod_expand_fast(const v_int16x32& a, const v_int16x32& b, const v_int64x8& c)
{ return v_dotprod_expand(a, b, c); }
// 32 >> 64f
inline v_float64x8 v_dotprod_expand_fast(const v_int32x16& a, const v_int32x16& b)
{ return v_dotprod_expand(a, b); }
inline v_float64x8 v_dotprod_expand_fast(const v_int32x16& a, const v_int32x16& b, const v_float64x8& c)
{ return v_dotprod_expand(a, b) + c; }
#define OPENCV_HAL_AVX512_SPLAT2_PS(a, im) \
v_float32x16(_mm512_permute_ps(a.val, _MM_SHUFFLE(im, im, im, im)))
inline v_float32x16 v_matmul(const v_float32x16& v,
const v_float32x16& m0, const v_float32x16& m1,
const v_float32x16& m2, const v_float32x16& m3)
{
v_float32x16 v04 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 0);
v_float32x16 v15 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 1);
v_float32x16 v26 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 2);
v_float32x16 v37 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 3);
return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, v37 * m3)));
}
inline v_float32x16 v_matmuladd(const v_float32x16& v,
const v_float32x16& m0, const v_float32x16& m1,
const v_float32x16& m2, const v_float32x16& a)
{
v_float32x16 v04 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 0);
v_float32x16 v15 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 1);
v_float32x16 v26 = OPENCV_HAL_AVX512_SPLAT2_PS(v, 2);
return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, a)));
}
#define OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \
inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \
const _Tpvec& a2, const _Tpvec& a3, \
_Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \
{ \
__m512i t0 = cast_from(_mm512_unpacklo_##suffix(a0.val, a1.val)); \
__m512i t1 = cast_from(_mm512_unpacklo_##suffix(a2.val, a3.val)); \
__m512i t2 = cast_from(_mm512_unpackhi_##suffix(a0.val, a1.val)); \
__m512i t3 = cast_from(_mm512_unpackhi_##suffix(a2.val, a3.val)); \
b0.val = cast_to(_mm512_unpacklo_epi64(t0, t1)); \
b1.val = cast_to(_mm512_unpackhi_epi64(t0, t1)); \
b2.val = cast_to(_mm512_unpacklo_epi64(t2, t3)); \
b3.val = cast_to(_mm512_unpackhi_epi64(t2, t3)); \
}
OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(v_uint32x16, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(v_int32x16, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
OPENCV_HAL_IMPL_AVX512_TRANSPOSE4x4(v_float32x16, ps, _mm512_castps_si512, _mm512_castsi512_ps)
//////////////// Value reordering ///////////////
/* Expand */
#define OPENCV_HAL_IMPL_AVX512_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \
inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \
{ \
b0.val = intrin(_v512_extract_low(a.val)); \
b1.val = intrin(_v512_extract_high(a.val)); \
} \
inline _Tpwvec v_expand_low(const _Tpvec& a) \
{ return _Tpwvec(intrin(_v512_extract_low(a.val))); } \
inline _Tpwvec v_expand_high(const _Tpvec& a) \
{ return _Tpwvec(intrin(_v512_extract_high(a.val))); } \
inline _Tpwvec v512_load_expand(const _Tp* ptr) \
{ \
__m256i a = _mm256_loadu_si256((const __m256i*)ptr); \
return _Tpwvec(intrin(a)); \
}
OPENCV_HAL_IMPL_AVX512_EXPAND(v_uint8x64, v_uint16x32, uchar, _mm512_cvtepu8_epi16)
OPENCV_HAL_IMPL_AVX512_EXPAND(v_int8x64, v_int16x32, schar, _mm512_cvtepi8_epi16)
OPENCV_HAL_IMPL_AVX512_EXPAND(v_uint16x32, v_uint32x16, ushort, _mm512_cvtepu16_epi32)
OPENCV_HAL_IMPL_AVX512_EXPAND(v_int16x32, v_int32x16, short, _mm512_cvtepi16_epi32)
OPENCV_HAL_IMPL_AVX512_EXPAND(v_uint32x16, v_uint64x8, unsigned, _mm512_cvtepu32_epi64)
OPENCV_HAL_IMPL_AVX512_EXPAND(v_int32x16, v_int64x8, int, _mm512_cvtepi32_epi64)
#define OPENCV_HAL_IMPL_AVX512_EXPAND_Q(_Tpvec, _Tp, intrin) \
inline _Tpvec v512_load_expand_q(const _Tp* ptr) \
{ \
__m128i a = _mm_loadu_si128((const __m128i*)ptr); \
return _Tpvec(intrin(a)); \
}
OPENCV_HAL_IMPL_AVX512_EXPAND_Q(v_uint32x16, uchar, _mm512_cvtepu8_epi32)
OPENCV_HAL_IMPL_AVX512_EXPAND_Q(v_int32x16, schar, _mm512_cvtepi8_epi32)
/* pack */
// 16
inline v_int8x64 v_pack(const v_int16x32& a, const v_int16x32& b)
{ return v_int8x64(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packs_epi16(a.val, b.val))); }
inline v_uint8x64 v_pack(const v_uint16x32& a, const v_uint16x32& b)
{
const __m512i t = _mm512_set1_epi16(255);
return v_uint8x64(_v512_combine(_mm512_cvtepi16_epi8(_mm512_min_epu16(a.val, t)), _mm512_cvtepi16_epi8(_mm512_min_epu16(b.val, t))));
}
inline v_uint8x64 v_pack_u(const v_int16x32& a, const v_int16x32& b)
{
return v_uint8x64(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packus_epi16(a.val, b.val)));
}
inline void v_pack_store(schar* ptr, const v_int16x32& a)
{ v_store_low(ptr, v_pack(a, a)); }
inline void v_pack_store(uchar* ptr, const v_uint16x32& a)
{
const __m512i m = _mm512_set1_epi16(255);
_mm256_storeu_si256((__m256i*)ptr, _mm512_cvtepi16_epi8(_mm512_min_epu16(a.val, m)));
}
inline void v_pack_u_store(uchar* ptr, const v_int16x32& a)
{ v_store_low(ptr, v_pack_u(a, a)); }
template<int n> inline
v_uint8x64 v_rshr_pack(const v_uint16x32& a, const v_uint16x32& b)
{
// we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers.
v_uint16x32 delta = v512_setall_u16((short)(1 << (n-1)));
return v_pack_u(v_reinterpret_as_s16((a + delta) >> n),
v_reinterpret_as_s16((b + delta) >> n));
}
template<int n> inline
void v_rshr_pack_store(uchar* ptr, const v_uint16x32& a)
{
v_uint16x32 delta = v512_setall_u16((short)(1 << (n-1)));
v_pack_u_store(ptr, v_reinterpret_as_s16((a + delta) >> n));
}
template<int n> inline
v_uint8x64 v_rshr_pack_u(const v_int16x32& a, const v_int16x32& b)
{
v_int16x32 delta = v512_setall_s16((short)(1 << (n-1)));
return v_pack_u((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_u_store(uchar* ptr, const v_int16x32& a)
{
v_int16x32 delta = v512_setall_s16((short)(1 << (n-1)));
v_pack_u_store(ptr, (a + delta) >> n);
}
template<int n> inline
v_int8x64 v_rshr_pack(const v_int16x32& a, const v_int16x32& b)
{
v_int16x32 delta = v512_setall_s16((short)(1 << (n-1)));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(schar* ptr, const v_int16x32& a)
{
v_int16x32 delta = v512_setall_s16((short)(1 << (n-1)));
v_pack_store(ptr, (a + delta) >> n);
}
// 32
inline v_int16x32 v_pack(const v_int32x16& a, const v_int32x16& b)
{ return v_int16x32(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packs_epi32(a.val, b.val))); }
inline v_uint16x32 v_pack(const v_uint32x16& a, const v_uint32x16& b)
{
const __m512i m = _mm512_set1_epi32(65535);
return v_uint16x32(_v512_combine(_mm512_cvtepi32_epi16(_mm512_min_epu32(a.val, m)), _mm512_cvtepi32_epi16(_mm512_min_epu32(b.val, m))));
}
inline v_uint16x32 v_pack_u(const v_int32x16& a, const v_int32x16& b)
{ return v_uint16x32(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packus_epi32(a.val, b.val))); }
inline void v_pack_store(short* ptr, const v_int32x16& a)
{ v_store_low(ptr, v_pack(a, a)); }
inline void v_pack_store(ushort* ptr, const v_uint32x16& a)
{
const __m512i m = _mm512_set1_epi32(65535);
_mm256_storeu_si256((__m256i*)ptr, _mm512_cvtepi32_epi16(_mm512_min_epu32(a.val, m)));
}
inline void v_pack_u_store(ushort* ptr, const v_int32x16& a)
{ v_store_low(ptr, v_pack_u(a, a)); }
template<int n> inline
v_uint16x32 v_rshr_pack(const v_uint32x16& a, const v_uint32x16& b)
{
v_uint32x16 delta = v512_setall_u32(1 << (n-1));
return v_pack_u(v_reinterpret_as_s32((a + delta) >> n),
v_reinterpret_as_s32((b + delta) >> n));
}
template<int n> inline
void v_rshr_pack_store(ushort* ptr, const v_uint32x16& a)
{
v_uint32x16 delta = v512_setall_u32(1 << (n-1));
v_pack_u_store(ptr, v_reinterpret_as_s32((a + delta) >> n));
}
template<int n> inline
v_uint16x32 v_rshr_pack_u(const v_int32x16& a, const v_int32x16& b)
{
v_int32x16 delta = v512_setall_s32(1 << (n-1));
return v_pack_u((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_u_store(ushort* ptr, const v_int32x16& a)
{
v_int32x16 delta = v512_setall_s32(1 << (n-1));
v_pack_u_store(ptr, (a + delta) >> n);
}
template<int n> inline
v_int16x32 v_rshr_pack(const v_int32x16& a, const v_int32x16& b)
{
v_int32x16 delta = v512_setall_s32(1 << (n-1));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(short* ptr, const v_int32x16& a)
{
v_int32x16 delta = v512_setall_s32(1 << (n-1));
v_pack_store(ptr, (a + delta) >> n);
}
// 64
// Non-saturating pack
inline v_uint32x16 v_pack(const v_uint64x8& a, const v_uint64x8& b)
{ return v_uint32x16(_v512_combine(_mm512_cvtepi64_epi32(a.val), _mm512_cvtepi64_epi32(b.val))); }
inline v_int32x16 v_pack(const v_int64x8& a, const v_int64x8& b)
{ return v_reinterpret_as_s32(v_pack(v_reinterpret_as_u64(a), v_reinterpret_as_u64(b))); }
inline void v_pack_store(unsigned* ptr, const v_uint64x8& a)
{ _mm256_storeu_si256((__m256i*)ptr, _mm512_cvtepi64_epi32(a.val)); }
inline void v_pack_store(int* ptr, const v_int64x8& b)
{ v_pack_store((unsigned*)ptr, v_reinterpret_as_u64(b)); }
template<int n> inline
v_uint32x16 v_rshr_pack(const v_uint64x8& a, const v_uint64x8& b)
{
v_uint64x8 delta = v512_setall_u64((uint64)1 << (n-1));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(unsigned* ptr, const v_uint64x8& a)
{
v_uint64x8 delta = v512_setall_u64((uint64)1 << (n-1));
v_pack_store(ptr, (a + delta) >> n);
}
template<int n> inline
v_int32x16 v_rshr_pack(const v_int64x8& a, const v_int64x8& b)
{
v_int64x8 delta = v512_setall_s64((int64)1 << (n-1));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(int* ptr, const v_int64x8& a)
{
v_int64x8 delta = v512_setall_s64((int64)1 << (n-1));
v_pack_store(ptr, (a + delta) >> n);
}
// pack boolean
inline v_uint8x64 v_pack_b(const v_uint16x32& a, const v_uint16x32& b)
{ return v_uint8x64(_mm512_permutexvar_epi64(_v512_set_epu64(7, 5, 3, 1, 6, 4, 2, 0), _mm512_packs_epi16(a.val, b.val))); }
inline v_uint8x64 v_pack_b(const v_uint32x16& a, const v_uint32x16& b,
const v_uint32x16& c, const v_uint32x16& d)
{
__m512i ab = _mm512_packs_epi32(a.val, b.val);
__m512i cd = _mm512_packs_epi32(c.val, d.val);
return v_uint8x64(_mm512_permutexvar_epi32(_v512_set_epu32(15, 11, 7, 3, 14, 10, 6, 2, 13, 9, 5, 1, 12, 8, 4, 0), _mm512_packs_epi16(ab, cd)));
}
inline v_uint8x64 v_pack_b(const v_uint64x8& a, const v_uint64x8& b, const v_uint64x8& c,
const v_uint64x8& d, const v_uint64x8& e, const v_uint64x8& f,
const v_uint64x8& g, const v_uint64x8& h)
{
__m512i ab = _mm512_packs_epi32(a.val, b.val);
__m512i cd = _mm512_packs_epi32(c.val, d.val);
__m512i ef = _mm512_packs_epi32(e.val, f.val);
__m512i gh = _mm512_packs_epi32(g.val, h.val);
__m512i abcd = _mm512_packs_epi32(ab, cd);
__m512i efgh = _mm512_packs_epi32(ef, gh);
return v_uint8x64(_mm512_permutexvar_epi16(_v512_set_epu16(31, 23, 15, 7, 30, 22, 14, 6, 29, 21, 13, 5, 28, 20, 12, 4,
27, 19, 11, 3, 26, 18, 10, 2, 25, 17, 9, 1, 24, 16, 8, 0), _mm512_packs_epi16(abcd, efgh)));
}
/* Recombine */
// its up there with load and store operations
/* Extract */
#define OPENCV_HAL_IMPL_AVX512_EXTRACT(_Tpvec) \
template<int s> \
inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \
{ return v_rotate_right<s>(a, b); }
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint8x64)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int8x64)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint16x32)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int16x32)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint32x16)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int32x16)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_uint64x8)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_int64x8)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_float32x16)
OPENCV_HAL_IMPL_AVX512_EXTRACT(v_float64x8)
#define OPENCV_HAL_IMPL_AVX512_EXTRACT_N(_Tpvec, _Tp) \
template<int i> inline _Tp v_extract_n(_Tpvec v) { return v_rotate_right<i>(v).get0(); }
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint8x64, uchar)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int8x64, schar)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint16x32, ushort)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int16x32, short)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint32x16, uint)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int32x16, int)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_uint64x8, uint64)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_int64x8, int64)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_float32x16, float)
OPENCV_HAL_IMPL_AVX512_EXTRACT_N(v_float64x8, double)
template<int i>
inline v_uint32x16 v_broadcast_element(v_uint32x16 a)
{
static const __m512i perm = _mm512_set1_epi32((char)i);
return v_uint32x16(_mm512_permutexvar_epi32(perm, a.val));
}
template<int i>
inline v_int32x16 v_broadcast_element(const v_int32x16 &a)
{ return v_reinterpret_as_s32(v_broadcast_element<i>(v_reinterpret_as_u32(a))); }
template<int i>
inline v_float32x16 v_broadcast_element(const v_float32x16 &a)
{ return v_reinterpret_as_f32(v_broadcast_element<i>(v_reinterpret_as_u32(a))); }
///////////////////// load deinterleave /////////////////////////////
inline void v_load_deinterleave( const uchar* ptr, v_uint8x64& a, v_uint8x64& b )
{
__m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 64));
#if CV_AVX_512VBMI
__m512i mask0 = _v512_set_epu8(126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96,
94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64,
62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32,
30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu8(127, 125, 123, 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99, 97,
95, 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65,
63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33,
31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
a = v_uint8x64(_mm512_permutex2var_epi8(ab0, mask0, ab1));
b = v_uint8x64(_mm512_permutex2var_epi8(ab0, mask1, ab1));
#else
__m512i mask0 = _mm512_set4_epi32(0x0f0d0b09, 0x07050301, 0x0e0c0a08, 0x06040200);
__m512i a0b0 = _mm512_shuffle_epi8(ab0, mask0);
__m512i a1b1 = _mm512_shuffle_epi8(ab1, mask0);
__m512i mask1 = _v512_set_epu64(14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask2 = _v512_set_epu64(15, 13, 11, 9, 7, 5, 3, 1);
a = v_uint8x64(_mm512_permutex2var_epi64(a0b0, mask1, a1b1));
b = v_uint8x64(_mm512_permutex2var_epi64(a0b0, mask2, a1b1));
#endif
}
inline void v_load_deinterleave( const ushort* ptr, v_uint16x32& a, v_uint16x32& b )
{
__m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 32));
__m512i mask0 = _v512_set_epu16(62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32,
30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu16(63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33,
31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
a = v_uint16x32(_mm512_permutex2var_epi16(ab0, mask0, ab1));
b = v_uint16x32(_mm512_permutex2var_epi16(ab0, mask1, ab1));
}
inline void v_load_deinterleave( const unsigned* ptr, v_uint32x16& a, v_uint32x16& b )
{
__m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 16));
__m512i mask0 = _v512_set_epu32(30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu32(31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
a = v_uint32x16(_mm512_permutex2var_epi32(ab0, mask0, ab1));
b = v_uint32x16(_mm512_permutex2var_epi32(ab0, mask1, ab1));
}
inline void v_load_deinterleave( const uint64* ptr, v_uint64x8& a, v_uint64x8& b )
{
__m512i ab0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i ab1 = _mm512_loadu_si512((const __m512i*)(ptr + 8));
__m512i mask0 = _v512_set_epu64(14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu64(15, 13, 11, 9, 7, 5, 3, 1);
a = v_uint64x8(_mm512_permutex2var_epi64(ab0, mask0, ab1));
b = v_uint64x8(_mm512_permutex2var_epi64(ab0, mask1, ab1));
}
inline void v_load_deinterleave( const uchar* ptr, v_uint8x64& a, v_uint8x64& b, v_uint8x64& c )
{
__m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 64));
__m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 128));
#if CV_AVX_512VBMI2
__m512i mask0 = _v512_set_epu8(126, 123, 120, 117, 114, 111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81,
78, 75, 72, 69, 66, 63, 60, 57, 54, 51, 48, 45, 42, 39, 36, 33,
30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0, 62, 59, 56, 53, 50,
47, 44, 41, 38, 35, 32, 29, 26, 23, 20, 17, 14, 11, 8, 5, 2);
__m512i r0b01 = _mm512_permutex2var_epi8(bgr0, mask0, bgr1);
__m512i b1g12 = _mm512_permutex2var_epi8(bgr1, mask0, bgr2);
__m512i r12b2 = _mm512_permutex2var_epi8(bgr1,
_v512_set_epu8(125, 122, 119, 116, 113, 110, 107, 104, 101, 98, 95, 92, 89, 86, 83, 80,
77, 74, 71, 68, 65, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97,
94, 91, 88, 85, 82, 79, 76, 73, 70, 67, 64, 61, 58, 55, 52, 49,
46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 13, 10, 7, 4, 1), bgr2);
a = v_uint8x64(_mm512_mask_compress_epi8(r12b2, 0xffffffffffe00000, r0b01));
b = v_uint8x64(_mm512_mask_compress_epi8(b1g12, 0x2492492492492492, bgr0));
c = v_uint8x64(_mm512_mask_expand_epi8(r0b01, 0xffffffffffe00000, r12b2));
#elif CV_AVX_512VBMI
__m512i b0g0b1 = _mm512_mask_blend_epi8(0xb6db6db6db6db6db, bgr1, bgr0);
__m512i g1r1g2 = _mm512_mask_blend_epi8(0xb6db6db6db6db6db, bgr2, bgr1);
__m512i r2b2r0 = _mm512_mask_blend_epi8(0xb6db6db6db6db6db, bgr0, bgr2);
a = v_uint8x64(_mm512_permutex2var_epi8(b0g0b1, _v512_set_epu8(125, 122, 119, 116, 113, 110, 107, 104, 101, 98, 95, 92, 89, 86, 83, 80,
77, 74, 71, 68, 65, 63, 61, 60, 58, 57, 55, 54, 52, 51, 49, 48,
46, 45, 43, 42, 40, 39, 37, 36, 34, 33, 31, 30, 28, 27, 25, 24,
23, 21, 20, 18, 17, 15, 14, 12, 11, 9, 8, 6, 5, 3, 2, 0), bgr2));
b = v_uint8x64(_mm512_permutex2var_epi8(g1r1g2, _v512_set_epu8( 63, 61, 60, 58, 57, 55, 54, 52, 51, 49, 48, 46, 45, 43, 42, 40,
39, 37, 36, 34, 33, 31, 30, 28, 27, 25, 24, 23, 21, 20, 18, 17,
15, 14, 12, 11, 9, 8, 6, 5, 3, 2, 0, 126, 123, 120, 117, 114,
111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81, 78, 75, 72, 69, 66), bgr0));
c = v_uint8x64(_mm512_permutex2var_epi8(r2b2r0, _v512_set_epu8( 63, 60, 57, 54, 51, 48, 45, 42, 39, 36, 33, 30, 27, 24, 21, 18,
15, 12, 9, 6, 3, 0, 125, 122, 119, 116, 113, 110, 107, 104, 101, 98,
95, 92, 89, 86, 83, 80, 77, 74, 71, 68, 65, 62, 59, 56, 53, 50,
47, 44, 41, 38, 35, 32, 29, 26, 23, 20, 17, 14, 11, 8, 5, 2), bgr1));
#else
__m512i mask0 = _v512_set_epu16(61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 63, 60, 57, 54, 51, 48,
45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0);
__m512i b01g1 = _mm512_permutex2var_epi16(bgr0, mask0, bgr1);
__m512i r12b2 = _mm512_permutex2var_epi16(bgr1, mask0, bgr2);
__m512i g20r0 = _mm512_permutex2var_epi16(bgr2, mask0, bgr0);
__m512i b0g0 = _mm512_mask_blend_epi32(0xf800, b01g1, r12b2);
__m512i r0b1 = _mm512_permutex2var_epi16(bgr1, _v512_set_epu16(42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 29, 26, 23, 20, 17,
14, 11, 8, 5, 2, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43), g20r0);
__m512i g1r1 = _mm512_alignr_epi32(r12b2, g20r0, 11);
a = v_uint8x64(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, b0g0, r0b1));
c = v_uint8x64(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, r0b1, g1r1));
b = v_uint8x64(_mm512_shuffle_epi8(_mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, g1r1, b0g0), _mm512_set4_epi32(0x0e0f0c0d, 0x0a0b0809, 0x06070405, 0x02030001)));
#endif
}
inline void v_load_deinterleave( const ushort* ptr, v_uint16x32& a, v_uint16x32& b, v_uint16x32& c )
{
__m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 32));
__m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 64));
__m512i mask0 = _v512_set_epu16(61, 58, 55, 52, 49, 46, 43, 40, 37, 34, 63, 60, 57, 54, 51, 48,
45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0);
__m512i b01g1 = _mm512_permutex2var_epi16(bgr0, mask0, bgr1);
__m512i r12b2 = _mm512_permutex2var_epi16(bgr1, mask0, bgr2);
__m512i g20r0 = _mm512_permutex2var_epi16(bgr2, mask0, bgr0);
a = v_uint16x32(_mm512_mask_blend_epi32(0xf800, b01g1, r12b2));
b = v_uint16x32(_mm512_permutex2var_epi16(bgr1, _v512_set_epu16(42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 29, 26, 23, 20, 17,
14, 11, 8, 5, 2, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43), g20r0));
c = v_uint16x32(_mm512_alignr_epi32(r12b2, g20r0, 11));
}
inline void v_load_deinterleave( const unsigned* ptr, v_uint32x16& a, v_uint32x16& b, v_uint32x16& c )
{
__m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 16));
__m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 32));
__m512i mask0 = _v512_set_epu32(29, 26, 23, 20, 17, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3, 0);
__m512i b01r1 = _mm512_permutex2var_epi32(bgr0, mask0, bgr1);
__m512i g12b2 = _mm512_permutex2var_epi32(bgr1, mask0, bgr2);
__m512i r20g0 = _mm512_permutex2var_epi32(bgr2, mask0, bgr0);
a = v_uint32x16(_mm512_mask_blend_epi32(0xf800, b01r1, g12b2));
b = v_uint32x16(_mm512_alignr_epi32(g12b2, r20g0, 11));
c = v_uint32x16(_mm512_permutex2var_epi32(bgr1, _v512_set_epu32(21, 20, 19, 18, 17, 16, 13, 10, 7, 4, 1, 26, 25, 24, 23, 22), r20g0));
}
inline void v_load_deinterleave( const uint64* ptr, v_uint64x8& a, v_uint64x8& b, v_uint64x8& c )
{
__m512i bgr0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgr1 = _mm512_loadu_si512((const __m512i*)(ptr + 8));
__m512i bgr2 = _mm512_loadu_si512((const __m512i*)(ptr + 16));
__m512i mask0 = _v512_set_epu64(13, 10, 15, 12, 9, 6, 3, 0);
__m512i b01g1 = _mm512_permutex2var_epi64(bgr0, mask0, bgr1);
__m512i r12b2 = _mm512_permutex2var_epi64(bgr1, mask0, bgr2);
__m512i g20r0 = _mm512_permutex2var_epi64(bgr2, mask0, bgr0);
a = v_uint64x8(_mm512_mask_blend_epi64(0xc0, b01g1, r12b2));
c = v_uint64x8(_mm512_alignr_epi64(r12b2, g20r0, 6));
b = v_uint64x8(_mm512_permutex2var_epi64(bgr1, _v512_set_epu64(10, 9, 8, 5, 2, 13, 12, 11), g20r0));
}
inline void v_load_deinterleave( const uchar* ptr, v_uint8x64& a, v_uint8x64& b, v_uint8x64& c, v_uint8x64& d )
{
__m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 64));
__m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 128));
__m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 192));
#if CV_AVX_512VBMI
__m512i mask0 = _v512_set_epu8(126, 124, 122, 120, 118, 116, 114, 112, 110, 108, 106, 104, 102, 100, 98, 96,
94, 92, 90, 88, 86, 84, 82, 80, 78, 76, 74, 72, 70, 68, 66, 64,
62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32,
30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu8(127, 125, 123, 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99, 97,
95, 93, 91, 89, 87, 85, 83, 81, 79, 77, 75, 73, 71, 69, 67, 65,
63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33,
31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
__m512i br01 = _mm512_permutex2var_epi8(bgra0, mask0, bgra1);
__m512i ga01 = _mm512_permutex2var_epi8(bgra0, mask1, bgra1);
__m512i br23 = _mm512_permutex2var_epi8(bgra2, mask0, bgra3);
__m512i ga23 = _mm512_permutex2var_epi8(bgra2, mask1, bgra3);
a = v_uint8x64(_mm512_permutex2var_epi8(br01, mask0, br23));
c = v_uint8x64(_mm512_permutex2var_epi8(br01, mask1, br23));
b = v_uint8x64(_mm512_permutex2var_epi8(ga01, mask0, ga23));
d = v_uint8x64(_mm512_permutex2var_epi8(ga01, mask1, ga23));
#else
__m512i mask = _mm512_set4_epi32(0x0f0b0703, 0x0e0a0602, 0x0d090501, 0x0c080400);
__m512i b0g0r0a0 = _mm512_shuffle_epi8(bgra0, mask);
__m512i b1g1r1a1 = _mm512_shuffle_epi8(bgra1, mask);
__m512i b2g2r2a2 = _mm512_shuffle_epi8(bgra2, mask);
__m512i b3g3r3a3 = _mm512_shuffle_epi8(bgra3, mask);
__m512i mask0 = _v512_set_epu32(30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu32(31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
__m512i br01 = _mm512_permutex2var_epi32(b0g0r0a0, mask0, b1g1r1a1);
__m512i ga01 = _mm512_permutex2var_epi32(b0g0r0a0, mask1, b1g1r1a1);
__m512i br23 = _mm512_permutex2var_epi32(b2g2r2a2, mask0, b3g3r3a3);
__m512i ga23 = _mm512_permutex2var_epi32(b2g2r2a2, mask1, b3g3r3a3);
a = v_uint8x64(_mm512_permutex2var_epi32(br01, mask0, br23));
c = v_uint8x64(_mm512_permutex2var_epi32(br01, mask1, br23));
b = v_uint8x64(_mm512_permutex2var_epi32(ga01, mask0, ga23));
d = v_uint8x64(_mm512_permutex2var_epi32(ga01, mask1, ga23));
#endif
}
inline void v_load_deinterleave( const ushort* ptr, v_uint16x32& a, v_uint16x32& b, v_uint16x32& c, v_uint16x32& d )
{
__m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 32));
__m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 64));
__m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 96));
__m512i mask0 = _v512_set_epu16(62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32,
30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu16(63, 61, 59, 57, 55, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 33,
31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
__m512i br01 = _mm512_permutex2var_epi16(bgra0, mask0, bgra1);
__m512i ga01 = _mm512_permutex2var_epi16(bgra0, mask1, bgra1);
__m512i br23 = _mm512_permutex2var_epi16(bgra2, mask0, bgra3);
__m512i ga23 = _mm512_permutex2var_epi16(bgra2, mask1, bgra3);
a = v_uint16x32(_mm512_permutex2var_epi16(br01, mask0, br23));
c = v_uint16x32(_mm512_permutex2var_epi16(br01, mask1, br23));
b = v_uint16x32(_mm512_permutex2var_epi16(ga01, mask0, ga23));
d = v_uint16x32(_mm512_permutex2var_epi16(ga01, mask1, ga23));
}
inline void v_load_deinterleave( const unsigned* ptr, v_uint32x16& a, v_uint32x16& b, v_uint32x16& c, v_uint32x16& d )
{
__m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 16));
__m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 32));
__m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 48));
__m512i mask0 = _v512_set_epu32(30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu32(31, 29, 27, 25, 23, 21, 19, 17, 15, 13, 11, 9, 7, 5, 3, 1);
__m512i br01 = _mm512_permutex2var_epi32(bgra0, mask0, bgra1);
__m512i ga01 = _mm512_permutex2var_epi32(bgra0, mask1, bgra1);
__m512i br23 = _mm512_permutex2var_epi32(bgra2, mask0, bgra3);
__m512i ga23 = _mm512_permutex2var_epi32(bgra2, mask1, bgra3);
a = v_uint32x16(_mm512_permutex2var_epi32(br01, mask0, br23));
c = v_uint32x16(_mm512_permutex2var_epi32(br01, mask1, br23));
b = v_uint32x16(_mm512_permutex2var_epi32(ga01, mask0, ga23));
d = v_uint32x16(_mm512_permutex2var_epi32(ga01, mask1, ga23));
}
inline void v_load_deinterleave( const uint64* ptr, v_uint64x8& a, v_uint64x8& b, v_uint64x8& c, v_uint64x8& d )
{
__m512i bgra0 = _mm512_loadu_si512((const __m512i*)ptr);
__m512i bgra1 = _mm512_loadu_si512((const __m512i*)(ptr + 8));
__m512i bgra2 = _mm512_loadu_si512((const __m512i*)(ptr + 16));
__m512i bgra3 = _mm512_loadu_si512((const __m512i*)(ptr + 24));
__m512i mask0 = _v512_set_epu64(14, 12, 10, 8, 6, 4, 2, 0);
__m512i mask1 = _v512_set_epu64(15, 13, 11, 9, 7, 5, 3, 1);
__m512i br01 = _mm512_permutex2var_epi64(bgra0, mask0, bgra1);
__m512i ga01 = _mm512_permutex2var_epi64(bgra0, mask1, bgra1);
__m512i br23 = _mm512_permutex2var_epi64(bgra2, mask0, bgra3);
__m512i ga23 = _mm512_permutex2var_epi64(bgra2, mask1, bgra3);
a = v_uint64x8(_mm512_permutex2var_epi64(br01, mask0, br23));
c = v_uint64x8(_mm512_permutex2var_epi64(br01, mask1, br23));
b = v_uint64x8(_mm512_permutex2var_epi64(ga01, mask0, ga23));
d = v_uint64x8(_mm512_permutex2var_epi64(ga01, mask1, ga23));
}
///////////////////////////// store interleave /////////////////////////////////////
inline void v_store_interleave( uchar* ptr, const v_uint8x64& x, const v_uint8x64& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint8x64 low, high;
v_zip(x, y, low, high);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, low.val);
_mm512_stream_si512((__m512i*)(ptr + 64), high.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, low.val);
_mm512_store_si512((__m512i*)(ptr + 64), high.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, low.val);
_mm512_storeu_si512((__m512i*)(ptr + 64), high.val);
}
}
inline void v_store_interleave( ushort* ptr, const v_uint16x32& x, const v_uint16x32& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint16x32 low, high;
v_zip(x, y, low, high);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, low.val);
_mm512_stream_si512((__m512i*)(ptr + 32), high.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, low.val);
_mm512_store_si512((__m512i*)(ptr + 32), high.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, low.val);
_mm512_storeu_si512((__m512i*)(ptr + 32), high.val);
}
}
inline void v_store_interleave( unsigned* ptr, const v_uint32x16& x, const v_uint32x16& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint32x16 low, high;
v_zip(x, y, low, high);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, low.val);
_mm512_stream_si512((__m512i*)(ptr + 16), high.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, low.val);
_mm512_store_si512((__m512i*)(ptr + 16), high.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, low.val);
_mm512_storeu_si512((__m512i*)(ptr + 16), high.val);
}
}
inline void v_store_interleave( uint64* ptr, const v_uint64x8& x, const v_uint64x8& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint64x8 low, high;
v_zip(x, y, low, high);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, low.val);
_mm512_stream_si512((__m512i*)(ptr + 8), high.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, low.val);
_mm512_store_si512((__m512i*)(ptr + 8), high.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, low.val);
_mm512_storeu_si512((__m512i*)(ptr + 8), high.val);
}
}
inline void v_store_interleave( uchar* ptr, const v_uint8x64& a, const v_uint8x64& b, const v_uint8x64& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
#if CV_AVX_512VBMI
__m512i mask0 = _v512_set_epu8(127, 84, 20, 126, 83, 19, 125, 82, 18, 124, 81, 17, 123, 80, 16, 122,
79, 15, 121, 78, 14, 120, 77, 13, 119, 76, 12, 118, 75, 11, 117, 74,
10, 116, 73, 9, 115, 72, 8, 114, 71, 7, 113, 70, 6, 112, 69, 5,
111, 68, 4, 110, 67, 3, 109, 66, 2, 108, 65, 1, 107, 64, 0, 106);
__m512i mask1 = _v512_set_epu8( 21, 42, 105, 20, 41, 104, 19, 40, 103, 18, 39, 102, 17, 38, 101, 16,
37, 100, 15, 36, 99, 14, 35, 98, 13, 34, 97, 12, 33, 96, 11, 32,
95, 10, 31, 94, 9, 30, 93, 8, 29, 92, 7, 28, 91, 6, 27, 90,
5, 26, 89, 4, 25, 88, 3, 24, 87, 2, 23, 86, 1, 22, 85, 0);
__m512i mask2 = _v512_set_epu8(106, 127, 63, 105, 126, 62, 104, 125, 61, 103, 124, 60, 102, 123, 59, 101,
122, 58, 100, 121, 57, 99, 120, 56, 98, 119, 55, 97, 118, 54, 96, 117,
53, 95, 116, 52, 94, 115, 51, 93, 114, 50, 92, 113, 49, 91, 112, 48,
90, 111, 47, 89, 110, 46, 88, 109, 45, 87, 108, 44, 86, 107, 43, 85);
__m512i r2g0r0 = _mm512_permutex2var_epi8(b.val, mask0, c.val);
__m512i b0r1b1 = _mm512_permutex2var_epi8(a.val, mask1, c.val);
__m512i g1b2g2 = _mm512_permutex2var_epi8(a.val, mask2, b.val);
__m512i bgr0 = _mm512_mask_blend_epi8(0x9249249249249249, r2g0r0, b0r1b1);
__m512i bgr1 = _mm512_mask_blend_epi8(0x9249249249249249, b0r1b1, g1b2g2);
__m512i bgr2 = _mm512_mask_blend_epi8(0x9249249249249249, g1b2g2, r2g0r0);
#else
__m512i g1g0 = _mm512_shuffle_epi8(b.val, _mm512_set4_epi32(0x0e0f0c0d, 0x0a0b0809, 0x06070405, 0x02030001));
__m512i b0g0 = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, a.val, g1g0);
__m512i r0b1 = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, c.val, a.val);
__m512i g1r1 = _mm512_mask_blend_epi8(0xAAAAAAAAAAAAAAAA, g1g0, c.val);
__m512i mask0 = _v512_set_epu16(42, 10, 31, 41, 9, 30, 40, 8, 29, 39, 7, 28, 38, 6, 27, 37,
5, 26, 36, 4, 25, 35, 3, 24, 34, 2, 23, 33, 1, 22, 32, 0);
__m512i mask1 = _v512_set_epu16(21, 52, 41, 20, 51, 40, 19, 50, 39, 18, 49, 38, 17, 48, 37, 16,
47, 36, 15, 46, 35, 14, 45, 34, 13, 44, 33, 12, 43, 32, 11, 42);
__m512i mask2 = _v512_set_epu16(63, 31, 20, 62, 30, 19, 61, 29, 18, 60, 28, 17, 59, 27, 16, 58,
26, 15, 57, 25, 14, 56, 24, 13, 55, 23, 12, 54, 22, 11, 53, 21);
__m512i b0g0b2 = _mm512_permutex2var_epi16(b0g0, mask0, r0b1);
__m512i r1b1r0 = _mm512_permutex2var_epi16(b0g0, mask1, g1r1);
__m512i g2r2g1 = _mm512_permutex2var_epi16(r0b1, mask2, g1r1);
__m512i bgr0 = _mm512_mask_blend_epi16(0x24924924, b0g0b2, r1b1r0);
__m512i bgr1 = _mm512_mask_blend_epi16(0x24924924, r1b1r0, g2r2g1);
__m512i bgr2 = _mm512_mask_blend_epi16(0x24924924, g2r2g1, b0g0b2);
#endif
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgr0);
_mm512_stream_si512((__m512i*)(ptr + 64), bgr1);
_mm512_stream_si512((__m512i*)(ptr + 128), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgr0);
_mm512_store_si512((__m512i*)(ptr + 64), bgr1);
_mm512_store_si512((__m512i*)(ptr + 128), bgr2);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgr0);
_mm512_storeu_si512((__m512i*)(ptr + 64), bgr1);
_mm512_storeu_si512((__m512i*)(ptr + 128), bgr2);
}
}
inline void v_store_interleave( ushort* ptr, const v_uint16x32& a, const v_uint16x32& b, const v_uint16x32& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m512i mask0 = _v512_set_epu16(42, 10, 31, 41, 9, 30, 40, 8, 29, 39, 7, 28, 38, 6, 27, 37,
5, 26, 36, 4, 25, 35, 3, 24, 34, 2, 23, 33, 1, 22, 32, 0);
__m512i mask1 = _v512_set_epu16(21, 52, 41, 20, 51, 40, 19, 50, 39, 18, 49, 38, 17, 48, 37, 16,
47, 36, 15, 46, 35, 14, 45, 34, 13, 44, 33, 12, 43, 32, 11, 42);
__m512i mask2 = _v512_set_epu16(63, 31, 20, 62, 30, 19, 61, 29, 18, 60, 28, 17, 59, 27, 16, 58,
26, 15, 57, 25, 14, 56, 24, 13, 55, 23, 12, 54, 22, 11, 53, 21);
__m512i b0g0b2 = _mm512_permutex2var_epi16(a.val, mask0, b.val);
__m512i r1b1r0 = _mm512_permutex2var_epi16(a.val, mask1, c.val);
__m512i g2r2g1 = _mm512_permutex2var_epi16(b.val, mask2, c.val);
__m512i bgr0 = _mm512_mask_blend_epi16(0x24924924, b0g0b2, r1b1r0);
__m512i bgr1 = _mm512_mask_blend_epi16(0x24924924, r1b1r0, g2r2g1);
__m512i bgr2 = _mm512_mask_blend_epi16(0x24924924, g2r2g1, b0g0b2);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgr0);
_mm512_stream_si512((__m512i*)(ptr + 32), bgr1);
_mm512_stream_si512((__m512i*)(ptr + 64), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgr0);
_mm512_store_si512((__m512i*)(ptr + 32), bgr1);
_mm512_store_si512((__m512i*)(ptr + 64), bgr2);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgr0);
_mm512_storeu_si512((__m512i*)(ptr + 32), bgr1);
_mm512_storeu_si512((__m512i*)(ptr + 64), bgr2);
}
}
inline void v_store_interleave( unsigned* ptr, const v_uint32x16& a, const v_uint32x16& b, const v_uint32x16& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m512i mask0 = _v512_set_epu32(26, 31, 15, 25, 30, 14, 24, 29, 13, 23, 28, 12, 22, 27, 11, 21);
__m512i mask1 = _v512_set_epu32(31, 10, 25, 30, 9, 24, 29, 8, 23, 28, 7, 22, 27, 6, 21, 26);
__m512i g1b2g2 = _mm512_permutex2var_epi32(a.val, mask0, b.val);
__m512i r2r1b1 = _mm512_permutex2var_epi32(a.val, mask1, c.val);
__m512i bgr0 = _mm512_mask_expand_epi32(_mm512_mask_expand_epi32(_mm512_maskz_expand_epi32(0x9249, a.val), 0x2492, b.val), 0x4924, c.val);
__m512i bgr1 = _mm512_mask_blend_epi32(0x9249, r2r1b1, g1b2g2);
__m512i bgr2 = _mm512_mask_blend_epi32(0x9249, g1b2g2, r2r1b1);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgr0);
_mm512_stream_si512((__m512i*)(ptr + 16), bgr1);
_mm512_stream_si512((__m512i*)(ptr + 32), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgr0);
_mm512_store_si512((__m512i*)(ptr + 16), bgr1);
_mm512_store_si512((__m512i*)(ptr + 32), bgr2);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgr0);
_mm512_storeu_si512((__m512i*)(ptr + 16), bgr1);
_mm512_storeu_si512((__m512i*)(ptr + 32), bgr2);
}
}
inline void v_store_interleave( uint64* ptr, const v_uint64x8& a, const v_uint64x8& b, const v_uint64x8& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m512i mask0 = _v512_set_epu64( 5, 12, 7, 4, 11, 6, 3, 10);
__m512i mask1 = _v512_set_epu64(15, 7, 4, 14, 6, 3, 13, 5);
__m512i r1b1b2 = _mm512_permutex2var_epi64(a.val, mask0, c.val);
__m512i g2r2g1 = _mm512_permutex2var_epi64(b.val, mask1, c.val);
__m512i bgr0 = _mm512_mask_expand_epi64(_mm512_mask_expand_epi64(_mm512_maskz_expand_epi64(0x49, a.val), 0x92, b.val), 0x24, c.val);
__m512i bgr1 = _mm512_mask_blend_epi64(0xdb, g2r2g1, r1b1b2);
__m512i bgr2 = _mm512_mask_blend_epi64(0xdb, r1b1b2, g2r2g1);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgr0);
_mm512_stream_si512((__m512i*)(ptr + 8), bgr1);
_mm512_stream_si512((__m512i*)(ptr + 16), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgr0);
_mm512_store_si512((__m512i*)(ptr + 8), bgr1);
_mm512_store_si512((__m512i*)(ptr + 16), bgr2);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgr0);
_mm512_storeu_si512((__m512i*)(ptr + 8), bgr1);
_mm512_storeu_si512((__m512i*)(ptr + 16), bgr2);
}
}
inline void v_store_interleave( uchar* ptr, const v_uint8x64& a, const v_uint8x64& b,
const v_uint8x64& c, const v_uint8x64& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint8x64 br01, br23, ga01, ga23;
v_zip(a, c, br01, br23);
v_zip(b, d, ga01, ga23);
v_uint8x64 bgra0, bgra1, bgra2, bgra3;
v_zip(br01, ga01, bgra0, bgra1);
v_zip(br23, ga23, bgra2, bgra3);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgra0.val);
_mm512_stream_si512((__m512i*)(ptr + 64), bgra1.val);
_mm512_stream_si512((__m512i*)(ptr + 128), bgra2.val);
_mm512_stream_si512((__m512i*)(ptr + 192), bgra3.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgra0.val);
_mm512_store_si512((__m512i*)(ptr + 64), bgra1.val);
_mm512_store_si512((__m512i*)(ptr + 128), bgra2.val);
_mm512_store_si512((__m512i*)(ptr + 192), bgra3.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgra0.val);
_mm512_storeu_si512((__m512i*)(ptr + 64), bgra1.val);
_mm512_storeu_si512((__m512i*)(ptr + 128), bgra2.val);
_mm512_storeu_si512((__m512i*)(ptr + 192), bgra3.val);
}
}
inline void v_store_interleave( ushort* ptr, const v_uint16x32& a, const v_uint16x32& b,
const v_uint16x32& c, const v_uint16x32& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint16x32 br01, br23, ga01, ga23;
v_zip(a, c, br01, br23);
v_zip(b, d, ga01, ga23);
v_uint16x32 bgra0, bgra1, bgra2, bgra3;
v_zip(br01, ga01, bgra0, bgra1);
v_zip(br23, ga23, bgra2, bgra3);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgra0.val);
_mm512_stream_si512((__m512i*)(ptr + 32), bgra1.val);
_mm512_stream_si512((__m512i*)(ptr + 64), bgra2.val);
_mm512_stream_si512((__m512i*)(ptr + 96), bgra3.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgra0.val);
_mm512_store_si512((__m512i*)(ptr + 32), bgra1.val);
_mm512_store_si512((__m512i*)(ptr + 64), bgra2.val);
_mm512_store_si512((__m512i*)(ptr + 96), bgra3.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgra0.val);
_mm512_storeu_si512((__m512i*)(ptr + 32), bgra1.val);
_mm512_storeu_si512((__m512i*)(ptr + 64), bgra2.val);
_mm512_storeu_si512((__m512i*)(ptr + 96), bgra3.val);
}
}
inline void v_store_interleave( unsigned* ptr, const v_uint32x16& a, const v_uint32x16& b,
const v_uint32x16& c, const v_uint32x16& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint32x16 br01, br23, ga01, ga23;
v_zip(a, c, br01, br23);
v_zip(b, d, ga01, ga23);
v_uint32x16 bgra0, bgra1, bgra2, bgra3;
v_zip(br01, ga01, bgra0, bgra1);
v_zip(br23, ga23, bgra2, bgra3);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgra0.val);
_mm512_stream_si512((__m512i*)(ptr + 16), bgra1.val);
_mm512_stream_si512((__m512i*)(ptr + 32), bgra2.val);
_mm512_stream_si512((__m512i*)(ptr + 48), bgra3.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgra0.val);
_mm512_store_si512((__m512i*)(ptr + 16), bgra1.val);
_mm512_store_si512((__m512i*)(ptr + 32), bgra2.val);
_mm512_store_si512((__m512i*)(ptr + 48), bgra3.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgra0.val);
_mm512_storeu_si512((__m512i*)(ptr + 16), bgra1.val);
_mm512_storeu_si512((__m512i*)(ptr + 32), bgra2.val);
_mm512_storeu_si512((__m512i*)(ptr + 48), bgra3.val);
}
}
inline void v_store_interleave( uint64* ptr, const v_uint64x8& a, const v_uint64x8& b,
const v_uint64x8& c, const v_uint64x8& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
v_uint64x8 br01, br23, ga01, ga23;
v_zip(a, c, br01, br23);
v_zip(b, d, ga01, ga23);
v_uint64x8 bgra0, bgra1, bgra2, bgra3;
v_zip(br01, ga01, bgra0, bgra1);
v_zip(br23, ga23, bgra2, bgra3);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm512_stream_si512((__m512i*)ptr, bgra0.val);
_mm512_stream_si512((__m512i*)(ptr + 8), bgra1.val);
_mm512_stream_si512((__m512i*)(ptr + 16), bgra2.val);
_mm512_stream_si512((__m512i*)(ptr + 24), bgra3.val);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm512_store_si512((__m512i*)ptr, bgra0.val);
_mm512_store_si512((__m512i*)(ptr + 8), bgra1.val);
_mm512_store_si512((__m512i*)(ptr + 16), bgra2.val);
_mm512_store_si512((__m512i*)(ptr + 24), bgra3.val);
}
else
{
_mm512_storeu_si512((__m512i*)ptr, bgra0.val);
_mm512_storeu_si512((__m512i*)(ptr + 8), bgra1.val);
_mm512_storeu_si512((__m512i*)(ptr + 16), bgra2.val);
_mm512_storeu_si512((__m512i*)(ptr + 24), bgra3.val);
}
}
#define OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \
inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \
{ \
_Tpvec1 a1, b1; \
v_load_deinterleave((const _Tp1*)ptr, a1, b1); \
a0 = v_reinterpret_as_##suffix0(a1); \
b0 = v_reinterpret_as_##suffix0(b1); \
} \
inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \
{ \
_Tpvec1 a1, b1, c1; \
v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \
a0 = v_reinterpret_as_##suffix0(a1); \
b0 = v_reinterpret_as_##suffix0(b1); \
c0 = v_reinterpret_as_##suffix0(c1); \
} \
inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \
{ \
_Tpvec1 a1, b1, c1, d1; \
v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \
a0 = v_reinterpret_as_##suffix0(a1); \
b0 = v_reinterpret_as_##suffix0(b1); \
c0 = v_reinterpret_as_##suffix0(c1); \
d0 = v_reinterpret_as_##suffix0(d1); \
} \
inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \
hal::StoreMode mode=hal::STORE_UNALIGNED ) \
{ \
_Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
_Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
v_store_interleave((_Tp1*)ptr, a1, b1, mode); \
} \
inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, const _Tpvec0& c0, \
hal::StoreMode mode=hal::STORE_UNALIGNED ) \
{ \
_Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
_Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
_Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \
v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \
} \
inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \
const _Tpvec0& c0, const _Tpvec0& d0, \
hal::StoreMode mode=hal::STORE_UNALIGNED ) \
{ \
_Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
_Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
_Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \
_Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \
v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \
}
OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int8x64, schar, s8, v_uint8x64, uchar, u8)
OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int16x32, short, s16, v_uint16x32, ushort, u16)
OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int32x16, int, s32, v_uint32x16, unsigned, u32)
OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_float32x16, float, f32, v_uint32x16, unsigned, u32)
OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_int64x8, int64, s64, v_uint64x8, uint64, u64)
OPENCV_HAL_IMPL_AVX512_LOADSTORE_INTERLEAVE(v_float64x8, double, f64, v_uint64x8, uint64, u64)
////////// Mask and checks /////////
/** Mask **/
inline int64 v_signmask(const v_int8x64& a) { return (int64)_mm512_movepi8_mask(a.val); }
inline int v_signmask(const v_int16x32& a) { return (int)_mm512_cmp_epi16_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); }
inline int v_signmask(const v_int32x16& a) { return (int)_mm512_cmp_epi32_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); }
inline int v_signmask(const v_int64x8& a) { return (int)_mm512_cmp_epi64_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); }
inline int64 v_signmask(const v_uint8x64& a) { return v_signmask(v_reinterpret_as_s8(a)); }
inline int v_signmask(const v_uint16x32& a) { return v_signmask(v_reinterpret_as_s16(a)); }
inline int v_signmask(const v_uint32x16& a) { return v_signmask(v_reinterpret_as_s32(a)); }
inline int v_signmask(const v_uint64x8& a) { return v_signmask(v_reinterpret_as_s64(a)); }
inline int v_signmask(const v_float32x16& a) { return v_signmask(v_reinterpret_as_s32(a)); }
inline int v_signmask(const v_float64x8& a) { return v_signmask(v_reinterpret_as_s64(a)); }
/** Checks **/
inline bool v_check_all(const v_int8x64& a) { return !(bool)_mm512_cmp_epi8_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); }
inline bool v_check_any(const v_int8x64& a) { return (bool)_mm512_movepi8_mask(a.val); }
inline bool v_check_all(const v_int16x32& a) { return !(bool)_mm512_cmp_epi16_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); }
inline bool v_check_any(const v_int16x32& a) { return (bool)_mm512_cmp_epi16_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); }
inline bool v_check_all(const v_int32x16& a) { return !(bool)_mm512_cmp_epi32_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); }
inline bool v_check_any(const v_int32x16& a) { return (bool)_mm512_cmp_epi32_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); }
inline bool v_check_all(const v_int64x8& a) { return !(bool)_mm512_cmp_epi64_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_NLT); }
inline bool v_check_any(const v_int64x8& a) { return (bool)_mm512_cmp_epi64_mask(a.val, _mm512_setzero_si512(), _MM_CMPINT_LT); }
inline bool v_check_all(const v_float32x16& a) { return v_check_all(v_reinterpret_as_s32(a)); }
inline bool v_check_any(const v_float32x16& a) { return v_check_any(v_reinterpret_as_s32(a)); }
inline bool v_check_all(const v_float64x8& a) { return v_check_all(v_reinterpret_as_s64(a)); }
inline bool v_check_any(const v_float64x8& a) { return v_check_any(v_reinterpret_as_s64(a)); }
inline bool v_check_all(const v_uint8x64& a) { return v_check_all(v_reinterpret_as_s8(a)); }
inline bool v_check_all(const v_uint16x32& a) { return v_check_all(v_reinterpret_as_s16(a)); }
inline bool v_check_all(const v_uint32x16& a) { return v_check_all(v_reinterpret_as_s32(a)); }
inline bool v_check_all(const v_uint64x8& a) { return v_check_all(v_reinterpret_as_s64(a)); }
inline bool v_check_any(const v_uint8x64& a) { return v_check_any(v_reinterpret_as_s8(a)); }
inline bool v_check_any(const v_uint16x32& a) { return v_check_any(v_reinterpret_as_s16(a)); }
inline bool v_check_any(const v_uint32x16& a) { return v_check_any(v_reinterpret_as_s32(a)); }
inline bool v_check_any(const v_uint64x8& a) { return v_check_any(v_reinterpret_as_s64(a)); }
inline int v_scan_forward(const v_int8x64& a)
{
int64 mask = _mm512_movepi8_mask(a.val);
int mask32 = (int)mask;
return mask != 0 ? mask32 != 0 ? trailingZeros32(mask32) : 32 + trailingZeros32((int)(mask >> 32)) : 0;
}
inline int v_scan_forward(const v_uint8x64& a) { return v_scan_forward(v_reinterpret_as_s8(a)); }
inline int v_scan_forward(const v_int16x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))); }
inline int v_scan_forward(const v_uint16x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))); }
inline int v_scan_forward(const v_int32x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 2; }
inline int v_scan_forward(const v_uint32x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 2; }
inline int v_scan_forward(const v_float32x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 2; }
inline int v_scan_forward(const v_int64x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 4; }
inline int v_scan_forward(const v_uint64x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 4; }
inline int v_scan_forward(const v_float64x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s16(a))) / 4; }
inline void v512_cleanup() { _mm256_zeroall(); }
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
//! @endcond
} // cv::
#endif // OPENCV_HAL_INTRIN_AVX_HPP
| 159,868 | intrin_avx512 | hpp | en | cpp | code | {"qsc_code_num_words": 22944, "qsc_code_num_chars": 159868.0, "qsc_code_mean_word_length": 4.0401848, "qsc_code_frac_words_unique": 0.04907601, "qsc_code_frac_chars_top_2grams": 0.02763814, "qsc_code_frac_chars_top_3grams": 0.03744417, "qsc_code_frac_chars_top_4grams": 0.0547261, "qsc_code_frac_chars_dupe_5grams": 0.78059937, "qsc_code_frac_chars_dupe_6grams": 0.72310082, "qsc_code_frac_chars_dupe_7grams": 0.65650823, "qsc_code_frac_chars_dupe_8grams": 0.5713284, "qsc_code_frac_chars_dupe_9grams": 0.52429394, "qsc_code_frac_chars_dupe_10grams": 0.46298734, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.19395729, "qsc_code_frac_chars_whitespace": 0.23957265, "qsc_code_size_file_byte": 159868.0, "qsc_code_num_lines": 3049.0, "qsc_code_num_chars_line_max": 189.0, "qsc_code_num_chars_line_mean": 52.43292883, "qsc_code_frac_chars_alphabet": 0.56856245, "qsc_code_frac_chars_comments": 0.01800861, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.2651341, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.02262579, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codecpp_frac_lines_preprocessor_directives": null, "qsc_codecpp_frac_lines_func_ratio": 0.29042146, "qsc_codecpp_cate_bitsstdc": 0.0, "qsc_codecpp_nums_lines_main": 0.0, "qsc_codecpp_frac_lines_goto": 0.0, "qsc_codecpp_cate_var_zero": 0.0, "qsc_codecpp_score_lines_no_logic": 0.2908046, "qsc_codecpp_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 1, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codecpp_frac_lines_func_ratio": 1, "qsc_codecpp_nums_lines_main": 0, "qsc_codecpp_score_lines_no_logic": 0, "qsc_codecpp_frac_lines_preprocessor_directives": 0, "qsc_codecpp_frac_lines_print": 0} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/hal/intrin_cpp.hpp | /*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Copyright (C) 2015, Itseez Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_HAL_INTRIN_CPP_HPP
#define OPENCV_HAL_INTRIN_CPP_HPP
#include <limits>
#include <cstring>
#include <algorithm>
#include "opencv2/core/saturate.hpp"
//! @cond IGNORED
#define CV_SIMD128_CPP 1
#if defined(CV_FORCE_SIMD128_CPP) || defined(CV_DOXYGEN)
#define CV_SIMD128 1
#define CV_SIMD128_64F 1
#endif
//! @endcond
namespace cv
{
#ifndef CV_DOXYGEN
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
#endif
/** @addtogroup core_hal_intrin
"Universal intrinsics" is a types and functions set intended to simplify vectorization of code on
different platforms. Currently there are two supported SIMD extensions: __SSE/SSE2__ on x86
architectures and __NEON__ on ARM architectures, both allow working with 128 bit registers
containing packed values of different types. In case when there is no SIMD extension available
during compilation, fallback C++ implementation of intrinsics will be chosen and code will work as
expected although it could be slower.
### Types
There are several types representing 128-bit register as a vector of packed values, each type is
implemented as a structure based on a one SIMD register.
- cv::v_uint8x16 and cv::v_int8x16: sixteen 8-bit integer values (unsigned/signed) - char
- cv::v_uint16x8 and cv::v_int16x8: eight 16-bit integer values (unsigned/signed) - short
- cv::v_uint32x4 and cv::v_int32x4: four 32-bit integer values (unsigned/signed) - int
- cv::v_uint64x2 and cv::v_int64x2: two 64-bit integer values (unsigned/signed) - int64
- cv::v_float32x4: four 32-bit floating point values (signed) - float
- cv::v_float64x2: two 64-bit floating point values (signed) - double
@note
cv::v_float64x2 is not implemented in NEON variant, if you want to use this type, don't forget to
check the CV_SIMD128_64F preprocessor definition:
@code
#if CV_SIMD128_64F
//...
#endif
@endcode
### Load and store operations
These operations allow to set contents of the register explicitly or by loading it from some memory
block and to save contents of the register to memory block.
- Constructors:
@ref v_reg::v_reg(const _Tp *ptr) "from memory",
@ref v_reg::v_reg(_Tp s0, _Tp s1) "from two values", ...
- Other create methods:
@ref v_setall_s8, @ref v_setall_u8, ...,
@ref v_setzero_u8, @ref v_setzero_s8, ...
- Memory operations:
@ref v_load, @ref v_load_aligned, @ref v_load_low, @ref v_load_halves,
@ref v_store, @ref v_store_aligned,
@ref v_store_high, @ref v_store_low
### Value reordering
These operations allow to reorder or recombine elements in one or multiple vectors.
- Interleave, deinterleave (2, 3 and 4 channels): @ref v_load_deinterleave, @ref v_store_interleave
- Expand: @ref v_load_expand, @ref v_load_expand_q, @ref v_expand, @ref v_expand_low, @ref v_expand_high
- Pack: @ref v_pack, @ref v_pack_u, @ref v_pack_b, @ref v_rshr_pack, @ref v_rshr_pack_u,
@ref v_pack_store, @ref v_pack_u_store, @ref v_rshr_pack_store, @ref v_rshr_pack_u_store
- Recombine: @ref v_zip, @ref v_recombine, @ref v_combine_low, @ref v_combine_high
- Reverse: @ref v_reverse
- Extract: @ref v_extract
### Arithmetic, bitwise and comparison operations
Element-wise binary and unary operations.
- Arithmetics:
@ref operator +(const v_reg &a, const v_reg &b) "+",
@ref operator -(const v_reg &a, const v_reg &b) "-",
@ref operator *(const v_reg &a, const v_reg &b) "*",
@ref operator /(const v_reg &a, const v_reg &b) "/",
@ref v_mul_expand
- Non-saturating arithmetics: @ref v_add_wrap, @ref v_sub_wrap
- Bitwise shifts:
@ref operator <<(const v_reg &a, int s) "<<",
@ref operator >>(const v_reg &a, int s) ">>",
@ref v_shl, @ref v_shr
- Bitwise logic:
@ref operator &(const v_reg &a, const v_reg &b) "&",
@ref operator |(const v_reg &a, const v_reg &b) "|",
@ref operator ^(const v_reg &a, const v_reg &b) "^",
@ref operator ~(const v_reg &a) "~"
- Comparison:
@ref operator >(const v_reg &a, const v_reg &b) ">",
@ref operator >=(const v_reg &a, const v_reg &b) ">=",
@ref operator <(const v_reg &a, const v_reg &b) "<",
@ref operator <=(const v_reg &a, const v_reg &b) "<=",
@ref operator==(const v_reg &a, const v_reg &b) "==",
@ref operator !=(const v_reg &a, const v_reg &b) "!="
- min/max: @ref v_min, @ref v_max
### Reduce and mask
Most of these operations return only one value.
- Reduce: @ref v_reduce_min, @ref v_reduce_max, @ref v_reduce_sum, @ref v_popcount
- Mask: @ref v_signmask, @ref v_check_all, @ref v_check_any, @ref v_select
### Other math
- Some frequent operations: @ref v_sqrt, @ref v_invsqrt, @ref v_magnitude, @ref v_sqr_magnitude
- Absolute values: @ref v_abs, @ref v_absdiff, @ref v_absdiffs
### Conversions
Different type conversions and casts:
- Rounding: @ref v_round, @ref v_floor, @ref v_ceil, @ref v_trunc,
- To float: @ref v_cvt_f32, @ref v_cvt_f64
- Reinterpret: @ref v_reinterpret_as_u8, @ref v_reinterpret_as_s8, ...
### Matrix operations
In these operations vectors represent matrix rows/columns: @ref v_dotprod, @ref v_dotprod_fast,
@ref v_dotprod_expand, @ref v_dotprod_expand_fast, @ref v_matmul, @ref v_transpose4x4
### Usability
Most operations are implemented only for some subset of the available types, following matrices
shows the applicability of different operations to the types.
Regular integers:
| Operations\\Types | uint 8x16 | int 8x16 | uint 16x8 | int 16x8 | uint 32x4 | int 32x4 |
|-------------------|:-:|:-:|:-:|:-:|:-:|:-:|
|load, store | x | x | x | x | x | x |
|interleave | x | x | x | x | x | x |
|expand | x | x | x | x | x | x |
|expand_low | x | x | x | x | x | x |
|expand_high | x | x | x | x | x | x |
|expand_q | x | x | | | | |
|add, sub | x | x | x | x | x | x |
|add_wrap, sub_wrap | x | x | x | x | | |
|mul_wrap | x | x | x | x | | |
|mul | x | x | x | x | x | x |
|mul_expand | x | x | x | x | x | |
|compare | x | x | x | x | x | x |
|shift | | | x | x | x | x |
|dotprod | | | | x | | x |
|dotprod_fast | | | | x | | x |
|dotprod_expand | x | x | x | x | | x |
|dotprod_expand_fast| x | x | x | x | | x |
|logical | x | x | x | x | x | x |
|min, max | x | x | x | x | x | x |
|absdiff | x | x | x | x | x | x |
|absdiffs | | x | | x | | |
|reduce | x | x | x | x | x | x |
|mask | x | x | x | x | x | x |
|pack | x | x | x | x | x | x |
|pack_u | x | | x | | | |
|pack_b | x | | | | | |
|unpack | x | x | x | x | x | x |
|extract | x | x | x | x | x | x |
|rotate (lanes) | x | x | x | x | x | x |
|cvt_flt32 | | | | | | x |
|cvt_flt64 | | | | | | x |
|transpose4x4 | | | | | x | x |
|reverse | x | x | x | x | x | x |
|extract_n | x | x | x | x | x | x |
|broadcast_element | | | | | x | x |
Big integers:
| Operations\\Types | uint 64x2 | int 64x2 |
|-------------------|:-:|:-:|
|load, store | x | x |
|add, sub | x | x |
|shift | x | x |
|logical | x | x |
|reverse | x | x |
|extract | x | x |
|rotate (lanes) | x | x |
|cvt_flt64 | | x |
|extract_n | x | x |
Floating point:
| Operations\\Types | float 32x4 | float 64x2 |
|-------------------|:-:|:-:|
|load, store | x | x |
|interleave | x | |
|add, sub | x | x |
|mul | x | x |
|div | x | x |
|compare | x | x |
|min, max | x | x |
|absdiff | x | x |
|reduce | x | |
|mask | x | x |
|unpack | x | x |
|cvt_flt32 | | x |
|cvt_flt64 | x | |
|sqrt, abs | x | x |
|float math | x | x |
|transpose4x4 | x | |
|extract | x | x |
|rotate (lanes) | x | x |
|reverse | x | x |
|extract_n | x | x |
|broadcast_element | x | |
@{ */
template<typename _Tp, int n> struct v_reg
{
//! @cond IGNORED
typedef _Tp lane_type;
enum { nlanes = n };
// !@endcond
/** @brief Constructor
Initializes register with data from memory
@param ptr pointer to memory block with data for register */
explicit v_reg(const _Tp* ptr) { for( int i = 0; i < n; i++ ) s[i] = ptr[i]; }
/** @brief Constructor
Initializes register with two 64-bit values */
v_reg(_Tp s0, _Tp s1) { s[0] = s0; s[1] = s1; }
/** @brief Constructor
Initializes register with four 32-bit values */
v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3) { s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3; }
/** @brief Constructor
Initializes register with eight 16-bit values */
v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3,
_Tp s4, _Tp s5, _Tp s6, _Tp s7)
{
s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3;
s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7;
}
/** @brief Constructor
Initializes register with sixteen 8-bit values */
v_reg(_Tp s0, _Tp s1, _Tp s2, _Tp s3,
_Tp s4, _Tp s5, _Tp s6, _Tp s7,
_Tp s8, _Tp s9, _Tp s10, _Tp s11,
_Tp s12, _Tp s13, _Tp s14, _Tp s15)
{
s[0] = s0; s[1] = s1; s[2] = s2; s[3] = s3;
s[4] = s4; s[5] = s5; s[6] = s6; s[7] = s7;
s[8] = s8; s[9] = s9; s[10] = s10; s[11] = s11;
s[12] = s12; s[13] = s13; s[14] = s14; s[15] = s15;
}
/** @brief Default constructor
Does not initialize anything*/
v_reg() {}
/** @brief Copy constructor */
v_reg(const v_reg<_Tp, n> & r)
{
for( int i = 0; i < n; i++ )
s[i] = r.s[i];
}
/** @brief Access first value
Returns value of the first lane according to register type, for example:
@code{.cpp}
v_int32x4 r(1, 2, 3, 4);
int v = r.get0(); // returns 1
v_uint64x2 r(1, 2);
uint64_t v = r.get0(); // returns 1
@endcode
*/
_Tp get0() const { return s[0]; }
//! @cond IGNORED
_Tp get(const int i) const { return s[i]; }
v_reg<_Tp, n> high() const
{
v_reg<_Tp, n> c;
int i;
for( i = 0; i < n/2; i++ )
{
c.s[i] = s[i+(n/2)];
c.s[i+(n/2)] = 0;
}
return c;
}
static v_reg<_Tp, n> zero()
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (_Tp)0;
return c;
}
static v_reg<_Tp, n> all(_Tp s)
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = s;
return c;
}
template<typename _Tp2, int n2> v_reg<_Tp2, n2> reinterpret_as() const
{
size_t bytes = std::min(sizeof(_Tp2)*n2, sizeof(_Tp)*n);
v_reg<_Tp2, n2> c;
std::memcpy(&c.s[0], &s[0], bytes);
return c;
}
v_reg& operator=(const v_reg<_Tp, n> & r)
{
for( int i = 0; i < n; i++ )
s[i] = r.s[i];
return *this;
}
_Tp s[n];
//! @endcond
};
/** @brief Sixteen 8-bit unsigned integer values */
typedef v_reg<uchar, 16> v_uint8x16;
/** @brief Sixteen 8-bit signed integer values */
typedef v_reg<schar, 16> v_int8x16;
/** @brief Eight 16-bit unsigned integer values */
typedef v_reg<ushort, 8> v_uint16x8;
/** @brief Eight 16-bit signed integer values */
typedef v_reg<short, 8> v_int16x8;
/** @brief Four 32-bit unsigned integer values */
typedef v_reg<unsigned, 4> v_uint32x4;
/** @brief Four 32-bit signed integer values */
typedef v_reg<int, 4> v_int32x4;
/** @brief Four 32-bit floating point values (single precision) */
typedef v_reg<float, 4> v_float32x4;
/** @brief Two 64-bit floating point values (double precision) */
typedef v_reg<double, 2> v_float64x2;
/** @brief Two 64-bit unsigned integer values */
typedef v_reg<uint64, 2> v_uint64x2;
/** @brief Two 64-bit signed integer values */
typedef v_reg<int64, 2> v_int64x2;
/** @brief Add values
For all types. */
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator+(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator+=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Subtract values
For all types. */
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator-(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator-=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Multiply values
For 16- and 32-bit integer types and floating types. */
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator*(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator*=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Divide values
For floating types only. */
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator/(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator/=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Bitwise AND
Only for integer types. */
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator&(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator&=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Bitwise OR
Only for integer types. */
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator|(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator|=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Bitwise XOR
Only for integer types.*/
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator^(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n>& operator^=(v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b);
/** @brief Bitwise NOT
Only for integer types.*/
template<typename _Tp, int n> CV_INLINE v_reg<_Tp, n> operator~(const v_reg<_Tp, n>& a);
#ifndef CV_DOXYGEN
#define CV__HAL_INTRIN_EXPAND_WITH_INTEGER_TYPES(macro_name, ...) \
__CV_EXPAND(macro_name(uchar, __VA_ARGS__)) \
__CV_EXPAND(macro_name(schar, __VA_ARGS__)) \
__CV_EXPAND(macro_name(ushort, __VA_ARGS__)) \
__CV_EXPAND(macro_name(short, __VA_ARGS__)) \
__CV_EXPAND(macro_name(unsigned, __VA_ARGS__)) \
__CV_EXPAND(macro_name(int, __VA_ARGS__)) \
__CV_EXPAND(macro_name(uint64, __VA_ARGS__)) \
__CV_EXPAND(macro_name(int64, __VA_ARGS__)) \
#define CV__HAL_INTRIN_EXPAND_WITH_FP_TYPES(macro_name, ...) \
__CV_EXPAND(macro_name(float, __VA_ARGS__)) \
__CV_EXPAND(macro_name(double, __VA_ARGS__)) \
#define CV__HAL_INTRIN_EXPAND_WITH_ALL_TYPES(macro_name, ...) \
CV__HAL_INTRIN_EXPAND_WITH_INTEGER_TYPES(macro_name, __VA_ARGS__) \
CV__HAL_INTRIN_EXPAND_WITH_FP_TYPES(macro_name, __VA_ARGS__) \
#define CV__HAL_INTRIN_IMPL_BIN_OP_(_Tp, bin_op) \
template<int n> inline \
v_reg<_Tp, n> operator bin_op (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
v_reg<_Tp, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \
return c; \
} \
template<int n> inline \
v_reg<_Tp, n>& operator bin_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
for( int i = 0; i < n; i++ ) \
a.s[i] = saturate_cast<_Tp>(a.s[i] bin_op b.s[i]); \
return a; \
}
#define CV__HAL_INTRIN_IMPL_BIN_OP(bin_op) CV__HAL_INTRIN_EXPAND_WITH_ALL_TYPES(CV__HAL_INTRIN_IMPL_BIN_OP_, bin_op)
CV__HAL_INTRIN_IMPL_BIN_OP(+)
CV__HAL_INTRIN_IMPL_BIN_OP(-)
CV__HAL_INTRIN_IMPL_BIN_OP(*)
CV__HAL_INTRIN_EXPAND_WITH_FP_TYPES(CV__HAL_INTRIN_IMPL_BIN_OP_, /)
#define CV__HAL_INTRIN_IMPL_BIT_OP_(_Tp, bit_op) \
template<int n> CV_INLINE \
v_reg<_Tp, n> operator bit_op (const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
v_reg<_Tp, n> c; \
typedef typename V_TypeTraits<_Tp>::int_type itype; \
for( int i = 0; i < n; i++ ) \
c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \
V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \
return c; \
} \
template<int n> CV_INLINE \
v_reg<_Tp, n>& operator bit_op##= (v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
typedef typename V_TypeTraits<_Tp>::int_type itype; \
for( int i = 0; i < n; i++ ) \
a.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) bit_op \
V_TypeTraits<_Tp>::reinterpret_int(b.s[i]))); \
return a; \
}
#define CV__HAL_INTRIN_IMPL_BIT_OP(bit_op) \
CV__HAL_INTRIN_EXPAND_WITH_INTEGER_TYPES(CV__HAL_INTRIN_IMPL_BIT_OP_, bit_op) \
CV__HAL_INTRIN_EXPAND_WITH_FP_TYPES(CV__HAL_INTRIN_IMPL_BIT_OP_, bit_op) /* TODO: FIXIT remove this after masks refactoring */
CV__HAL_INTRIN_IMPL_BIT_OP(&)
CV__HAL_INTRIN_IMPL_BIT_OP(|)
CV__HAL_INTRIN_IMPL_BIT_OP(^)
#define CV__HAL_INTRIN_IMPL_BITWISE_NOT_(_Tp, dummy) \
template<int n> CV_INLINE \
v_reg<_Tp, n> operator ~ (const v_reg<_Tp, n>& a) \
{ \
v_reg<_Tp, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int(~V_TypeTraits<_Tp>::reinterpret_int(a.s[i])); \
return c; \
} \
CV__HAL_INTRIN_EXPAND_WITH_INTEGER_TYPES(CV__HAL_INTRIN_IMPL_BITWISE_NOT_, ~)
#endif // !CV_DOXYGEN
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_MATH_FUNC(func, cfunc, _Tp2) \
template<typename _Tp, int n> inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a) \
{ \
v_reg<_Tp2, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = cfunc(a.s[i]); \
return c; \
}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(func, cfunc) \
inline v_reg<int, 4> func(const v_reg<float, 4>& a) \
{ \
v_reg<int, 4> c; \
for( int i = 0; i < 4; i++ ) \
c.s[i] = cfunc(a.s[i]); \
return c; \
} \
inline v_reg<int, 4> func(const v_reg<double, 2>& a) \
{ \
v_reg<int, 4> c; \
for( int i = 0; i < 2; i++ ) \
{ \
c.s[i] = cfunc(a.s[i]); \
c.s[i + 2] = 0; \
} \
return c; \
}
/** @brief Square root of elements
Only for floating point types.*/
OPENCV_HAL_IMPL_MATH_FUNC(v_sqrt, std::sqrt, _Tp)
//! @cond IGNORED
OPENCV_HAL_IMPL_MATH_FUNC(v_sin, std::sin, _Tp)
OPENCV_HAL_IMPL_MATH_FUNC(v_cos, std::cos, _Tp)
OPENCV_HAL_IMPL_MATH_FUNC(v_exp, std::exp, _Tp)
OPENCV_HAL_IMPL_MATH_FUNC(v_log, std::log, _Tp)
//! @endcond
/** @brief Absolute value of elements
Only for floating point types.*/
OPENCV_HAL_IMPL_MATH_FUNC(v_abs, (typename V_TypeTraits<_Tp>::abs_type)std::abs,
typename V_TypeTraits<_Tp>::abs_type)
/** @brief Round elements
Only for floating point types.*/
OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_round, cvRound)
/** @brief Floor elements
Only for floating point types.*/
OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_floor, cvFloor)
/** @brief Ceil elements
Only for floating point types.*/
OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_ceil, cvCeil)
/** @brief Truncate elements
Only for floating point types.*/
OPENCV_HAL_IMPL_MATH_FUNC_FLOAT(v_trunc, int)
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_MINMAX_FUNC(func, cfunc) \
template<typename _Tp, int n> inline v_reg<_Tp, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
v_reg<_Tp, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = cfunc(a.s[i], b.s[i]); \
return c; \
}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(func, cfunc) \
template<typename _Tp, int n> inline _Tp func(const v_reg<_Tp, n>& a) \
{ \
_Tp c = a.s[0]; \
for( int i = 1; i < n; i++ ) \
c = cfunc(c, a.s[i]); \
return c; \
}
/** @brief Choose min values for each pair
Scheme:
@code
{A1 A2 ...}
{B1 B2 ...}
--------------
{min(A1,B1) min(A2,B2) ...}
@endcode
For all types except 64-bit integer. */
OPENCV_HAL_IMPL_MINMAX_FUNC(v_min, std::min)
/** @brief Choose max values for each pair
Scheme:
@code
{A1 A2 ...}
{B1 B2 ...}
--------------
{max(A1,B1) max(A2,B2) ...}
@endcode
For all types except 64-bit integer. */
OPENCV_HAL_IMPL_MINMAX_FUNC(v_max, std::max)
/** @brief Find one min value
Scheme:
@code
{A1 A2 A3 ...} => min(A1,A2,A3,...)
@endcode
For all types except 64-bit integer and 64-bit floating point types. */
OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_min, std::min)
/** @brief Find one max value
Scheme:
@code
{A1 A2 A3 ...} => max(A1,A2,A3,...)
@endcode
For all types except 64-bit integer and 64-bit floating point types. */
OPENCV_HAL_IMPL_REDUCE_MINMAX_FUNC(v_reduce_max, std::max)
static const unsigned char popCountTable[] =
{
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
};
/** @brief Count the 1 bits in the vector lanes and return result as corresponding unsigned type
Scheme:
@code
{A1 A2 A3 ...} => {popcount(A1), popcount(A2), popcount(A3), ...}
@endcode
For all integer types. */
template<typename _Tp, int n>
inline v_reg<typename V_TypeTraits<_Tp>::abs_type, n> v_popcount(const v_reg<_Tp, n>& a)
{
v_reg<typename V_TypeTraits<_Tp>::abs_type, n> b = v_reg<typename V_TypeTraits<_Tp>::abs_type, n>::zero();
for (int i = 0; i < n*(int)sizeof(_Tp); i++)
b.s[i/sizeof(_Tp)] += popCountTable[v_reinterpret_as_u8(a).s[i]];
return b;
}
//! @cond IGNORED
template<typename _Tp, int n>
inline void v_minmax( const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
v_reg<_Tp, n>& minval, v_reg<_Tp, n>& maxval )
{
for( int i = 0; i < n; i++ )
{
minval.s[i] = std::min(a.s[i], b.s[i]);
maxval.s[i] = std::max(a.s[i], b.s[i]);
}
}
//! @endcond
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_CMP_OP(cmp_op) \
template<typename _Tp, int n> \
inline v_reg<_Tp, n> operator cmp_op(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
typedef typename V_TypeTraits<_Tp>::int_type itype; \
v_reg<_Tp, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = V_TypeTraits<_Tp>::reinterpret_from_int((itype)-(int)(a.s[i] cmp_op b.s[i])); \
return c; \
}
/** @brief Less-than comparison
For all types except 64-bit integer values. */
OPENCV_HAL_IMPL_CMP_OP(<)
/** @brief Greater-than comparison
For all types except 64-bit integer values. */
OPENCV_HAL_IMPL_CMP_OP(>)
/** @brief Less-than or equal comparison
For all types except 64-bit integer values. */
OPENCV_HAL_IMPL_CMP_OP(<=)
/** @brief Greater-than or equal comparison
For all types except 64-bit integer values. */
OPENCV_HAL_IMPL_CMP_OP(>=)
/** @brief Equal comparison
For all types except 64-bit integer values. */
OPENCV_HAL_IMPL_CMP_OP(==)
/** @brief Not equal comparison
For all types except 64-bit integer values. */
OPENCV_HAL_IMPL_CMP_OP(!=)
template<int n>
inline v_reg<float, n> v_not_nan(const v_reg<float, n>& a)
{
typedef typename V_TypeTraits<float>::int_type itype;
v_reg<float, n> c;
for (int i = 0; i < n; i++)
c.s[i] = V_TypeTraits<float>::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i]));
return c;
}
template<int n>
inline v_reg<double, n> v_not_nan(const v_reg<double, n>& a)
{
typedef typename V_TypeTraits<double>::int_type itype;
v_reg<double, n> c;
for (int i = 0; i < n; i++)
c.s[i] = V_TypeTraits<double>::reinterpret_from_int((itype)-(int)(a.s[i] == a.s[i]));
return c;
}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_ARITHM_OP(func, bin_op, cast_op, _Tp2) \
template<typename _Tp, int n> \
inline v_reg<_Tp2, n> func(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
typedef _Tp2 rtype; \
v_reg<rtype, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = cast_op(a.s[i] bin_op b.s[i]); \
return c; \
}
/** @brief Add values without saturation
For 8- and 16-bit integer values. */
OPENCV_HAL_IMPL_ARITHM_OP(v_add_wrap, +, (_Tp), _Tp)
/** @brief Subtract values without saturation
For 8- and 16-bit integer values. */
OPENCV_HAL_IMPL_ARITHM_OP(v_sub_wrap, -, (_Tp), _Tp)
/** @brief Multiply values without saturation
For 8- and 16-bit integer values. */
OPENCV_HAL_IMPL_ARITHM_OP(v_mul_wrap, *, (_Tp), _Tp)
//! @cond IGNORED
template<typename T> inline T _absdiff(T a, T b)
{
return a > b ? a - b : b - a;
}
//! @endcond
/** @brief Absolute difference
Returns \f$ |a - b| \f$ converted to corresponding unsigned type.
Example:
@code{.cpp}
v_int32x4 a, b; // {1, 2, 3, 4} and {4, 3, 2, 1}
v_uint32x4 c = v_absdiff(a, b); // result is {3, 1, 1, 3}
@endcode
For 8-, 16-, 32-bit integer source types. */
template<typename _Tp, int n>
inline v_reg<typename V_TypeTraits<_Tp>::abs_type, n> v_absdiff(const v_reg<_Tp, n>& a, const v_reg<_Tp, n> & b)
{
typedef typename V_TypeTraits<_Tp>::abs_type rtype;
v_reg<rtype, n> c;
const rtype mask = (rtype)(std::numeric_limits<_Tp>::is_signed ? (1 << (sizeof(rtype)*8 - 1)) : 0);
for( int i = 0; i < n; i++ )
{
rtype ua = a.s[i] ^ mask;
rtype ub = b.s[i] ^ mask;
c.s[i] = _absdiff(ua, ub);
}
return c;
}
/** @overload
For 32-bit floating point values */
inline v_float32x4 v_absdiff(const v_float32x4& a, const v_float32x4& b)
{
v_float32x4 c;
for( int i = 0; i < c.nlanes; i++ )
c.s[i] = _absdiff(a.s[i], b.s[i]);
return c;
}
/** @overload
For 64-bit floating point values */
inline v_float64x2 v_absdiff(const v_float64x2& a, const v_float64x2& b)
{
v_float64x2 c;
for( int i = 0; i < c.nlanes; i++ )
c.s[i] = _absdiff(a.s[i], b.s[i]);
return c;
}
/** @brief Saturating absolute difference
Returns \f$ saturate(|a - b|) \f$ .
For 8-, 16-bit signed integer source types. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_absdiffs(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++)
c.s[i] = saturate_cast<_Tp>(std::abs(a.s[i] - b.s[i]));
return c;
}
/** @brief Inversed square root
Returns \f$ 1/sqrt(a) \f$
For floating point types only. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_invsqrt(const v_reg<_Tp, n>& a)
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = 1.f/std::sqrt(a.s[i]);
return c;
}
/** @brief Magnitude
Returns \f$ sqrt(a^2 + b^2) \f$
For floating point types only. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = std::sqrt(a.s[i]*a.s[i] + b.s[i]*b.s[i]);
return c;
}
/** @brief Square of the magnitude
Returns \f$ a^2 + b^2 \f$
For floating point types only. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_sqr_magnitude(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = a.s[i]*a.s[i] + b.s[i]*b.s[i];
return c;
}
/** @brief Multiply and add
Returns \f$ a*b + c \f$
For floating point types and signed 32bit int only. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_fma(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
const v_reg<_Tp, n>& c)
{
v_reg<_Tp, n> d;
for( int i = 0; i < n; i++ )
d.s[i] = a.s[i]*b.s[i] + c.s[i];
return d;
}
/** @brief A synonym for v_fma */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_muladd(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
const v_reg<_Tp, n>& c)
{
return v_fma(a, b, c);
}
/** @brief Dot product of elements
Multiply values in two registers and sum adjacent result pairs.
Scheme:
@code
{A1 A2 ...} // 16-bit
x {B1 B2 ...} // 16-bit
-------------
{A1B1+A2B2 ...} // 32-bit
@endcode
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>
v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
typedef typename V_TypeTraits<_Tp>::w_type w_type;
v_reg<w_type, n/2> c;
for( int i = 0; i < (n/2); i++ )
c.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1];
return c;
}
/** @brief Dot product of elements
Same as cv::v_dotprod, but add a third element to the sum of adjacent pairs.
Scheme:
@code
{A1 A2 ...} // 16-bit
x {B1 B2 ...} // 16-bit
-------------
{A1B1+A2B2+C1 ...} // 32-bit
@endcode
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>
v_dotprod(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
const v_reg<typename V_TypeTraits<_Tp>::w_type, n / 2>& c)
{
typedef typename V_TypeTraits<_Tp>::w_type w_type;
v_reg<w_type, n/2> s;
for( int i = 0; i < (n/2); i++ )
s.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1] + c.s[i];
return s;
}
/** @brief Fast Dot product of elements
Same as cv::v_dotprod, but it may perform unorder sum between result pairs in some platforms,
this intrinsic can be used if the sum among all lanes is only matters
and also it should be yielding better performance on the affected platforms.
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>
v_dotprod_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{ return v_dotprod(a, b); }
/** @brief Fast Dot product of elements
Same as cv::v_dotprod_fast, but add a third element to the sum of adjacent pairs.
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>
v_dotprod_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
const v_reg<typename V_TypeTraits<_Tp>::w_type, n / 2>& c)
{ return v_dotprod(a, b, c); }
/** @brief Dot product of elements and expand
Multiply values in two registers and expand the sum of adjacent result pairs.
Scheme:
@code
{A1 A2 A3 A4 ...} // 8-bit
x {B1 B2 B3 B4 ...} // 8-bit
-------------
{A1B1+A2B2+A3B3+A4B4 ...} // 32-bit
@endcode
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::q_type, n/4>
v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
typedef typename V_TypeTraits<_Tp>::q_type q_type;
v_reg<q_type, n/4> s;
for( int i = 0; i < (n/4); i++ )
s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] +
(q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3];
return s;
}
/** @brief Dot product of elements
Same as cv::v_dotprod_expand, but add a third element to the sum of adjacent pairs.
Scheme:
@code
{A1 A2 A3 A4 ...} // 8-bit
x {B1 B2 B3 B4 ...} // 8-bit
-------------
{A1B1+A2B2+A3B3+A4B4+C1 ...} // 32-bit
@endcode
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::q_type, n/4>
v_dotprod_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
const v_reg<typename V_TypeTraits<_Tp>::q_type, n / 4>& c)
{
typedef typename V_TypeTraits<_Tp>::q_type q_type;
v_reg<q_type, n/4> s;
for( int i = 0; i < (n/4); i++ )
s.s[i] = (q_type)a.s[i*4 ]*b.s[i*4 ] + (q_type)a.s[i*4 + 1]*b.s[i*4 + 1] +
(q_type)a.s[i*4 + 2]*b.s[i*4 + 2] + (q_type)a.s[i*4 + 3]*b.s[i*4 + 3] + c.s[i];
return s;
}
/** @brief Fast Dot product of elements and expand
Multiply values in two registers and expand the sum of adjacent result pairs.
Same as cv::v_dotprod_expand, but it may perform unorder sum between result pairs in some platforms,
this intrinsic can be used if the sum among all lanes is only matters
and also it should be yielding better performance on the affected platforms.
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::q_type, n/4>
v_dotprod_expand_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{ return v_dotprod_expand(a, b); }
/** @brief Fast Dot product of elements
Same as cv::v_dotprod_expand_fast, but add a third element to the sum of adjacent pairs.
*/
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::q_type, n/4>
v_dotprod_expand_fast(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
const v_reg<typename V_TypeTraits<_Tp>::q_type, n / 4>& c)
{ return v_dotprod_expand(a, b, c); }
/** @brief Multiply and expand
Multiply values two registers and store results in two registers with wider pack type.
Scheme:
@code
{A B C D} // 32-bit
x {E F G H} // 32-bit
---------------
{AE BF} // 64-bit
{CG DH} // 64-bit
@endcode
Example:
@code{.cpp}
v_uint32x4 a, b; // {1,2,3,4} and {2,2,2,2}
v_uint64x2 c, d; // results
v_mul_expand(a, b, c, d); // c, d = {2,4}, {6, 8}
@endcode
Implemented only for 16- and unsigned 32-bit source types (v_int16x8, v_uint16x8, v_uint32x4).
*/
template<typename _Tp, int n> inline void v_mul_expand(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& c,
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& d)
{
typedef typename V_TypeTraits<_Tp>::w_type w_type;
for( int i = 0; i < (n/2); i++ )
{
c.s[i] = (w_type)a.s[i]*b.s[i];
d.s[i] = (w_type)a.s[i+(n/2)]*b.s[i+(n/2)];
}
}
/** @brief Multiply and extract high part
Multiply values two registers and store high part of the results.
Implemented only for 16-bit source types (v_int16x8, v_uint16x8). Returns \f$ a*b >> 16 \f$
*/
template<typename _Tp, int n> inline v_reg<_Tp, n> v_mul_hi(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
typedef typename V_TypeTraits<_Tp>::w_type w_type;
v_reg<_Tp, n> c;
for (int i = 0; i < n; i++)
c.s[i] = (_Tp)(((w_type)a.s[i] * b.s[i]) >> sizeof(_Tp)*8);
return c;
}
//! @cond IGNORED
template<typename _Tp, int n> inline void v_hsum(const v_reg<_Tp, n>& a,
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& c)
{
typedef typename V_TypeTraits<_Tp>::w_type w_type;
for( int i = 0; i < (n/2); i++ )
{
c.s[i] = (w_type)a.s[i*2] + a.s[i*2+1];
}
}
//! @endcond
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_SHIFT_OP(shift_op) \
template<typename _Tp, int n> inline v_reg<_Tp, n> operator shift_op(const v_reg<_Tp, n>& a, int imm) \
{ \
v_reg<_Tp, n> c; \
for( int i = 0; i < n; i++ ) \
c.s[i] = (_Tp)(a.s[i] shift_op imm); \
return c; \
}
/** @brief Bitwise shift left
For 16-, 32- and 64-bit integer values. */
OPENCV_HAL_IMPL_SHIFT_OP(<< )
/** @brief Bitwise shift right
For 16-, 32- and 64-bit integer values. */
OPENCV_HAL_IMPL_SHIFT_OP(>> )
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(suffix,opA,opB) \
template<int imm, typename _Tp, int n> inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a) \
{ \
v_reg<_Tp, n> b; \
for (int i = 0; i < n; i++) \
{ \
int sIndex = i opA imm; \
if (0 <= sIndex && sIndex < n) \
{ \
b.s[i] = a.s[sIndex]; \
} \
else \
{ \
b.s[i] = 0; \
} \
} \
return b; \
} \
template<int imm, typename _Tp, int n> inline v_reg<_Tp, n> v_rotate_##suffix(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b) \
{ \
v_reg<_Tp, n> c; \
for (int i = 0; i < n; i++) \
{ \
int aIndex = i opA imm; \
int bIndex = i opA imm opB n; \
if (0 <= bIndex && bIndex < n) \
{ \
c.s[i] = b.s[bIndex]; \
} \
else if (0 <= aIndex && aIndex < n) \
{ \
c.s[i] = a.s[aIndex]; \
} \
else \
{ \
c.s[i] = 0; \
} \
} \
return c; \
}
/** @brief Element shift left among vector
For all type */
OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(left, -, +)
/** @brief Element shift right among vector
For all type */
OPENCV_HAL_IMPL_ROTATE_SHIFT_OP(right, +, -)
/** @brief Sum packed values
Scheme:
@code
{A1 A2 A3 ...} => sum{A1,A2,A3,...}
@endcode
*/
template<typename _Tp, int n> inline typename V_TypeTraits<_Tp>::sum_type v_reduce_sum(const v_reg<_Tp, n>& a)
{
typename V_TypeTraits<_Tp>::sum_type c = a.s[0];
for( int i = 1; i < n; i++ )
c += a.s[i];
return c;
}
/** @brief Sums all elements of each input vector, returns the vector of sums
Scheme:
@code
result[0] = a[0] + a[1] + a[2] + a[3]
result[1] = b[0] + b[1] + b[2] + b[3]
result[2] = c[0] + c[1] + c[2] + c[3]
result[3] = d[0] + d[1] + d[2] + d[3]
@endcode
*/
inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b,
const v_float32x4& c, const v_float32x4& d)
{
v_float32x4 r;
r.s[0] = a.s[0] + a.s[1] + a.s[2] + a.s[3];
r.s[1] = b.s[0] + b.s[1] + b.s[2] + b.s[3];
r.s[2] = c.s[0] + c.s[1] + c.s[2] + c.s[3];
r.s[3] = d.s[0] + d.s[1] + d.s[2] + d.s[3];
return r;
}
/** @brief Sum absolute differences of values
Scheme:
@code
{A1 A2 A3 ...} {B1 B2 B3 ...} => sum{ABS(A1-B1),abs(A2-B2),abs(A3-B3),...}
@endcode
For all types except 64-bit types.*/
template<typename _Tp, int n> inline typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type v_reduce_sad(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
typename V_TypeTraits< typename V_TypeTraits<_Tp>::abs_type >::sum_type c = _absdiff(a.s[0], b.s[0]);
for (int i = 1; i < n; i++)
c += _absdiff(a.s[i], b.s[i]);
return c;
}
/** @brief Get negative values mask
@deprecated v_signmask depends on a lane count heavily and therefore isn't universal enough
Returned value is a bit mask with bits set to 1 on places corresponding to negative packed values indexes.
Example:
@code{.cpp}
v_int32x4 r; // set to {-1, -1, 1, 1}
int mask = v_signmask(r); // mask = 3 <== 00000000 00000000 00000000 00000011
@endcode
*/
template<typename _Tp, int n> inline int v_signmask(const v_reg<_Tp, n>& a)
{
int mask = 0;
for( int i = 0; i < n; i++ )
mask |= (V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0) << i;
return mask;
}
/** @brief Get first negative lane index
Returned value is an index of first negative lane (undefined for input of all positive values)
Example:
@code{.cpp}
v_int32x4 r; // set to {0, 0, -1, -1}
int idx = v_heading_zeros(r); // idx = 2
@endcode
*/
template <typename _Tp, int n> inline int v_scan_forward(const v_reg<_Tp, n>& a)
{
for (int i = 0; i < n; i++)
if(V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0)
return i;
return 0;
}
/** @brief Check if all packed values are less than zero
Unsigned values will be casted to signed: `uchar 254 => char -2`.
*/
template<typename _Tp, int n> inline bool v_check_all(const v_reg<_Tp, n>& a)
{
for( int i = 0; i < n; i++ )
if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) >= 0 )
return false;
return true;
}
/** @brief Check if any of packed values is less than zero
Unsigned values will be casted to signed: `uchar 254 => char -2`.
*/
template<typename _Tp, int n> inline bool v_check_any(const v_reg<_Tp, n>& a)
{
for( int i = 0; i < n; i++ )
if( V_TypeTraits<_Tp>::reinterpret_int(a.s[i]) < 0 )
return true;
return false;
}
/** @brief Per-element select (blend operation)
Return value will be built by combining values _a_ and _b_ using the following scheme:
result[i] = mask[i] ? a[i] : b[i];
@note: _mask_ element values are restricted to these values:
- 0: select element from _b_
- 0xff/0xffff/etc: select element from _a_
(fully compatible with bitwise-based operator)
*/
template<typename _Tp, int n> inline v_reg<_Tp, n> v_select(const v_reg<_Tp, n>& mask,
const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
typedef V_TypeTraits<_Tp> Traits;
typedef typename Traits::int_type int_type;
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
{
int_type m = Traits::reinterpret_int(mask.s[i]);
CV_DbgAssert(m == 0 || m == (~(int_type)0)); // restrict mask values: 0 or 0xff/0xffff/etc
c.s[i] = m ? a.s[i] : b.s[i];
}
return c;
}
/** @brief Expand values to the wider pack type
Copy contents of register to two registers with 2x wider pack type.
Scheme:
@code
int32x4 int64x2 int64x2
{A B C D} ==> {A B} , {C D}
@endcode */
template<typename _Tp, int n> inline void v_expand(const v_reg<_Tp, n>& a,
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& b0,
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>& b1)
{
for( int i = 0; i < (n/2); i++ )
{
b0.s[i] = a.s[i];
b1.s[i] = a.s[i+(n/2)];
}
}
/** @brief Expand lower values to the wider pack type
Same as cv::v_expand, but return lower half of the vector.
Scheme:
@code
int32x4 int64x2
{A B C D} ==> {A B}
@endcode */
template<typename _Tp, int n>
inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>
v_expand_low(const v_reg<_Tp, n>& a)
{
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> b;
for( int i = 0; i < (n/2); i++ )
b.s[i] = a.s[i];
return b;
}
/** @brief Expand higher values to the wider pack type
Same as cv::v_expand_low, but expand higher half of the vector instead.
Scheme:
@code
int32x4 int64x2
{A B C D} ==> {C D}
@endcode */
template<typename _Tp, int n>
inline v_reg<typename V_TypeTraits<_Tp>::w_type, n/2>
v_expand_high(const v_reg<_Tp, n>& a)
{
v_reg<typename V_TypeTraits<_Tp>::w_type, n/2> b;
for( int i = 0; i < (n/2); i++ )
b.s[i] = a.s[i+(n/2)];
return b;
}
//! @cond IGNORED
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::int_type, n>
v_reinterpret_as_int(const v_reg<_Tp, n>& a)
{
v_reg<typename V_TypeTraits<_Tp>::int_type, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = V_TypeTraits<_Tp>::reinterpret_int(a.s[i]);
return c;
}
template<typename _Tp, int n> inline v_reg<typename V_TypeTraits<_Tp>::uint_type, n>
v_reinterpret_as_uint(const v_reg<_Tp, n>& a)
{
v_reg<typename V_TypeTraits<_Tp>::uint_type, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = V_TypeTraits<_Tp>::reinterpret_uint(a.s[i]);
return c;
}
//! @endcond
/** @brief Interleave two vectors
Scheme:
@code
{A1 A2 A3 A4}
{B1 B2 B3 B4}
---------------
{A1 B1 A2 B2} and {A3 B3 A4 B4}
@endcode
For all types except 64-bit.
*/
template<typename _Tp, int n> inline void v_zip( const v_reg<_Tp, n>& a0, const v_reg<_Tp, n>& a1,
v_reg<_Tp, n>& b0, v_reg<_Tp, n>& b1 )
{
int i;
for( i = 0; i < n/2; i++ )
{
b0.s[i*2] = a0.s[i];
b0.s[i*2+1] = a1.s[i];
}
for( ; i < n; i++ )
{
b1.s[i*2-n] = a0.s[i];
b1.s[i*2-n+1] = a1.s[i];
}
}
/** @brief Load register contents from memory
@param ptr pointer to memory block with data
@return register object
@note Returned type will be detected from passed pointer type, for example uchar ==> cv::v_uint8x16, int ==> cv::v_int32x4, etc.
@note Alignment requirement:
if CV_STRONG_ALIGNMENT=1 then passed pointer must be aligned (`sizeof(lane type)` should be enough).
Do not cast pointer types without runtime check for pointer alignment (like `uchar*` => `int*`).
*/
template<typename _Tp>
inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load(const _Tp* ptr)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr);
}
/** @brief Load register contents from memory (aligned)
similar to cv::v_load, but source memory block should be aligned (to 16-byte boundary in case of SIMD128, 32-byte - SIMD256, etc)
*/
template<typename _Tp>
inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_aligned(const _Tp* ptr)
{
CV_Assert(isAligned<sizeof(v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>)>(ptr));
return v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128>(ptr);
}
/** @brief Load 64-bits of data to lower part (high part is undefined).
@param ptr memory block containing data for first half (0..n/2)
@code{.cpp}
int lo[2] = { 1, 2 };
v_int32x4 r = v_load_low(lo);
@endcode
*/
template<typename _Tp>
inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_low(const _Tp* ptr)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c;
for( int i = 0; i < c.nlanes/2; i++ )
{
c.s[i] = ptr[i];
}
return c;
}
/** @brief Load register contents from two memory blocks
@param loptr memory block containing data for first half (0..n/2)
@param hiptr memory block containing data for second half (n/2..n)
@code{.cpp}
int lo[2] = { 1, 2 }, hi[2] = { 3, 4 };
v_int32x4 r = v_load_halves(lo, hi);
@endcode
*/
template<typename _Tp>
inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_load_halves(const _Tp* loptr, const _Tp* hiptr)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(loptr));
CV_Assert(isAligned<sizeof(_Tp)>(hiptr));
#endif
v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c;
for( int i = 0; i < c.nlanes/2; i++ )
{
c.s[i] = loptr[i];
c.s[i+c.nlanes/2] = hiptr[i];
}
return c;
}
/** @brief Load register contents from memory with double expand
Same as cv::v_load, but result pack type will be 2x wider than memory type.
@code{.cpp}
short buf[4] = {1, 2, 3, 4}; // type is int16
v_int32x4 r = v_load_expand(buf); // r = {1, 2, 3, 4} - type is int32
@endcode
For 8-, 16-, 32-bit integer source types. */
template<typename _Tp>
inline v_reg<typename V_TypeTraits<_Tp>::w_type, V_TypeTraits<_Tp>::nlanes128 / 2>
v_load_expand(const _Tp* ptr)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
typedef typename V_TypeTraits<_Tp>::w_type w_type;
v_reg<w_type, V_TypeTraits<w_type>::nlanes128> c;
for( int i = 0; i < c.nlanes; i++ )
{
c.s[i] = ptr[i];
}
return c;
}
/** @brief Load register contents from memory with quad expand
Same as cv::v_load_expand, but result type is 4 times wider than source.
@code{.cpp}
char buf[4] = {1, 2, 3, 4}; // type is int8
v_int32x4 r = v_load_q(buf); // r = {1, 2, 3, 4} - type is int32
@endcode
For 8-bit integer source types. */
template<typename _Tp>
inline v_reg<typename V_TypeTraits<_Tp>::q_type, V_TypeTraits<_Tp>::nlanes128 / 4>
v_load_expand_q(const _Tp* ptr)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
typedef typename V_TypeTraits<_Tp>::q_type q_type;
v_reg<q_type, V_TypeTraits<q_type>::nlanes128> c;
for( int i = 0; i < c.nlanes; i++ )
{
c.s[i] = ptr[i];
}
return c;
}
/** @brief Load and deinterleave (2 channels)
Load data from memory deinterleave and store to 2 registers.
Scheme:
@code
{A1 B1 A2 B2 ...} ==> {A1 A2 ...}, {B1 B2 ...}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n> inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a,
v_reg<_Tp, n>& b)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
int i, i2;
for( i = i2 = 0; i < n; i++, i2 += 2 )
{
a.s[i] = ptr[i2];
b.s[i] = ptr[i2+1];
}
}
/** @brief Load and deinterleave (3 channels)
Load data from memory deinterleave and store to 3 registers.
Scheme:
@code
{A1 B1 C1 A2 B2 C2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n> inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a,
v_reg<_Tp, n>& b, v_reg<_Tp, n>& c)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
int i, i3;
for( i = i3 = 0; i < n; i++, i3 += 3 )
{
a.s[i] = ptr[i3];
b.s[i] = ptr[i3+1];
c.s[i] = ptr[i3+2];
}
}
/** @brief Load and deinterleave (4 channels)
Load data from memory deinterleave and store to 4 registers.
Scheme:
@code
{A1 B1 C1 D1 A2 B2 C2 D2 ...} ==> {A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n>
inline void v_load_deinterleave(const _Tp* ptr, v_reg<_Tp, n>& a,
v_reg<_Tp, n>& b, v_reg<_Tp, n>& c,
v_reg<_Tp, n>& d)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
int i, i4;
for( i = i4 = 0; i < n; i++, i4 += 4 )
{
a.s[i] = ptr[i4];
b.s[i] = ptr[i4+1];
c.s[i] = ptr[i4+2];
d.s[i] = ptr[i4+3];
}
}
/** @brief Interleave and store (2 channels)
Interleave and store data from 2 registers to memory.
Scheme:
@code
{A1 A2 ...}, {B1 B2 ...} ==> {A1 B1 A2 B2 ...}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n>
inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a,
const v_reg<_Tp, n>& b,
hal::StoreMode /*mode*/=hal::STORE_UNALIGNED)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
int i, i2;
for( i = i2 = 0; i < n; i++, i2 += 2 )
{
ptr[i2] = a.s[i];
ptr[i2+1] = b.s[i];
}
}
/** @brief Interleave and store (3 channels)
Interleave and store data from 3 registers to memory.
Scheme:
@code
{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...} ==> {A1 B1 C1 A2 B2 C2 ...}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n>
inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a,
const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c,
hal::StoreMode /*mode*/=hal::STORE_UNALIGNED)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
int i, i3;
for( i = i3 = 0; i < n; i++, i3 += 3 )
{
ptr[i3] = a.s[i];
ptr[i3+1] = b.s[i];
ptr[i3+2] = c.s[i];
}
}
/** @brief Interleave and store (4 channels)
Interleave and store data from 4 registers to memory.
Scheme:
@code
{A1 A2 ...}, {B1 B2 ...}, {C1 C2 ...}, {D1 D2 ...} ==> {A1 B1 C1 D1 A2 B2 C2 D2 ...}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n> inline void v_store_interleave( _Tp* ptr, const v_reg<_Tp, n>& a,
const v_reg<_Tp, n>& b, const v_reg<_Tp, n>& c,
const v_reg<_Tp, n>& d,
hal::StoreMode /*mode*/=hal::STORE_UNALIGNED)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
int i, i4;
for( i = i4 = 0; i < n; i++, i4 += 4 )
{
ptr[i4] = a.s[i];
ptr[i4+1] = b.s[i];
ptr[i4+2] = c.s[i];
ptr[i4+3] = d.s[i];
}
}
/** @brief Store data to memory
Store register contents to memory.
Scheme:
@code
REG {A B C D} ==> MEM {A B C D}
@endcode
Pointer can be unaligned. */
template<typename _Tp, int n>
inline void v_store(_Tp* ptr, const v_reg<_Tp, n>& a)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
for( int i = 0; i < n; i++ )
ptr[i] = a.s[i];
}
template<typename _Tp, int n>
inline void v_store(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
v_store(ptr, a);
}
/** @brief Store data to memory (lower half)
Store lower half of register contents to memory.
Scheme:
@code
REG {A B C D} ==> MEM {A B}
@endcode */
template<typename _Tp, int n>
inline void v_store_low(_Tp* ptr, const v_reg<_Tp, n>& a)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
for( int i = 0; i < (n/2); i++ )
ptr[i] = a.s[i];
}
/** @brief Store data to memory (higher half)
Store higher half of register contents to memory.
Scheme:
@code
REG {A B C D} ==> MEM {C D}
@endcode */
template<typename _Tp, int n>
inline void v_store_high(_Tp* ptr, const v_reg<_Tp, n>& a)
{
#if CV_STRONG_ALIGNMENT
CV_Assert(isAligned<sizeof(_Tp)>(ptr));
#endif
for( int i = 0; i < (n/2); i++ )
ptr[i] = a.s[i+(n/2)];
}
/** @brief Store data to memory (aligned)
Store register contents to memory.
Scheme:
@code
REG {A B C D} ==> MEM {A B C D}
@endcode
Pointer __should__ be aligned by 16-byte boundary. */
template<typename _Tp, int n>
inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a)
{
CV_Assert(isAligned<sizeof(v_reg<_Tp, n>)>(ptr));
v_store(ptr, a);
}
template<typename _Tp, int n>
inline void v_store_aligned_nocache(_Tp* ptr, const v_reg<_Tp, n>& a)
{
CV_Assert(isAligned<sizeof(v_reg<_Tp, n>)>(ptr));
v_store(ptr, a);
}
template<typename _Tp, int n>
inline void v_store_aligned(_Tp* ptr, const v_reg<_Tp, n>& a, hal::StoreMode /*mode*/)
{
CV_Assert(isAligned<sizeof(v_reg<_Tp, n>)>(ptr));
v_store(ptr, a);
}
/** @brief Combine vector from first elements of two vectors
Scheme:
@code
{A1 A2 A3 A4}
{B1 B2 B3 B4}
---------------
{A1 A2 B1 B2}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_combine_low(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
v_reg<_Tp, n> c;
for( int i = 0; i < (n/2); i++ )
{
c.s[i] = a.s[i];
c.s[i+(n/2)] = b.s[i];
}
return c;
}
/** @brief Combine vector from last elements of two vectors
Scheme:
@code
{A1 A2 A3 A4}
{B1 B2 B3 B4}
---------------
{A3 A4 B3 B4}
@endcode
For all types except 64-bit. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_combine_high(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
v_reg<_Tp, n> c;
for( int i = 0; i < (n/2); i++ )
{
c.s[i] = a.s[i+(n/2)];
c.s[i+(n/2)] = b.s[i+(n/2)];
}
return c;
}
/** @brief Combine two vectors from lower and higher parts of two other vectors
@code{.cpp}
low = cv::v_combine_low(a, b);
high = cv::v_combine_high(a, b);
@endcode */
template<typename _Tp, int n>
inline void v_recombine(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b,
v_reg<_Tp, n>& low, v_reg<_Tp, n>& high)
{
for( int i = 0; i < (n/2); i++ )
{
low.s[i] = a.s[i];
low.s[i+(n/2)] = b.s[i];
high.s[i] = a.s[i+(n/2)];
high.s[i+(n/2)] = b.s[i+(n/2)];
}
}
/** @brief Vector reverse order
Reverse the order of the vector
Scheme:
@code
REG {A1 ... An} ==> REG {An ... A1}
@endcode
For all types. */
template<typename _Tp, int n>
inline v_reg<_Tp, n> v_reverse(const v_reg<_Tp, n>& a)
{
v_reg<_Tp, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = a.s[n-i-1];
return c;
}
/** @brief Vector extract
Scheme:
@code
{A1 A2 A3 A4}
{B1 B2 B3 B4}
========================
shift = 1 {A2 A3 A4 B1}
shift = 2 {A3 A4 B1 B2}
shift = 3 {A4 B1 B2 B3}
@endcode
Restriction: 0 <= shift < nlanes
Usage:
@code
v_int32x4 a, b, c;
c = v_extract<2>(a, b);
@endcode
For all types. */
template<int s, typename _Tp, int n>
inline v_reg<_Tp, n> v_extract(const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
v_reg<_Tp, n> r;
const int shift = n - s;
int i = 0;
for (; i < shift; ++i)
r.s[i] = a.s[i+s];
for (; i < n; ++i)
r.s[i] = b.s[i-shift];
return r;
}
/** @brief Vector extract
Scheme:
Return the s-th element of v.
Restriction: 0 <= s < nlanes
Usage:
@code
v_int32x4 a;
int r;
r = v_extract_n<2>(a);
@endcode
For all types. */
template<int s, typename _Tp, int n>
inline _Tp v_extract_n(const v_reg<_Tp, n>& v)
{
CV_DbgAssert(s >= 0 && s < n);
return v.s[s];
}
/** @brief Broadcast i-th element of vector
Scheme:
@code
{ v[0] v[1] v[2] ... v[SZ] } => { v[i], v[i], v[i] ... v[i] }
@endcode
Restriction: 0 <= i < nlanes
Supported types: 32-bit integers and floats (s32/u32/f32)
*/
template<int i, typename _Tp, int n>
inline v_reg<_Tp, n> v_broadcast_element(const v_reg<_Tp, n>& a)
{
CV_DbgAssert(i >= 0 && i < n);
return v_reg<_Tp, n>::all(a.s[i]);
}
/** @brief Round
Rounds each value. Input type is float vector ==> output type is int vector.*/
template<int n> inline v_reg<int, n> v_round(const v_reg<float, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = cvRound(a.s[i]);
return c;
}
/** @overload */
template<int n> inline v_reg<int, n*2> v_round(const v_reg<double, n>& a, const v_reg<double, n>& b)
{
v_reg<int, n*2> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = cvRound(a.s[i]);
c.s[i+n] = cvRound(b.s[i]);
}
return c;
}
/** @brief Floor
Floor each value. Input type is float vector ==> output type is int vector.*/
template<int n> inline v_reg<int, n> v_floor(const v_reg<float, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = cvFloor(a.s[i]);
return c;
}
/** @brief Ceil
Ceil each value. Input type is float vector ==> output type is int vector.*/
template<int n> inline v_reg<int, n> v_ceil(const v_reg<float, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = cvCeil(a.s[i]);
return c;
}
/** @brief Trunc
Truncate each value. Input type is float vector ==> output type is int vector.*/
template<int n> inline v_reg<int, n> v_trunc(const v_reg<float, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (int)(a.s[i]);
return c;
}
/** @overload */
template<int n> inline v_reg<int, n*2> v_round(const v_reg<double, n>& a)
{
v_reg<int, n*2> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = cvRound(a.s[i]);
c.s[i+n] = 0;
}
return c;
}
/** @overload */
template<int n> inline v_reg<int, n*2> v_floor(const v_reg<double, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = cvFloor(a.s[i]);
c.s[i+n] = 0;
}
return c;
}
/** @overload */
template<int n> inline v_reg<int, n*2> v_ceil(const v_reg<double, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = cvCeil(a.s[i]);
c.s[i+n] = 0;
}
return c;
}
/** @overload */
template<int n> inline v_reg<int, n*2> v_trunc(const v_reg<double, n>& a)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = cvCeil(a.s[i]);
c.s[i+n] = 0;
}
return c;
}
/** @brief Convert to float
Supported input type is cv::v_int32x4. */
template<int n> inline v_reg<float, n> v_cvt_f32(const v_reg<int, n>& a)
{
v_reg<float, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (float)a.s[i];
return c;
}
template<int n> inline v_reg<float, n*2> v_cvt_f32(const v_reg<double, n>& a)
{
v_reg<float, n*2> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = (float)a.s[i];
c.s[i+n] = 0;
}
return c;
}
template<int n> inline v_reg<float, n*2> v_cvt_f32(const v_reg<double, n>& a, const v_reg<double, n>& b)
{
v_reg<float, n*2> c;
for( int i = 0; i < n; i++ )
{
c.s[i] = (float)a.s[i];
c.s[i+n] = (float)b.s[i];
}
return c;
}
/** @brief Convert to double
Supported input type is cv::v_int32x4. */
CV_INLINE v_reg<double, 2> v_cvt_f64(const v_reg<int, 4>& a)
{
enum { n = 2 };
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (double)a.s[i];
return c;
}
/** @brief Convert to double high part of vector
Supported input type is cv::v_int32x4. */
CV_INLINE v_reg<double, 2> v_cvt_f64_high(const v_reg<int, 4>& a)
{
enum { n = 2 };
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (double)a.s[i + 2];
return c;
}
/** @brief Convert to double
Supported input type is cv::v_float32x4. */
CV_INLINE v_reg<double, 2> v_cvt_f64(const v_reg<float, 4>& a)
{
enum { n = 2 };
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (double)a.s[i];
return c;
}
/** @brief Convert to double high part of vector
Supported input type is cv::v_float32x4. */
CV_INLINE v_reg<double, 2> v_cvt_f64_high(const v_reg<float, 4>& a)
{
enum { n = 2 };
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (double)a.s[i + 2];
return c;
}
/** @brief Convert to double
Supported input type is cv::v_int64x2. */
CV_INLINE v_reg<double, 2> v_cvt_f64(const v_reg<int64, 2>& a)
{
enum { n = 2 };
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (double)a.s[i];
return c;
}
/** @brief Convert to double high part of vector
Supported input type is cv::v_int64x2. */
CV_INLINE v_reg<double, 2> v_cvt_f64_high(const v_reg<int64, 2>& a)
{
enum { n = 2 };
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = (double)a.s[i];
return c;
}
template<typename _Tp> inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut(const _Tp* tab, const int* idx)
{
v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c;
for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++)
c.s[i] = tab[idx[i]];
return c;
}
template<typename _Tp> inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_pairs(const _Tp* tab, const int* idx)
{
v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c;
for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++)
c.s[i] = tab[idx[i / 2] + i % 2];
return c;
}
template<typename _Tp> inline v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> v_lut_quads(const _Tp* tab, const int* idx)
{
v_reg<_Tp, V_TypeTraits<_Tp>::nlanes128> c;
for (int i = 0; i < V_TypeTraits<_Tp>::nlanes128; i++)
c.s[i] = tab[idx[i / 4] + i % 4];
return c;
}
template<int n> inline v_reg<int, n> v_lut(const int* tab, const v_reg<int, n>& idx)
{
v_reg<int, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = tab[idx.s[i]];
return c;
}
template<int n> inline v_reg<unsigned, n> v_lut(const unsigned* tab, const v_reg<int, n>& idx)
{
v_reg<int, n> c;
for (int i = 0; i < n; i++)
c.s[i] = tab[idx.s[i]];
return c;
}
template<int n> inline v_reg<float, n> v_lut(const float* tab, const v_reg<int, n>& idx)
{
v_reg<float, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = tab[idx.s[i]];
return c;
}
template<int n> inline v_reg<double, n> v_lut(const double* tab, const v_reg<int, n*2>& idx)
{
v_reg<double, n> c;
for( int i = 0; i < n; i++ )
c.s[i] = tab[idx.s[i]];
return c;
}
inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec)
{
return v_lut(tab, idxvec.s);
}
inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec)
{
return v_lut(tab, idxvec.s);
}
inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec)
{
return v_lut(tab, idxvec.s);
}
inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec)
{
return v_lut(tab, idxvec.s);
}
template<int n> inline void v_lut_deinterleave(const float* tab, const v_reg<int, n>& idx,
v_reg<float, n>& x, v_reg<float, n>& y)
{
for( int i = 0; i < n; i++ )
{
int j = idx.s[i];
x.s[i] = tab[j];
y.s[i] = tab[j+1];
}
}
template<int n> inline void v_lut_deinterleave(const double* tab, const v_reg<int, n*2>& idx,
v_reg<double, n>& x, v_reg<double, n>& y)
{
for( int i = 0; i < n; i++ )
{
int j = idx.s[i];
x.s[i] = tab[j];
y.s[i] = tab[j+1];
}
}
template<typename _Tp, int n> inline v_reg<_Tp, n> v_interleave_pairs(const v_reg<_Tp, n>& vec)
{
v_reg<_Tp, n> c;
for (int i = 0; i < n/4; i++)
{
c.s[4*i ] = vec.s[4*i ];
c.s[4*i+1] = vec.s[4*i+2];
c.s[4*i+2] = vec.s[4*i+1];
c.s[4*i+3] = vec.s[4*i+3];
}
return c;
}
template<typename _Tp, int n> inline v_reg<_Tp, n> v_interleave_quads(const v_reg<_Tp, n>& vec)
{
v_reg<_Tp, n> c;
for (int i = 0; i < n/8; i++)
{
c.s[8*i ] = vec.s[8*i ];
c.s[8*i+1] = vec.s[8*i+4];
c.s[8*i+2] = vec.s[8*i+1];
c.s[8*i+3] = vec.s[8*i+5];
c.s[8*i+4] = vec.s[8*i+2];
c.s[8*i+5] = vec.s[8*i+6];
c.s[8*i+6] = vec.s[8*i+3];
c.s[8*i+7] = vec.s[8*i+7];
}
return c;
}
template<typename _Tp, int n> inline v_reg<_Tp, n> v_pack_triplets(const v_reg<_Tp, n>& vec)
{
v_reg<_Tp, n> c;
for (int i = 0; i < n/4; i++)
{
c.s[3*i ] = vec.s[4*i ];
c.s[3*i+1] = vec.s[4*i+1];
c.s[3*i+2] = vec.s[4*i+2];
}
return c;
}
/** @brief Transpose 4x4 matrix
Scheme:
@code
a0 {A1 A2 A3 A4}
a1 {B1 B2 B3 B4}
a2 {C1 C2 C3 C4}
a3 {D1 D2 D3 D4}
===============
b0 {A1 B1 C1 D1}
b1 {A2 B2 C2 D2}
b2 {A3 B3 C3 D3}
b3 {A4 B4 C4 D4}
@endcode
*/
template<typename _Tp>
inline void v_transpose4x4( v_reg<_Tp, 4>& a0, const v_reg<_Tp, 4>& a1,
const v_reg<_Tp, 4>& a2, const v_reg<_Tp, 4>& a3,
v_reg<_Tp, 4>& b0, v_reg<_Tp, 4>& b1,
v_reg<_Tp, 4>& b2, v_reg<_Tp, 4>& b3 )
{
b0 = v_reg<_Tp, 4>(a0.s[0], a1.s[0], a2.s[0], a3.s[0]);
b1 = v_reg<_Tp, 4>(a0.s[1], a1.s[1], a2.s[1], a3.s[1]);
b2 = v_reg<_Tp, 4>(a0.s[2], a1.s[2], a2.s[2], a3.s[2]);
b3 = v_reg<_Tp, 4>(a0.s[3], a1.s[3], a2.s[3], a3.s[3]);
}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_INIT_ZERO(_Tpvec, _Tp, suffix) \
inline _Tpvec v_setzero_##suffix() { return _Tpvec::zero(); }
//! @name Init with zero
//! @{
//! @brief Create new vector with zero elements
OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint8x16, uchar, u8)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_int8x16, schar, s8)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint16x8, ushort, u16)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_int16x8, short, s16)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint32x4, unsigned, u32)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_int32x4, int, s32)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_float32x4, float, f32)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_float64x2, double, f64)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_uint64x2, uint64, u64)
OPENCV_HAL_IMPL_C_INIT_ZERO(v_int64x2, int64, s64)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_INIT_VAL(_Tpvec, _Tp, suffix) \
inline _Tpvec v_setall_##suffix(_Tp val) { return _Tpvec::all(val); }
//! @name Init with value
//! @{
//! @brief Create new vector with elements set to a specific value
OPENCV_HAL_IMPL_C_INIT_VAL(v_uint8x16, uchar, u8)
OPENCV_HAL_IMPL_C_INIT_VAL(v_int8x16, schar, s8)
OPENCV_HAL_IMPL_C_INIT_VAL(v_uint16x8, ushort, u16)
OPENCV_HAL_IMPL_C_INIT_VAL(v_int16x8, short, s16)
OPENCV_HAL_IMPL_C_INIT_VAL(v_uint32x4, unsigned, u32)
OPENCV_HAL_IMPL_C_INIT_VAL(v_int32x4, int, s32)
OPENCV_HAL_IMPL_C_INIT_VAL(v_float32x4, float, f32)
OPENCV_HAL_IMPL_C_INIT_VAL(v_float64x2, double, f64)
OPENCV_HAL_IMPL_C_INIT_VAL(v_uint64x2, uint64, u64)
OPENCV_HAL_IMPL_C_INIT_VAL(v_int64x2, int64, s64)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_REINTERPRET(_Tpvec, _Tp, suffix) \
template<typename _Tp0, int n0> inline _Tpvec \
v_reinterpret_as_##suffix(const v_reg<_Tp0, n0>& a) \
{ return a.template reinterpret_as<_Tp, _Tpvec::nlanes>(); }
//! @name Reinterpret
//! @{
//! @brief Convert vector to different type without modifying underlying data.
OPENCV_HAL_IMPL_C_REINTERPRET(v_uint8x16, uchar, u8)
OPENCV_HAL_IMPL_C_REINTERPRET(v_int8x16, schar, s8)
OPENCV_HAL_IMPL_C_REINTERPRET(v_uint16x8, ushort, u16)
OPENCV_HAL_IMPL_C_REINTERPRET(v_int16x8, short, s16)
OPENCV_HAL_IMPL_C_REINTERPRET(v_uint32x4, unsigned, u32)
OPENCV_HAL_IMPL_C_REINTERPRET(v_int32x4, int, s32)
OPENCV_HAL_IMPL_C_REINTERPRET(v_float32x4, float, f32)
OPENCV_HAL_IMPL_C_REINTERPRET(v_float64x2, double, f64)
OPENCV_HAL_IMPL_C_REINTERPRET(v_uint64x2, uint64, u64)
OPENCV_HAL_IMPL_C_REINTERPRET(v_int64x2, int64, s64)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_SHIFTL(_Tpvec, _Tp) \
template<int n> inline _Tpvec v_shl(const _Tpvec& a) \
{ return a << n; }
//! @name Left shift
//! @{
//! @brief Shift left
OPENCV_HAL_IMPL_C_SHIFTL(v_uint16x8, ushort)
OPENCV_HAL_IMPL_C_SHIFTL(v_int16x8, short)
OPENCV_HAL_IMPL_C_SHIFTL(v_uint32x4, unsigned)
OPENCV_HAL_IMPL_C_SHIFTL(v_int32x4, int)
OPENCV_HAL_IMPL_C_SHIFTL(v_uint64x2, uint64)
OPENCV_HAL_IMPL_C_SHIFTL(v_int64x2, int64)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_SHIFTR(_Tpvec, _Tp) \
template<int n> inline _Tpvec v_shr(const _Tpvec& a) \
{ return a >> n; }
//! @name Right shift
//! @{
//! @brief Shift right
OPENCV_HAL_IMPL_C_SHIFTR(v_uint16x8, ushort)
OPENCV_HAL_IMPL_C_SHIFTR(v_int16x8, short)
OPENCV_HAL_IMPL_C_SHIFTR(v_uint32x4, unsigned)
OPENCV_HAL_IMPL_C_SHIFTR(v_int32x4, int)
OPENCV_HAL_IMPL_C_SHIFTR(v_uint64x2, uint64)
OPENCV_HAL_IMPL_C_SHIFTR(v_int64x2, int64)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_RSHIFTR(_Tpvec, _Tp) \
template<int n> inline _Tpvec v_rshr(const _Tpvec& a) \
{ \
_Tpvec c; \
for( int i = 0; i < _Tpvec::nlanes; i++ ) \
c.s[i] = (_Tp)((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \
return c; \
}
//! @name Rounding shift
//! @{
//! @brief Rounding shift right
OPENCV_HAL_IMPL_C_RSHIFTR(v_uint16x8, ushort)
OPENCV_HAL_IMPL_C_RSHIFTR(v_int16x8, short)
OPENCV_HAL_IMPL_C_RSHIFTR(v_uint32x4, unsigned)
OPENCV_HAL_IMPL_C_RSHIFTR(v_int32x4, int)
OPENCV_HAL_IMPL_C_RSHIFTR(v_uint64x2, uint64)
OPENCV_HAL_IMPL_C_RSHIFTR(v_int64x2, int64)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_PACK(_Tpvec, _Tpnvec, _Tpn, pack_suffix, cast) \
inline _Tpnvec v_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \
{ \
_Tpnvec c; \
for( int i = 0; i < _Tpvec::nlanes; i++ ) \
{ \
c.s[i] = cast<_Tpn>(a.s[i]); \
c.s[i+_Tpvec::nlanes] = cast<_Tpn>(b.s[i]); \
} \
return c; \
}
//! @name Pack
//! @{
//! @brief Pack values from two vectors to one
//!
//! Return vector type have twice more elements than input vector types. Variant with _u_ suffix also
//! converts to corresponding unsigned type.
//!
//! - pack: for 16-, 32- and 64-bit integer input types
//! - pack_u: for 16- and 32-bit signed integer input types
//!
//! @note All variants except 64-bit use saturation.
OPENCV_HAL_IMPL_C_PACK(v_uint16x8, v_uint8x16, uchar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_int8x16, schar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK(v_uint32x4, v_uint16x8, ushort, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_int16x8, short, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK(v_uint64x2, v_uint32x4, unsigned, pack, static_cast)
OPENCV_HAL_IMPL_C_PACK(v_int64x2, v_int32x4, int, pack, static_cast)
OPENCV_HAL_IMPL_C_PACK(v_int16x8, v_uint8x16, uchar, pack_u, saturate_cast)
OPENCV_HAL_IMPL_C_PACK(v_int32x4, v_uint16x8, ushort, pack_u, saturate_cast)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_RSHR_PACK(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \
template<int n> inline _Tpnvec v_rshr_##pack_suffix(const _Tpvec& a, const _Tpvec& b) \
{ \
_Tpnvec c; \
for( int i = 0; i < _Tpvec::nlanes; i++ ) \
{ \
c.s[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \
c.s[i+_Tpvec::nlanes] = cast<_Tpn>((b.s[i] + ((_Tp)1 << (n - 1))) >> n); \
} \
return c; \
}
//! @name Pack with rounding shift
//! @{
//! @brief Pack values from two vectors to one with rounding shift
//!
//! Values from the input vectors will be shifted right by _n_ bits with rounding, converted to narrower
//! type and returned in the result vector. Variant with _u_ suffix converts to unsigned type.
//!
//! - pack: for 16-, 32- and 64-bit integer input types
//! - pack_u: for 16- and 32-bit signed integer input types
//!
//! @note All variants except 64-bit use saturation.
OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_int8x16, schar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_int16x8, short, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_int64x2, int64, v_int32x4, int, pack, static_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \
inline void v_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \
{ \
for( int i = 0; i < _Tpvec::nlanes; i++ ) \
ptr[i] = cast<_Tpn>(a.s[i]); \
}
//! @name Pack and store
//! @{
//! @brief Store values from the input vector into memory with pack
//!
//! Values will be stored into memory with conversion to narrower type.
//! Variant with _u_ suffix converts to corresponding unsigned type.
//!
//! - pack: for 16-, 32- and 64-bit integer input types
//! - pack_u: for 16- and 32-bit signed integer input types
//!
//! @note All variants except 64-bit use saturation.
OPENCV_HAL_IMPL_C_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast)
OPENCV_HAL_IMPL_C_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast)
//! @}
//! @brief Helper macro
//! @ingroup core_hal_intrin_impl
#define OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(_Tpvec, _Tp, _Tpnvec, _Tpn, pack_suffix, cast) \
template<int n> inline void v_rshr_##pack_suffix##_store(_Tpn* ptr, const _Tpvec& a) \
{ \
for( int i = 0; i < _Tpvec::nlanes; i++ ) \
ptr[i] = cast<_Tpn>((a.s[i] + ((_Tp)1 << (n - 1))) >> n); \
}
//! @name Pack and store with rounding shift
//! @{
//! @brief Store values from the input vector into memory with pack
//!
//! Values will be shifted _n_ bits right with rounding, converted to narrower type and stored into
//! memory. Variant with _u_ suffix converts to unsigned type.
//!
//! - pack: for 16-, 32- and 64-bit integer input types
//! - pack_u: for 16- and 32-bit signed integer input types
//!
//! @note All variants except 64-bit use saturation.
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint16x8, ushort, v_uint8x16, uchar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_int8x16, schar, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint32x4, unsigned, v_uint16x8, ushort, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_int16x8, short, pack, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_uint64x2, uint64, v_uint32x4, unsigned, pack, static_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int64x2, int64, v_int32x4, int, pack, static_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int16x8, short, v_uint8x16, uchar, pack_u, saturate_cast)
OPENCV_HAL_IMPL_C_RSHR_PACK_STORE(v_int32x4, int, v_uint16x8, ushort, pack_u, saturate_cast)
//! @}
//! @cond IGNORED
template<typename _Tpm, typename _Tp, int n>
inline void _pack_b(_Tpm* mptr, const v_reg<_Tp, n>& a, const v_reg<_Tp, n>& b)
{
for (int i = 0; i < n; ++i)
{
mptr[i] = (_Tpm)a.s[i];
mptr[i + n] = (_Tpm)b.s[i];
}
}
//! @endcond
//! @name Pack boolean values
//! @{
//! @brief Pack boolean values from multiple vectors to one unsigned 8-bit integer vector
//!
//! @note Must provide valid boolean values to guarantee same result for all architectures.
/** @brief
//! For 16-bit boolean values
Scheme:
@code
a {0xFFFF 0 0 0xFFFF 0 0xFFFF 0xFFFF 0}
b {0xFFFF 0 0xFFFF 0 0 0xFFFF 0 0xFFFF}
===============
{
0xFF 0 0 0xFF 0 0xFF 0xFF 0
0xFF 0 0xFF 0 0 0xFF 0 0xFF
}
@endcode */
inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b)
{
v_uint8x16 mask;
_pack_b(mask.s, a, b);
return mask;
}
/** @overload
For 32-bit boolean values
Scheme:
@code
a {0xFFFF.. 0 0 0xFFFF..}
b {0 0xFFFF.. 0xFFFF.. 0}
c {0xFFFF.. 0 0xFFFF.. 0}
d {0 0xFFFF.. 0 0xFFFF..}
===============
{
0xFF 0 0 0xFF 0 0xFF 0xFF 0
0xFF 0 0xFF 0 0 0xFF 0 0xFF
}
@endcode */
inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b,
const v_uint32x4& c, const v_uint32x4& d)
{
v_uint8x16 mask;
_pack_b(mask.s, a, b);
_pack_b(mask.s + 8, c, d);
return mask;
}
/** @overload
For 64-bit boolean values
Scheme:
@code
a {0xFFFF.. 0}
b {0 0xFFFF..}
c {0xFFFF.. 0}
d {0 0xFFFF..}
e {0xFFFF.. 0}
f {0xFFFF.. 0}
g {0 0xFFFF..}
h {0 0xFFFF..}
===============
{
0xFF 0 0 0xFF 0xFF 0 0 0xFF
0xFF 0 0xFF 0 0 0xFF 0 0xFF
}
@endcode */
inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c,
const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f,
const v_uint64x2& g, const v_uint64x2& h)
{
v_uint8x16 mask;
_pack_b(mask.s, a, b);
_pack_b(mask.s + 4, c, d);
_pack_b(mask.s + 8, e, f);
_pack_b(mask.s + 12, g, h);
return mask;
}
//! @}
/** @brief Matrix multiplication
Scheme:
@code
{A0 A1 A2 A3} |V0|
{B0 B1 B2 B3} |V1|
{C0 C1 C2 C3} |V2|
{D0 D1 D2 D3} x |V3|
====================
{R0 R1 R2 R3}, where:
R0 = A0V0 + A1V1 + A2V2 + A3V3,
R1 = B0V0 + B1V1 + B2V2 + B3V3
...
@endcode
*/
inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0,
const v_float32x4& m1, const v_float32x4& m2,
const v_float32x4& m3)
{
return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + v.s[3]*m3.s[0],
v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + v.s[3]*m3.s[1],
v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + v.s[3]*m3.s[2],
v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + v.s[3]*m3.s[3]);
}
/** @brief Matrix multiplication and add
Scheme:
@code
{A0 A1 A2 } |V0| |D0|
{B0 B1 B2 } |V1| |D1|
{C0 C1 C2 } x |V2| + |D2|
====================
{R0 R1 R2 R3}, where:
R0 = A0V0 + A1V1 + A2V2 + D0,
R1 = B0V0 + B1V1 + B2V2 + D1
...
@endcode
*/
inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0,
const v_float32x4& m1, const v_float32x4& m2,
const v_float32x4& m3)
{
return v_float32x4(v.s[0]*m0.s[0] + v.s[1]*m1.s[0] + v.s[2]*m2.s[0] + m3.s[0],
v.s[0]*m0.s[1] + v.s[1]*m1.s[1] + v.s[2]*m2.s[1] + m3.s[1],
v.s[0]*m0.s[2] + v.s[1]*m1.s[2] + v.s[2]*m2.s[2] + m3.s[2],
v.s[0]*m0.s[3] + v.s[1]*m1.s[3] + v.s[2]*m2.s[3] + m3.s[3]);
}
inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b)
{ return v_fma(v_cvt_f64(a), v_cvt_f64(b), v_cvt_f64_high(a) * v_cvt_f64_high(b)); }
inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c)
{ return v_fma(v_cvt_f64(a), v_cvt_f64(b), v_fma(v_cvt_f64_high(a), v_cvt_f64_high(b), c)); }
inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b)
{ return v_dotprod_expand(a, b); }
inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c)
{ return v_dotprod_expand(a, b, c); }
////// FP16 support ///////
inline v_reg<float, V_TypeTraits<float>::nlanes128>
v_load_expand(const float16_t* ptr)
{
v_reg<float, V_TypeTraits<float>::nlanes128> v;
for( int i = 0; i < v.nlanes; i++ )
{
v.s[i] = ptr[i];
}
return v;
}
inline void
v_pack_store(float16_t* ptr, const v_reg<float, V_TypeTraits<float>::nlanes128>& v)
{
for( int i = 0; i < v.nlanes; i++ )
{
ptr[i] = float16_t(v.s[i]);
}
}
inline void v_cleanup() {}
//! @}
#ifndef CV_DOXYGEN
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
#endif
}
#endif
| 83,374 | intrin_cpp | hpp | en | cpp | code | {"qsc_code_num_words": 14555, "qsc_code_num_chars": 83374.0, "qsc_code_mean_word_length": 3.30285125, "qsc_code_frac_words_unique": 0.05400206, "qsc_code_frac_chars_top_2grams": 0.03669419, "qsc_code_frac_chars_top_3grams": 0.03245065, "qsc_code_frac_chars_top_4grams": 0.03319951, "qsc_code_frac_chars_dupe_5grams": 0.73219895, "qsc_code_frac_chars_dupe_6grams": 0.68689285, "qsc_code_frac_chars_dupe_7grams": 0.6409627, "qsc_code_frac_chars_dupe_8grams": 0.59998336, "qsc_code_frac_chars_dupe_9grams": 0.5722963, "qsc_code_frac_chars_dupe_10grams": 0.53483244, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.04559454, "qsc_code_frac_chars_whitespace": 0.22502219, "qsc_code_size_file_byte": 83374.0, "qsc_code_num_lines": 2781.0, "qsc_code_num_chars_line_max": 170.0, "qsc_code_num_chars_line_mean": 29.97986336, "qsc_code_frac_chars_alphabet": 0.69841982, "qsc_code_frac_chars_comments": 0.37965073, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.37113402, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00048336, "qsc_code_frac_chars_long_word_length": 0.00048336, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00035958, "qsc_code_frac_lines_assert": 0.01580756, "qsc_codecpp_frac_lines_preprocessor_directives": null, "qsc_codecpp_frac_lines_func_ratio": 0.08178694, "qsc_codecpp_cate_bitsstdc": 0.0, "qsc_codecpp_nums_lines_main": 0.0, "qsc_codecpp_frac_lines_goto": 0.0, "qsc_codecpp_cate_var_zero": 0.0, "qsc_codecpp_score_lines_no_logic": 0.13745704, "qsc_codecpp_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codecpp_frac_lines_func_ratio": 0, "qsc_codecpp_nums_lines_main": 0, "qsc_codecpp_score_lines_no_logic": 0, "qsc_codecpp_frac_lines_preprocessor_directives": 0, "qsc_codecpp_frac_lines_print": 0} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/opencl/ocl_defs.hpp | // This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
#ifndef OPENCV_CORE_OPENCL_DEFS_HPP
#define OPENCV_CORE_OPENCL_DEFS_HPP
#include "opencv2/core/utility.hpp"
#include "cvconfig.h"
namespace cv { namespace ocl {
#ifdef HAVE_OPENCL
/// Call is similar to useOpenCL() but doesn't try to load OpenCL runtime or create OpenCL context
CV_EXPORTS bool isOpenCLActivated();
#else
static inline bool isOpenCLActivated() { return false; }
#endif
}} // namespace
//#define CV_OPENCL_RUN_ASSERT
#ifdef HAVE_OPENCL
#ifdef CV_OPENCL_RUN_VERBOSE
#define CV_OCL_RUN_(condition, func, ...) \
{ \
if (cv::ocl::isOpenCLActivated() && (condition) && func) \
{ \
printf("%s: OpenCL implementation is running\n", CV_Func); \
fflush(stdout); \
CV_IMPL_ADD(CV_IMPL_OCL); \
return __VA_ARGS__; \
} \
else \
{ \
printf("%s: Plain implementation is running\n", CV_Func); \
fflush(stdout); \
} \
}
#elif defined CV_OPENCL_RUN_ASSERT
#define CV_OCL_RUN_(condition, func, ...) \
{ \
if (cv::ocl::isOpenCLActivated() && (condition)) \
{ \
if(func) \
{ \
CV_IMPL_ADD(CV_IMPL_OCL); \
} \
else \
{ \
CV_Error(cv::Error::StsAssert, #func); \
} \
return __VA_ARGS__; \
} \
}
#else
#define CV_OCL_RUN_(condition, func, ...) \
try \
{ \
if (cv::ocl::isOpenCLActivated() && (condition) && func) \
{ \
CV_IMPL_ADD(CV_IMPL_OCL); \
return __VA_ARGS__; \
} \
} \
catch (const cv::Exception& e) \
{ \
CV_UNUSED(e); /* TODO: Add some logging here */ \
}
#endif
#else
#define CV_OCL_RUN_(condition, func, ...)
#endif
#define CV_OCL_RUN(condition, func) CV_OCL_RUN_(condition, func)
#endif // OPENCV_CORE_OPENCL_DEFS_HPP
| 3,734 | ocl_defs | hpp | en | cpp | code | {"qsc_code_num_words": 264, "qsc_code_num_chars": 3734.0, "qsc_code_mean_word_length": 4.76136364, "qsc_code_frac_words_unique": 0.41666667, "qsc_code_frac_chars_top_2grams": 0.03579952, "qsc_code_frac_chars_top_3grams": 0.03818616, "qsc_code_frac_chars_top_4grams": 0.08114558, "qsc_code_frac_chars_dupe_5grams": 0.41050119, "qsc_code_frac_chars_dupe_6grams": 0.35560859, "qsc_code_frac_chars_dupe_7grams": 0.28003182, "qsc_code_frac_chars_dupe_8grams": 0.21002387, "qsc_code_frac_chars_dupe_9grams": 0.14319809, "qsc_code_frac_chars_dupe_10grams": 0.09546539, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00311915, "qsc_code_frac_chars_whitespace": 0.57070166, "qsc_code_size_file_byte": 3734.0, "qsc_code_num_lines": 82.0, "qsc_code_num_chars_line_max": 99.0, "qsc_code_num_chars_line_mean": 45.53658537, "qsc_code_frac_chars_alphabet": 0.78103556, "qsc_code_frac_chars_comments": 0.14515265, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.640625, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.03414787, "qsc_code_frac_chars_long_word_length": 0.0075188, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.01219512, "qsc_code_frac_lines_assert": 0.03125, "qsc_codecpp_frac_lines_preprocessor_directives": null, "qsc_codecpp_frac_lines_func_ratio": 0.109375, "qsc_codecpp_cate_bitsstdc": 0.0, "qsc_codecpp_nums_lines_main": 0.0, "qsc_codecpp_frac_lines_goto": 0.0, "qsc_codecpp_cate_var_zero": 0.0, "qsc_codecpp_score_lines_no_logic": 0.140625, "qsc_codecpp_frac_lines_print": 0.03125} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 1, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 1, "qsc_code_frac_lines_assert": 0, "qsc_codecpp_frac_lines_func_ratio": 0, "qsc_codecpp_nums_lines_main": 0, "qsc_codecpp_score_lines_no_logic": 0, "qsc_codecpp_frac_lines_preprocessor_directives": 0, "qsc_codecpp_frac_lines_print": 0} |
00Julian00/Nova2 | examples/3. Context and Transcriptor.ipynb/3.3 The transcriptor.ipynb | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3.3 The transcriptor"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The transcriptor is a built in system that can read an audio stream from the microphone and transcribe speech into text using OpenAI's [Whisper](https://github.com/openai/whisper). It also generates speaker embeddings which are high dimensional vectors that represent the voice of a speaker which can be used to differentiate between multiple speakers. The transcriptor used in Nova is a slightly modified version of my [Voice Analysis Toolkit](https://github.com/00Julian00/Voice-Analysis-Toolkit). This notebook will show you how to use the transcriptor and how to connect it to the context system."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run this code so python can find the scripts. This is not required when importing Nova from outside the root folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"nova_path = Path().absolute().parent.parent.parent\n",
"if str(nova_path) not in sys.path:\n",
" sys.path.insert(0, str(nova_path))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from nova import *\n",
"\n",
"nova = Nova()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Setting up the transcriptor mirrors how the LLM and TTS system is set up, except that you only need a conditioning object and no inference engine:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"conditioning = TranscriptorConditioning(\n",
" microphone_index=0\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make sure you pass the correct microphone index of the device you intend to use. You can find a list of all microphones and their indices by using the \"sounddevice\" library (which you should already have installed if you installed the requirements):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sounddevice as sd\n",
"\n",
"sd.query_devices()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As always, configure the transcriptor and apply the configuration:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nova.configure_transcriptor(conditioning=conditioning)\n",
"\n",
"nova.apply_config_transcriptor()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now want to start the transcriptor. This will give us a \"ContextGenerator\" object which is essentially a wrapper for all systems that continuously yield context data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"context_generator = nova.start_transcriptor()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To automatically add the yielded context data to the context, we need to bind the context generator to the context system."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nova.bind_context_source(source=context_generator)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now all of the data produced by the transcriptor will automatically be added to the context. \n",
"Additionally, any voices the transcriptor encounters will be stored in a database as a voice embedding. They will initially be represented as \"UnknownVoiceX\" in the context, but the LLM can rename the voice if it learns your name. Note that this is only possible if default tools are loaded."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Additional parameters of \"TranscriptorConditoning\":"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- model: Which whisper model to use. You can find all available models [here](https://github.com/openai/whisper?tab=readme-ov-file#available-models-and-languages)\n",
"- device: Choose between \"cuda\" and \"cpu\".\n",
"- voice_boost: How much the speech's volume should be boosted compared to other sounds in the audio data whisper receives. Can be useful in noisy environments.\n",
"- language: Must be a valid language code or \"None\". Force whisper to interpret the speech in a certain language. Can improve results if you are only talking in one language. Set to \"None\" to let whisper automatically determine the spoken language.\n",
"- vad_threshold: The threshold the voice-activity-detection system needs to surpass in its evaluation whether an audio chunk contains speech."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
| 5,563 | 3.3 The transcriptor | ipynb | en | jupyter notebook | excluded | {} | 0 | {} |
00Julian00/Nova2 | examples/3. Context and Transcriptor.ipynb/3.1 Context datapoints.ipynb | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3.1 The Context system"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Nova has a built in context management system. It stores recorded data from several different sources together with additional metadata. This can then be fed into the LLM. You can use this to give the LLM as much information as possible, as well as help it understand where particular information came from. This notebook shows you the basics of how the context system works."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run this code so python can find the scripts. This is not required when importing Nova from outside the root folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"nova_path = Path().absolute().parent.parent.parent\n",
"if str(nova_path) not in sys.path:\n",
" sys.path.insert(0, str(nova_path))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from nova import *\n",
"\n",
"nova = Nova()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before we hook other systems up to the context system, let's first add our custom data to the context. The context consists of a list of \"ContextDatapoint\" objects. A datapoint contains the source of the information (together with source specific metadata), the content and a timestamp."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"datapoint = ContextDatapoint(\n",
" source=ContextSource_User(), # ContextSource_User has no additional metadata\n",
" content=\"This is our custom datapoint.\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The timestamp will be saved automatically. We can now add this datapoint to the context."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nova.add_datapoint_to_context(datapoint=datapoint)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The context is stored as json. This is how our datapoint looks when stored:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"{\n",
" \"source\": {\n",
" \"type\": \"ContextSource_User\"\n",
" },\n",
" \"content\": \"This is our custom datapoint.\",\n",
" \"timestamp\": \"2025-03-14T14:36:45\"\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Because the context is stored in a file, you still have access to it even after restarting Nova."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
| 3,406 | 3.1 Context datapoints | ipynb | en | jupyter notebook | excluded | {} | 0 | {} |
00Julian00/Nova2 | examples/3. Context and Transcriptor.ipynb/3.2 Modifying context.ipynb | {
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3.2 Modifying the context data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run this code so python can find the scripts. This is not required when importing Nova from outside the root folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from pathlib import Path\n",
"nova_path = Path().absolute().parent.parent.parent\n",
"if str(nova_path) not in sys.path:\n",
" sys.path.insert(0, str(nova_path))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from nova import *\n",
"\n",
"nova = Nova()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The whole context can be accessed via the \"Context\" object."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"context = nova.get_context()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Context object contains a list of datapoints, as well as a method to convert the context to a Conversation object. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"conversation = context.to_conversation()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can now freely modify the context data. Overwrite the stored context data like this:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nova.set_context(context=context)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
| 2,045 | 3.2 Modifying context | ipynb | en | jupyter notebook | excluded | {} | 0 | {} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/opencl/opencl_svm.hpp | /* See LICENSE file in the root OpenCV directory */
#ifndef OPENCV_CORE_OPENCL_SVM_HPP
#define OPENCV_CORE_OPENCL_SVM_HPP
//
// Internal usage only (binary compatibility is not guaranteed)
//
#ifndef __OPENCV_BUILD
#error Internal header file
#endif
#if defined(HAVE_OPENCL) && defined(HAVE_OPENCL_SVM)
#include "runtime/opencl_core.hpp"
#include "runtime/opencl_svm_20.hpp"
#include "runtime/opencl_svm_hsa_extension.hpp"
namespace cv { namespace ocl { namespace svm {
struct SVMCapabilities
{
enum Value
{
SVM_COARSE_GRAIN_BUFFER = (1 << 0),
SVM_FINE_GRAIN_BUFFER = (1 << 1),
SVM_FINE_GRAIN_SYSTEM = (1 << 2),
SVM_ATOMICS = (1 << 3),
};
int value_;
SVMCapabilities(int capabilities = 0) : value_(capabilities) { }
operator int() const { return value_; }
inline bool isNoSVMSupport() const { return value_ == 0; }
inline bool isSupportCoarseGrainBuffer() const { return (value_ & SVM_COARSE_GRAIN_BUFFER) != 0; }
inline bool isSupportFineGrainBuffer() const { return (value_ & SVM_FINE_GRAIN_BUFFER) != 0; }
inline bool isSupportFineGrainSystem() const { return (value_ & SVM_FINE_GRAIN_SYSTEM) != 0; }
inline bool isSupportAtomics() const { return (value_ & SVM_ATOMICS) != 0; }
};
CV_EXPORTS const SVMCapabilities getSVMCapabilitites(const ocl::Context& context);
struct SVMFunctions
{
clSVMAllocAMD_fn fn_clSVMAlloc;
clSVMFreeAMD_fn fn_clSVMFree;
clSetKernelArgSVMPointerAMD_fn fn_clSetKernelArgSVMPointer;
//clSetKernelExecInfoAMD_fn fn_clSetKernelExecInfo;
//clEnqueueSVMFreeAMD_fn fn_clEnqueueSVMFree;
clEnqueueSVMMemcpyAMD_fn fn_clEnqueueSVMMemcpy;
clEnqueueSVMMemFillAMD_fn fn_clEnqueueSVMMemFill;
clEnqueueSVMMapAMD_fn fn_clEnqueueSVMMap;
clEnqueueSVMUnmapAMD_fn fn_clEnqueueSVMUnmap;
inline SVMFunctions()
: fn_clSVMAlloc(NULL), fn_clSVMFree(NULL),
fn_clSetKernelArgSVMPointer(NULL), /*fn_clSetKernelExecInfo(NULL),*/
/*fn_clEnqueueSVMFree(NULL),*/ fn_clEnqueueSVMMemcpy(NULL), fn_clEnqueueSVMMemFill(NULL),
fn_clEnqueueSVMMap(NULL), fn_clEnqueueSVMUnmap(NULL)
{
// nothing
}
inline bool isValid() const
{
return fn_clSVMAlloc != NULL && fn_clSVMFree && fn_clSetKernelArgSVMPointer &&
/*fn_clSetKernelExecInfo && fn_clEnqueueSVMFree &&*/ fn_clEnqueueSVMMemcpy &&
fn_clEnqueueSVMMemFill && fn_clEnqueueSVMMap && fn_clEnqueueSVMUnmap;
}
};
// We should guarantee that SVMFunctions lifetime is not less than context's lifetime
CV_EXPORTS const SVMFunctions* getSVMFunctions(const ocl::Context& context);
CV_EXPORTS bool useSVM(UMatUsageFlags usageFlags);
}}} //namespace cv::ocl::svm
#endif
#endif // OPENCV_CORE_OPENCL_SVM_HPP
/* End of file. */
| 2,792 | opencl_svm | hpp | en | cpp | code | {"qsc_code_num_words": 299, "qsc_code_num_chars": 2792.0, "qsc_code_mean_word_length": 6.52508361, "qsc_code_frac_words_unique": 0.34448161, "qsc_code_frac_chars_top_2grams": 0.01845208, "qsc_code_frac_chars_top_3grams": 0.04920554, "qsc_code_frac_chars_top_4grams": 0.03895438, "qsc_code_frac_chars_dupe_5grams": 0.15684264, "qsc_code_frac_chars_dupe_6grams": 0.02870323, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00696864, "qsc_code_frac_chars_whitespace": 0.17765043, "qsc_code_size_file_byte": 2792.0, "qsc_code_num_lines": 81.0, "qsc_code_num_chars_line_max": 103.0, "qsc_code_num_chars_line_mean": 34.4691358, "qsc_code_frac_chars_alphabet": 0.84277003, "qsc_code_frac_chars_comments": 0.18051576, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.08928571, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.03671329, "qsc_code_frac_chars_long_word_length": 0.03671329, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codecpp_frac_lines_preprocessor_directives": null, "qsc_codecpp_frac_lines_func_ratio": 0.21428571, "qsc_codecpp_cate_bitsstdc": 0.0, "qsc_codecpp_nums_lines_main": 0.0, "qsc_codecpp_frac_lines_goto": 0.0, "qsc_codecpp_cate_var_zero": 0.0, "qsc_codecpp_score_lines_no_logic": 0.28571429, "qsc_codecpp_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codecpp_frac_lines_func_ratio": 1, "qsc_codecpp_nums_lines_main": 0, "qsc_codecpp_score_lines_no_logic": 0, "qsc_codecpp_frac_lines_preprocessor_directives": 0, "qsc_codecpp_frac_lines_print": 0} |
00Julian00/Nova2 | tools/internal_rename_voices/main.py | from Nova2.tool_api import ToolBaseClass
from Nova2.app import database_manager, context_manager
from Nova2.app import api_tools
class Main(ToolBaseClass):
def on_startup(self):
self._db = database_manager.VoiceDatabaseManager()
self._api = api_tools.ToolAPI()
self._context = context_manager.ContextManager()
@ToolBaseClass.tool
def rename_voice(self, current_name: str, new_name: str) -> None:
"""
By default, a new voice is called UnknownVoiceX. When the name of the speaker becomes known,
this tool can be used to rename the voice in the context and the database.
Arguments:
current_name (str): The current name of the voice.
new_name (str): What the voice should be renamed to.
"""
if not self._db.edit_voice_name(current_name, new_name):
self._api.add_to_context(name="Rename voice", content=f"Voice {current_name} does not exist in the database.", tool_call_id=self._tool_call_id) # type: ignore
else:
self._api.add_to_context(name="Rename voice", content=f"{current_name} was renamed to {new_name}.", tool_call_id=self._tool_call_id) # type: ignore
self._context.rename_voice(old_name=current_name, new_name=new_name) | 1,278 | main | py | en | python | code | {"qsc_code_num_words": 184, "qsc_code_num_chars": 1278.0, "qsc_code_mean_word_length": 4.63586957, "qsc_code_frac_words_unique": 0.35869565, "qsc_code_frac_chars_top_2grams": 0.09026964, "qsc_code_frac_chars_top_3grams": 0.04689332, "qsc_code_frac_chars_top_4grams": 0.04220399, "qsc_code_frac_chars_dupe_5grams": 0.22977726, "qsc_code_frac_chars_dupe_6grams": 0.17819461, "qsc_code_frac_chars_dupe_7grams": 0.17819461, "qsc_code_frac_chars_dupe_8grams": 0.17819461, "qsc_code_frac_chars_dupe_9grams": 0.17819461, "qsc_code_frac_chars_dupe_10grams": 0.09847597, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00297619, "qsc_code_frac_chars_whitespace": 0.21126761, "qsc_code_size_file_byte": 1278.0, "qsc_code_num_lines": 27.0, "qsc_code_num_chars_line_max": 171.0, "qsc_code_num_chars_line_mean": 47.33333333, "qsc_code_frac_chars_alphabet": 0.84325397, "qsc_code_frac_chars_comments": 0.24882629, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.12942478, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.13333333, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.2, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.4, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | gradlew | #!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
| 4,717 | gradlew | en | shell | code | {"qsc_code_num_words": 678, "qsc_code_num_chars": 4717.0, "qsc_code_mean_word_length": 4.21681416, "qsc_code_frac_words_unique": 0.33480826, "qsc_code_frac_chars_top_2grams": 0.03357817, "qsc_code_frac_chars_top_3grams": 0.03637636, "qsc_code_frac_chars_top_4grams": 0.04407135, "qsc_code_frac_chars_dupe_5grams": 0.17978314, "qsc_code_frac_chars_dupe_6grams": 0.14725428, "qsc_code_frac_chars_dupe_7grams": 0.11577475, "qsc_code_frac_chars_dupe_8grams": 0.10423225, "qsc_code_frac_chars_dupe_9grams": 0.09094089, "qsc_code_frac_chars_dupe_10grams": 0.06086044, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01894628, "qsc_code_frac_chars_whitespace": 0.18316727, "qsc_code_size_file_byte": 4717.0, "qsc_code_num_lines": 164.0, "qsc_code_num_chars_line_max": 115.0, "qsc_code_num_chars_line_mean": 28.76219512, "qsc_code_frac_chars_alphabet": 0.72307293, "qsc_code_frac_chars_comments": 0.27051092, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.29752066, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.255449, "qsc_code_frac_chars_long_word_length": 0.0331299, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0} | |
00-Evan/shattered-pixel-dungeon-gdx | build.gradle | buildscript {
repositories {
mavenCentral()
mavenLocal()
jcenter()
maven { url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' }
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.4'
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.2.0'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '0.7.5f'
ext {
versionCode = 383
appName = 'shattered-pixel-dungeon'
appTitle = 'Shattered Pixel Dungeon'
appId = 'com.shatteredpixel.shatteredpixeldungeon'
gdxVersion = '1.9.10'
roboVMVersion = '2.3.3'
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
}
}
/*project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
}
}
project(":ios") {
apply plugin: "java"
apply plugin: "robovm"
configurations { natives }
dependencies {
compile project(":core")
compile "com.mobidevelop.robovm:robovm-rt:${roboVMVersion}"
compile "com.mobidevelop.robovm:robovm-cocoatouch:${roboVMVersion}"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
}
}
project(":html") {
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-gwt:$gdxVersion:sources"
}
}*/
project(":core") {
apply plugin: "java"
dependencies {
compile project(":PD-classes")
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
}
}
project(":PD-classes") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "org.json:json:20140107"
}
}
tasks.eclipse.doLast {
delete ".project"
}
| 3,293 | build | gradle | en | gradle | data | {"qsc_code_num_words": 375, "qsc_code_num_chars": 3293.0, "qsc_code_mean_word_length": 6.53333333, "qsc_code_frac_words_unique": 0.232, "qsc_code_frac_chars_top_2grams": 0.15673469, "qsc_code_frac_chars_top_3grams": 0.18612245, "qsc_code_frac_chars_top_4grams": 0.2155102, "qsc_code_frac_chars_dupe_5grams": 0.65714286, "qsc_code_frac_chars_dupe_6grams": 0.62326531, "qsc_code_frac_chars_dupe_7grams": 0.5677551, "qsc_code_frac_chars_dupe_8grams": 0.51510204, "qsc_code_frac_chars_dupe_9grams": 0.32734694, "qsc_code_frac_chars_dupe_10grams": 0.19755102, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00988749, "qsc_code_frac_chars_whitespace": 0.10932281, "qsc_code_size_file_byte": 3293.0, "qsc_code_num_lines": 122.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 26.99180328, "qsc_code_frac_chars_alphabet": 0.82543471, "qsc_code_frac_chars_comments": 0.44791983, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.27419355, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.55390539, "qsc_code_frac_chars_long_word_length": 0.39438944, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 1, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | ios/robovm.xml | <config>
<executableName>${app.executable}</executableName>
<mainClass>${app.mainclass}</mainClass>
<os>ios</os>
<arch>thumbv7</arch>
<target>ios</target>
<iosInfoPList>Info.plist.xml</iosInfoPList>
<resources>
<resource>
<directory>../android/assets</directory>
<includes>
<include>**</include>
</includes>
<skipPngCrush>true</skipPngCrush>
</resource>
<resource>
<directory>data</directory>
</resource>
</resources>
<forceLinkClasses>
<pattern>com.badlogic.gdx.scenes.scene2d.ui.*</pattern>
<pattern>com.badlogic.gdx.physics.bullet.**</pattern>
<pattern>com.android.okhttp.HttpHandler</pattern>
<pattern>com.android.okhttp.HttpsHandler</pattern>
<pattern>com.android.org.conscrypt.**</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.BouncyCastleProvider</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.BC$Mappings</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi$Std</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi</pattern>
<pattern>com.android.org.bouncycastle.crypto.digests.AndroidDigestFactoryOpenSSL</pattern>
<pattern>org.apache.harmony.security.provider.cert.DRLCertFactory</pattern>
<pattern>org.apache.harmony.security.provider.crypto.CryptoProvider</pattern>
</forceLinkClasses>
<libs>
<lib>build/libs/ios/libgdx.a</lib>
<lib>build/libs/ios/libObjectAL.a</lib>
</libs>
<frameworks>
<framework>UIKit</framework>
<framework>OpenGLES</framework>
<framework>QuartzCore</framework>
<framework>CoreGraphics</framework>
<framework>OpenAL</framework>
<framework>AudioToolbox</framework>
<framework>AVFoundation</framework>
</frameworks>
</config>
| 1,829 | robovm | xml | en | xml | data | {"qsc_code_num_words": 197, "qsc_code_num_chars": 1829.0, "qsc_code_mean_word_length": 7.1319797, "qsc_code_frac_words_unique": 0.37563452, "qsc_code_frac_chars_top_2grams": 0.11957295, "qsc_code_frac_chars_top_3grams": 0.12099644, "qsc_code_frac_chars_top_4grams": 0.15373665, "qsc_code_frac_chars_dupe_5grams": 0.37935943, "qsc_code_frac_chars_dupe_6grams": 0.31743772, "qsc_code_frac_chars_dupe_7grams": 0.28967972, "qsc_code_frac_chars_dupe_8grams": 0.22419929, "qsc_code_frac_chars_dupe_9grams": 0.15302491, "qsc_code_frac_chars_dupe_10grams": 0.15302491, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00116959, "qsc_code_frac_chars_whitespace": 0.06506288, "qsc_code_size_file_byte": 1829.0, "qsc_code_num_lines": 48.0, "qsc_code_num_chars_line_max": 95.0, "qsc_code_num_chars_line_mean": 38.10416667, "qsc_code_frac_chars_alphabet": 0.82046784, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.08333333, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 1, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | ios/build.gradle | sourceSets.main.java.srcDirs = [ "src/" ]
sourceCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
ext {
mainClassName = "com.watabou.pd.IOSLauncher"
mainExecutable = "IOSLauncher"
}
// Extracts native libs (*.a) from the native-ios.jar and places them
// under build/libs/ios/.
task copyNatives << {
file("build/libs/ios/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if (jar.name.endsWith("natives-ios.jar")) outputDir = file("build/libs/ios")
if (outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.a"
}
}
}
}
// Updates a robovm.xml file.
task updateRoboVMXML << {
def xml = file('robovm.xml')
if (!xml.exists()) {
return
}
// Find all native (*.a) libraries beneath libs
def libtree = fileTree(dir: 'build/libs', include: '**/*.a')
def config = new groovy.util.XmlParser().parse(xml)
config.libs.each {libs ->
libs.children().clear()
libtree.each { File file ->
libs.appendNode('lib', 'build/libs/ios/' + file.getName())
}
}
def writer = new FileWriter(xml)
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace true
printer.print(config)
}
task updateRoboVMProps << {
ant.propertyfile(file: 'robovm.properties') {
entry (key: 'app.version', value: version)
entry (key: 'app.build', value: versionCode)
entry (key: 'app.name', value: appTitle)
entry (key: 'app.id', value: appId)
entry (key: 'app.mainclass', value: mainClassName)
entry (key: 'app.executable', value: mainExecutable)
}
}
updateRoboVMXML.dependsOn copyNatives
build.dependsOn updateRoboVMXML, updateRoboVMProps
tasks.eclipse.dependsOn updateRoboVMXML, updateRoboVMProps
launchIPhoneSimulator.dependsOn build
launchIPadSimulator.dependsOn build
launchIOSDevice.dependsOn build
createIPA.dependsOn build
eclipse.project {
name = appName + "-ios"
natures 'org.robovm.eclipse.RoboVMNature'
} | 1,970 | build | gradle | en | gradle | data | {"qsc_code_num_words": 229, "qsc_code_num_chars": 1970.0, "qsc_code_mean_word_length": 6.06113537, "qsc_code_frac_words_unique": 0.48471616, "qsc_code_frac_chars_top_2grams": 0.03458213, "qsc_code_frac_chars_top_3grams": 0.04755043, "qsc_code_frac_chars_top_4grams": 0.02305476, "qsc_code_frac_chars_dupe_5grams": 0.0, "qsc_code_frac_chars_dupe_6grams": 0.0, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00179533, "qsc_code_frac_chars_whitespace": 0.15177665, "qsc_code_size_file_byte": 1970.0, "qsc_code_num_lines": 77.0, "qsc_code_num_chars_line_max": 78.0, "qsc_code_num_chars_line_mean": 25.58441558, "qsc_code_frac_chars_alphabet": 0.828845, "qsc_code_frac_chars_comments": 0.88883249, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.22374429, "qsc_code_frac_chars_long_word_length": 0.11872146, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 1, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | ios/Info.plist.xml | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${app.name}</string>
<key>CFBundleExecutable</key>
<string>${app.executable}</string>
<key>CFBundleIdentifier</key>
<string>${app.id}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${app.name}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>${app.version}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${app.build}</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarHidden</key>
<true/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>opengles-2</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleIcons</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>Icon</string>
<string>Icon-72</string>
</array>
</dict>
</dict>
</dict>
</plist>
| 1,572 | Info.plist | xml | en | xml | data | {"qsc_code_num_words": 169, "qsc_code_num_chars": 1572.0, "qsc_code_mean_word_length": 6.61538462, "qsc_code_frac_words_unique": 0.34911243, "qsc_code_frac_chars_top_2grams": 0.08050089, "qsc_code_frac_chars_top_3grams": 0.06440072, "qsc_code_frac_chars_top_4grams": 0.02862254, "qsc_code_frac_chars_dupe_5grams": 0.04472272, "qsc_code_frac_chars_dupe_6grams": 0.04472272, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01189643, "qsc_code_frac_chars_whitespace": 0.09096692, "qsc_code_size_file_byte": 1572.0, "qsc_code_num_lines": 59.0, "qsc_code_num_chars_line_max": 103.0, "qsc_code_num_chars_line_mean": 26.6440678, "qsc_code_frac_chars_alphabet": 0.77046886, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 1.0, "qsc_code_frac_lines_dupe_lines": 0.30508475, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.05343511, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 1, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 1, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | html/build.gradle | apply plugin: "java"
apply plugin: "jetty"
gwt {
gwtVersion='2.6.0' // Should match the gwt version used for building the gwt backend
maxHeapSize="1G" // Default 256m is not enough for gwt compiler. GWT is HUNGRY
minHeapSize="1G"
src = files(file("src/")) // Needs to be in front of "modules" below.
modules 'com.shatteredpixel.shatteredpixeldungeon.GdxDefinition'
devModules 'com.shatteredpixel.shatteredpixeldungeon.GdxDefinitionSuperdev'
project.webAppDirName = 'webapp'
compiler {
strict = true;
enableClosureCompiler = true;
disableCastChecking = true;
}
}
task draftRun(type: JettyRunWar) {
dependsOn draftWar
dependsOn.remove('war')
webApp=draftWar.archivePath
daemon=true
}
task superDev(type: de.richsource.gradle.plugins.gwt.GwtSuperDev) {
dependsOn draftRun
doFirst {
gwt.modules = gwt.devModules
}
}
task dist(dependsOn: [clean, compileGwt]) {
doLast {
file("build/dist").mkdirs()
copy {
from "build/gwt/out"
into "build/dist"
}
copy {
from "webapp"
into "build/dist"
}
copy {
from "war"
into "build/dist"
}
}
}
draftWar {
from "war"
}
task addSource << {
sourceSets.main.compileClasspath += files(project(':PD-classes').sourceSets.main.allJava.srcDirs)
sourceSets.main.compileClasspath += files(project(':core').sourceSets.main.allJava.srcDirs)
}
tasks.compileGwt.dependsOn(addSource)
tasks.draftCompileGwt.dependsOn(addSource)
sourceCompatibility = 1.7
sourceSets.main.java.srcDirs = [ "src/" ]
eclipse.project {
name = appName + "-html"
}
| 1,531 | build | gradle | en | gradle | data | {"qsc_code_num_words": 176, "qsc_code_num_chars": 1531.0, "qsc_code_mean_word_length": 6.27840909, "qsc_code_frac_words_unique": 0.54545455, "qsc_code_frac_chars_top_2grams": 0.06334842, "qsc_code_frac_chars_top_3grams": 0.03529412, "qsc_code_frac_chars_top_4grams": 0.03076923, "qsc_code_frac_chars_dupe_5grams": 0.11402715, "qsc_code_frac_chars_dupe_6grams": 0.0, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00769823, "qsc_code_frac_chars_whitespace": 0.15153494, "qsc_code_size_file_byte": 1531.0, "qsc_code_num_lines": 71.0, "qsc_code_num_chars_line_max": 99.0, "qsc_code_num_chars_line_mean": 21.56338028, "qsc_code_frac_chars_alphabet": 0.84295612, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13559322, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.15937296, "qsc_code_frac_chars_long_word_length": 0.07576747, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | desktop/build.gradle | apply plugin: "java"
sourceSets.main.java.srcDirs = [ "src/" ]
project.ext.mainClassName = "com.watabou.pd.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../android/assets");
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task dist(type: Jar) {
from files(sourceSets.main.output.classesDirs)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);
manifest {
attributes 'Main-Class': project.mainClassName
attributes 'Specification-Version': version
attributes 'Implementation-Version': versionCode
}
}
dist.dependsOn classes
eclipse {
project {
name = appName + "-desktop"
linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'
}
}
task afterEclipseImport(description: "Post processing after project generation", group: "IDE") {
doLast {
def classpath = new XmlParser().parse(file(".classpath"))
new Node(classpath, "classpathentry", [ kind: 'src', path: 'assets' ]);
def writer = new FileWriter(file(".classpath"))
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.setPreserveWhitespace(true)
printer.print(classpath)
}
} | 1,359 | build | gradle | en | gradle | data | {"qsc_code_num_words": 149, "qsc_code_num_chars": 1359.0, "qsc_code_mean_word_length": 6.82550336, "qsc_code_frac_words_unique": 0.5704698, "qsc_code_frac_chars_top_2grams": 0.05506391, "qsc_code_frac_chars_top_3grams": 0.03343166, "qsc_code_frac_chars_top_4grams": 0.04523107, "qsc_code_frac_chars_dupe_5grams": 0.05703048, "qsc_code_frac_chars_dupe_6grams": 0.0, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00167504, "qsc_code_frac_chars_whitespace": 0.1214128, "qsc_code_size_file_byte": 1359.0, "qsc_code_num_lines": 47.0, "qsc_code_num_chars_line_max": 97.0, "qsc_code_num_chars_line_mean": 28.91489362, "qsc_code_frac_chars_alphabet": 0.85008375, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.18543046, "qsc_code_frac_chars_long_word_length": 0.08535688, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | android/build.gradle | android {
buildToolsVersion '25.0.3'
compileSdkVersion 25
defaultConfig {
applicationId appId
versionCode project.ext.versionCode
versionName version
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDir 'libs'
}
instrumentTest.setRoot('tests')
}
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
task run(type: Exec) {
def path
def localProperties = project.file("../local.properties")
if (localProperties.exists()) {
Properties properties = new Properties()
localProperties.withInputStream { instr ->
properties.load(instr)
}
def sdkDir = properties.getProperty('sdk.dir')
if (sdkDir) {
path = sdkDir
} else {
path = "$System.env.ANDROID_HOME"
}
} else {
path = "$System.env.ANDROID_HOME"
}
def adb = path + "/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.watabou.pd.android/com.watabou.pd.android.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
classpath {
plusConfigurations += project.configurations.compile
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [ COMPILE: [plus:[project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value:"true")
}
}
}
}
}
}
}
| 3,151 | build | gradle | en | gradle | data | {"qsc_code_num_words": 366, "qsc_code_num_chars": 3151.0, "qsc_code_mean_word_length": 5.93169399, "qsc_code_frac_words_unique": 0.48907104, "qsc_code_frac_chars_top_2grams": 0.02210963, "qsc_code_frac_chars_top_3grams": 0.03592814, "qsc_code_frac_chars_top_4grams": 0.05527407, "qsc_code_frac_chars_dupe_5grams": 0.19898664, "qsc_code_frac_chars_dupe_6grams": 0.13127591, "qsc_code_frac_chars_dupe_7grams": 0.02855827, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00727691, "qsc_code_frac_chars_whitespace": 0.17137417, "qsc_code_size_file_byte": 3151.0, "qsc_code_num_lines": 121.0, "qsc_code_num_chars_line_max": 115.0, "qsc_code_num_chars_line_mean": 26.04132231, "qsc_code_frac_chars_alphabet": 0.82420529, "qsc_code_frac_chars_comments": 0.86067915, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.11845103, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_words_unique": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 1, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/IconButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class IconButton extends Button {
protected Image icon;
public IconButton(){
super();
}
public IconButton( Image icon ){
super();
icon( icon );
}
@Override
protected void layout() {
super.layout();
if (icon != null) {
icon.x = x + (width - icon.width()) / 2f;
icon.y = y + (height - icon.height()) / 2f;
PixelScene.align(icon);
}
}
@Override
protected void onTouchDown() {
if (icon != null) icon.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
if (icon != null) icon.resetColor();
}
public void enable( boolean value ) {
active = value;
if (icon != null) icon.alpha( value ? 1.0f : 0.3f );
}
public void icon( Image icon ) {
if (this.icon != null) {
remove( this.icon );
}
this.icon = icon;
if (this.icon != null) {
add( this.icon );
layout();
}
}
public Image icon(){
return icon;
}
}
| 2,009 | IconButton | java | en | java | code | {"qsc_code_num_words": 269, "qsc_code_num_chars": 2009.0, "qsc_code_mean_word_length": 5.11895911, "qsc_code_frac_words_unique": 0.48327138, "qsc_code_frac_chars_top_2grams": 0.03485839, "qsc_code_frac_chars_top_3grams": 0.02904866, "qsc_code_frac_chars_top_4grams": 0.04066812, "qsc_code_frac_chars_dupe_5grams": 0.08569354, "qsc_code_frac_chars_dupe_6grams": 0.04066812, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01558603, "qsc_code_frac_chars_whitespace": 0.20159283, "qsc_code_size_file_byte": 2009.0, "qsc_code_num_lines": 84.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 23.91666667, "qsc_code_frac_chars_alphabet": 0.84289277, "qsc_code_frac_chars_comments": 0.38875062, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.1372549, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.11764706, "qsc_codejava_score_lines_no_logic": 0.2745098, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toast.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.ui.Component;
public class Toast extends Component {
private static final float MARGIN_HOR = 2;
private static final float MARGIN_VER = 2;
protected NinePatch bg;
protected SimpleButton close;
protected RenderedTextBlock text;
public Toast( String text ) {
super();
text( text );
width = this.text.width() + close.width() + bg.marginHor() + MARGIN_HOR * 3;
height = Math.max( this.text.height(), close.height() ) + bg.marginVer() + MARGIN_VER * 2;
}
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.TOAST_TR );
add( bg );
close = new SimpleButton( Icons.get( Icons.CLOSE ) ) {
protected void onClick() {
onClose();
}
};
add( close );
text = PixelScene.renderTextBlock(8);
add( text );
}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
close.setPos(
bg.x + bg.width() - bg.marginHor() / 2f - MARGIN_HOR - close.width(),
y + (height - close.height()) / 2f );
PixelScene.align(close);
text.setPos(close.left() - MARGIN_HOR - text.width(), y + (height - text.height()) / 2);
PixelScene.align(text);
}
public void text( String txt ) {
text.text( txt );
}
protected void onClose() {}
}
| 2,293 | Toast | java | en | java | code | {"qsc_code_num_words": 305, "qsc_code_num_chars": 2293.0, "qsc_code_mean_word_length": 5.21967213, "qsc_code_frac_words_unique": 0.45245902, "qsc_code_frac_chars_top_2grams": 0.02261307, "qsc_code_frac_chars_top_3grams": 0.02449749, "qsc_code_frac_chars_top_4grams": 0.03580402, "qsc_code_frac_chars_dupe_5grams": 0.0879397, "qsc_code_frac_chars_dupe_6grams": 0.03517588, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01343364, "qsc_code_frac_chars_whitespace": 0.18839948, "qsc_code_size_file_byte": 2293.0, "qsc_code_num_lines": 85.0, "qsc_code_num_chars_line_max": 93.0, "qsc_code_num_chars_line_mean": 26.97647059, "qsc_code_frac_chars_alphabet": 0.84202042, "qsc_code_frac_chars_comments": 0.34060183, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04081633, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.10204082, "qsc_codejava_score_lines_no_logic": 0.26530612, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/BuffIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoBuff;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.Image;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.tweeners.AlphaTweener;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
import java.util.LinkedHashMap;
public class BuffIndicator extends Component {
//transparent icon
public static final int NONE = 63;
//FIXME this is becoming a mess, should do a big cleaning pass on all of these
//and think about tinting options
public static final int MIND_VISION = 0;
public static final int LEVITATION = 1;
public static final int FIRE = 2;
public static final int POISON = 3;
public static final int PARALYSIS = 4;
public static final int HUNGER = 5;
public static final int STARVATION = 6;
public static final int SLOW = 7;
public static final int OOZE = 8;
public static final int AMOK = 9;
public static final int TERROR = 10;
public static final int ROOTS = 11;
public static final int INVISIBLE = 12;
public static final int SHADOWS = 13;
public static final int WEAKNESS = 14;
public static final int FROST = 15;
public static final int BLINDNESS = 16;
public static final int COMBO = 17;
public static final int FURY = 18;
public static final int HERB_HEALING= 19;
public static final int ARMOR = 20;
public static final int HEART = 21;
public static final int LIGHT = 22;
public static final int CRIPPLE = 23;
public static final int BARKSKIN = 24;
public static final int IMMUNITY = 25;
public static final int BLEEDING = 26;
public static final int MARK = 27;
public static final int DEFERRED = 28;
public static final int DROWSY = 29;
public static final int MAGIC_SLEEP = 30;
public static final int THORNS = 31;
public static final int FORESIGHT = 32;
public static final int VERTIGO = 33;
public static final int RECHARGING = 34;
public static final int LOCKED_FLOOR= 35;
public static final int CORRUPT = 36;
public static final int BLESS = 37;
public static final int RAGE = 38;
public static final int SACRIFICE = 39;
public static final int BERSERK = 40;
public static final int MOMENTUM = 41;
public static final int PREPARATION = 42;
public static final int WELL_FED = 43;
public static final int HEALING = 44;
public static final int WEAPON = 45;
public static final int SIZE = 7;
private static BuffIndicator heroInstance;
private SmartTexture texture;
private TextureFilm film;
private LinkedHashMap<Buff, BuffIcon> buffIcons = new LinkedHashMap<>();
private boolean needsRefresh;
private Char ch;
public BuffIndicator( Char ch ) {
super();
this.ch = ch;
if (ch == Dungeon.hero) {
heroInstance = this;
}
}
@Override
public void destroy() {
super.destroy();
if (this == heroInstance) {
heroInstance = null;
}
}
@Override
protected void createChildren() {
texture = TextureCache.get( Assets.BUFFS_SMALL );
film = new TextureFilm( texture, SIZE, SIZE );
}
@Override
public synchronized void update() {
super.update();
if (needsRefresh){
needsRefresh = false;
layout();
}
}
@Override
protected void layout() {
ArrayList<Buff> newBuffs = new ArrayList<>();
for (Buff buff : ch.buffs()) {
if (buff.icon() != NONE) {
newBuffs.add(buff);
}
}
//remove any icons no longer present
for (Buff buff : buffIcons.keySet().toArray(new Buff[0])){
if (!newBuffs.contains(buff)){
Image icon = buffIcons.get( buff ).icon;
icon.origin.set( SIZE / 2 );
add( icon );
add( new AlphaTweener( icon, 0, 0.6f ) {
@Override
protected void updateValues( float progress ) {
super.updateValues( progress );
image.scale.set( 1 + 5 * progress );
}
@Override
protected void onComplete() {
image.killAndErase();
}
} );
buffIcons.get( buff ).destroy();
remove(buffIcons.get( buff ));
buffIcons.remove( buff );
}
}
//add new icons
for (Buff buff : newBuffs) {
if (!buffIcons.containsKey(buff)) {
BuffIcon icon = new BuffIcon( buff );
add(icon);
buffIcons.put( buff, icon );
}
}
//layout
int pos = 0;
for (BuffIcon icon : buffIcons.values()){
icon.updateIcon();
icon.setRect(x + pos * (SIZE + 2), y, 9, 12);
pos++;
}
}
private class BuffIcon extends Button {
private Buff buff;
public Image icon;
public BuffIcon( Buff buff ){
super();
this.buff = buff;
icon = new Image( texture );
icon.frame( film.get( buff.icon() ) );
add( icon );
}
public void updateIcon(){
icon.frame( film.get( buff.icon() ) );
buff.tintIcon(icon);
}
@Override
protected void layout() {
super.layout();
icon.x = this.x+1;
icon.y = this.y+2;
}
@Override
protected void onClick() {
if (buff.icon() != NONE)
GameScene.show(new WndInfoBuff(buff));
}
}
public static void refreshHero() {
if (heroInstance != null) {
heroInstance.needsRefresh = true;
}
}
}
| 6,306 | BuffIndicator | java | en | java | code | {"qsc_code_num_words": 821, "qsc_code_num_chars": 6306.0, "qsc_code_mean_word_length": 5.32521315, "qsc_code_frac_words_unique": 0.34713764, "qsc_code_frac_chars_top_2grams": 0.13449222, "qsc_code_frac_chars_top_3grams": 0.18664227, "qsc_code_frac_chars_top_4grams": 0.21957914, "qsc_code_frac_chars_dupe_5grams": 0.063129, "qsc_code_frac_chars_dupe_6grams": 0.02378774, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02334474, "qsc_code_frac_chars_whitespace": 0.2120203, "qsc_code_size_file_byte": 6306.0, "qsc_code_num_lines": 230.0, "qsc_code_num_chars_line_max": 80.0, "qsc_code_num_chars_line_mean": 27.4173913, "qsc_code_frac_chars_alphabet": 0.85651036, "qsc_code_frac_chars_comments": 0.15366318, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0982659, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00434783, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05202312, "qsc_codejava_score_lines_no_logic": 0.19075145, "qsc_codejava_frac_words_no_modifier": 0.81818182, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/BossHealthBar.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle;
import com.watabou.noosa.Image;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.ui.Component;
public class BossHealthBar extends Component {
private Image bar;
private Image hp;
private static Mob boss;
private Image skull;
private Emitter blood;
private static String asset = Assets.BOSSHP;
private static BossHealthBar instance;
private static boolean bleeding;
BossHealthBar() {
super();
visible = active = (boss != null);
instance = this;
}
@Override
protected void createChildren() {
bar = new Image(asset, 0, 0, 64, 16);
add(bar);
width = bar.width;
height = bar.height;
hp = new Image(asset, 15, 19, 47, 4);
add(hp);
skull = new Image(asset, 5, 18, 6, 6);
add(skull);
blood = new Emitter();
blood.pos(skull);
blood.pour(BloodParticle.FACTORY, 0.3f);
blood.autoKill = false;
blood.on = false;
add( blood );
}
@Override
protected void layout() {
bar.x = x;
bar.y = y;
hp.x = bar.x+15;
hp.y = bar.y+6;
skull.x = bar.x+5;
skull.y = bar.y+5;
}
@Override
public void update() {
super.update();
if (boss != null){
if (!boss.isAlive() || !Dungeon.level.mobs.contains(boss)){
boss = null;
visible = active = false;
} else {
hp.scale.x = (float)boss.HP/boss.HT;
if (hp.scale.x < 0.25f) bleed( true );
if (bleeding != blood.on){
if (bleeding) skull.tint( 0xcc0000, 0.6f );
else skull.resetColor();
blood.on = bleeding;
}
}
}
}
public static void assignBoss(Mob boss){
BossHealthBar.boss = boss;
bleed(false);
if (instance != null) {
instance.visible = instance.active = true;
}
}
public static boolean isAssigned(){
return boss != null && boss.isAlive() && Dungeon.level.mobs.contains(boss);
}
public static void bleed(boolean value){
bleeding = value;
}
}
| 2,944 | BossHealthBar | java | en | java | code | {"qsc_code_num_words": 397, "qsc_code_num_chars": 2944.0, "qsc_code_mean_word_length": 5.11335013, "qsc_code_frac_words_unique": 0.41057935, "qsc_code_frac_chars_top_2grams": 0.03103448, "qsc_code_frac_chars_top_3grams": 0.09359606, "qsc_code_frac_chars_top_4grams": 0.08669951, "qsc_code_frac_chars_dupe_5grams": 0.07881773, "qsc_code_frac_chars_dupe_6grams": 0.06600985, "qsc_code_frac_chars_dupe_7grams": 0.03842365, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02195019, "qsc_code_frac_chars_whitespace": 0.1953125, "qsc_code_size_file_byte": 2944.0, "qsc_code_num_lines": 122.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 24.13114754, "qsc_code_frac_chars_alphabet": 0.83495146, "qsc_code_frac_chars_comments": 0.26528533, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0375, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00369857, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.075, "qsc_codejava_score_lines_no_logic": 0.2625, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Icons.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.watabou.noosa.Image;
public enum Icons {
//button icons
CHECKED,
UNCHECKED,
INFO,
CHALLENGE_OFF,
CHALLENGE_ON,
PREFS,
LANGS,
EXIT,
CLOSE,
ARROW,
//ingame UI icons
SKULL,
BUSY,
COMPASS,
SLEEP,
ALERT,
LOST,
TARGET,
BACKPACK,
SEED_POUCH,
SCROLL_HOLDER,
POTION_BANDOLIER,
WAND_HOLSTER,
//hero & rankings icons
DEPTH,
WARRIOR,
MAGE,
ROGUE,
HUNTRESS,
//main menu icons
ENTER,
GOLD,
RANKINGS,
BADGES,
CHANGES,
SHPX,
//misc icons
LIBGDX,
WATA,
WARNING;
public Image get() {
return get( this );
}
public static Image get( Icons type ) {
Image icon = new Image( Assets.ICONS );
switch (type) {
case CHECKED:
icon.frame( icon.texture.uvRect( 0, 0, 12, 12 ) );
break;
case UNCHECKED:
icon.frame( icon.texture.uvRect( 16, 0, 28, 12 ) );
break;
case INFO:
icon.frame( icon.texture.uvRect( 32, 0, 46, 14 ) );
break;
case CHALLENGE_ON:
icon.frame( icon.texture.uvRect( 48, 0, 62, 12 ) );
break;
case CHALLENGE_OFF:
icon.frame( icon.texture.uvRect( 64, 0, 78, 12 ) );
break;
case PREFS:
icon.frame( icon.texture.uvRect( 80, 0, 92, 12 ) );
break;
case LANGS:
icon.frame( icon.texture.uvRect( 96, 0, 108, 9 ) );
break;
case EXIT:
icon.frame( icon.texture.uvRect( 112, 0, 125, 9 ) );
break;
case CLOSE:
icon.frame( icon.texture.uvRect( 0, 16, 11, 27 ) );
break;
case ARROW:
icon.frame( icon.texture.uvRect( 16, 16, 27, 27 ) );
break;
case SKULL:
icon.frame( icon.texture.uvRect( 0, 32, 8, 40 ) );
break;
case BUSY:
icon.frame( icon.texture.uvRect( 8, 32, 16, 40 ) );
break;
case COMPASS:
icon.frame( icon.texture.uvRect( 0, 40, 7, 45 ) );
break;
case SLEEP:
icon.frame( icon.texture.uvRect( 16, 32, 25, 40 ) );
break;
case ALERT:
icon.frame( icon.texture.uvRect( 16, 40, 24, 48 ) );
break;
case LOST:
icon.frame( icon.texture.uvRect( 24, 40, 32, 48 ) );
break;
case TARGET:
icon.frame( icon.texture.uvRect( 32, 32, 48, 48 ) );
break;
case BACKPACK:
icon.frame( icon.texture.uvRect( 48, 32, 58, 42 ) );
break;
case SCROLL_HOLDER:
icon.frame( icon.texture.uvRect( 58, 32, 68, 42 ) );
break;
case SEED_POUCH:
icon.frame( icon.texture.uvRect( 68, 32, 78, 42 ) );
break;
case WAND_HOLSTER:
icon.frame( icon.texture.uvRect( 78, 32, 88, 42 ) );
break;
case POTION_BANDOLIER:
icon.frame( icon.texture.uvRect( 88, 32, 98, 42 ) );
break;
case DEPTH:
icon.frame( icon.texture.uvRect( 0, 48, 13, 64 ) );
break;
case WARRIOR:
icon.frame( icon.texture.uvRect( 16, 48, 25, 63 ) );
break;
case MAGE:
icon.frame( icon.texture.uvRect( 32, 48, 47, 62 ) );
break;
case ROGUE:
icon.frame( icon.texture.uvRect( 48, 48, 57, 63 ) );
break;
case HUNTRESS:
icon.frame( icon.texture.uvRect( 64, 48, 80, 64 ) );
break;
case ENTER:
icon.frame( icon.texture.uvRect( 0, 64, 17, 81 ) );
break;
case RANKINGS:
icon.frame( icon.texture.uvRect( 17, 64, 34, 81 ) );
break;
case BADGES:
icon.frame( icon.texture.uvRect( 34, 64, 51, 81 ) );
break;
case CHANGES:
icon.frame( icon.texture.uvRect( 51, 64, 68, 79 ) );
break;
case SHPX:
icon.frame( icon.texture.uvRect( 68, 64, 84, 80 ) );
break;
case GOLD:
icon.frame( icon.texture.uvRect( 85, 64, 102, 80 ) );
break;
case LIBGDX:
icon.frame( icon.texture.uvRect( 0, 81, 16, 94 ) );
break;
case WATA:
icon.frame( icon.texture.uvRect( 17, 81, 34, 93 ) );
break;
case WARNING:
icon.frame( icon.texture.uvRect( 34, 81, 48, 95 ) );
break;
}
return icon;
}
public static Image get( HeroClass cl ) {
switch (cl) {
case WARRIOR:
return get( WARRIOR );
case MAGE:
return get( MAGE );
case ROGUE:
return get( ROGUE );
case HUNTRESS:
return get( HUNTRESS );
default:
return null;
}
}
}
| 4,843 | Icons | java | en | java | code | {"qsc_code_num_words": 692, "qsc_code_num_chars": 4843.0, "qsc_code_mean_word_length": 4.49132948, "qsc_code_frac_words_unique": 0.28901734, "qsc_code_frac_chars_top_2grams": 0.1042471, "qsc_code_frac_chars_top_3grams": 0.15057915, "qsc_code_frac_chars_top_4grams": 0.23166023, "qsc_code_frac_chars_dupe_5grams": 0.34202059, "qsc_code_frac_chars_dupe_6grams": 0.25, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.07702559, "qsc_code_frac_chars_whitespace": 0.22527359, "qsc_code_size_file_byte": 4843.0, "qsc_code_num_lines": 212.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 22.84433962, "qsc_code_frac_chars_alphabet": 0.75133262, "qsc_code_frac_chars_comments": 0.17840182, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.25433526, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04624277, "qsc_codejava_score_lines_no_logic": 0.07514451, "qsc_codejava_frac_words_no_modifier": 0.375, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": null, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/SimpleButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.Image;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.ui.Component;
public class SimpleButton extends Component {
private Image image;
public SimpleButton( Image image ) {
super();
this.image.copy( image );
width = image.width;
height = image.height;
}
@Override
protected void createChildren() {
image = new Image();
add( image );
add( new TouchArea( image ) {
@Override
protected void onTouchDown(NoosaInputProcessor.Touch touch) {
image.brightness( 1.2f );
};
@Override
protected void onTouchUp(NoosaInputProcessor.Touch touch) {
image.brightness( 1.0f );
};
@Override
protected void onClick( NoosaInputProcessor.Touch touch ) {
SimpleButton.this.onClick();
};
} );
}
@Override
protected void layout() {
image.x = x;
image.y = y;
}
protected void onClick() {}
}
| 1,774 | SimpleButton | java | en | java | code | {"qsc_code_num_words": 228, "qsc_code_num_chars": 1774.0, "qsc_code_mean_word_length": 5.53947368, "qsc_code_frac_words_unique": 0.50438596, "qsc_code_frac_chars_top_2grams": 0.06175772, "qsc_code_frac_chars_top_3grams": 0.08313539, "qsc_code_frac_chars_top_4grams": 0.04513064, "qsc_code_frac_chars_dupe_5grams": 0.13618369, "qsc_code_frac_chars_dupe_6grams": 0.11559778, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01473684, "qsc_code_frac_chars_whitespace": 0.19673055, "qsc_code_size_file_byte": 1774.0, "qsc_code_num_lines": 68.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 26.08823529, "qsc_code_frac_chars_alphabet": 0.87157895, "qsc_code_frac_chars_comments": 0.44024803, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.20512821, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.15384615, "qsc_codejava_score_lines_no_logic": 0.30769231, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/UpdateNotification.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.badlogic.gdx.Gdx;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Game;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Callback;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
public class UpdateNotification extends Component {
//0 means no connection yet, -1 means connection failure.
private static int latestVersion = 0;
private static boolean updateAvailable;
private static boolean latestIsUpdate;
private static String latestMessage;
private static String updateURL;
private NinePatch panel;
private RenderedTextBlock updateMessage;
private TouchArea touchUpdate;
private float alpha;
//initially indev this thing always displayed even when it couldn't find an update.
//decided that was a little too annoying, but decided to keep the logic around.
//flip this flag to re-enable that old functionality, which is still in the code below.
private static boolean quiet = true;
public UpdateNotification(){
super();
if (latestVersion <= 1) {
Thread thread = new Thread() {
@Override
public void run() {
try {
int currentVersion = Game.versionCode;
URL versionInfo = new URL("https://raw.githubusercontent.com/00-Evan/shattered-pixel-dungeon-gdx/master/desktop/VersionInfo.txt");
BufferedReader inforeader = new BufferedReader(new InputStreamReader(versionInfo.openStream()));
latestVersion = Integer.parseInt(inforeader.readLine());
if (latestVersion > currentVersion) {
updateAvailable = true;
} else {
updateAvailable = false;
updateMessage();
return;
}
//Update vs Patch, where a patch just appends a letter and usually fixes bugs.
int latestFullRelease = Integer.parseInt(inforeader.readLine());
latestIsUpdate = (currentVersion < latestFullRelease);
// Affects visibility. Basically, if we don't have the latest update, grab its message,
// otherwise grab the latest version's message, this way your told about an update
// you don't have, even if the latest version is a patch.
String latestVersionMessage = inforeader.readLine();
String latestUpdateMessage = inforeader.readLine();
latestMessage = latestIsUpdate ? latestUpdateMessage : latestVersionMessage;
updateURL = inforeader.readLine();
updateMessage();
} catch (Exception e) {
latestVersion = -1;
updateMessage();
}
}
};
thread.start();
}
}
@Override
protected void createChildren() {
panel = Chrome.get(Chrome.Type.GREY_BUTTON_TR);
add( panel );
//updateMessage = new BitmapText("Checking Updates", PixelScene.font1x);
updateMessage = PixelScene.renderTextBlock("Checking Updates", 9);
add(updateMessage);
touchUpdate = new TouchArea( panel ){
@Override
protected void onClick( NoosaInputProcessor.Touch touch ) {
if (updateAvailable) {
parent.add(new WndUpdate() );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
}
};
add(touchUpdate);
updateMessage();
}
@Override
protected void layout() {
panel.x = this.x;
panel.y = this.y;
panel.alpha(alpha);
panel.visible = updateAvailable || !quiet;
updateMessage.setPos( panel.x+panel.marginLeft(), panel.y+panel.marginTop() );
//updateMessage.measure();
updateMessage.alpha(alpha);
updateMessage.visible = updateAvailable || !quiet;
panel.size( panel.marginHor()+updateMessage.width(), panel.marginVer()+updateMessage.height());
this.width = panel.width();
this.height = panel.height();
}
private void updateMessage(){
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
if (latestVersion == -1){
updateMessage.text("Connection Failed");
updateMessage.hardlight( 0xFFCC66 );
alpha = 1f;
} else if (latestVersion == 0){
updateMessage.text("Checking Updates");
updateMessage.hardlight( 0xFFFFFF );
alpha = 0.8f;
} else if (!updateAvailable){
updateMessage.text("Up to Date!");
updateMessage.hardlight( 0xFFFFFF );
alpha = 0.8f;
} else {
if (!latestIsUpdate){
updateMessage.text("Patch!");
} else {
updateMessage.text("Update!");
}
updateMessage.hardlight( Window.SHPX_COLOR );
alpha = 1f;
}
layout();
}
});
}
@Override
public void update() {
super.update();
//connection failed
if (latestVersion == -1) {
alpha -= Game.elapsed/4f;
//up to date
} else if (!updateAvailable && latestVersion > 0){
alpha -= Game.elapsed/2f;
//update available
} else if (updateAvailable){
alpha = (float) (0.7f + Math.sin(Game.timeTotal*3)*0.3f);
}
layout();
if (alpha <= 0f) {
visible = false;
} else {
visible = true;
}
}
public static class WndUpdate extends WndOptions {
private static final String TTL_UPD = "An Update is Ready!:";
private static final String TTL_PTH = "A Patch is Ready!:";
private static final String MSG_UPD = "%s\n" +
"\n" +
"Updates include new content, bugfixes, balance tweaks, and various small improvements.\n" +
"\n" +
"Simply download the new executable and run it to start playing on the latest version!";
private static final String MSG_PTH = "%s\n" +
"\n" +
"Patches contain bugfixes, balance tweaks, and occasional bits of new content.\n" +
"\n" +
"Simply download the new executable and run it to start playing with the latest patch!";
private static final String BTN_UPD = "Quit and Download Update";
private static final String BTN_PTH = "Quit and Download Patch";
public WndUpdate(){
super(
latestIsUpdate ? TTL_UPD : TTL_PTH,
Messages.format((latestIsUpdate ? MSG_UPD : MSG_PTH), latestMessage),
latestIsUpdate ? BTN_UPD : BTN_PTH);
}
@Override
protected void onSelect(int index) {
if (index == 0) {
Gdx.net.openURI("http://" + updateURL);
Game.instance.finish();
}
}
}
}
| 7,277 | UpdateNotification | java | en | java | code | {"qsc_code_num_words": 846, "qsc_code_num_chars": 7277.0, "qsc_code_mean_word_length": 6.02600473, "qsc_code_frac_words_unique": 0.37115839, "qsc_code_frac_chars_top_2grams": 0.02471557, "qsc_code_frac_chars_top_3grams": 0.02510789, "qsc_code_frac_chars_top_4grams": 0.02471557, "qsc_code_frac_chars_dupe_5grams": 0.08905453, "qsc_code_frac_chars_dupe_6grams": 0.06159278, "qsc_code_frac_chars_dupe_7grams": 0.03844645, "qsc_code_frac_chars_dupe_8grams": 0.03844645, "qsc_code_frac_chars_dupe_9grams": 0.02118478, "qsc_code_frac_chars_dupe_10grams": 0.02118478, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00850629, "qsc_code_frac_chars_whitespace": 0.19224955, "qsc_code_size_file_byte": 7277.0, "qsc_code_num_lines": 244.0, "qsc_code_num_chars_line_max": 137.0, "qsc_code_num_chars_line_mean": 29.82377049, "qsc_code_frac_chars_alphabet": 0.85879551, "qsc_code_frac_chars_comments": 0.21135083, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.18235294, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.00588235, "qsc_code_frac_chars_string_length": 0.10770303, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00418264, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04705882, "qsc_codejava_score_lines_no_logic": 0.20588235, "qsc_codejava_frac_words_no_modifier": 0.88888889, "qsc_codejava_frac_words_legal_var_name": 0.95454545, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/BadgesList.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
public class BadgesList extends ScrollPane {
private ArrayList<ListItem> items = new ArrayList<>();
public BadgesList( boolean global ) {
super( new Component() );
for (Badges.Badge badge : Badges.filtered( global )) {
if (badge.image == -1) {
continue;
}
ListItem item = new ListItem( badge );
content.add( item );
items.add( item );
}
}
@Override
protected void layout() {
float pos = 0;
int size = items.size();
for (int i=0; i < size; i++) {
items.get( i ).setRect( 0, pos, width, ListItem.HEIGHT );
pos += ListItem.HEIGHT;
}
content.setSize( width, pos );
super.layout();
}
@Override
public void onClick( float x, float y ) {
int size = items.size();
for (int i=0; i < size; i++) {
if (items.get( i ).onClick( x, y )) {
break;
}
}
}
private class ListItem extends Component {
private static final float HEIGHT = 20;
private Badges.Badge badge;
private Image icon;
private RenderedTextBlock label;
public ListItem( Badges.Badge badge ) {
super();
this.badge = badge;
icon.copy( BadgeBanner.image( badge.image ));
label.text( badge.desc() );
}
@Override
protected void createChildren() {
icon = new Image();
add( icon );
label = PixelScene.renderTextBlock( 6 );
add( label );
}
@Override
protected void layout() {
icon.x = x;
icon.y = y + (height - icon.height) / 2;
PixelScene.align(icon);
label.setPos(
icon.x + icon.width + 2,
y + (height - label.height()) / 2
);
PixelScene.align(label);
}
public boolean onClick( float x, float y ) {
if (inside( x, y )) {
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
Game.scene().add( new WndBadge( badge ) );
return true;
} else {
return false;
}
}
}
}
| 3,169 | BadgesList | java | en | java | code | {"qsc_code_num_words": 405, "qsc_code_num_chars": 3169.0, "qsc_code_mean_word_length": 5.26666667, "qsc_code_frac_words_unique": 0.40740741, "qsc_code_frac_chars_top_2grams": 0.03797468, "qsc_code_frac_chars_top_3grams": 0.1068917, "qsc_code_frac_chars_top_4grams": 0.10314112, "qsc_code_frac_chars_dupe_5grams": 0.08438819, "qsc_code_frac_chars_dupe_6grams": 0.0543835, "qsc_code_frac_chars_dupe_7grams": 0.0281294, "qsc_code_frac_chars_dupe_8grams": 0.0281294, "qsc_code_frac_chars_dupe_9grams": 0.0281294, "qsc_code_frac_chars_dupe_10grams": 0.0281294, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01363819, "qsc_code_frac_chars_whitespace": 0.2133165, "qsc_code_size_file_byte": 3169.0, "qsc_code_num_lines": 129.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 24.56589147, "qsc_code_frac_chars_alphabet": 0.84195748, "qsc_code_frac_chars_comments": 0.24644998, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11904762, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05952381, "qsc_codejava_score_lines_no_logic": 0.25, "qsc_codejava_frac_words_no_modifier": 0.71428571, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/ResumeIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
public class ResumeIndicator extends Tag {
private Image icon;
public ResumeIndicator() {
super(0xCDD5C0);
hotKey = GameAction.RESUME;
setSize( 24, 24 );
visible = false;
}
@Override
protected void createChildren() {
super.createChildren();
icon = Icons.get( Icons.ARROW);
add( icon );
}
@Override
protected void layout() {
super.layout();
icon.x = x+1 + (width - icon.width) / 2f;
icon.y = y + (height - icon.height) / 2f;
PixelScene.align(icon);
}
@Override
protected void onClick() {
Dungeon.hero.resume();
}
@Override
public void update() {
if (!Dungeon.hero.isAlive())
visible = false;
else if (visible != (Dungeon.hero.lastAction != null)){
visible = Dungeon.hero.lastAction != null;
if (visible)
flash();
}
super.update();
}
}
| 1,864 | ResumeIndicator | java | en | java | code | {"qsc_code_num_words": 239, "qsc_code_num_chars": 1864.0, "qsc_code_mean_word_length": 5.57740586, "qsc_code_frac_words_unique": 0.53974895, "qsc_code_frac_chars_top_2grams": 0.05101275, "qsc_code_frac_chars_top_3grams": 0.11402851, "qsc_code_frac_chars_top_4grams": 0.04276069, "qsc_code_frac_chars_dupe_5grams": 0.10952738, "qsc_code_frac_chars_dupe_6grams": 0.0420105, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01770492, "qsc_code_frac_chars_whitespace": 0.18186695, "qsc_code_size_file_byte": 1864.0, "qsc_code_num_lines": 75.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 24.85333333, "qsc_code_frac_chars_alphabet": 0.85639344, "qsc_code_frac_chars_comments": 0.41899142, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.14285714, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00738689, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.0952381, "qsc_codejava_score_lines_no_logic": 0.23809524, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/KeyDisplay.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.CrystalKey;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.GoldenKey;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey;
import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Quad;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.Visual;
import com.watabou.utils.RectF;
import java.nio.FloatBuffer;
import java.util.LinkedHashMap;
public class KeyDisplay extends Visual {
private float[] vertices = new float[16];
private FloatBuffer quads;
private Vertexbuffer buffer;
private SmartTexture tx = TextureCache.get(Assets.MENU);
private boolean dirty = true;
private int[] keys;
//mapping of key types to slots in the array, 0 is reserved for black (missed) keys
//this also determines the order these keys will appear (lower first)
//and the order they will be truncated if there is no space (higher first, larger counts first)
private static final LinkedHashMap<Class<? extends Key>, Integer> keyMap = new LinkedHashMap<>();
static {
keyMap.put(SkeletonKey.class, 1);
keyMap.put(CrystalKey.class, 2);
keyMap.put(GoldenKey.class, 3);
keyMap.put(IronKey.class, 4);
}
private int totalKeys = 0;
public KeyDisplay() {
super(0, 0, 0, 0);
}
public void updateKeys(){
keys = new int[keyMap.size()+1];
for (Notes.KeyRecord rec : Notes.getRecords(Notes.KeyRecord.class)){
if (rec.depth() < Dungeon.depth){
//only ever 1 black key
keys[0] = 1;
} else if (rec.depth() == Dungeon.depth){
keys[keyMap.get(rec.type())] += rec.quantity();
}
}
totalKeys = 0;
for (int k : keys){
totalKeys += k;
}
dirty = true;
}
public int keyCount(){
return totalKeys;
}
@Override
public void draw() {
super.draw();
if (dirty){
updateVertices();
quads.limit(quads.position());
if (buffer == null)
buffer = new Vertexbuffer(quads);
else
buffer.updateVertices(quads);
}
NoosaScript script = NoosaScript.get();
tx.bind();
script.camera( camera() );
script.uModel.valueM4( matrix );
script.lighting(
rm, gm, bm, am,
ra, ga, ba, aa );
script.drawQuadSet( buffer, totalKeys, 0 );
}
private void updateVertices(){
//assumes shorter key sprite
int maxRows = (int)(height +1) / 5;
//1 pixel of padding between each key
int maxPerRow = (int)(width + 1) / 4;
int maxKeys = maxPerRow * maxRows;
while (totalKeys > maxKeys){
Class<? extends Key> mostType = null;
int mostNum = 0;
for (Class<?extends Key> k : keyMap.keySet()){
if (keys[keyMap.get(k)] >= mostNum){
mostType = k;
mostNum = keys[keyMap.get(k)];
}
}
keys[keyMap.get(mostType)]--;
totalKeys--;
}
int rows = (int)Math.ceil(totalKeys / (float)maxPerRow);
boolean shortKeys = (rows * 8) > height;
float left;
if (totalKeys > maxPerRow){
left = 0;
} else {
left = (width + 1 - (totalKeys*4))/2;
}
float top = (height + 1 - (rows * (shortKeys ? 5 : 8)))/2;
quads = Quad.createSet(totalKeys);
for (int i = 0; i < totalKeys; i++){
int keyIdx = 0;
if (i == 0 && keys[0] > 0){
//black key
keyIdx = 0;
} else {
for (int j = 1; j < keys.length; j++){
if (keys[j] > 0){
keys[j]--;
keyIdx = j;
break;
}
}
}
//texture coordinates
RectF r = tx.uvRect(43 + 3*keyIdx, shortKeys ? 8 : 0,
46 + 3*keyIdx, shortKeys ? 12 : 7);
vertices[2] = r.left;
vertices[3] = r.top;
vertices[6] = r.right;
vertices[7] = r.top;
vertices[10] = r.right;
vertices[11] = r.bottom;
vertices[14] = r.left;
vertices[15] = r.bottom;
//screen coordinates
vertices[0] = left;
vertices[1] = top;
vertices[4] = left + 3;
vertices[5] = top;
vertices[8] = left + 3;
vertices[9] = top + (shortKeys ? 4 : 7);
vertices[12] = left;
vertices[13] = top + (shortKeys ? 4 : 7);
quads.put(vertices);
//move to the right for more keys, drop down if the row is done
left += 4;
if (left + 3 > width){
left = 0;
top += (shortKeys ? 5 : 8);
}
}
dirty = false;
}
}
| 5,440 | KeyDisplay | java | en | java | code | {"qsc_code_num_words": 708, "qsc_code_num_chars": 5440.0, "qsc_code_mean_word_length": 5.04661017, "qsc_code_frac_words_unique": 0.3559322, "qsc_code_frac_chars_top_2grams": 0.03778338, "qsc_code_frac_chars_top_3grams": 0.09571788, "qsc_code_frac_chars_top_4grams": 0.09851665, "qsc_code_frac_chars_dupe_5grams": 0.10943185, "qsc_code_frac_chars_dupe_6grams": 0.08984047, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02416706, "qsc_code_frac_chars_whitespace": 0.21654412, "qsc_code_size_file_byte": 5440.0, "qsc_code_num_lines": 216.0, "qsc_code_num_chars_line_max": 99.0, "qsc_code_num_chars_line_mean": 25.18518519, "qsc_code_frac_chars_alphabet": 0.81417175, "qsc_code_frac_chars_comments": 0.22628676, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.02836879, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02836879, "qsc_codejava_score_lines_no_logic": 0.18439716, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/CharHealthIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
public class CharHealthIndicator extends HealthBar {
private static final int HEIGHT = 1;
private Char target;
public CharHealthIndicator( Char c ){
target = c;
GameScene.add(this);
}
@Override
protected void createChildren() {
super.createChildren();
height = HEIGHT;
}
@Override
public void update() {
super.update();
if (target != null && target.isAlive() && target.sprite.visible) {
CharSprite sprite = target.sprite;
width = sprite.width()*(4/6f);
x = sprite.x + sprite.width()/6f;
y = sprite.y - 2;
level( target );
visible = target.HP < target.HT || target.shielding() > 0;
} else {
visible = false;
}
}
public void target( Char ch ) {
if (ch != null && ch.isAlive()) {
target = ch;
} else {
target = null;
}
}
public Char target() {
return target;
}
}
| 1,875 | CharHealthIndicator | java | en | java | code | {"qsc_code_num_words": 241, "qsc_code_num_chars": 1875.0, "qsc_code_mean_word_length": 5.46887967, "qsc_code_frac_words_unique": 0.52697095, "qsc_code_frac_chars_top_2grams": 0.05159332, "qsc_code_frac_chars_top_3grams": 0.11532625, "qsc_code_frac_chars_top_4grams": 0.04324734, "qsc_code_frac_chars_dupe_5grams": 0.06221548, "qsc_code_frac_chars_dupe_6grams": 0.04248862, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01528239, "qsc_code_frac_chars_whitespace": 0.19733333, "qsc_code_size_file_byte": 1875.0, "qsc_code_num_lines": 72.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 26.04166667, "qsc_code_frac_chars_alphabet": 0.86046512, "qsc_code_frac_chars_comments": 0.41653333, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.09756098, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09756098, "qsc_codejava_score_lines_no_logic": 0.24390244, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Banner.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
public class Banner extends Image {
private enum State {
FADE_IN, STATIC, FADE_OUT
}
private State state;
private float time;
private int color;
private float fadeTime;
private float showTime;
public Banner( Image sample ) {
super();
copy( sample );
alpha( 0 );
}
public Banner( Object tx ) {
super( tx );
alpha( 0 );
}
public void show( int color, float fadeTime, float showTime ) {
this.color = color;
this.fadeTime = fadeTime;
this.showTime = showTime;
state = State.FADE_IN;
time = fadeTime;
}
public void show( int color, float fadeTime ) {
show( color, fadeTime, Float.MAX_VALUE );
}
@Override
public void update() {
super.update();
time -= Game.elapsed;
if (time >= 0) {
float p = time / fadeTime;
switch (state) {
case FADE_IN:
tint( color, p );
alpha( 1 - p );
break;
case STATIC:
resetColor();
break;
case FADE_OUT:
resetColor();
alpha( p );
break;
}
} else {
switch (state) {
case FADE_IN:
time = showTime;
state = State.STATIC;
break;
case STATIC:
time = fadeTime;
state = State.FADE_OUT;
break;
case FADE_OUT:
killAndErase();
break;
}
}
}
}
| 2,151 | Banner | java | en | java | code | {"qsc_code_num_words": 283, "qsc_code_num_chars": 2151.0, "qsc_code_mean_word_length": 4.95759717, "qsc_code_frac_words_unique": 0.44169611, "qsc_code_frac_chars_top_2grams": 0.0171062, "qsc_code_frac_chars_top_3grams": 0.02779758, "qsc_code_frac_chars_top_4grams": 0.04062723, "qsc_code_frac_chars_dupe_5grams": 0.13827512, "qsc_code_frac_chars_dupe_6grams": 0.08980756, "qsc_code_frac_chars_dupe_7grams": 0.04989309, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01301922, "qsc_code_frac_chars_whitespace": 0.25011623, "qsc_code_size_file_byte": 2151.0, "qsc_code_num_lines": 106.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 20.29245283, "qsc_code_frac_chars_alphabet": 0.85678859, "qsc_code_frac_chars_comments": 0.36308694, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.29850746, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04477612, "qsc_codejava_score_lines_no_logic": 0.1641791, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/GoldIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Game;
import com.watabou.noosa.ui.Component;
public class GoldIndicator extends Component {
private static final float TIME = 2f;
private int lastValue = 0;
private BitmapText tf;
private float time;
@Override
protected void createChildren() {
tf = new BitmapText( PixelScene.pixelFont);
tf.hardlight( 0xFFFF00 );
add( tf );
visible = false;
}
@Override
protected void layout() {
tf.x = x + (width - tf.width()) / 2;
tf.y = bottom() - tf.height();
}
@Override
public void update() {
super.update();
if (visible) {
time -= Game.elapsed;
if (time > 0) {
tf.alpha( time > TIME / 2 ? 1f : time * 2 / TIME );
} else {
visible = false;
}
}
if (Dungeon.gold != lastValue) {
lastValue = Dungeon.gold;
tf.text( Integer.toString( lastValue ) );
tf.measure();
visible = true;
time = TIME;
layout();
}
}
}
| 1,936 | GoldIndicator | java | en | java | code | {"qsc_code_num_words": 251, "qsc_code_num_chars": 1936.0, "qsc_code_mean_word_length": 5.28685259, "qsc_code_frac_words_unique": 0.53386454, "qsc_code_frac_chars_top_2grams": 0.03391108, "qsc_code_frac_chars_top_3grams": 0.0293896, "qsc_code_frac_chars_top_4grams": 0.04295403, "qsc_code_frac_chars_dupe_5grams": 0.06179352, "qsc_code_frac_chars_dupe_6grams": 0.04220045, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01777485, "qsc_code_frac_chars_whitespace": 0.21539256, "qsc_code_size_file_byte": 1936.0, "qsc_code_num_lines": 82.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 23.6097561, "qsc_code_frac_chars_alphabet": 0.8558262, "qsc_code_frac_chars_comments": 0.40340909, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11363636, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00692641, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06818182, "qsc_codejava_score_lines_no_logic": 0.25, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/RedButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
public class RedButton extends StyledButton {
public RedButton( String label ) {
this(label, 9);
}
public RedButton( String label, int size ){
super( Chrome.Type.RED_BUTTON, label, size);
}
}
| 1,098 | RedButton | java | en | java | code | {"qsc_code_num_words": 156, "qsc_code_num_chars": 1098.0, "qsc_code_mean_word_length": 5.21794872, "qsc_code_frac_words_unique": 0.62820513, "qsc_code_frac_chars_top_2grams": 0.04054054, "qsc_code_frac_chars_top_3grams": 0.04791155, "qsc_code_frac_chars_top_4grams": 0.07002457, "qsc_code_frac_chars_dupe_5grams": 0.1007371, "qsc_code_frac_chars_dupe_6grams": 0.06879607, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02011173, "qsc_code_frac_chars_whitespace": 0.1848816, "qsc_code_size_file_byte": 1098.0, "qsc_code_num_lines": 35.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 31.37142857, "qsc_code_frac_chars_alphabet": 0.88938547, "qsc_code_frac_chars_comments": 0.71129326, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.0, "qsc_codejava_score_lines_no_logic": 0.2, "qsc_codejava_frac_words_no_modifier": 0.0, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": null, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/AttackIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.badlogic.gdx.utils.reflect.ClassReflection;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.watabou.noosa.Game;
import com.watabou.utils.Random;
import com.watabou.utils.Reflection;
import java.util.ArrayList;
public class AttackIndicator extends Tag {
private static final float ENABLED = 1.0f;
private static final float DISABLED = 0.3f;
private static float delay;
private static AttackIndicator instance;
private CharSprite sprite = null;
private static Mob lastTarget;
private ArrayList<Mob> candidates = new ArrayList<>();
public AttackIndicator() {
super( DangerIndicator.COLOR );
instance = this;
lastTarget = null;
hotKey = GameAction.TAG_ATTACK;
setSize( 24, 24 );
visible( false );
enable( false );
}
@Override
protected void createChildren() {
super.createChildren();
}
@Override
protected synchronized void layout() {
super.layout();
if (sprite != null) {
sprite.x = x + (width - sprite.width()) / 2;
sprite.y = y + (height - sprite.height()) / 2;
PixelScene.align(sprite);
}
}
@Override
public synchronized void update() {
super.update();
if (!bg.visible){
enable(false);
if (delay > 0f) delay -= Game.elapsed;
if (delay <= 0f) active = false;
} else {
delay = 0.75f;
active = true;
if (Dungeon.hero.isAlive()) {
enable(Dungeon.hero.ready);
} else {
visible( false );
enable( false );
}
}
}
private synchronized void checkEnemies() {
candidates.clear();
int v = Dungeon.hero.visibleEnemies();
for (int i=0; i < v; i++) {
Mob mob = Dungeon.hero.visibleEnemy( i );
if ( Dungeon.hero.canAttack( mob) ) {
candidates.add( mob );
}
}
if (!candidates.contains( lastTarget )) {
if (candidates.isEmpty()) {
lastTarget = null;
} else {
active = true;
lastTarget = Random.element( candidates );
updateImage();
flash();
}
} else {
if (!bg.visible) {
active = true;
flash();
}
}
visible( lastTarget != null );
enable( bg.visible );
}
private synchronized void updateImage() {
if (sprite != null) {
sprite.killAndErase();
sprite = null;
}
sprite = Reflection.newInstance(lastTarget.spriteClass);
active = true;
sprite.linkVisuals(lastTarget);
sprite.idle();
sprite.paused = true;
add( sprite );
sprite.x = x + (width - sprite.width()) / 2 + 1;
sprite.y = y + (height - sprite.height()) / 2;
PixelScene.align(sprite);
}
private boolean enabled = true;
private synchronized void enable( boolean value ) {
enabled = value;
if (sprite != null) {
sprite.alpha( value ? ENABLED : DISABLED );
}
}
private synchronized void visible( boolean value ) {
bg.visible = value;
if (sprite != null) {
sprite.visible = value;
}
}
@Override
protected void onClick() {
if (enabled) {
if (Dungeon.hero.handle( lastTarget.pos )) {
Dungeon.hero.next();
}
}
}
public static void target( Char target ) {
lastTarget = (Mob)target;
instance.updateImage();
TargetHealthIndicator.instance.target( target );
}
public static void updateState() {
instance.checkEnemies();
}
}
| 4,429 | AttackIndicator | java | en | java | code | {"qsc_code_num_words": 509, "qsc_code_num_chars": 4429.0, "qsc_code_mean_word_length": 5.96267191, "qsc_code_frac_words_unique": 0.37328094, "qsc_code_frac_chars_top_2grams": 0.03261944, "qsc_code_frac_chars_top_3grams": 0.10016474, "qsc_code_frac_chars_top_4grams": 0.1014827, "qsc_code_frac_chars_dupe_5grams": 0.123229, "qsc_code_frac_chars_dupe_6grams": 0.06655684, "qsc_code_frac_chars_dupe_7grams": 0.04810544, "qsc_code_frac_chars_dupe_8grams": 0.03163097, "qsc_code_frac_chars_dupe_9grams": 0.03163097, "qsc_code_frac_chars_dupe_10grams": 0.03163097, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01015515, "qsc_code_frac_chars_whitespace": 0.19959359, "qsc_code_size_file_byte": 4429.0, "qsc_code_num_lines": 187.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 23.68449198, "qsc_code_frac_chars_alphabet": 0.84598025, "qsc_code_frac_chars_comments": 0.17633777, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.23308271, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03007519, "qsc_codejava_score_lines_no_logic": 0.15037594, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/PrefsButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndSettings;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class PrefsButton extends Button<GameAction> {
private Image image;
@Override
protected void createChildren() {
super.createChildren();
image = Icons.PREFS.get();
add( image );
}
@Override
protected void layout() {
super.layout();
image.x = x + (width - image.width)/2f;
image.y = y + (height - image.height)/2f;
PixelScene.align(image);
}
@Override
protected void onTouchDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
image.resetColor();
}
@Override
protected void onClick() {
parent.add( new WndSettings() );
}
}
| 1,850 | PrefsButton | java | en | java | code | {"qsc_code_num_words": 238, "qsc_code_num_chars": 1850.0, "qsc_code_mean_word_length": 5.75210084, "qsc_code_frac_words_unique": 0.54621849, "qsc_code_frac_chars_top_2grams": 0.04601899, "qsc_code_frac_chars_top_3grams": 0.13878744, "qsc_code_frac_chars_top_4grams": 0.12856099, "qsc_code_frac_chars_dupe_5grams": 0.05989774, "qsc_code_frac_chars_dupe_6grams": 0.04090577, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01357466, "qsc_code_frac_chars_whitespace": 0.16378378, "qsc_code_size_file_byte": 1850.0, "qsc_code_num_lines": 67.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 27.6119403, "qsc_code_frac_chars_alphabet": 0.87136393, "qsc_code_frac_chars_comments": 0.42216216, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13513514, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.13513514, "qsc_codejava_score_lines_no_logic": 0.37837838, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Belongings;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.journal.Notes;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.watabou.noosa.Game;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
import com.watabou.utils.FileUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.UUID;
public enum Rankings {
INSTANCE;
public static final int TABLE_SIZE = 11;
public static final String RANKINGS_FILE = "rankings.dat";
public ArrayList<Record> records;
public int lastRecord;
public int totalNumber;
public int wonNumber;
public void submit( boolean win, Class cause ) {
load();
Record rec = new Record();
rec.cause = cause;
rec.win = win;
rec.heroClass = Dungeon.hero.heroClass;
rec.armorTier = Dungeon.hero.tier();
rec.herolevel = Dungeon.hero.lvl;
rec.depth = Dungeon.depth;
rec.score = score( win );
INSTANCE.saveGameData(rec);
rec.gameID = UUID.randomUUID().toString();
records.add( rec );
Collections.sort( records, scoreComparator );
lastRecord = records.indexOf( rec );
int size = records.size();
while (size > TABLE_SIZE) {
if (lastRecord == size - 1) {
records.remove( size - 2 );
lastRecord--;
} else {
records.remove( size - 1 );
}
size = records.size();
}
totalNumber++;
if (win) {
wonNumber++;
}
Badges.validateGamesPlayed();
save();
}
private int score( boolean win ) {
return (Statistics.goldCollected + Dungeon.hero.lvl * (win ? 26 : Dungeon.depth ) * 100) * (win ? 2 : 1);
}
public static final String HERO = "hero";
public static final String STATS = "stats";
public static final String BADGES = "badges";
public static final String HANDLERS = "handlers";
public static final String CHALLENGES = "challenges";
public void saveGameData(Record rec){
rec.gameData = new Bundle();
Belongings belongings = Dungeon.hero.belongings;
//save the hero and belongings
ArrayList<Item> allItems = (ArrayList<Item>) belongings.backpack.items.clone();
//remove items that won't show up in the rankings screen
for (Item item : belongings.backpack.items.toArray( new Item[0])) {
if (item instanceof Bag){
for (Item bagItem : ((Bag) item).items.toArray( new Item[0])){
if (Dungeon.quickslot.contains(bagItem)) belongings.backpack.items.add(bagItem);
}
belongings.backpack.items.remove(item);
} else if (!Dungeon.quickslot.contains(item))
belongings.backpack.items.remove(item);
}
rec.gameData.put( HERO, Dungeon.hero );
//save stats
Bundle stats = new Bundle();
Statistics.storeInBundle(stats);
rec.gameData.put( STATS, stats);
//save badges
Bundle badges = new Bundle();
Badges.saveLocal(badges);
rec.gameData.put( BADGES, badges);
//save handler information
Bundle handler = new Bundle();
Scroll.saveSelectively(handler, belongings.backpack.items);
Potion.saveSelectively(handler, belongings.backpack.items);
//include worn rings
if (belongings.misc1 != null) belongings.backpack.items.add(belongings.misc1);
if (belongings.misc2 != null) belongings.backpack.items.add(belongings.misc2);
Ring.saveSelectively(handler, belongings.backpack.items);
rec.gameData.put( HANDLERS, handler);
//restore items now that we're done saving
belongings.backpack.items = allItems;
//save challenges
rec.gameData.put( CHALLENGES, Dungeon.challenges );
}
public void loadGameData(Record rec){
Bundle data = rec.gameData;
Actor.clear();
Dungeon.hero = null;
Dungeon.level = null;
Generator.reset();
Notes.reset();
Dungeon.quickslot.reset();
QuickSlotButton.reset();
Bundle handler = data.getBundle(HANDLERS);
Scroll.restore(handler);
Potion.restore(handler);
Ring.restore(handler);
Badges.loadLocal(data.getBundle(BADGES));
Dungeon.hero = (Hero)data.get(HERO);
Statistics.restoreFromBundle(data.getBundle(STATS));
Dungeon.challenges = data.getInt(CHALLENGES);
}
private static final String RECORDS = "records";
private static final String LATEST = "latest";
private static final String TOTAL = "total";
private static final String WON = "won";
public void save() {
Bundle bundle = new Bundle();
bundle.put( RECORDS, records );
bundle.put( LATEST, lastRecord );
bundle.put( TOTAL, totalNumber );
bundle.put( WON, wonNumber );
try {
FileUtils.bundleToFile( RANKINGS_FILE, bundle);
} catch (IOException e) {
ShatteredPixelDungeon.reportException(e);
}
}
public void load() {
if (records != null) {
return;
}
records = new ArrayList<>();
try {
Bundle bundle = FileUtils.bundleFromFile( RANKINGS_FILE );
for (Bundlable record : bundle.getCollection( RECORDS )) {
records.add( (Record)record );
}
lastRecord = bundle.getInt( LATEST );
totalNumber = bundle.getInt( TOTAL );
if (totalNumber == 0) {
totalNumber = records.size();
}
wonNumber = bundle.getInt( WON );
if (wonNumber == 0) {
for (Record rec : records) {
if (rec.win) {
wonNumber++;
}
}
}
} catch (IOException e) {
}
}
public static class Record implements Bundlable {
private static final String CAUSE = "cause";
private static final String WIN = "win";
private static final String SCORE = "score";
private static final String TIER = "tier";
private static final String LEVEL = "level";
private static final String DEPTH = "depth";
private static final String DATA = "gameData";
private static final String ID = "gameID";
public Class cause;
public boolean win;
public HeroClass heroClass;
public int armorTier;
public int herolevel;
public int depth;
public Bundle gameData;
public String gameID;
public int score;
public String desc(){
if (cause == null) {
return Messages.get(this, "something");
} else {
String result = Messages.get(cause, "rankings_desc", (Messages.get(cause, "name")));
if (result.contains("!!!NO TEXT FOUND!!!")){
return Messages.get(this, "something");
} else {
return result;
}
}
}
@Override
public void restoreFromBundle( Bundle bundle ) {
if (bundle.contains( CAUSE )) {
cause = bundle.getClass( CAUSE );
} else {
cause = null;
}
win = bundle.getBoolean( WIN );
score = bundle.getInt( SCORE );
heroClass = HeroClass.restoreInBundle( bundle );
armorTier = bundle.getInt( TIER );
if (bundle.contains(DATA)) gameData = bundle.getBundle(DATA);
if (bundle.contains(ID)) gameID = bundle.getString(ID);
if (gameID == null) gameID = UUID.randomUUID().toString();
depth = bundle.getInt( DEPTH );
herolevel = bundle.getInt( LEVEL );
}
@Override
public void storeInBundle( Bundle bundle ) {
if (cause != null) bundle.put( CAUSE, cause );
bundle.put( WIN, win );
bundle.put( SCORE, score );
heroClass.storeInBundle( bundle );
bundle.put( TIER, armorTier );
bundle.put( LEVEL, herolevel );
bundle.put( DEPTH, depth );
if (gameData != null) bundle.put( DATA, gameData );
bundle.put( ID, gameID );
}
}
private static final Comparator<Record> scoreComparator = new Comparator<Rankings.Record>() {
@Override
public int compare( Record lhs, Record rhs ) {
int result = (int)Math.signum( rhs.score - lhs.score );
if (result == 0) {
return (int)Math.signum( rhs.gameID.hashCode() - lhs.gameID.hashCode());
} else{
return result;
}
}
};
}
| 9,112 | Rankings | java | en | java | code | {"qsc_code_num_words": 1070, "qsc_code_num_chars": 9112.0, "qsc_code_mean_word_length": 5.96635514, "qsc_code_frac_words_unique": 0.23084112, "qsc_code_frac_chars_top_2grams": 0.03446115, "qsc_code_frac_chars_top_3grams": 0.04793233, "qsc_code_frac_chars_top_4grams": 0.089599, "qsc_code_frac_chars_dupe_5grams": 0.15366541, "qsc_code_frac_chars_dupe_6grams": 0.06422306, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00509588, "qsc_code_frac_chars_whitespace": 0.18162862, "qsc_code_size_file_byte": 9112.0, "qsc_code_num_lines": 332.0, "qsc_code_num_chars_line_max": 108.0, "qsc_code_num_chars_line_mean": 27.44578313, "qsc_code_frac_chars_alphabet": 0.85101247, "qsc_code_frac_chars_comments": 0.10941615, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.08583691, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0198398, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04291845, "qsc_codejava_score_lines_no_logic": 0.20600858, "qsc_codejava_frac_words_no_modifier": 1.0, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": null, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/Chrome.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.watabou.noosa.NinePatch;
public class Chrome {
public enum Type {
TOAST,
TOAST_TR,
WINDOW,
RED_BUTTON,
GREY_BUTTON,
GREY_BUTTON_TR,
TAG,
GEM,
SCROLL,
TAB_SET,
TAB_SELECTED,
TAB_UNSELECTED
}
public static NinePatch get( Type type ) {
String Asset = Assets.CHROME;
switch (type) {
case WINDOW:
return new NinePatch( Asset, 0, 0, 20, 20, 6 );
case TOAST:
return new NinePatch( Asset, 22, 0, 18, 18, 5 );
case TOAST_TR:
return new NinePatch( Asset, 40, 0, 18, 18, 5 );
case RED_BUTTON:
return new NinePatch( Asset, 58, 0, 6, 6, 2 );
case GREY_BUTTON:
return new NinePatch( Asset, 58, 6, 6, 6, 2 );
case TAG:
return new NinePatch( Asset, 22, 18, 16, 14, 3 );
case GEM:
return new NinePatch( Asset, 0, 32, 32, 32, 13 );
case GREY_BUTTON_TR:
return new NinePatch( Asset, 53, 20, 9, 9, 5 );
case SCROLL:
return new NinePatch( Asset, 32, 32, 32, 32, 5, 11, 5, 11 );
case TAB_SET:
return new NinePatch( Asset, 64, 0, 20, 20, 6 );
case TAB_SELECTED:
return new NinePatch( Asset, 65, 22, 8, 13, 3, 7, 3, 5 );
case TAB_UNSELECTED:
return new NinePatch( Asset, 75, 22, 8, 13, 3, 7, 3, 5 );
default:
return null;
}
}
}
| 2,052 | Chrome | java | en | java | code | {"qsc_code_num_words": 320, "qsc_code_num_chars": 2052.0, "qsc_code_mean_word_length": 4.29375, "qsc_code_frac_words_unique": 0.421875, "qsc_code_frac_chars_top_2grams": 0.07860262, "qsc_code_frac_chars_top_3grams": 0.15720524, "qsc_code_frac_chars_top_4grams": 0.20087336, "qsc_code_frac_chars_dupe_5grams": 0.25473071, "qsc_code_frac_chars_dupe_6grams": 0.09898108, "qsc_code_frac_chars_dupe_7grams": 0.01310044, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.07600503, "qsc_code_frac_chars_whitespace": 0.22417154, "qsc_code_size_file_byte": 2052.0, "qsc_code_num_lines": 73.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 28.10958904, "qsc_code_frac_chars_alphabet": 0.7870603, "qsc_code_frac_chars_comments": 0.38060429, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02040816, "qsc_codejava_score_lines_no_logic": 0.08163265, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/GamesInProgress.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.utils.Bundle;
import com.watabou.utils.FileUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
public class GamesInProgress {
public static final int MAX_SLOTS = 4;
//null means we have loaded info and it is empty, no entry means unknown.
private static HashMap<Integer, Info> slotStates = new HashMap<>();
public static int curSlot;
public static HeroClass selectedClass;
private static final String GAME_FOLDER = "game%d";
private static final String GAME_FILE = "game.dat";
private static final String DEPTH_FILE = "depth%d.dat";
public static boolean gameExists( int slot ){
return FileUtils.dirExists(Messages.format(GAME_FOLDER, slot));
}
public static String gameFolder( int slot ){
return Messages.format(GAME_FOLDER, slot);
}
public static String gameFile( int slot ){
return gameFolder(slot) + "/" + GAME_FILE;
}
public static String depthFile( int slot, int depth ) {
return gameFolder(slot) + "/" + Messages.format(DEPTH_FILE, depth);
}
public static int firstEmpty(){
for (int i = 1; i <= MAX_SLOTS; i++){
if (check(i) == null) return i;
}
return -1;
}
public static ArrayList<Info> checkAll(){
ArrayList<Info> result = new ArrayList<>();
for (int i = 0; i <= MAX_SLOTS; i++){
Info curr = check(i);
if (curr != null) result.add(curr);
}
Collections.sort(result, scoreComparator);
return result;
}
public static Info check( int slot ) {
if (slotStates.containsKey( slot )) {
return slotStates.get( slot );
} else if (!gameExists( slot )) {
slotStates.put(slot, null);
return null;
} else {
Info info;
try {
Bundle bundle = FileUtils.bundleFromFile(gameFile(slot));
info = new Info();
info.slot = slot;
Dungeon.preview(info, bundle);
//saves from before 0.6.5c are not supported
if (info.version < ShatteredPixelDungeon.v0_6_5c) {
info = null;
}
} catch (IOException e) {
info = null;
} catch (Exception e){
ShatteredPixelDungeon.reportException( e );
info = null;
}
slotStates.put( slot, info );
return info;
}
}
public static void set(int slot, int depth, int challenges,
Hero hero) {
Info info = new Info();
info.slot = slot;
info.depth = depth;
info.challenges = challenges;
info.level = hero.lvl;
info.str = hero.STR;
info.exp = hero.exp;
info.hp = hero.HP;
info.ht = hero.HT;
info.shld = hero.shielding();
info.heroClass = hero.heroClass;
info.subClass = hero.subClass;
info.armorTier = hero.tier();
info.goldCollected = Statistics.goldCollected;
info.maxDepth = Statistics.deepestFloor;
slotStates.put( slot, info );
}
public static void setUnknown( int slot ) {
slotStates.remove( slot );
}
public static void delete( int slot ) {
slotStates.put( slot, null );
}
public static class Info {
public int slot;
public int depth;
public int version;
public int challenges;
public int level;
public int str;
public int exp;
public int hp;
public int ht;
public int shld;
public HeroClass heroClass;
public HeroSubClass subClass;
public int armorTier;
public int goldCollected;
public int maxDepth;
}
public static final Comparator<GamesInProgress.Info> scoreComparator = new Comparator<GamesInProgress.Info>() {
@Override
public int compare(GamesInProgress.Info lhs, GamesInProgress.Info rhs ) {
int lScore = (lhs.level * lhs.maxDepth * 100) + lhs.goldCollected;
int rScore = (rhs.level * rhs.maxDepth * 100) + rhs.goldCollected;
return (int)Math.signum( rScore - lScore );
}
};
}
| 4,869 | GamesInProgress | java | en | java | code | {"qsc_code_num_words": 621, "qsc_code_num_chars": 4869.0, "qsc_code_mean_word_length": 5.45088567, "qsc_code_frac_words_unique": 0.32045089, "qsc_code_frac_chars_top_2grams": 0.05317578, "qsc_code_frac_chars_top_3grams": 0.05612999, "qsc_code_frac_chars_top_4grams": 0.05199409, "qsc_code_frac_chars_dupe_5grams": 0.14416544, "qsc_code_frac_chars_dupe_6grams": 0.10516987, "qsc_code_frac_chars_dupe_7grams": 0.02717873, "qsc_code_frac_chars_dupe_8grams": 0.02717873, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00848547, "qsc_code_frac_chars_whitespace": 0.20127336, "qsc_code_size_file_byte": 4869.0, "qsc_code_num_lines": 183.0, "qsc_code_num_chars_line_max": 113.0, "qsc_code_num_chars_line_mean": 26.60655738, "qsc_code_frac_chars_alphabet": 0.86191823, "qsc_code_frac_chars_comments": 0.18443212, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.07258065, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00679929, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09677419, "qsc_codejava_score_lines_no_logic": 0.36290323, "qsc_codejava_frac_words_no_modifier": 0.76923077, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/QuickSlot.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
import java.util.ArrayList;
import java.util.Collection;
public class QuickSlot {
/**
* Slots contain objects which are also in a player's inventory. The one exception to this is when quantity is 0,
* which can happen for a stackable item that has been 'used up', these are refered to a placeholders.
*/
//note that the current max size is coded at 4, due to UI constraints, but it could be much much bigger with no issue.
public static int SIZE = 4;
private Item[] slots = new Item[SIZE];
//direct array interaction methods, everything should build from these methods.
public void setSlot(int slot, Item item){
clearItem(item); //we don't want to allow the same item in multiple slots.
slots[slot] = item;
}
public void clearSlot(int slot){
slots[slot] = null;
}
public void reset(){
slots = new Item[SIZE];
}
public Item getItem(int slot){
return slots[slot];
}
//utility methods, for easier use of the internal array.
public int getSlot(Item item) {
for (int i = 0; i < SIZE; i++)
if (getItem(i) == item)
return i;
return -1;
}
public Boolean isPlaceholder(int slot){
return getItem(slot) != null && getItem(slot).quantity() == 0;
}
public Boolean isNonePlaceholder(int slot){
return getItem(slot) != null && getItem(slot).quantity() > 0;
}
public void clearItem(Item item){
if (contains(item))
clearSlot(getSlot(item));
}
public boolean contains(Item item){
return getSlot(item) != -1;
}
public void replacePlaceholder(Item item){
for (int i = 0; i < SIZE; i++)
if (isPlaceholder(i) && item.isSimilar(getItem(i)))
setSlot( i , item );
}
public void convertToPlaceholder(Item item){
if (contains(item)) {
Item placeholder = item.virtual();
if (placeholder == null) return;
for (int i = 0; i < SIZE; i++) {
if (getItem(i) == item) setSlot(i, placeholder);
}
}
}
public Item randomNonePlaceholder(){
ArrayList<Item> result = new ArrayList<>();
for (int i = 0; i < SIZE; i ++)
if (getItem(i) != null && !isPlaceholder(i))
result.add(getItem(i));
return Random.element(result);
}
private final String PLACEHOLDERS = "placeholders";
private final String PLACEMENTS = "placements";
/**
* Placements array is used as order is preserved while bundling, but exact index is not, so if we
* bundle both the placeholders (which preserves their order) and an array telling us where the placeholders are,
* we can reconstruct them perfectly.
*/
public void storePlaceholders(Bundle bundle){
ArrayList<Item> placeholders = new ArrayList<>(SIZE);
boolean[] placements = new boolean[SIZE];
for (int i = 0; i < SIZE; i++)
if (isPlaceholder(i)) {
placeholders.add(getItem(i));
placements[i] = true;
}
bundle.put( PLACEHOLDERS, placeholders );
bundle.put( PLACEMENTS, placements );
}
public void restorePlaceholders(Bundle bundle){
Collection<Bundlable> placeholders = bundle.getCollection(PLACEHOLDERS);
boolean[] placements = bundle.getBooleanArray( PLACEMENTS );
int i = 0;
for (Bundlable item : placeholders){
while (!placements[i]) i++;
setSlot( i, (Item)item );
i++;
}
}
}
| 4,159 | QuickSlot | java | en | java | code | {"qsc_code_num_words": 567, "qsc_code_num_chars": 4159.0, "qsc_code_mean_word_length": 5.11816578, "qsc_code_frac_words_unique": 0.36507937, "qsc_code_frac_chars_top_2grams": 0.0275672, "qsc_code_frac_chars_top_3grams": 0.0103377, "qsc_code_frac_chars_top_4grams": 0.0137836, "qsc_code_frac_chars_dupe_5grams": 0.13439008, "qsc_code_frac_chars_dupe_6grams": 0.11026878, "qsc_code_frac_chars_dupe_7grams": 0.09097174, "qsc_code_frac_chars_dupe_8grams": 0.09097174, "qsc_code_frac_chars_dupe_9grams": 0.09097174, "qsc_code_frac_chars_dupe_10grams": 0.09097174, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00893655, "qsc_code_frac_chars_whitespace": 0.19283482, "qsc_code_size_file_byte": 4159.0, "qsc_code_num_lines": 150.0, "qsc_code_num_chars_line_max": 120.0, "qsc_code_num_chars_line_mean": 27.72666667, "qsc_code_frac_chars_alphabet": 0.85552577, "qsc_code_frac_chars_comments": 0.37989901, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04597701, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00853044, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.1954023, "qsc_codejava_score_lines_no_logic": 0.28735632, "qsc_codejava_frac_words_no_modifier": 0.77777778, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/Statistics.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.watabou.utils.Bundle;
public class Statistics {
public static int goldCollected;
public static int deepestFloor;
public static int enemiesSlain;
public static int foodEaten;
public static int potionsCooked;
public static int piranhasKilled;
public static int ankhsUsed;
//used for hero unlock badges
public static int upgradesUsed;
public static int sneakAttacks;
public static int thrownAssists;
public static float duration;
public static boolean qualifiedForNoKilling = false;
public static boolean completedWithNoKilling = false;
public static boolean amuletObtained = false;
public static void reset() {
goldCollected = 0;
deepestFloor = 0;
enemiesSlain = 0;
foodEaten = 0;
potionsCooked = 0;
piranhasKilled = 0;
ankhsUsed = 0;
upgradesUsed = 0;
sneakAttacks = 0;
thrownAssists = 0;
duration = 0;
qualifiedForNoKilling = false;
amuletObtained = false;
}
private static final String GOLD = "score";
private static final String DEEPEST = "maxDepth";
private static final String SLAIN = "enemiesSlain";
private static final String FOOD = "foodEaten";
private static final String ALCHEMY = "potionsCooked";
private static final String PIRANHAS = "priranhas";
private static final String ANKHS = "ankhsUsed";
private static final String UPGRADES = "upgradesUsed";
private static final String SNEAKS = "sneakAttacks";
private static final String THROWN = "thrownAssists";
private static final String DURATION = "duration";
private static final String AMULET = "amuletObtained";
public static void storeInBundle( Bundle bundle ) {
bundle.put( GOLD, goldCollected );
bundle.put( DEEPEST, deepestFloor );
bundle.put( SLAIN, enemiesSlain );
bundle.put( FOOD, foodEaten );
bundle.put( ALCHEMY, potionsCooked );
bundle.put( PIRANHAS, piranhasKilled );
bundle.put( ANKHS, ankhsUsed );
bundle.put( UPGRADES, upgradesUsed );
bundle.put( SNEAKS, sneakAttacks );
bundle.put( THROWN, thrownAssists );
bundle.put( DURATION, duration );
bundle.put( AMULET, amuletObtained );
}
public static void restoreFromBundle( Bundle bundle ) {
goldCollected = bundle.getInt( GOLD );
deepestFloor = bundle.getInt( DEEPEST );
enemiesSlain = bundle.getInt( SLAIN );
foodEaten = bundle.getInt( FOOD );
potionsCooked = bundle.getInt( ALCHEMY );
piranhasKilled = bundle.getInt( PIRANHAS );
ankhsUsed = bundle.getInt( ANKHS );
upgradesUsed = bundle.getInt( UPGRADES );
sneakAttacks = bundle.getInt( SNEAKS );
thrownAssists = bundle.getInt( THROWN );
duration = bundle.getFloat( DURATION );
amuletObtained = bundle.getBoolean( AMULET );
}
public static void preview( GamesInProgress.Info info, Bundle bundle ){
info.goldCollected = bundle.getInt( GOLD );
info.maxDepth = bundle.getInt( DEEPEST );
}
}
| 3,734 | Statistics | java | en | java | code | {"qsc_code_num_words": 426, "qsc_code_num_chars": 3734.0, "qsc_code_mean_word_length": 6.34037559, "qsc_code_frac_words_unique": 0.3286385, "qsc_code_frac_chars_top_2grams": 0.07997038, "qsc_code_frac_chars_top_3grams": 0.07997038, "qsc_code_frac_chars_top_4grams": 0.10662718, "qsc_code_frac_chars_dupe_5grams": 0.05701592, "qsc_code_frac_chars_dupe_6grams": 0.02073306, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00932401, "qsc_code_frac_chars_whitespace": 0.19576861, "qsc_code_size_file_byte": 3734.0, "qsc_code_num_lines": 126.0, "qsc_code_num_chars_line_max": 73.0, "qsc_code_num_chars_line_mean": 29.63492063, "qsc_code_frac_chars_alphabet": 0.89010989, "qsc_code_frac_chars_comments": 0.21692555, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.04240766, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05194805, "qsc_codejava_score_lines_no_logic": 0.22077922, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/Challenges.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Dewdrop;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.ClassArmor;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.ClothArmor;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HornOfPlenty;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
import com.shatteredpixel.shatteredpixeldungeon.items.food.SmallRation;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfHealing;
public class Challenges {
//Some of these internal IDs are outdated and don't represent what these challenges do
public static final int NO_FOOD = 1;
public static final int NO_ARMOR = 2;
public static final int NO_HEALING = 4;
public static final int NO_HERBALISM = 8;
public static final int SWARM_INTELLIGENCE = 16;
public static final int DARKNESS = 32;
public static final int NO_SCROLLS = 64;
public static final int MAX_VALUE = 127;
public static final String[] NAME_IDS = {
"no_food",
"no_armor",
"no_healing",
"no_herbalism",
"swarm_intelligence",
"darkness",
"no_scrolls"
};
public static final int[] MASKS = {
NO_FOOD, NO_ARMOR, NO_HEALING, NO_HERBALISM, SWARM_INTELLIGENCE, DARKNESS, NO_SCROLLS
};
public static boolean isItemBlocked( Item item ){
if (Dungeon.isChallenged(NO_FOOD)){
if (item instanceof Food && !(item instanceof SmallRation)) {
return true;
} else if (item instanceof HornOfPlenty){
return true;
}
}
if (Dungeon.isChallenged(NO_ARMOR)){
if (item instanceof Armor && !(item instanceof ClothArmor || item instanceof ClassArmor)) {
return true;
}
}
if (Dungeon.isChallenged(NO_HEALING)){
if (item instanceof PotionOfHealing){
return true;
} else if (item instanceof Blandfruit
&& ((Blandfruit) item).potionAttrib instanceof PotionOfHealing){
return true;
}
}
if (Dungeon.isChallenged(NO_HERBALISM)){
if (item instanceof Dewdrop) {
return true;
}
}
return false;
}
} | 3,077 | Challenges | java | en | java | code | {"qsc_code_num_words": 383, "qsc_code_num_chars": 3077.0, "qsc_code_mean_word_length": 5.95039164, "qsc_code_frac_words_unique": 0.36814621, "qsc_code_frac_chars_top_2grams": 0.08205353, "qsc_code_frac_chars_top_3grams": 0.18341378, "qsc_code_frac_chars_top_4grams": 0.19306713, "qsc_code_frac_chars_dupe_5grams": 0.45019746, "qsc_code_frac_chars_dupe_6grams": 0.30451953, "qsc_code_frac_chars_dupe_7grams": 0.06932865, "qsc_code_frac_chars_dupe_8grams": 0.06932865, "qsc_code_frac_chars_dupe_9grams": 0.06932865, "qsc_code_frac_chars_dupe_10grams": 0.06932865, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01174168, "qsc_code_frac_chars_whitespace": 0.16964576, "qsc_code_size_file_byte": 3077.0, "qsc_code_num_lines": 95.0, "qsc_code_num_chars_line_max": 95.0, "qsc_code_num_chars_line_mean": 32.38947368, "qsc_code_frac_chars_alphabet": 0.88023483, "qsc_code_frac_chars_comments": 0.28176796, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13114754, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.03301673, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.01639344, "qsc_codejava_score_lines_no_logic": 0.31147541, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/Assets.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon;
public class Assets {
public static final String ARCS_BG = "arcs1.png";
public static final String ARCS_FG = "arcs2.png";
public static final String DASHBOARD = "dashboard.png";
public static final String BANNERS = "banners.png";
public static final String BADGES = "badges.png";
public static final String LOCKED = "locked_badge.png";
public static final String AMULET = "amulet.png";
public static final String CHROME = "chrome.png";
public static final String ICONS = "icons.png";
public static final String STATUS = "status_pane.png";
public static final String MENU = "menu_button.png";
public static final String HP_BAR = "hp_bar.png";
public static final String SHLD_BAR = "shield_bar.png";
public static final String XP_BAR = "exp_bar.png";
public static final String TOOLBAR = "toolbar.png";
public static final String SHADOW = "shadow.png";
public static final String BOSSHP = "boss_hp.png";
public static final String WARRIOR = "warrior.png";
public static final String MAGE = "mage.png";
public static final String ROGUE = "rogue.png";
public static final String HUNTRESS = "huntress.png";
public static final String AVATARS = "avatars.png";
public static final String PET = "pet.png";
public static final String SURFACE = "surface.png";
public static final String FIREBALL = "fireball.png";
public static final String SPECKS = "specks.png";
public static final String EFFECTS = "effects.png";
public static final String RAT = "rat.png";
public static final String GNOLL = "gnoll.png";
public static final String CRAB = "crab.png";
public static final String GOO = "goo.png";
public static final String SWARM = "swarm.png";
public static final String SKELETON = "skeleton.png";
public static final String SHAMAN = "shaman.png";
public static final String THIEF = "thief.png";
public static final String TENGU = "tengu.png";
public static final String SHEEP = "sheep.png";
public static final String KEEPER = "shopkeeper.png";
public static final String BAT = "bat.png";
public static final String BRUTE = "brute.png";
public static final String SPINNER = "spinner.png";
public static final String DM300 = "dm300.png";
public static final String WRAITH = "wraith.png";
public static final String ELEMENTAL= "elemental.png";
public static final String MONK = "monk.png";
public static final String WARLOCK = "warlock.png";
public static final String GOLEM = "golem.png";
public static final String UNDEAD = "undead.png";
public static final String KING = "king.png";
public static final String STATUE = "statue.png";
public static final String PIRANHA = "piranha.png";
public static final String EYE = "eye.png";
public static final String SUCCUBUS = "succubus.png";
public static final String SCORPIO = "scorpio.png";
public static final String ROTTING = "rotting_fist.png";
public static final String BURNING = "burning_fist.png";
public static final String YOG = "yog.png";
public static final String LARVA = "larva.png";
public static final String GHOST = "ghost.png";
public static final String MAKER = "wandmaker.png";
public static final String TROLL = "blacksmith.png";
public static final String IMP = "demon.png";
public static final String RATKING = "ratking.png";
public static final String BEE = "bee.png";
public static final String MIMIC = "mimic.png";
public static final String ROT_LASH = "rot_lasher.png";
public static final String ROT_HEART= "rot_heart.png";
public static final String GUARD = "guard.png";
public static final String WARDS = "wards.png";
public static final String GUARDIAN = "guardian.png";
public static final String SLIME = "slime.png";
public static final String SNAKE = "snake.png";
public static final String NECRO = "necromancer.png";
public static final String ITEMS = "items.png";
public static final String TERRAIN_FEATURES = "terrain_features.png";
public static final String TILES_SEWERS = "tiles_sewers.png";
public static final String TILES_PRISON = "tiles_prison.png";
public static final String TILES_CAVES = "tiles_caves.png";
public static final String TILES_CITY = "tiles_city.png";
public static final String TILES_HALLS = "tiles_halls.png";
public static final String WATER_SEWERS = "water0.png";
public static final String WATER_PRISON = "water1.png";
public static final String WATER_CAVES = "water2.png";
public static final String WATER_CITY = "water3.png";
public static final String WATER_HALLS = "water4.png";
public static final String LOADING_SEWERS = "loading_sewers.png";
public static final String LOADING_PRISON = "loading_prison.png";
public static final String LOADING_CAVES = "loading_caves.png";
public static final String LOADING_CITY = "loading_city.png";
public static final String LOADING_HALLS = "loading_halls.png";
public static final String WEAK_FLOOR = "custom_tiles/weak_floor.png";
public static final String SEWER_BOSS = "custom_tiles/sewer_boss.png";
public static final String PRISON_QUEST = "custom_tiles/prison_quests.png";
public static final String PRISON_EXIT_OLD = "custom_tiles/prison_exit_old.png";
public static final String PRISON_EXIT_NEW = "custom_tiles/prison_exit_new.png";
public static final String BUFFS_SMALL = "buffs.png";
public static final String BUFFS_LARGE = "large_buffs.png";
public static final String SPELL_ICONS = "spell_icons.png";
public static final String CONS_ICONS = "consumable_icons.png";
public static final String PIXELFONT = "pixel_font.png";
public static final String FONT1X = "font1x.png";
public static final String FONT2X = "font2x.png";
public static final String THEME = "theme.ogg";
public static final String TUNE = "game.ogg";
public static final String HAPPY = "surface.ogg";
public static final String SND_CLICK = "snd_click.mp3";
public static final String SND_BADGE = "snd_badge.mp3";
public static final String SND_GOLD = "snd_gold.mp3";
public static final String SND_OPEN = "snd_door_open.mp3";
public static final String SND_UNLOCK = "snd_unlock.mp3";
public static final String SND_ITEM = "snd_item.mp3";
public static final String SND_DEWDROP = "snd_dewdrop.mp3";
public static final String SND_HIT = "snd_hit.mp3";
public static final String SND_MISS = "snd_miss.mp3";
public static final String SND_STEP = "snd_step.mp3";
public static final String SND_WATER = "snd_water.mp3";
public static final String SND_DESCEND = "snd_descend.mp3";
public static final String SND_EAT = "snd_eat.mp3";
public static final String SND_READ = "snd_read.mp3";
public static final String SND_LULLABY = "snd_lullaby.mp3";
public static final String SND_DRINK = "snd_drink.mp3";
public static final String SND_SHATTER = "snd_shatter.mp3";
public static final String SND_ZAP = "snd_zap.mp3";
public static final String SND_LIGHTNING= "snd_lightning.mp3";
public static final String SND_LEVELUP = "snd_levelup.mp3";
public static final String SND_DEATH = "snd_death.mp3";
public static final String SND_CHALLENGE= "snd_challenge.mp3";
public static final String SND_CURSED = "snd_cursed.mp3";
public static final String SND_TRAP = "snd_trap.mp3";
public static final String SND_EVOKE = "snd_evoke.mp3";
public static final String SND_TOMB = "snd_tomb.mp3";
public static final String SND_ALERT = "snd_alert.mp3";
public static final String SND_MELD = "snd_meld.mp3";
public static final String SND_BOSS = "snd_boss.mp3";
public static final String SND_BLAST = "snd_blast.mp3";
public static final String SND_PLANT = "snd_plant.mp3";
public static final String SND_RAY = "snd_ray.mp3";
public static final String SND_BEACON = "snd_beacon.mp3";
public static final String SND_TELEPORT = "snd_teleport.mp3";
public static final String SND_CHARMS = "snd_charms.mp3";
public static final String SND_MASTERY = "snd_mastery.mp3";
public static final String SND_PUFF = "snd_puff.mp3";
public static final String SND_ROCKS = "snd_rocks.mp3";
public static final String SND_BURNING = "snd_burning.mp3";
public static final String SND_FALLING = "snd_falling.mp3";
public static final String SND_GHOST = "snd_ghost.mp3";
public static final String SND_SECRET = "snd_secret.mp3";
public static final String SND_BONES = "snd_bones.mp3";
public static final String SND_BEE = "snd_bee.mp3";
public static final String SND_DEGRADE = "snd_degrade.mp3";
public static final String SND_MIMIC = "snd_mimic.mp3";
}
| 9,354 | Assets | java | en | java | code | {"qsc_code_num_words": 1355, "qsc_code_num_chars": 9354.0, "qsc_code_mean_word_length": 5.06937269, "qsc_code_frac_words_unique": 0.19261993, "qsc_code_frac_chars_top_2grams": 0.26379386, "qsc_code_frac_chars_top_3grams": 0.37370796, "qsc_code_frac_chars_top_4grams": 0.50560489, "qsc_code_frac_chars_dupe_5grams": 0.63648275, "qsc_code_frac_chars_dupe_6grams": 0.35143398, "qsc_code_frac_chars_dupe_7grams": 0.01048188, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01019238, "qsc_code_frac_chars_whitespace": 0.16089374, "qsc_code_size_file_byte": 9354.0, "qsc_code_num_lines": 192.0, "qsc_code_num_chars_line_max": 83.0, "qsc_code_num_chars_line_mean": 48.71875, "qsc_code_frac_chars_alphabet": 0.86495095, "qsc_code_frac_chars_comments": 0.08349369, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.22057623, "qsc_code_frac_chars_long_word_length": 0.0172635, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.0, "qsc_codejava_score_lines_no_logic": 0.00649351, "qsc_codejava_frac_words_no_modifier": 0.0, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": null, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 1, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Window.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.badlogic.gdx.Input;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.effects.ShadowBox;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea;
import com.watabou.utils.Signal;
public class Window extends Group implements Signal.Listener<NoosaInputProcessor.Key<GameAction>> {
protected int width;
protected int height;
protected int yOffset;
protected TouchArea blocker;
protected ShadowBox shadow;
protected NinePatch chrome;
public static final int TITLE_COLOR = 0xFFFF44;
public static final int SHPX_COLOR = 0x33BB33;
public Window() {
this( 0, 0, 0, Chrome.get( Chrome.Type.WINDOW ) );
}
public Window( int width, int height ) {
this( width, height, 0, Chrome.get( Chrome.Type.WINDOW ) );
}
public Window( int width, int height, NinePatch chrome ) {
this(width, height, 0, chrome);
}
public Window( int width, int height, int yOffset, NinePatch chrome ) {
super();
this.yOffset = yOffset;
blocker = new TouchArea( 0, 0, PixelScene.uiCamera.width, PixelScene.uiCamera.height ) {
@Override
protected void onClick( NoosaInputProcessor.Touch touch ) {
if (Window.this.parent != null && !Window.this.chrome.overlapsScreenPoint(
(int)touch.current.x,
(int)touch.current.y )) {
onBackPressed();
}
}
};
blocker.camera = PixelScene.uiCamera;
add( blocker );
this.chrome = chrome;
this.width = width;
this.height = height;
shadow = new ShadowBox();
shadow.am = 0.5f;
shadow.camera = PixelScene.uiCamera.visible ?
PixelScene.uiCamera : Camera.main;
add( shadow );
chrome.x = -chrome.marginLeft();
chrome.y = -chrome.marginTop();
chrome.size(
width - chrome.x + chrome.marginRight(),
height - chrome.y + chrome.marginBottom() );
add( chrome );
camera = new Camera( 0, 0,
(int)chrome.width,
(int)chrome.height,
PixelScene.defaultZoom );
camera.x = (int)(Game.width - camera.width * camera.zoom) / 2;
camera.y = (int)(Game.height - camera.height * camera.zoom) / 2;
camera.y -= yOffset * camera.zoom;
camera.scroll.set( chrome.x, chrome.y );
Camera.add( camera );
shadow.boxRect(
camera.x / camera.zoom,
camera.y / camera.zoom,
chrome.width(), chrome.height );
Game.instance.getInputProcessor().addKeyListener(this);
}
public void resize( int w, int h ) {
this.width = w;
this.height = h;
chrome.size(
width + chrome.marginHor(),
height + chrome.marginVer() );
camera.resize( (int)chrome.width, (int)chrome.height );
camera.x = (int)(Game.width - camera.screenWidth()) / 2;
camera.y = (int)(Game.height - camera.screenHeight()) / 2;
camera.y += yOffset * camera.zoom;
shadow.boxRect( camera.x / camera.zoom, camera.y / camera.zoom, chrome.width(), chrome.height );
}
public void offset( int yOffset ){
camera.y -= this.yOffset * camera.zoom;
this.yOffset = yOffset;
camera.y += yOffset * camera.zoom;
shadow.boxRect( camera.x / camera.zoom, camera.y / camera.zoom, chrome.width(), chrome.height );
}
public void hide() {
if (parent != null) {
parent.erase(this);
}
destroy();
}
@Override
public void destroy() {
super.destroy();
Camera.remove( camera );
Game.instance.getInputProcessor().removeKeyListener(this);
}
@Override
public void onSignal( NoosaInputProcessor.Key<GameAction> key ) {
if (key.pressed) {
switch (key.code) {
case Input.Keys.BACK:
case Input.Keys.ESCAPE:
onBackPressed();
break;
case Input.Keys.MENU:
onMenuPressed();
break;
default:
onKeyDown(key);
break;
}
} else {
onKeyUp( key );
}
Game.instance.getInputProcessor().cancelKeyEvent();
}
protected void onKeyDown(NoosaInputProcessor.Key key) {
}
protected void onKeyUp( NoosaInputProcessor.Key<GameAction> key ) {
}
public void onBackPressed() {
hide();
}
public void onMenuPressed() {
}
}
| 5,063 | Window | java | en | java | code | {"qsc_code_num_words": 625, "qsc_code_num_chars": 5063.0, "qsc_code_mean_word_length": 5.6592, "qsc_code_frac_words_unique": 0.3008, "qsc_code_frac_chars_top_2grams": 0.03053435, "qsc_code_frac_chars_top_3grams": 0.03166525, "qsc_code_frac_chars_top_4grams": 0.02968617, "qsc_code_frac_chars_dupe_5grams": 0.21034775, "qsc_code_frac_chars_dupe_6grams": 0.18688154, "qsc_code_frac_chars_dupe_7grams": 0.12496466, "qsc_code_frac_chars_dupe_8grams": 0.10969748, "qsc_code_frac_chars_dupe_9grams": 0.10969748, "qsc_code_frac_chars_dupe_10grams": 0.10969748, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00962927, "qsc_code_frac_chars_whitespace": 0.17953782, "qsc_code_size_file_byte": 5063.0, "qsc_code_num_lines": 190.0, "qsc_code_num_chars_line_max": 100.0, "qsc_code_num_chars_line_mean": 26.64736842, "qsc_code_frac_chars_alphabet": 0.84183919, "qsc_code_frac_chars_comments": 0.15425637, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11851852, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00373657, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07407407, "qsc_codejava_score_lines_no_logic": 0.21481481, "qsc_codejava_frac_words_no_modifier": 0.90909091, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/TargetHealthIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
public class TargetHealthIndicator extends HealthBar {
public static TargetHealthIndicator instance;
private Char target;
public TargetHealthIndicator() {
super();
instance = this;
}
@Override
public void update() {
super.update();
if (target != null && target.isAlive() && target.sprite.visible) {
CharSprite sprite = target.sprite;
width = sprite.width;
x = sprite.x;
y = sprite.y - 3;
level( target );
visible = true;
} else {
visible = false;
}
}
public void target( Char ch ) {
if (ch != null && ch.isAlive()) {
target = ch;
} else {
target = null;
}
}
public Char target() {
return target;
}
}
| 1,642 | TargetHealthIndicator | java | en | java | code | {"qsc_code_num_words": 210, "qsc_code_num_chars": 1642.0, "qsc_code_mean_word_length": 5.5, "qsc_code_frac_words_unique": 0.53809524, "qsc_code_frac_chars_top_2grams": 0.02857143, "qsc_code_frac_chars_top_3grams": 0.03376623, "qsc_code_frac_chars_top_4grams": 0.04935065, "qsc_code_frac_chars_dupe_5grams": 0.07099567, "qsc_code_frac_chars_dupe_6grams": 0.04848485, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01380368, "qsc_code_frac_chars_whitespace": 0.20584653, "qsc_code_size_file_byte": 1642.0, "qsc_code_num_lines": 65.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 25.26153846, "qsc_code_frac_chars_alphabet": 0.87193252, "qsc_code_frac_chars_comments": 0.47563946, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05714286, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08571429, "qsc_codejava_score_lines_no_logic": 0.25714286, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Compass.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.utils.PointF;
public class Compass extends Image {
private static final float RAD_2_G = 180f / 3.1415926f;
private static final float RADIUS = 12;
private int cell;
private PointF cellCenter;
private PointF lastScroll = new PointF();
public Compass( int cell ) {
super();
copy( Icons.COMPASS.get() );
origin.set( width / 2, RADIUS );
this.cell = cell;
cellCenter = DungeonTilemap.tileCenterToWorld( cell );
visible = false;
}
@Override
public void update() {
super.update();
if (cell < 0 || cell >= Dungeon.level.length()){
visible = false;
return;
}
if (!visible) {
visible = Dungeon.level.visited[cell] || Dungeon.level.mapped[cell];
}
if (visible) {
PointF scroll = Camera.main.scroll;
if (!scroll.equals( lastScroll )) {
lastScroll.set( scroll );
PointF center = Camera.main.center().offset( scroll );
angle = (float)Math.atan2( cellCenter.x - center.x, center.y - cellCenter.y ) * RAD_2_G;
}
}
}
}
| 2,041 | Compass | java | en | java | code | {"qsc_code_num_words": 270, "qsc_code_num_chars": 2041.0, "qsc_code_mean_word_length": 5.35185185, "qsc_code_frac_words_unique": 0.51481481, "qsc_code_frac_chars_top_2grams": 0.03114187, "qsc_code_frac_chars_top_3grams": 0.02698962, "qsc_code_frac_chars_top_4grams": 0.03944637, "qsc_code_frac_chars_dupe_5grams": 0.0567474, "qsc_code_frac_chars_dupe_6grams": 0.03875433, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02116082, "qsc_code_frac_chars_whitespace": 0.18961293, "qsc_code_size_file_byte": 2041.0, "qsc_code_num_lines": 72.0, "qsc_code_num_chars_line_max": 93.0, "qsc_code_num_chars_line_mean": 28.34722222, "qsc_code_frac_chars_alphabet": 0.85247884, "qsc_code_frac_chars_comments": 0.38265556, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.025, "qsc_codejava_score_lines_no_logic": 0.25, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Archs.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.noosa.SkinnedBlock;
import com.watabou.noosa.ui.Component;
public class Archs extends Component {
private static final float SCROLL_SPEED = 20f;
private SkinnedBlock arcsBg;
private SkinnedBlock arcsFg;
private Image darkness;
private static float offsB = 0;
private static float offsF = 0;
public boolean reversed = false;
@Override
protected void createChildren() {
arcsBg = new SkinnedBlock( 1, 1, Assets.ARCS_BG ){
@Override
protected NoosaScript script() {
return NoosaScriptNoLighting.get();
}
@Override
public void draw() {
//arch bg has no alpha component, this improves performance
Blending.disable();
super.draw();
Blending.enable();
}
};
arcsBg.autoAdjust = true;
arcsBg.offsetTo( 0, offsB );
add( arcsBg );
arcsFg = new SkinnedBlock( 1, 1, Assets.ARCS_FG ){
@Override
protected NoosaScript script() {
return NoosaScriptNoLighting.get();
}
};
arcsFg.autoAdjust = true;
arcsFg.offsetTo( 0, offsF );
add( arcsFg );
darkness= new Image(TextureCache.createGradient(0x00000000, 0x22000000, 0x55000000, 0x99000000, 0xEE000000));
darkness.angle = 90;
add(darkness);
}
@Override
protected void layout() {
arcsBg.size( width, height );
arcsBg.offset( arcsBg.texture.width / 4 - (width % arcsBg.texture.width) / 2, 0 );
arcsFg.size( width, height );
arcsFg.offset( arcsFg.texture.width / 4 - (width % arcsFg.texture.width) / 2, 0 );
darkness.x = width;
darkness.scale.x = height/5f;
darkness.scale.y = width;
}
@Override
public void update() {
super.update();
float shift = Game.elapsed * SCROLL_SPEED;
if (reversed) {
shift = -shift;
}
arcsBg.offset( 0, shift );
arcsFg.offset( 0, shift * 2 );
offsB = arcsBg.offsetY();
offsF = arcsFg.offsetY();
}
}
| 2,937 | Archs | java | en | java | code | {"qsc_code_num_words": 372, "qsc_code_num_chars": 2937.0, "qsc_code_mean_word_length": 5.63709677, "qsc_code_frac_words_unique": 0.44623656, "qsc_code_frac_chars_top_2grams": 0.03862661, "qsc_code_frac_chars_top_3grams": 0.06103958, "qsc_code_frac_chars_top_4grams": 0.06008584, "qsc_code_frac_chars_dupe_5grams": 0.12589413, "qsc_code_frac_chars_dupe_6grams": 0.11349547, "qsc_code_frac_chars_dupe_7grams": 0.06103958, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.03412401, "qsc_code_frac_chars_whitespace": 0.18181818, "qsc_code_size_file_byte": 2937.0, "qsc_code_num_lines": 110.0, "qsc_code_num_chars_line_max": 112.0, "qsc_code_num_chars_line_mean": 26.7, "qsc_code_frac_chars_alphabet": 0.83853516, "qsc_code_frac_chars_comments": 0.28600613, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.16901408, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.02384359, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08450704, "qsc_codejava_score_lines_no_logic": 0.26760563, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/DangerIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
public class DangerIndicator extends Tag {
public static final int COLOR = 0xFF4C4C;
private BitmapText number;
private Image icon;
private int enemyIndex = 0;
private int lastNumber = -1;
public DangerIndicator() {
super( 0xFF4C4C );
hotKey = GameAction.TAG_DANGER;
setSize( 24, 16 );
visible = false;
}
@Override
protected void createChildren() {
super.createChildren();
number = new BitmapText( PixelScene.pixelFont);
add( number );
icon = Icons.SKULL.get();
add( icon );
}
@Override
protected void layout() {
super.layout();
icon.x = right() - 10;
icon.y = y + (height - icon.height) / 2;
placeNumber();
}
private void placeNumber() {
number.x = right() - 11 - number.width();
number.y = y + (height - number.baseLine()) / 2f;
PixelScene.align(number);
}
@Override
public void update() {
if (Dungeon.hero.isAlive()) {
int v = Dungeon.hero.visibleEnemies();
if (v != lastNumber) {
lastNumber = v;
if (visible = lastNumber > 0) {
number.text( Integer.toString( lastNumber ) );
number.measure();
placeNumber();
flash();
}
}
} else {
visible = false;
}
super.update();
}
@Override
protected void onClick() {
if (Dungeon.hero.visibleEnemies() > 0) {
Mob target = Dungeon.hero.visibleEnemy(enemyIndex++);
TargetHealthIndicator.instance.target(target == TargetHealthIndicator.instance.target() ? null : target);
if (Dungeon.hero.curAction == null) {
Camera.main.panTo(target.sprite.center(), 5f);
}
}
}
}
| 2,768 | DangerIndicator | java | en | java | code | {"qsc_code_num_words": 331, "qsc_code_num_chars": 2768.0, "qsc_code_mean_word_length": 5.81873112, "qsc_code_frac_words_unique": 0.50151057, "qsc_code_frac_chars_top_2grams": 0.03271028, "qsc_code_frac_chars_top_3grams": 0.09865005, "qsc_code_frac_chars_top_4grams": 0.0913811, "qsc_code_frac_chars_dupe_5grams": 0.04257529, "qsc_code_frac_chars_dupe_6grams": 0.0290758, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01701747, "qsc_code_frac_chars_whitespace": 0.19328035, "qsc_code_size_file_byte": 2768.0, "qsc_code_num_lines": 114.0, "qsc_code_num_chars_line_max": 109.0, "qsc_code_num_chars_line_mean": 24.28070175, "qsc_code_frac_chars_alphabet": 0.84549933, "qsc_code_frac_chars_comments": 0.28215318, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11594203, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00805234, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07246377, "qsc_codejava_score_lines_no_logic": 0.2173913, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/ActionIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
public class ActionIndicator extends Tag {
Image icon;
public static Action action;
public static ActionIndicator instance;
public ActionIndicator() {
super( 0xFFFF4C );
instance = this;
setSize( 24, 24 );
visible = false;
}
@Override
public void destroy() {
super.destroy();
instance = null;
}
@Override
protected synchronized void layout() {
super.layout();
if (icon != null){
icon.x = x + (width - icon.width()) / 2;
icon.y = y + (height - icon.height()) / 2;
PixelScene.align(icon);
if (!members.contains(icon))
add(icon);
}
}
private boolean needsLayout = false;
@Override
public synchronized void update() {
super.update();
if (!Dungeon.hero.ready){
if (icon != null) icon.alpha(0.5f);
} else {
if (icon != null) icon.alpha(1f);
}
if (!visible && action != null){
visible = true;
updateIcon();
flash();
} else {
visible = action != null;
}
if (needsLayout){
layout();
needsLayout = false;
}
}
@Override
protected void onClick() {
if (action != null && Dungeon.hero.ready)
action.doAction();
}
public static void setAction(Action action){
ActionIndicator.action = action;
updateIcon();
}
public static void clearAction(Action action){
if (ActionIndicator.action == action)
ActionIndicator.action = null;
}
public static void updateIcon(){
if (instance != null){
synchronized (instance) {
if (instance.icon != null) {
instance.icon.killAndErase();
instance.icon = null;
}
if (action != null) {
instance.icon = action.getIcon();
instance.needsLayout = true;
}
}
}
}
public interface Action{
public Image getIcon();
public void doAction();
}
}
| 2,734 | ActionIndicator | java | en | java | code | {"qsc_code_num_words": 328, "qsc_code_num_chars": 2734.0, "qsc_code_mean_word_length": 5.63414634, "qsc_code_frac_words_unique": 0.42682927, "qsc_code_frac_chars_top_2grams": 0.03246753, "qsc_code_frac_chars_top_3grams": 0.0211039, "qsc_code_frac_chars_top_4grams": 0.03084416, "qsc_code_frac_chars_dupe_5grams": 0.06493506, "qsc_code_frac_chars_dupe_6grams": 0.03030303, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01298701, "qsc_code_frac_chars_whitespace": 0.21141185, "qsc_code_size_file_byte": 2734.0, "qsc_code_num_lines": 127.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 21.52755906, "qsc_code_frac_chars_alphabet": 0.84415584, "qsc_code_frac_chars_comments": 0.28566203, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.09638554, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00409626, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08433735, "qsc_codejava_score_lines_no_logic": 0.1686747, "qsc_codejava_frac_words_no_modifier": 0.875, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/CheckBox.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
public class CheckBox extends RedButton {
private boolean checked = false;
public CheckBox( String label ) {
super( label );
icon( Icons.get( Icons.UNCHECKED ) );
}
@Override
protected void layout() {
super.layout();
float margin = (height - text.height()) / 2;
text.setPos( x + margin, y + margin);
PixelScene.align(text);
margin = (height - icon.height) / 2;
icon.x = x + width - margin - icon.width;
icon.y = y + margin;
PixelScene.align(icon);
}
public boolean checked() {
return checked;
}
public void checked( boolean value ) {
if (checked != value) {
checked = value;
icon.copy( Icons.get( checked ? Icons.CHECKED : Icons.UNCHECKED ) );
}
}
@Override
protected void onClick() {
super.onClick();
checked( !checked );
}
}
| 1,701 | CheckBox | java | en | java | code | {"qsc_code_num_words": 224, "qsc_code_num_chars": 1701.0, "qsc_code_mean_word_length": 5.29017857, "qsc_code_frac_words_unique": 0.52678571, "qsc_code_frac_chars_top_2grams": 0.0278481, "qsc_code_frac_chars_top_3grams": 0.03291139, "qsc_code_frac_chars_top_4grams": 0.04810127, "qsc_code_frac_chars_dupe_5grams": 0.12827004, "qsc_code_frac_chars_dupe_6grams": 0.04725738, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0140325, "qsc_code_frac_chars_whitespace": 0.20399765, "qsc_code_size_file_byte": 1701.0, "qsc_code_num_lines": 67.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 25.3880597, "qsc_code_frac_chars_alphabet": 0.86115214, "qsc_code_frac_chars_comments": 0.45914168, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05882353, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.11764706, "qsc_codejava_score_lines_no_logic": 0.20588235, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Toolbar.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Point;
import com.watabou.utils.PointF;
public class Toolbar extends Component {
private Tool btnWait;
private Tool btnSearch;
private Tool btnInventory;
private QuickslotTool[] btnQuick;
private PickedUpItem pickedUp;
private boolean lastEnabled = true;
public boolean examining = false;
private static Toolbar instance;
public enum Mode {
SPLIT,
GROUP,
CENTER
}
public Toolbar() {
super();
instance = this;
height = btnInventory.height();
}
@Override
protected void createChildren() {
add( btnWait = new Tool(24, 0, 20, 26, GameAction.REST ) {
@Override
protected void onClick() {
examining = false;
Dungeon.hero.rest(false);
}
protected boolean onLongClick() {
examining = false;
Dungeon.hero.rest(true);
return true;
}
});
add( btnSearch = new Tool(44, 0, 20, 26, GameAction.SEARCH ) {
@Override
protected void onClick() {
if (!examining) {
GameScene.selectCell(informer);
examining = true;
} else {
informer.onSelect(null);
Dungeon.hero.search(true);
}
}
@Override
protected boolean onLongClick() {
Dungeon.hero.search(true);
return true;
}
});
btnQuick = new QuickslotTool[4];
add( btnQuick[3] = new QuickslotTool( 64, 0, 22, 24, 3, GameAction.QUICKSLOT_4) );
add( btnQuick[2] = new QuickslotTool( 64, 0, 22, 24, 2, GameAction.QUICKSLOT_3) );
add(btnQuick[1] = new QuickslotTool(64, 0, 22, 24, 1, GameAction.QUICKSLOT_2));
add(btnQuick[0] = new QuickslotTool(64, 0, 22, 24, 0, GameAction.QUICKSLOT_1));
add(btnInventory = new Tool(0, 0, 24, 26, GameAction.BACKPACK ) {
private GoldIndicator gold;
@Override
protected void onClick() {
GameScene.show(new WndBag(Dungeon.hero.belongings.backpack, null, WndBag.Mode.ALL, null));
}
@Override
protected boolean onLongClick() {
WndJournal.last_index = 3; //catalog page
GameScene.show(new WndJournal());
return true;
}
@Override
protected void createChildren() {
super.createChildren();
gold = new GoldIndicator();
add(gold);
}
@Override
protected void layout() {
super.layout();
gold.fill(this);
}
});
add(pickedUp = new PickedUpItem());
}
@Override
protected void layout() {
int[] visible = new int[4];
int slots = SPDSettings.quickSlots();
for(int i = 0; i <= 3; i++)
visible[i] = (int)((slots > i) ? y+2 : y+25);
for(int i = 0; i <= 3; i++) {
btnQuick[i].visible = btnQuick[i].active = slots > i;
//decides on quickslot layout, depending on available screen size.
if (slots == 4 && width < 152){
if (width < 138){
if ((SPDSettings.flipToolbar() && i == 3) ||
(!SPDSettings.flipToolbar() && i == 0)) {
btnQuick[i].border(0, 0);
btnQuick[i].frame(88, 0, 17, 24);
} else {
btnQuick[i].border(0, 1);
btnQuick[i].frame(88, 0, 18, 24);
}
} else {
if (i == 0 && !SPDSettings.flipToolbar() ||
i == 3 && SPDSettings.flipToolbar()){
btnQuick[i].border(0, 2);
btnQuick[i].frame(106, 0, 19, 24);
} else if (i == 0 && SPDSettings.flipToolbar() ||
i == 3 && !SPDSettings.flipToolbar()){
btnQuick[i].border(2, 1);
btnQuick[i].frame(86, 0, 20, 24);
} else {
btnQuick[i].border(0, 1);
btnQuick[i].frame(88, 0, 18, 24);
}
}
} else {
btnQuick[i].border(2, 2);
btnQuick[i].frame(64, 0, 22, 24);
}
}
float right = width;
switch(Mode.valueOf(SPDSettings.toolbarMode())){
case SPLIT:
btnWait.setPos(x, y);
btnSearch.setPos(btnWait.right(), y);
btnInventory.setPos(right - btnInventory.width(), y);
btnQuick[0].setPos(btnInventory.left() - btnQuick[0].width(), visible[0]);
btnQuick[1].setPos(btnQuick[0].left() - btnQuick[1].width(), visible[1]);
btnQuick[2].setPos(btnQuick[1].left() - btnQuick[2].width(), visible[2]);
btnQuick[3].setPos(btnQuick[2].left() - btnQuick[3].width(), visible[3]);
break;
//center = group but.. well.. centered, so all we need to do is pre-emptively set the right side further in.
case CENTER:
float toolbarWidth = btnWait.width() + btnSearch.width() + btnInventory.width();
for(Button slot : btnQuick){
if (slot.visible) toolbarWidth += slot.width();
}
right = (width + toolbarWidth)/2;
case GROUP:
btnWait.setPos(right - btnWait.width(), y);
btnSearch.setPos(btnWait.left() - btnSearch.width(), y);
btnInventory.setPos(btnSearch.left() - btnInventory.width(), y);
btnQuick[0].setPos(btnInventory.left() - btnQuick[0].width(), visible[0]);
btnQuick[1].setPos(btnQuick[0].left() - btnQuick[1].width(), visible[1]);
btnQuick[2].setPos(btnQuick[1].left() - btnQuick[2].width(), visible[2]);
btnQuick[3].setPos(btnQuick[2].left() - btnQuick[3].width(), visible[3]);
break;
}
right = width;
if (SPDSettings.flipToolbar()) {
btnWait.setPos( (right - btnWait.right()), y);
btnSearch.setPos( (right - btnSearch.right()), y);
btnInventory.setPos( (right - btnInventory.right()), y);
for(int i = 0; i <= 3; i++) {
btnQuick[i].setPos( right - btnQuick[i].right(), visible[i]);
}
}
}
public static void updateLayout(){
if (instance != null) instance.layout();
}
@Override
public void update() {
super.update();
if (lastEnabled != (Dungeon.hero.ready && Dungeon.hero.isAlive())) {
lastEnabled = (Dungeon.hero.ready && Dungeon.hero.isAlive());
for (Gizmo tool : members) {
if (tool instanceof Tool) {
((Tool)tool).enable( lastEnabled );
}
}
}
if (!Dungeon.hero.isAlive()) {
btnInventory.enable(true);
}
}
public void pickup( Item item, int cell ) {
pickedUp.reset( item,
cell,
btnInventory.centerX(),
btnInventory.centerY());
}
private static CellSelector.Listener informer = new CellSelector.Listener() {
@Override
public void onSelect( Integer cell ) {
instance.examining = false;
GameScene.examineCell( cell );
}
@Override
public String prompt() {
return Messages.get(Toolbar.class, "examine_prompt");
}
};
private static class Tool extends Button<GameAction> {
private static final int BGCOLOR = 0x7B8073;
private Image base;
public Tool(int x, int y, int width, int height, GameAction hotKey ) {
super();
hotArea.blockWhenInactive = true;
frame(x, y, width, height);
this.hotKey = hotKey;
}
public void frame( int x, int y, int width, int height) {
base.frame( x, y, width, height );
this.width = width;
this.height = height;
}
@Override
protected void createChildren() {
super.createChildren();
base = new Image( Assets.TOOLBAR );
add( base );
}
@Override
protected void layout() {
super.layout();
base.x = x;
base.y = y;
}
@Override
protected void onTouchDown() {
base.brightness( 1.4f );
}
@Override
protected void onTouchUp() {
if (active) {
base.resetColor();
} else {
base.tint( BGCOLOR, 0.7f );
}
}
public void enable( boolean value ) {
if (value != active) {
if (value) {
base.resetColor();
} else {
base.tint( BGCOLOR, 0.7f );
}
active = value;
}
}
}
private static class QuickslotTool extends Tool {
private QuickSlotButton slot;
private int borderLeft = 2;
private int borderRight = 2;
public QuickslotTool( int x, int y, int width, int height, int slotNum, GameAction hotKey) {
super(x, y, width, height, null);
slot = new QuickSlotButton( slotNum, hotKey );
add(slot);
}
public void border( int left, int right ){
borderLeft = left;
borderRight = right;
layout();
}
@Override
protected void layout() {
super.layout();
slot.setRect( x + borderLeft, y + 2, width - borderLeft-borderRight, height - 4 );
}
@Override
public void enable( boolean value ) {
super.enable( value );
slot.enable( value );
}
}
public static class PickedUpItem extends ItemSprite {
private static final float DURATION = 0.5f;
private float startScale;
private float startX, startY;
private float endX, endY;
private float left;
public PickedUpItem() {
super();
originToCenter();
active =
visible =
false;
}
public void reset( Item item, int cell, float endX, float endY ) {
view( item );
active =
visible =
true;
PointF tile = DungeonTerrainTilemap.raisedTileCenterToWorld(cell);
Point screen = Camera.main.cameraToScreen(tile.x, tile.y);
PointF start = camera().screenToCamera(screen.x, screen.y);
x = this.startX = start.x - ItemSprite.SIZE / 2;
y = this.startY = start.y - ItemSprite.SIZE / 2;
this.endX = endX - ItemSprite.SIZE / 2;
this.endY = endY - ItemSprite.SIZE / 2;
left = DURATION;
scale.set( startScale = Camera.main.zoom / camera().zoom );
}
@Override
public void update() {
super.update();
if ((left -= Game.elapsed) <= 0) {
visible =
active =
false;
if (emitter != null) emitter.on = false;
} else {
float p = left / DURATION;
scale.set( startScale * (float)Math.sqrt( p ) );
x = startX*p + endX*(1-p);
y = startY*p + endY*(1-p);
}
}
}
}
| 11,072 | Toolbar | java | en | java | code | {"qsc_code_num_words": 1330, "qsc_code_num_chars": 11072.0, "qsc_code_mean_word_length": 5.44210526, "qsc_code_frac_words_unique": 0.21729323, "qsc_code_frac_chars_top_2grams": 0.02486875, "qsc_code_frac_chars_top_3grams": 0.0682509, "qsc_code_frac_chars_top_4grams": 0.07294833, "qsc_code_frac_chars_dupe_5grams": 0.29054988, "qsc_code_frac_chars_dupe_6grams": 0.21773971, "qsc_code_frac_chars_dupe_7grams": 0.14451506, "qsc_code_frac_chars_dupe_8grams": 0.12033711, "qsc_code_frac_chars_dupe_9grams": 0.10002763, "qsc_code_frac_chars_dupe_10grams": 0.09450124, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02431784, "qsc_code_frac_chars_whitespace": 0.20890535, "qsc_code_size_file_byte": 11072.0, "qsc_code_num_lines": 441.0, "qsc_code_num_chars_line_max": 112.0, "qsc_code_num_chars_line_mean": 25.10657596, "qsc_code_frac_chars_alphabet": 0.8020322, "qsc_code_frac_chars_comments": 0.08751806, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.27878788, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00138573, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00079184, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07878788, "qsc_codejava_score_lines_no_logic": 0.18181818, "qsc_codejava_frac_words_no_modifier": 0.96296296, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/BusyIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.watabou.noosa.Image;
public class BusyIndicator extends Image {
public BusyIndicator() {
super();
copy( Icons.BUSY.get() );
origin.set( width / 2, height / 2 );
angularSpeed = 720;
}
@Override
public void update() {
super.update();
visible = Dungeon.hero.isAlive() && !Dungeon.hero.ready;
}
}
| 1,222 | BusyIndicator | java | en | java | code | {"qsc_code_num_words": 169, "qsc_code_num_chars": 1222.0, "qsc_code_mean_word_length": 5.26035503, "qsc_code_frac_words_unique": 0.63905325, "qsc_code_frac_chars_top_2grams": 0.03712036, "qsc_code_frac_chars_top_3grams": 0.04386952, "qsc_code_frac_chars_top_4grams": 0.06411699, "qsc_code_frac_chars_dupe_5grams": 0.09223847, "qsc_code_frac_chars_dupe_6grams": 0.06299213, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02208835, "qsc_code_frac_chars_whitespace": 0.18494272, "qsc_code_size_file_byte": 1222.0, "qsc_code_num_lines": 41.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 29.80487805, "qsc_code_frac_chars_alphabet": 0.87048193, "qsc_code_frac_chars_comments": 0.6391162, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.0625, "qsc_codejava_score_lines_no_logic": 0.25, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/hal/interface.h | #ifndef OPENCV_CORE_HAL_INTERFACE_H
#define OPENCV_CORE_HAL_INTERFACE_H
//! @addtogroup core_hal_interface
//! @{
//! @name Return codes
//! @{
#define CV_HAL_ERROR_OK 0
#define CV_HAL_ERROR_NOT_IMPLEMENTED 1
#define CV_HAL_ERROR_UNKNOWN -1
//! @}
#ifdef __cplusplus
#include <cstddef>
#else
#include <stddef.h>
#include <stdbool.h>
#endif
//! @name Data types
//! primitive types
//! - schar - signed 1 byte integer
//! - uchar - unsigned 1 byte integer
//! - short - signed 2 byte integer
//! - ushort - unsigned 2 byte integer
//! - int - signed 4 byte integer
//! - uint - unsigned 4 byte integer
//! - int64 - signed 8 byte integer
//! - uint64 - unsigned 8 byte integer
//! @{
#if !defined _MSC_VER && !defined __BORLANDC__
# if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__
# include <cstdint>
# ifdef __NEWLIB__
typedef unsigned int uint;
# else
typedef std::uint32_t uint;
# endif
# else
# include <stdint.h>
typedef uint32_t uint;
# endif
#else
typedef unsigned uint;
#endif
typedef signed char schar;
#ifndef __IPL_H__
typedef unsigned char uchar;
typedef unsigned short ushort;
#endif
#if defined _MSC_VER || defined __BORLANDC__
typedef __int64 int64;
typedef unsigned __int64 uint64;
# define CV_BIG_INT(n) n##I64
# define CV_BIG_UINT(n) n##UI64
#else
typedef int64_t int64;
typedef uint64_t uint64;
# define CV_BIG_INT(n) n##LL
# define CV_BIG_UINT(n) n##ULL
#endif
#define CV_USRTYPE1 (void)"CV_USRTYPE1 support has been dropped in OpenCV 4.0"
#define CV_CN_MAX 512
#define CV_CN_SHIFT 3
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
#define CV_8U 0
#define CV_8S 1
#define CV_16U 2
#define CV_16S 3
#define CV_32S 4
#define CV_32F 5
#define CV_64F 6
#define CV_16F 7
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
#define CV_MAKE_TYPE CV_MAKETYPE
#define CV_8UC1 CV_MAKETYPE(CV_8U,1)
#define CV_8UC2 CV_MAKETYPE(CV_8U,2)
#define CV_8UC3 CV_MAKETYPE(CV_8U,3)
#define CV_8UC4 CV_MAKETYPE(CV_8U,4)
#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
#define CV_8SC1 CV_MAKETYPE(CV_8S,1)
#define CV_8SC2 CV_MAKETYPE(CV_8S,2)
#define CV_8SC3 CV_MAKETYPE(CV_8S,3)
#define CV_8SC4 CV_MAKETYPE(CV_8S,4)
#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
#define CV_16UC1 CV_MAKETYPE(CV_16U,1)
#define CV_16UC2 CV_MAKETYPE(CV_16U,2)
#define CV_16UC3 CV_MAKETYPE(CV_16U,3)
#define CV_16UC4 CV_MAKETYPE(CV_16U,4)
#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
#define CV_16SC1 CV_MAKETYPE(CV_16S,1)
#define CV_16SC2 CV_MAKETYPE(CV_16S,2)
#define CV_16SC3 CV_MAKETYPE(CV_16S,3)
#define CV_16SC4 CV_MAKETYPE(CV_16S,4)
#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
#define CV_32SC1 CV_MAKETYPE(CV_32S,1)
#define CV_32SC2 CV_MAKETYPE(CV_32S,2)
#define CV_32SC3 CV_MAKETYPE(CV_32S,3)
#define CV_32SC4 CV_MAKETYPE(CV_32S,4)
#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
#define CV_32FC1 CV_MAKETYPE(CV_32F,1)
#define CV_32FC2 CV_MAKETYPE(CV_32F,2)
#define CV_32FC3 CV_MAKETYPE(CV_32F,3)
#define CV_32FC4 CV_MAKETYPE(CV_32F,4)
#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
#define CV_64FC1 CV_MAKETYPE(CV_64F,1)
#define CV_64FC2 CV_MAKETYPE(CV_64F,2)
#define CV_64FC3 CV_MAKETYPE(CV_64F,3)
#define CV_64FC4 CV_MAKETYPE(CV_64F,4)
#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
#define CV_16FC1 CV_MAKETYPE(CV_16F,1)
#define CV_16FC2 CV_MAKETYPE(CV_16F,2)
#define CV_16FC3 CV_MAKETYPE(CV_16F,3)
#define CV_16FC4 CV_MAKETYPE(CV_16F,4)
#define CV_16FC(n) CV_MAKETYPE(CV_16F,(n))
//! @}
//! @name Comparison operation
//! @sa cv::CmpTypes
//! @{
#define CV_HAL_CMP_EQ 0
#define CV_HAL_CMP_GT 1
#define CV_HAL_CMP_GE 2
#define CV_HAL_CMP_LT 3
#define CV_HAL_CMP_LE 4
#define CV_HAL_CMP_NE 5
//! @}
//! @name Border processing modes
//! @sa cv::BorderTypes
//! @{
#define CV_HAL_BORDER_CONSTANT 0
#define CV_HAL_BORDER_REPLICATE 1
#define CV_HAL_BORDER_REFLECT 2
#define CV_HAL_BORDER_WRAP 3
#define CV_HAL_BORDER_REFLECT_101 4
#define CV_HAL_BORDER_TRANSPARENT 5
#define CV_HAL_BORDER_ISOLATED 16
//! @}
//! @name DFT flags
//! @{
#define CV_HAL_DFT_INVERSE 1
#define CV_HAL_DFT_SCALE 2
#define CV_HAL_DFT_ROWS 4
#define CV_HAL_DFT_COMPLEX_OUTPUT 16
#define CV_HAL_DFT_REAL_OUTPUT 32
#define CV_HAL_DFT_TWO_STAGE 64
#define CV_HAL_DFT_STAGE_COLS 128
#define CV_HAL_DFT_IS_CONTINUOUS 512
#define CV_HAL_DFT_IS_INPLACE 1024
//! @}
//! @name SVD flags
//! @{
#define CV_HAL_SVD_NO_UV 1
#define CV_HAL_SVD_SHORT_UV 2
#define CV_HAL_SVD_MODIFY_A 4
#define CV_HAL_SVD_FULL_UV 8
//! @}
//! @name Gemm flags
//! @{
#define CV_HAL_GEMM_1_T 1
#define CV_HAL_GEMM_2_T 2
#define CV_HAL_GEMM_3_T 4
//! @}
//! @}
#endif
| 4,787 | interface | h | en | c | code | {"qsc_code_num_words": 846, "qsc_code_num_chars": 4787.0, "qsc_code_mean_word_length": 3.8144208, "qsc_code_frac_words_unique": 0.21749409, "qsc_code_frac_chars_top_2grams": 0.22807561, "qsc_code_frac_chars_top_3grams": 0.14874496, "qsc_code_frac_chars_top_4grams": 0.03904555, "qsc_code_frac_chars_dupe_5grams": 0.13758909, "qsc_code_frac_chars_dupe_6grams": 0.05392005, "qsc_code_frac_chars_dupe_7grams": 0.01363496, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.08041187, "qsc_code_frac_chars_whitespace": 0.14790056, "qsc_code_size_file_byte": 4787.0, "qsc_code_num_lines": 190.0, "qsc_code_num_chars_line_max": 80.0, "qsc_code_num_chars_line_mean": 25.19473684, "qsc_code_frac_chars_alphabet": 0.71071341, "qsc_code_frac_chars_comments": 0.14330478, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.09375, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01219215, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codec_frac_lines_func_ratio": 0.359375, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 0.0, "qsc_codec_score_lines_no_logic": 0.3984375, "qsc_codec_frac_lines_print": 0.0, "qsc_codec_frac_lines_preprocessor_directives": null} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 1, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 1, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/hal/intrin_msa.hpp | // This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_HAL_INTRIN_MSA_HPP
#define OPENCV_HAL_INTRIN_MSA_HPP
#include <algorithm>
#include "opencv2/core/utility.hpp"
namespace cv
{
//! @cond IGNORED
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
#define CV_SIMD128 1
//MSA implements 128-bit wide vector registers shared with the 64-bit wide floating-point unit registers.
//MSA and FPU can not be both present, unless the FPU has 64-bit floating-point registers.
#define CV_SIMD128_64F 1
struct v_uint8x16
{
typedef uchar lane_type;
enum { nlanes = 16 };
v_uint8x16() : val(msa_dupq_n_u8(0)) {}
explicit v_uint8x16(v16u8 v) : val(v) {}
v_uint8x16(uchar v0, uchar v1, uchar v2, uchar v3, uchar v4, uchar v5, uchar v6, uchar v7,
uchar v8, uchar v9, uchar v10, uchar v11, uchar v12, uchar v13, uchar v14, uchar v15)
{
uchar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15};
val = msa_ld1q_u8(v);
}
uchar get0() const
{
return msa_getq_lane_u8(val, 0);
}
v16u8 val;
};
struct v_int8x16
{
typedef schar lane_type;
enum { nlanes = 16 };
v_int8x16() : val(msa_dupq_n_s8(0)) {}
explicit v_int8x16(v16i8 v) : val(v) {}
v_int8x16(schar v0, schar v1, schar v2, schar v3, schar v4, schar v5, schar v6, schar v7,
schar v8, schar v9, schar v10, schar v11, schar v12, schar v13, schar v14, schar v15)
{
schar v[] = {v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15};
val = msa_ld1q_s8(v);
}
schar get0() const
{
return msa_getq_lane_s8(val, 0);
}
v16i8 val;
};
struct v_uint16x8
{
typedef ushort lane_type;
enum { nlanes = 8 };
v_uint16x8() : val(msa_dupq_n_u16(0)) {}
explicit v_uint16x8(v8u16 v) : val(v) {}
v_uint16x8(ushort v0, ushort v1, ushort v2, ushort v3, ushort v4, ushort v5, ushort v6, ushort v7)
{
ushort v[] = {v0, v1, v2, v3, v4, v5, v6, v7};
val = msa_ld1q_u16(v);
}
ushort get0() const
{
return msa_getq_lane_u16(val, 0);
}
v8u16 val;
};
struct v_int16x8
{
typedef short lane_type;
enum { nlanes = 8 };
v_int16x8() : val(msa_dupq_n_s16(0)) {}
explicit v_int16x8(v8i16 v) : val(v) {}
v_int16x8(short v0, short v1, short v2, short v3, short v4, short v5, short v6, short v7)
{
short v[] = {v0, v1, v2, v3, v4, v5, v6, v7};
val = msa_ld1q_s16(v);
}
short get0() const
{
return msa_getq_lane_s16(val, 0);
}
v8i16 val;
};
struct v_uint32x4
{
typedef unsigned int lane_type;
enum { nlanes = 4 };
v_uint32x4() : val(msa_dupq_n_u32(0)) {}
explicit v_uint32x4(v4u32 v) : val(v) {}
v_uint32x4(unsigned int v0, unsigned int v1, unsigned int v2, unsigned int v3)
{
unsigned int v[] = {v0, v1, v2, v3};
val = msa_ld1q_u32(v);
}
unsigned int get0() const
{
return msa_getq_lane_u32(val, 0);
}
v4u32 val;
};
struct v_int32x4
{
typedef int lane_type;
enum { nlanes = 4 };
v_int32x4() : val(msa_dupq_n_s32(0)) {}
explicit v_int32x4(v4i32 v) : val(v) {}
v_int32x4(int v0, int v1, int v2, int v3)
{
int v[] = {v0, v1, v2, v3};
val = msa_ld1q_s32(v);
}
int get0() const
{
return msa_getq_lane_s32(val, 0);
}
v4i32 val;
};
struct v_float32x4
{
typedef float lane_type;
enum { nlanes = 4 };
v_float32x4() : val(msa_dupq_n_f32(0.0f)) {}
explicit v_float32x4(v4f32 v) : val(v) {}
v_float32x4(float v0, float v1, float v2, float v3)
{
float v[] = {v0, v1, v2, v3};
val = msa_ld1q_f32(v);
}
float get0() const
{
return msa_getq_lane_f32(val, 0);
}
v4f32 val;
};
struct v_uint64x2
{
typedef uint64 lane_type;
enum { nlanes = 2 };
v_uint64x2() : val(msa_dupq_n_u64(0)) {}
explicit v_uint64x2(v2u64 v) : val(v) {}
v_uint64x2(uint64 v0, uint64 v1)
{
uint64 v[] = {v0, v1};
val = msa_ld1q_u64(v);
}
uint64 get0() const
{
return msa_getq_lane_u64(val, 0);
}
v2u64 val;
};
struct v_int64x2
{
typedef int64 lane_type;
enum { nlanes = 2 };
v_int64x2() : val(msa_dupq_n_s64(0)) {}
explicit v_int64x2(v2i64 v) : val(v) {}
v_int64x2(int64 v0, int64 v1)
{
int64 v[] = {v0, v1};
val = msa_ld1q_s64(v);
}
int64 get0() const
{
return msa_getq_lane_s64(val, 0);
}
v2i64 val;
};
struct v_float64x2
{
typedef double lane_type;
enum { nlanes = 2 };
v_float64x2() : val(msa_dupq_n_f64(0.0f)) {}
explicit v_float64x2(v2f64 v) : val(v) {}
v_float64x2(double v0, double v1)
{
double v[] = {v0, v1};
val = msa_ld1q_f64(v);
}
double get0() const
{
return msa_getq_lane_f64(val, 0);
}
v2f64 val;
};
#define OPENCV_HAL_IMPL_MSA_INIT(_Tpv, _Tp, suffix) \
inline v_##_Tpv v_setzero_##suffix() { return v_##_Tpv(msa_dupq_n_##suffix((_Tp)0)); } \
inline v_##_Tpv v_setall_##suffix(_Tp v) { return v_##_Tpv(msa_dupq_n_##suffix(v)); } \
inline v_uint8x16 v_reinterpret_as_u8(const v_##_Tpv& v) { return v_uint8x16(MSA_TPV_REINTERPRET(v16u8, v.val)); } \
inline v_int8x16 v_reinterpret_as_s8(const v_##_Tpv& v) { return v_int8x16(MSA_TPV_REINTERPRET(v16i8, v.val)); } \
inline v_uint16x8 v_reinterpret_as_u16(const v_##_Tpv& v) { return v_uint16x8(MSA_TPV_REINTERPRET(v8u16, v.val)); } \
inline v_int16x8 v_reinterpret_as_s16(const v_##_Tpv& v) { return v_int16x8(MSA_TPV_REINTERPRET(v8i16, v.val)); } \
inline v_uint32x4 v_reinterpret_as_u32(const v_##_Tpv& v) { return v_uint32x4(MSA_TPV_REINTERPRET(v4u32, v.val)); } \
inline v_int32x4 v_reinterpret_as_s32(const v_##_Tpv& v) { return v_int32x4(MSA_TPV_REINTERPRET(v4i32, v.val)); } \
inline v_uint64x2 v_reinterpret_as_u64(const v_##_Tpv& v) { return v_uint64x2(MSA_TPV_REINTERPRET(v2u64, v.val)); } \
inline v_int64x2 v_reinterpret_as_s64(const v_##_Tpv& v) { return v_int64x2(MSA_TPV_REINTERPRET(v2i64, v.val)); } \
inline v_float32x4 v_reinterpret_as_f32(const v_##_Tpv& v) { return v_float32x4(MSA_TPV_REINTERPRET(v4f32, v.val)); } \
inline v_float64x2 v_reinterpret_as_f64(const v_##_Tpv& v) { return v_float64x2(MSA_TPV_REINTERPRET(v2f64, v.val)); }
OPENCV_HAL_IMPL_MSA_INIT(uint8x16, uchar, u8)
OPENCV_HAL_IMPL_MSA_INIT(int8x16, schar, s8)
OPENCV_HAL_IMPL_MSA_INIT(uint16x8, ushort, u16)
OPENCV_HAL_IMPL_MSA_INIT(int16x8, short, s16)
OPENCV_HAL_IMPL_MSA_INIT(uint32x4, unsigned int, u32)
OPENCV_HAL_IMPL_MSA_INIT(int32x4, int, s32)
OPENCV_HAL_IMPL_MSA_INIT(uint64x2, uint64, u64)
OPENCV_HAL_IMPL_MSA_INIT(int64x2, int64, s64)
OPENCV_HAL_IMPL_MSA_INIT(float32x4, float, f32)
OPENCV_HAL_IMPL_MSA_INIT(float64x2, double, f64)
#define OPENCV_HAL_IMPL_MSA_PACK(_Tpvec, _Tpwvec, pack, mov, rshr) \
inline _Tpvec v_##pack(const _Tpwvec& a, const _Tpwvec& b) \
{ \
return _Tpvec(mov(a.val, b.val)); \
} \
template<int n> inline \
_Tpvec v_rshr_##pack(const _Tpwvec& a, const _Tpwvec& b) \
{ \
return _Tpvec(rshr(a.val, b.val, n)); \
}
OPENCV_HAL_IMPL_MSA_PACK(v_uint8x16, v_uint16x8, pack, msa_qpack_u16, msa_qrpackr_u16)
OPENCV_HAL_IMPL_MSA_PACK(v_int8x16, v_int16x8, pack, msa_qpack_s16, msa_qrpackr_s16)
OPENCV_HAL_IMPL_MSA_PACK(v_uint16x8, v_uint32x4, pack, msa_qpack_u32, msa_qrpackr_u32)
OPENCV_HAL_IMPL_MSA_PACK(v_int16x8, v_int32x4, pack, msa_qpack_s32, msa_qrpackr_s32)
OPENCV_HAL_IMPL_MSA_PACK(v_uint32x4, v_uint64x2, pack, msa_pack_u64, msa_rpackr_u64)
OPENCV_HAL_IMPL_MSA_PACK(v_int32x4, v_int64x2, pack, msa_pack_s64, msa_rpackr_s64)
OPENCV_HAL_IMPL_MSA_PACK(v_uint8x16, v_int16x8, pack_u, msa_qpacku_s16, msa_qrpackru_s16)
OPENCV_HAL_IMPL_MSA_PACK(v_uint16x8, v_int32x4, pack_u, msa_qpacku_s32, msa_qrpackru_s32)
#define OPENCV_HAL_IMPL_MSA_PACK_STORE(_Tpvec, _Tp, hreg, suffix, _Tpwvec, pack, mov, rshr) \
inline void v_##pack##_store(_Tp* ptr, const _Tpwvec& a) \
{ \
hreg a1 = mov(a.val); \
msa_st1_##suffix(ptr, a1); \
} \
template<int n> inline \
void v_rshr_##pack##_store(_Tp* ptr, const _Tpwvec& a) \
{ \
hreg a1 = rshr(a.val, n); \
msa_st1_##suffix(ptr, a1); \
}
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint8x16, uchar, v8u8, u8, v_uint16x8, pack, msa_qmovn_u16, msa_qrshrn_n_u16)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_int8x16, schar, v8i8, s8, v_int16x8, pack, msa_qmovn_s16, msa_qrshrn_n_s16)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint16x8, ushort, v4u16, u16, v_uint32x4, pack, msa_qmovn_u32, msa_qrshrn_n_u32)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_int16x8, short, v4i16, s16, v_int32x4, pack, msa_qmovn_s32, msa_qrshrn_n_s32)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint32x4, unsigned, v2u32, u32, v_uint64x2, pack, msa_movn_u64, msa_rshrn_n_u64)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_int32x4, int, v2i32, s32, v_int64x2, pack, msa_movn_s64, msa_rshrn_n_s64)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint8x16, uchar, v8u8, u8, v_int16x8, pack_u, msa_qmovun_s16, msa_qrshrun_n_s16)
OPENCV_HAL_IMPL_MSA_PACK_STORE(v_uint16x8, ushort, v4u16, u16, v_int32x4, pack_u, msa_qmovun_s32, msa_qrshrun_n_s32)
// pack boolean
inline v_uint8x16 v_pack_b(const v_uint16x8& a, const v_uint16x8& b)
{
return v_uint8x16(msa_pack_u16(a.val, b.val));
}
inline v_uint8x16 v_pack_b(const v_uint32x4& a, const v_uint32x4& b,
const v_uint32x4& c, const v_uint32x4& d)
{
return v_uint8x16(msa_pack_u16(msa_pack_u32(a.val, b.val), msa_pack_u32(c.val, d.val)));
}
inline v_uint8x16 v_pack_b(const v_uint64x2& a, const v_uint64x2& b, const v_uint64x2& c,
const v_uint64x2& d, const v_uint64x2& e, const v_uint64x2& f,
const v_uint64x2& g, const v_uint64x2& h)
{
v8u16 abcd = msa_pack_u32(msa_pack_u64(a.val, b.val), msa_pack_u64(c.val, d.val));
v8u16 efgh = msa_pack_u32(msa_pack_u64(e.val, f.val), msa_pack_u64(g.val, h.val));
return v_uint8x16(msa_pack_u16(abcd, efgh));
}
inline v_float32x4 v_matmul(const v_float32x4& v, const v_float32x4& m0,
const v_float32x4& m1, const v_float32x4& m2,
const v_float32x4& m3)
{
v4f32 v0 = v.val;
v4f32 res = msa_mulq_lane_f32(m0.val, v0, 0);
res = msa_mlaq_lane_f32(res, m1.val, v0, 1);
res = msa_mlaq_lane_f32(res, m2.val, v0, 2);
res = msa_mlaq_lane_f32(res, m3.val, v0, 3);
return v_float32x4(res);
}
inline v_float32x4 v_matmuladd(const v_float32x4& v, const v_float32x4& m0,
const v_float32x4& m1, const v_float32x4& m2,
const v_float32x4& a)
{
v4f32 v0 = v.val;
v4f32 res = msa_mulq_lane_f32(m0.val, v0, 0);
res = msa_mlaq_lane_f32(res, m1.val, v0, 1);
res = msa_mlaq_lane_f32(res, m2.val, v0, 2);
res = msa_addq_f32(res, a.val);
return v_float32x4(res);
}
#define OPENCV_HAL_IMPL_MSA_BIN_OP(bin_op, _Tpvec, intrin) \
inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(intrin(a.val, b.val)); \
} \
inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \
{ \
a.val = intrin(a.val, b.val); \
return a; \
}
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint8x16, msa_qaddq_u8)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint8x16, msa_qsubq_u8)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int8x16, msa_qaddq_s8)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int8x16, msa_qsubq_s8)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint16x8, msa_qaddq_u16)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint16x8, msa_qsubq_u16)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int16x8, msa_qaddq_s16)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int16x8, msa_qsubq_s16)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int32x4, msa_addq_s32)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int32x4, msa_subq_s32)
OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_int32x4, msa_mulq_s32)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint32x4, msa_addq_u32)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint32x4, msa_subq_u32)
OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_uint32x4, msa_mulq_u32)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_float32x4, msa_addq_f32)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_float32x4, msa_subq_f32)
OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_float32x4, msa_mulq_f32)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_int64x2, msa_addq_s64)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_int64x2, msa_subq_s64)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_uint64x2, msa_addq_u64)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_uint64x2, msa_subq_u64)
OPENCV_HAL_IMPL_MSA_BIN_OP(/, v_float32x4, msa_divq_f32)
OPENCV_HAL_IMPL_MSA_BIN_OP(+, v_float64x2, msa_addq_f64)
OPENCV_HAL_IMPL_MSA_BIN_OP(-, v_float64x2, msa_subq_f64)
OPENCV_HAL_IMPL_MSA_BIN_OP(*, v_float64x2, msa_mulq_f64)
OPENCV_HAL_IMPL_MSA_BIN_OP(/, v_float64x2, msa_divq_f64)
// saturating multiply 8-bit, 16-bit
#define OPENCV_HAL_IMPL_MSA_MUL_SAT(_Tpvec, _Tpwvec) \
inline _Tpvec operator * (const _Tpvec& a, const _Tpvec& b) \
{ \
_Tpwvec c, d; \
v_mul_expand(a, b, c, d); \
return v_pack(c, d); \
} \
inline _Tpvec& operator *= (_Tpvec& a, const _Tpvec& b) \
{a = a * b; return a; }
OPENCV_HAL_IMPL_MSA_MUL_SAT(v_int8x16, v_int16x8)
OPENCV_HAL_IMPL_MSA_MUL_SAT(v_uint8x16, v_uint16x8)
OPENCV_HAL_IMPL_MSA_MUL_SAT(v_int16x8, v_int32x4)
OPENCV_HAL_IMPL_MSA_MUL_SAT(v_uint16x8, v_uint32x4)
// Multiply and expand
inline void v_mul_expand(const v_int8x16& a, const v_int8x16& b,
v_int16x8& c, v_int16x8& d)
{
v16i8 a_lo, a_hi, b_lo, b_hi;
ILVRL_B2_SB(a.val, msa_dupq_n_s8(0), a_lo, a_hi);
ILVRL_B2_SB(b.val, msa_dupq_n_s8(0), b_lo, b_hi);
c.val = msa_mulq_s16(msa_paddlq_s8(a_lo), msa_paddlq_s8(b_lo));
d.val = msa_mulq_s16(msa_paddlq_s8(a_hi), msa_paddlq_s8(b_hi));
}
inline void v_mul_expand(const v_uint8x16& a, const v_uint8x16& b,
v_uint16x8& c, v_uint16x8& d)
{
v16u8 a_lo, a_hi, b_lo, b_hi;
ILVRL_B2_UB(a.val, msa_dupq_n_u8(0), a_lo, a_hi);
ILVRL_B2_UB(b.val, msa_dupq_n_u8(0), b_lo, b_hi);
c.val = msa_mulq_u16(msa_paddlq_u8(a_lo), msa_paddlq_u8(b_lo));
d.val = msa_mulq_u16(msa_paddlq_u8(a_hi), msa_paddlq_u8(b_hi));
}
inline void v_mul_expand(const v_int16x8& a, const v_int16x8& b,
v_int32x4& c, v_int32x4& d)
{
v8i16 a_lo, a_hi, b_lo, b_hi;
ILVRL_H2_SH(a.val, msa_dupq_n_s16(0), a_lo, a_hi);
ILVRL_H2_SH(b.val, msa_dupq_n_s16(0), b_lo, b_hi);
c.val = msa_mulq_s32(msa_paddlq_s16(a_lo), msa_paddlq_s16(b_lo));
d.val = msa_mulq_s32(msa_paddlq_s16(a_hi), msa_paddlq_s16(b_hi));
}
inline void v_mul_expand(const v_uint16x8& a, const v_uint16x8& b,
v_uint32x4& c, v_uint32x4& d)
{
v8u16 a_lo, a_hi, b_lo, b_hi;
ILVRL_H2_UH(a.val, msa_dupq_n_u16(0), a_lo, a_hi);
ILVRL_H2_UH(b.val, msa_dupq_n_u16(0), b_lo, b_hi);
c.val = msa_mulq_u32(msa_paddlq_u16(a_lo), msa_paddlq_u16(b_lo));
d.val = msa_mulq_u32(msa_paddlq_u16(a_hi), msa_paddlq_u16(b_hi));
}
inline void v_mul_expand(const v_uint32x4& a, const v_uint32x4& b,
v_uint64x2& c, v_uint64x2& d)
{
v4u32 a_lo, a_hi, b_lo, b_hi;
ILVRL_W2_UW(a.val, msa_dupq_n_u32(0), a_lo, a_hi);
ILVRL_W2_UW(b.val, msa_dupq_n_u32(0), b_lo, b_hi);
c.val = msa_mulq_u64(msa_paddlq_u32(a_lo), msa_paddlq_u32(b_lo));
d.val = msa_mulq_u64(msa_paddlq_u32(a_hi), msa_paddlq_u32(b_hi));
}
inline v_int16x8 v_mul_hi(const v_int16x8& a, const v_int16x8& b)
{
v8i16 a_lo, a_hi, b_lo, b_hi;
ILVRL_H2_SH(a.val, msa_dupq_n_s16(0), a_lo, a_hi);
ILVRL_H2_SH(b.val, msa_dupq_n_s16(0), b_lo, b_hi);
return v_int16x8(msa_packr_s32(msa_mulq_s32(msa_paddlq_s16(a_lo), msa_paddlq_s16(b_lo)),
msa_mulq_s32(msa_paddlq_s16(a_hi), msa_paddlq_s16(b_hi)), 16));
}
inline v_uint16x8 v_mul_hi(const v_uint16x8& a, const v_uint16x8& b)
{
v8u16 a_lo, a_hi, b_lo, b_hi;
ILVRL_H2_UH(a.val, msa_dupq_n_u16(0), a_lo, a_hi);
ILVRL_H2_UH(b.val, msa_dupq_n_u16(0), b_lo, b_hi);
return v_uint16x8(msa_packr_u32(msa_mulq_u32(msa_paddlq_u16(a_lo), msa_paddlq_u16(b_lo)),
msa_mulq_u32(msa_paddlq_u16(a_hi), msa_paddlq_u16(b_hi)), 16));
}
//////// Dot Product ////////
// 16 >> 32
inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b)
{ return v_int32x4(msa_dotp_s_w(a.val, b.val)); }
inline v_int32x4 v_dotprod(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c)
{ return v_int32x4(msa_dpadd_s_w(c.val , a.val, b.val)); }
// 32 >> 64
inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b)
{ return v_int64x2(msa_dotp_s_d(a.val, b.val)); }
inline v_int64x2 v_dotprod(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c)
{ return v_int64x2(msa_dpadd_s_d(c.val , a.val, b.val)); }
// 8 >> 32
inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b)
{
v8u16 even_a = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8), 8);
v8u16 odd_a = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8);
v8u16 even_b = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8), 8);
v8u16 odd_b = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8);
v4u32 prod = msa_dotp_u_w(even_a, even_b);
return v_uint32x4(msa_dpadd_u_w(prod, odd_a, odd_b));
}
inline v_uint32x4 v_dotprod_expand(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c)
{
v8u16 even_a = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8), 8);
v8u16 odd_a = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, a.val), 8);
v8u16 even_b = msa_shrq_n_u16(msa_shlq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8), 8);
v8u16 odd_b = msa_shrq_n_u16(MSA_TPV_REINTERPRET(v8u16, b.val), 8);
v4u32 prod = msa_dpadd_u_w(c.val, even_a, even_b);
return v_uint32x4(msa_dpadd_u_w(prod, odd_a, odd_b));
}
inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b)
{
v8i16 prod = msa_dotp_s_h(a.val, b.val);
return v_int32x4(msa_hadd_s32(prod, prod));
}
inline v_int32x4 v_dotprod_expand(const v_int8x16& a, const v_int8x16& b,
const v_int32x4& c)
{ return v_dotprod_expand(a, b) + c; }
// 16 >> 64
inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b)
{
v4u32 even_a = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16), 16);
v4u32 odd_a = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16);
v4u32 even_b = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16), 16);
v4u32 odd_b = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16);
v2u64 prod = msa_dotp_u_d(even_a, even_b);
return v_uint64x2(msa_dpadd_u_d(prod, odd_a, odd_b));
}
inline v_uint64x2 v_dotprod_expand(const v_uint16x8& a, const v_uint16x8& b,
const v_uint64x2& c)
{
v4u32 even_a = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16), 16);
v4u32 odd_a = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, a.val), 16);
v4u32 even_b = msa_shrq_n_u32(msa_shlq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16), 16);
v4u32 odd_b = msa_shrq_n_u32(MSA_TPV_REINTERPRET(v4u32, b.val), 16);
v2u64 prod = msa_dpadd_u_d(c.val, even_a, even_b);
return v_uint64x2(msa_dpadd_u_d(prod, odd_a, odd_b));
}
inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b)
{
v4i32 prod = msa_dotp_s_w(a.val, b.val);
return v_int64x2(msa_hadd_s64(prod, prod));
}
inline v_int64x2 v_dotprod_expand(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c)
{ return v_dotprod_expand(a, b) + c; }
// 32 >> 64f
inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b)
{ return v_cvt_f64(v_dotprod(a, b)); }
inline v_float64x2 v_dotprod_expand(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c)
{ return v_dotprod_expand(a, b) + c; }
//////// Fast Dot Product ////////
// 16 >> 32
inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b)
{ return v_dotprod(a, b); }
inline v_int32x4 v_dotprod_fast(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c)
{ return v_dotprod(a, b, c); }
// 32 >> 64
inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b)
{ return v_dotprod(a, b); }
inline v_int64x2 v_dotprod_fast(const v_int32x4& a, const v_int32x4& b, const v_int64x2& c)
{ return v_dotprod(a, b, c); }
// 8 >> 32
inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b)
{ return v_dotprod_expand(a, b); }
inline v_uint32x4 v_dotprod_expand_fast(const v_uint8x16& a, const v_uint8x16& b, const v_uint32x4& c)
{ return v_dotprod_expand(a, b, c); }
inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b)
{ return v_dotprod_expand(a, b); }
inline v_int32x4 v_dotprod_expand_fast(const v_int8x16& a, const v_int8x16& b, const v_int32x4& c)
{ return v_dotprod_expand(a, b, c); }
// 16 >> 64
inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b)
{ return v_dotprod_expand(a, b); }
inline v_uint64x2 v_dotprod_expand_fast(const v_uint16x8& a, const v_uint16x8& b, const v_uint64x2& c)
{ return v_dotprod_expand(a, b, c); }
inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b)
{ return v_dotprod_expand(a, b); }
inline v_int64x2 v_dotprod_expand_fast(const v_int16x8& a, const v_int16x8& b, const v_int64x2& c)
{ return v_dotprod_expand(a, b, c); }
// 32 >> 64f
inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b)
{ return v_dotprod_expand(a, b); }
inline v_float64x2 v_dotprod_expand_fast(const v_int32x4& a, const v_int32x4& b, const v_float64x2& c)
{ return v_dotprod_expand(a, b, c); }
#define OPENCV_HAL_IMPL_MSA_LOGIC_OP(_Tpvec, _Tpv, suffix) \
OPENCV_HAL_IMPL_MSA_BIN_OP(&, _Tpvec, msa_andq_##suffix) \
OPENCV_HAL_IMPL_MSA_BIN_OP(|, _Tpvec, msa_orrq_##suffix) \
OPENCV_HAL_IMPL_MSA_BIN_OP(^, _Tpvec, msa_eorq_##suffix) \
inline _Tpvec operator ~ (const _Tpvec& a) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_mvnq_u8(MSA_TPV_REINTERPRET(v16u8, a.val)))); \
}
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint8x16, v16u8, u8)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int8x16, v16i8, s8)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint16x8, v8u16, u16)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int16x8, v8i16, s16)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint32x4, v4u32, u32)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int32x4, v4i32, s32)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_uint64x2, v2u64, u64)
OPENCV_HAL_IMPL_MSA_LOGIC_OP(v_int64x2, v2i64, s64)
#define OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(bin_op, intrin) \
inline v_float32x4 operator bin_op (const v_float32x4& a, const v_float32x4& b) \
{ \
return v_float32x4(MSA_TPV_REINTERPRET(v4f32, intrin(MSA_TPV_REINTERPRET(v4i32, a.val), MSA_TPV_REINTERPRET(v4i32, b.val)))); \
} \
inline v_float32x4& operator bin_op##= (v_float32x4& a, const v_float32x4& b) \
{ \
a.val = MSA_TPV_REINTERPRET(v4f32, intrin(MSA_TPV_REINTERPRET(v4i32, a.val), MSA_TPV_REINTERPRET(v4i32, b.val))); \
return a; \
}
OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(&, msa_andq_s32)
OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(|, msa_orrq_s32)
OPENCV_HAL_IMPL_MSA_FLT_BIT_OP(^, msa_eorq_s32)
inline v_float32x4 operator ~ (const v_float32x4& a)
{
return v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_mvnq_s32(MSA_TPV_REINTERPRET(v4i32, a.val))));
}
/* v_abs */
#define OPENCV_HAL_IMPL_MSA_ABS(_Tpuvec, _Tpsvec, usuffix, ssuffix) \
inline _Tpuvec v_abs(const _Tpsvec& a) \
{ \
return v_reinterpret_as_##usuffix(_Tpsvec(msa_absq_##ssuffix(a.val))); \
}
OPENCV_HAL_IMPL_MSA_ABS(v_uint8x16, v_int8x16, u8, s8)
OPENCV_HAL_IMPL_MSA_ABS(v_uint16x8, v_int16x8, u16, s16)
OPENCV_HAL_IMPL_MSA_ABS(v_uint32x4, v_int32x4, u32, s32)
/* v_abs(float), v_sqrt, v_invsqrt */
#define OPENCV_HAL_IMPL_MSA_BASIC_FUNC(_Tpvec, func, intrin) \
inline _Tpvec func(const _Tpvec& a) \
{ \
return _Tpvec(intrin(a.val)); \
}
OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float32x4, v_abs, msa_absq_f32)
OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float64x2, v_abs, msa_absq_f64)
OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float32x4, v_sqrt, msa_sqrtq_f32)
OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float32x4, v_invsqrt, msa_rsqrtq_f32)
OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float64x2, v_sqrt, msa_sqrtq_f64)
OPENCV_HAL_IMPL_MSA_BASIC_FUNC(v_float64x2, v_invsqrt, msa_rsqrtq_f64)
#define OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(bin_op, intrin) \
inline v_float64x2 operator bin_op (const v_float64x2& a, const v_float64x2& b) \
{ \
return v_float64x2(MSA_TPV_REINTERPRET(v2f64, intrin(MSA_TPV_REINTERPRET(v2i64, a.val), MSA_TPV_REINTERPRET(v2i64, b.val)))); \
} \
inline v_float64x2& operator bin_op##= (v_float64x2& a, const v_float64x2& b) \
{ \
a.val = MSA_TPV_REINTERPRET(v2f64, intrin(MSA_TPV_REINTERPRET(v2i64, a.val), MSA_TPV_REINTERPRET(v2i64, b.val))); \
return a; \
}
OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(&, msa_andq_s64)
OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(|, msa_orrq_s64)
OPENCV_HAL_IMPL_MSA_DBL_BIT_OP(^, msa_eorq_s64)
inline v_float64x2 operator ~ (const v_float64x2& a)
{
return v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_mvnq_s32(MSA_TPV_REINTERPRET(v4i32, a.val))));
}
// TODO: exp, log, sin, cos
#define OPENCV_HAL_IMPL_MSA_BIN_FUNC(_Tpvec, func, intrin) \
inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(intrin(a.val, b.val)); \
}
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_min, msa_minq_u8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_max, msa_maxq_u8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_min, msa_minq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_max, msa_maxq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_min, msa_minq_u16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_max, msa_maxq_u16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_min, msa_minq_s16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_max, msa_maxq_s16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint32x4, v_min, msa_minq_u32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint32x4, v_max, msa_maxq_u32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int32x4, v_min, msa_minq_s32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int32x4, v_max, msa_maxq_s32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float32x4, v_min, msa_minq_f32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float32x4, v_max, msa_maxq_f32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float64x2, v_min, msa_minq_f64)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float64x2, v_max, msa_maxq_f64)
#define OPENCV_HAL_IMPL_MSA_INT_CMP_OP(_Tpvec, _Tpv, suffix, not_suffix) \
inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_ceqq_##suffix(a.val, b.val))); } \
inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_mvnq_##not_suffix(msa_ceqq_##suffix(a.val, b.val)))); } \
inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cltq_##suffix(a.val, b.val))); } \
inline _Tpvec operator > (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cgtq_##suffix(a.val, b.val))); } \
inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cleq_##suffix(a.val, b.val))); } \
inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_cgeq_##suffix(a.val, b.val))); }
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint8x16, v16u8, u8, u8)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int8x16, v16i8, s8, u8)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint16x8, v8u16, u16, u16)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int16x8, v8i16, s16, u16)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint32x4, v4u32, u32, u32)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int32x4, v4i32, s32, u32)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_float32x4, v4f32, f32, u32)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_uint64x2, v2u64, u64, u64)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_int64x2, v2i64, s64, u64)
OPENCV_HAL_IMPL_MSA_INT_CMP_OP(v_float64x2, v2f64, f64, u64)
inline v_float32x4 v_not_nan(const v_float32x4& a)
{ return v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ceqq_f32(a.val, a.val))); }
inline v_float64x2 v_not_nan(const v_float64x2& a)
{ return v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_ceqq_f64(a.val, a.val))); }
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_add_wrap, msa_addq_u8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_add_wrap, msa_addq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_add_wrap, msa_addq_u16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_add_wrap, msa_addq_s16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_sub_wrap, msa_subq_u8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_sub_wrap, msa_subq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_sub_wrap, msa_subq_u16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_sub_wrap, msa_subq_s16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_mul_wrap, msa_mulq_u8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_mul_wrap, msa_mulq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_mul_wrap, msa_mulq_u16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_mul_wrap, msa_mulq_s16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint8x16, v_absdiff, msa_abdq_u8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint16x8, v_absdiff, msa_abdq_u16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_uint32x4, v_absdiff, msa_abdq_u32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float32x4, v_absdiff, msa_abdq_f32)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_float64x2, v_absdiff, msa_abdq_f64)
/** Saturating absolute difference **/
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int8x16, v_absdiffs, msa_qabdq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC(v_int16x8, v_absdiffs, msa_qabdq_s16)
#define OPENCV_HAL_IMPL_MSA_BIN_FUNC2(_Tpvec, _Tpvec2, _Tpv, func, intrin) \
inline _Tpvec2 func(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec2(MSA_TPV_REINTERPRET(_Tpv, intrin(a.val, b.val))); \
}
OPENCV_HAL_IMPL_MSA_BIN_FUNC2(v_int8x16, v_uint8x16, v16u8, v_absdiff, msa_abdq_s8)
OPENCV_HAL_IMPL_MSA_BIN_FUNC2(v_int16x8, v_uint16x8, v8u16, v_absdiff, msa_abdq_s16)
OPENCV_HAL_IMPL_MSA_BIN_FUNC2(v_int32x4, v_uint32x4, v4u32, v_absdiff, msa_abdq_s32)
/* v_magnitude, v_sqr_magnitude, v_fma, v_muladd */
inline v_float32x4 v_magnitude(const v_float32x4& a, const v_float32x4& b)
{
v_float32x4 x(msa_mlaq_f32(msa_mulq_f32(a.val, a.val), b.val, b.val));
return v_sqrt(x);
}
inline v_float32x4 v_sqr_magnitude(const v_float32x4& a, const v_float32x4& b)
{
return v_float32x4(msa_mlaq_f32(msa_mulq_f32(a.val, a.val), b.val, b.val));
}
inline v_float32x4 v_fma(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c)
{
return v_float32x4(msa_mlaq_f32(c.val, a.val, b.val));
}
inline v_int32x4 v_fma(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c)
{
return v_int32x4(msa_mlaq_s32(c.val, a.val, b.val));
}
inline v_float32x4 v_muladd(const v_float32x4& a, const v_float32x4& b, const v_float32x4& c)
{
return v_fma(a, b, c);
}
inline v_int32x4 v_muladd(const v_int32x4& a, const v_int32x4& b, const v_int32x4& c)
{
return v_fma(a, b, c);
}
inline v_float64x2 v_magnitude(const v_float64x2& a, const v_float64x2& b)
{
v_float64x2 x(msa_mlaq_f64(msa_mulq_f64(a.val, a.val), b.val, b.val));
return v_sqrt(x);
}
inline v_float64x2 v_sqr_magnitude(const v_float64x2& a, const v_float64x2& b)
{
return v_float64x2(msa_mlaq_f64(msa_mulq_f64(a.val, a.val), b.val, b.val));
}
inline v_float64x2 v_fma(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c)
{
return v_float64x2(msa_mlaq_f64(c.val, a.val, b.val));
}
inline v_float64x2 v_muladd(const v_float64x2& a, const v_float64x2& b, const v_float64x2& c)
{
return v_fma(a, b, c);
}
// trade efficiency for convenience
#define OPENCV_HAL_IMPL_MSA_SHIFT_OP(_Tpvec, suffix, _Tps, ssuffix) \
inline _Tpvec operator << (const _Tpvec& a, int n) \
{ return _Tpvec(msa_shlq_##suffix(a.val, msa_dupq_n_##ssuffix((_Tps)n))); } \
inline _Tpvec operator >> (const _Tpvec& a, int n) \
{ return _Tpvec(msa_shrq_##suffix(a.val, msa_dupq_n_##ssuffix((_Tps)n))); } \
template<int n> inline _Tpvec v_shl(const _Tpvec& a) \
{ return _Tpvec(msa_shlq_n_##suffix(a.val, n)); } \
template<int n> inline _Tpvec v_shr(const _Tpvec& a) \
{ return _Tpvec(msa_shrq_n_##suffix(a.val, n)); } \
template<int n> inline _Tpvec v_rshr(const _Tpvec& a) \
{ return _Tpvec(msa_rshrq_n_##suffix(a.val, n)); }
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint8x16, u8, schar, s8)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int8x16, s8, schar, s8)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint16x8, u16, short, s16)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int16x8, s16, short, s16)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint32x4, u32, int, s32)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int32x4, s32, int, s32)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_uint64x2, u64, int64, s64)
OPENCV_HAL_IMPL_MSA_SHIFT_OP(v_int64x2, s64, int64, s64)
/* v_rotate_right, v_rotate_left */
#define OPENCV_HAL_IMPL_MSA_ROTATE_OP(_Tpvec, _Tpv, _Tpvs, suffix) \
template<int n> inline _Tpvec v_rotate_right(const _Tpvec& a) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##suffix(0), n))); \
} \
template<int n> inline _Tpvec v_rotate_left(const _Tpvec& a) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(msa_dupq_n_##suffix(0), MSA_TPV_REINTERPRET(_Tpvs, a.val), _Tpvec::nlanes - n))); \
} \
template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a) \
{ \
return a; \
} \
template<int n> inline _Tpvec v_rotate_right(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), MSA_TPV_REINTERPRET(_Tpvs, b.val), n))); \
} \
template<int n> inline _Tpvec v_rotate_left(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, b.val), MSA_TPV_REINTERPRET(_Tpvs, a.val), _Tpvec::nlanes - n))); \
} \
template<> inline _Tpvec v_rotate_left<0>(const _Tpvec& a, const _Tpvec& b) \
{ \
CV_UNUSED(b); \
return a; \
}
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint8x16, v16u8, v16i8, s8)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int8x16, v16i8, v16i8, s8)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint16x8, v8u16, v8i16, s16)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int16x8, v8i16, v8i16, s16)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint32x4, v4u32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int32x4, v4i32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_float32x4, v4f32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_uint64x2, v2u64, v2i64, s64)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_int64x2, v2i64, v2i64, s64)
OPENCV_HAL_IMPL_MSA_ROTATE_OP(v_float64x2, v2f64, v2i64, s64)
#define OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(_Tpvec, _Tp, suffix) \
inline _Tpvec v_load(const _Tp* ptr) \
{ return _Tpvec(msa_ld1q_##suffix(ptr)); } \
inline _Tpvec v_load_aligned(const _Tp* ptr) \
{ return _Tpvec(msa_ld1q_##suffix(ptr)); } \
inline _Tpvec v_load_low(const _Tp* ptr) \
{ return _Tpvec(msa_combine_##suffix(msa_ld1_##suffix(ptr), msa_dup_n_##suffix((_Tp)0))); } \
inline _Tpvec v_load_halves(const _Tp* ptr0, const _Tp* ptr1) \
{ return _Tpvec(msa_combine_##suffix(msa_ld1_##suffix(ptr0), msa_ld1_##suffix(ptr1))); } \
inline void v_store(_Tp* ptr, const _Tpvec& a) \
{ msa_st1q_##suffix(ptr, a.val); } \
inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \
{ msa_st1q_##suffix(ptr, a.val); } \
inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \
{ msa_st1q_##suffix(ptr, a.val); } \
inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode /*mode*/) \
{ msa_st1q_##suffix(ptr, a.val); } \
inline void v_store_low(_Tp* ptr, const _Tpvec& a) \
{ \
int n = _Tpvec::nlanes; \
for( int i = 0; i < (n/2); i++ ) \
ptr[i] = a.val[i]; \
} \
inline void v_store_high(_Tp* ptr, const _Tpvec& a) \
{ \
int n = _Tpvec::nlanes; \
for( int i = 0; i < (n/2); i++ ) \
ptr[i] = a.val[i+(n/2)]; \
}
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint8x16, uchar, u8)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int8x16, schar, s8)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint16x8, ushort, u16)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int16x8, short, s16)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint32x4, unsigned, u32)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int32x4, int, s32)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_uint64x2, uint64, u64)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_int64x2, int64, s64)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_float32x4, float, f32)
OPENCV_HAL_IMPL_MSA_LOADSTORE_OP(v_float64x2, double, f64)
/** Reverse **/
inline v_uint8x16 v_reverse(const v_uint8x16 &a)
{
v_uint8x16 c = v_uint8x16((v16u8)__builtin_msa_vshf_b((v16i8)((v2i64){0x08090A0B0C0D0E0F, 0x0001020304050607}), msa_dupq_n_s8(0), (v16i8)a.val));
return c;
}
inline v_int8x16 v_reverse(const v_int8x16 &a)
{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); }
inline v_uint16x8 v_reverse(const v_uint16x8 &a)
{
v_uint16x8 c = v_uint16x8((v8u16)__builtin_msa_vshf_h((v8i16)((v2i64){0x0004000500060007, 0x0000000100020003}), msa_dupq_n_s16(0), (v8i16)a.val));
return c;
}
inline v_int16x8 v_reverse(const v_int16x8 &a)
{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); }
inline v_uint32x4 v_reverse(const v_uint32x4 &a)
{
v_uint32x4 c;
c.val[0] = a.val[3];
c.val[1] = a.val[2];
c.val[2] = a.val[1];
c.val[3] = a.val[0];
return c;
}
inline v_int32x4 v_reverse(const v_int32x4 &a)
{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); }
inline v_float32x4 v_reverse(const v_float32x4 &a)
{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); }
inline v_uint64x2 v_reverse(const v_uint64x2 &a)
{
v_uint64x2 c;
c.val[0] = a.val[1];
c.val[1] = a.val[0];
return c;
}
inline v_int64x2 v_reverse(const v_int64x2 &a)
{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); }
inline v_float64x2 v_reverse(const v_float64x2 &a)
{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); }
#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_8U(func, cfunc) \
inline unsigned short v_reduce_##func(const v_uint16x8& a) \
{ \
v8u16 a_lo, a_hi; \
ILVRL_H2_UH(a.val, msa_dupq_n_u16(0), a_lo, a_hi); \
v4u32 b = msa_##func##q_u32(msa_paddlq_u16(a_lo), msa_paddlq_u16(a_hi)); \
v4u32 b_lo, b_hi; \
ILVRL_W2_UW(b, msa_dupq_n_u32(0), b_lo, b_hi); \
v2u64 c = msa_##func##q_u64(msa_paddlq_u32(b_lo), msa_paddlq_u32(b_hi)); \
return (unsigned short)cfunc(c[0], c[1]); \
}
OPENCV_HAL_IMPL_MSA_REDUCE_OP_8U(max, std::max)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_8U(min, std::min)
#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_8S(func, cfunc) \
inline short v_reduce_##func(const v_int16x8& a) \
{ \
v8i16 a_lo, a_hi; \
ILVRL_H2_SH(a.val, msa_dupq_n_s16(0), a_lo, a_hi); \
v4i32 b = msa_##func##q_s32(msa_paddlq_s16(a_lo), msa_paddlq_s16(a_hi)); \
v4i32 b_lo, b_hi; \
ILVRL_W2_SW(b, msa_dupq_n_s32(0), b_lo, b_hi); \
v2i64 c = msa_##func##q_s64(msa_paddlq_s32(b_lo), msa_paddlq_s32(b_hi)); \
return (short)cfunc(c[0], c[1]); \
}
OPENCV_HAL_IMPL_MSA_REDUCE_OP_8S(max, std::max)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_8S(min, std::min)
#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(_Tpvec, scalartype, func, cfunc) \
inline scalartype v_reduce_##func(const _Tpvec& a) \
{ \
return (scalartype)cfunc(cfunc(a.val[0], a.val[1]), cfunc(a.val[2], a.val[3])); \
}
OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_uint32x4, unsigned, max, std::max)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_uint32x4, unsigned, min, std::min)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_int32x4, int, max, std::max)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_int32x4, int, min, std::min)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_float32x4, float, max, std::max)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_4(v_float32x4, float, min, std::min)
#define OPENCV_HAL_IMPL_MSA_REDUCE_OP_16(_Tpvec, scalartype, _Tpvec2, func) \
inline scalartype v_reduce_##func(const _Tpvec& a) \
{ \
_Tpvec2 a1, a2; \
v_expand(a, a1, a2); \
return (scalartype)v_reduce_##func(v_##func(a1, a2)); \
}
OPENCV_HAL_IMPL_MSA_REDUCE_OP_16(v_uint8x16, uchar, v_uint16x8, min)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_16(v_uint8x16, uchar, v_uint16x8, max)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_16(v_int8x16, char, v_int16x8, min)
OPENCV_HAL_IMPL_MSA_REDUCE_OP_16(v_int8x16, char, v_int16x8, max)
#define OPENCV_HAL_IMPL_MSA_REDUCE_SUM(_Tpvec, scalartype, suffix) \
inline scalartype v_reduce_sum(const _Tpvec& a) \
{ \
return (scalartype)msa_sum_##suffix(a.val); \
}
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_uint8x16, unsigned char, u8)
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_int8x16, char, s8)
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_uint16x8, unsigned short, u16)
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_int16x8, short, s16)
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_uint32x4, unsigned, u32)
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_int32x4, int, s32)
OPENCV_HAL_IMPL_MSA_REDUCE_SUM(v_float32x4, float, f32)
inline uint64 v_reduce_sum(const v_uint64x2& a)
{ return (uint64)(msa_getq_lane_u64(a.val, 0) + msa_getq_lane_u64(a.val, 1)); }
inline int64 v_reduce_sum(const v_int64x2& a)
{ return (int64)(msa_getq_lane_s64(a.val, 0) + msa_getq_lane_s64(a.val, 1)); }
inline double v_reduce_sum(const v_float64x2& a)
{
return msa_getq_lane_f64(a.val, 0) + msa_getq_lane_f64(a.val, 1);
}
/* v_reduce_sum4, v_reduce_sad */
inline v_float32x4 v_reduce_sum4(const v_float32x4& a, const v_float32x4& b,
const v_float32x4& c, const v_float32x4& d)
{
v4f32 u0 = msa_addq_f32(MSA_TPV_REINTERPRET(v4f32, msa_ilvevq_s32(MSA_TPV_REINTERPRET(v4i32, b.val), MSA_TPV_REINTERPRET(v4i32, a.val))),
MSA_TPV_REINTERPRET(v4f32, msa_ilvodq_s32(MSA_TPV_REINTERPRET(v4i32, b.val), MSA_TPV_REINTERPRET(v4i32, a.val)))); // a0+a1 b0+b1 a2+a3 b2+b3
v4f32 u1 = msa_addq_f32(MSA_TPV_REINTERPRET(v4f32, msa_ilvevq_s32(MSA_TPV_REINTERPRET(v4i32, d.val), MSA_TPV_REINTERPRET(v4i32, c.val))),
MSA_TPV_REINTERPRET(v4f32, msa_ilvodq_s32(MSA_TPV_REINTERPRET(v4i32, d.val), MSA_TPV_REINTERPRET(v4i32, c.val)))); // c0+c1 d0+d1 c2+c3 d2+d3
return v_float32x4(msa_addq_f32(MSA_TPV_REINTERPRET(v4f32, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, u1), MSA_TPV_REINTERPRET(v2i64, u0))),
MSA_TPV_REINTERPRET(v4f32, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, u1), MSA_TPV_REINTERPRET(v2i64, u0)))));
}
inline unsigned v_reduce_sad(const v_uint8x16& a, const v_uint8x16& b)
{
v16u8 t0 = msa_abdq_u8(a.val, b.val);
v8u16 t1 = msa_paddlq_u8(t0);
v4u32 t2 = msa_paddlq_u16(t1);
return msa_sum_u32(t2);
}
inline unsigned v_reduce_sad(const v_int8x16& a, const v_int8x16& b)
{
v16u8 t0 = MSA_TPV_REINTERPRET(v16u8, msa_abdq_s8(a.val, b.val));
v8u16 t1 = msa_paddlq_u8(t0);
v4u32 t2 = msa_paddlq_u16(t1);
return msa_sum_u32(t2);
}
inline unsigned v_reduce_sad(const v_uint16x8& a, const v_uint16x8& b)
{
v8u16 t0 = msa_abdq_u16(a.val, b.val);
v4u32 t1 = msa_paddlq_u16(t0);
return msa_sum_u32(t1);
}
inline unsigned v_reduce_sad(const v_int16x8& a, const v_int16x8& b)
{
v8u16 t0 = MSA_TPV_REINTERPRET(v8u16, msa_abdq_s16(a.val, b.val));
v4u32 t1 = msa_paddlq_u16(t0);
return msa_sum_u32(t1);
}
inline unsigned v_reduce_sad(const v_uint32x4& a, const v_uint32x4& b)
{
v4u32 t0 = msa_abdq_u32(a.val, b.val);
return msa_sum_u32(t0);
}
inline unsigned v_reduce_sad(const v_int32x4& a, const v_int32x4& b)
{
v4u32 t0 = MSA_TPV_REINTERPRET(v4u32, msa_abdq_s32(a.val, b.val));
return msa_sum_u32(t0);
}
inline float v_reduce_sad(const v_float32x4& a, const v_float32x4& b)
{
v4f32 t0 = msa_abdq_f32(a.val, b.val);
return msa_sum_f32(t0);
}
/* v_popcount */
#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE8(_Tpvec) \
inline v_uint8x16 v_popcount(const _Tpvec& a) \
{ \
v16u8 t = MSA_TPV_REINTERPRET(v16u8, msa_cntq_s8(MSA_TPV_REINTERPRET(v16i8, a.val))); \
return v_uint8x16(t); \
}
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE8(v_uint8x16)
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE8(v_int8x16)
#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE16(_Tpvec) \
inline v_uint16x8 v_popcount(const _Tpvec& a) \
{ \
v8u16 t = MSA_TPV_REINTERPRET(v8u16, msa_cntq_s16(MSA_TPV_REINTERPRET(v8i16, a.val))); \
return v_uint16x8(t); \
}
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE16(v_uint16x8)
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE16(v_int16x8)
#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE32(_Tpvec) \
inline v_uint32x4 v_popcount(const _Tpvec& a) \
{ \
v4u32 t = MSA_TPV_REINTERPRET(v4u32, msa_cntq_s32(MSA_TPV_REINTERPRET(v4i32, a.val))); \
return v_uint32x4(t); \
}
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE32(v_uint32x4)
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE32(v_int32x4)
#define OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE64(_Tpvec) \
inline v_uint64x2 v_popcount(const _Tpvec& a) \
{ \
v2u64 t = MSA_TPV_REINTERPRET(v2u64, msa_cntq_s64(MSA_TPV_REINTERPRET(v2i64, a.val))); \
return v_uint64x2(t); \
}
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE64(v_uint64x2)
OPENCV_HAL_IMPL_MSA_POPCOUNT_SIZE64(v_int64x2)
inline int v_signmask(const v_uint8x16& a)
{
v8i8 m0 = msa_create_s8(CV_BIG_UINT(0x0706050403020100));
v16u8 v0 = msa_shlq_u8(msa_shrq_n_u8(a.val, 7), msa_combine_s8(m0, m0));
v8u16 v1 = msa_paddlq_u8(v0);
v4u32 v2 = msa_paddlq_u16(v1);
v2u64 v3 = msa_paddlq_u32(v2);
return (int)msa_getq_lane_u64(v3, 0) + ((int)msa_getq_lane_u64(v3, 1) << 8);
}
inline int v_signmask(const v_int8x16& a)
{ return v_signmask(v_reinterpret_as_u8(a)); }
inline int v_signmask(const v_uint16x8& a)
{
v4i16 m0 = msa_create_s16(CV_BIG_UINT(0x0003000200010000));
v8u16 v0 = msa_shlq_u16(msa_shrq_n_u16(a.val, 15), msa_combine_s16(m0, m0));
v4u32 v1 = msa_paddlq_u16(v0);
v2u64 v2 = msa_paddlq_u32(v1);
return (int)msa_getq_lane_u64(v2, 0) + ((int)msa_getq_lane_u64(v2, 1) << 4);
}
inline int v_signmask(const v_int16x8& a)
{ return v_signmask(v_reinterpret_as_u16(a)); }
inline int v_signmask(const v_uint32x4& a)
{
v2i32 m0 = msa_create_s32(CV_BIG_UINT(0x0000000100000000));
v4u32 v0 = msa_shlq_u32(msa_shrq_n_u32(a.val, 31), msa_combine_s32(m0, m0));
v2u64 v1 = msa_paddlq_u32(v0);
return (int)msa_getq_lane_u64(v1, 0) + ((int)msa_getq_lane_u64(v1, 1) << 2);
}
inline int v_signmask(const v_int32x4& a)
{ return v_signmask(v_reinterpret_as_u32(a)); }
inline int v_signmask(const v_float32x4& a)
{ return v_signmask(v_reinterpret_as_u32(a)); }
inline int v_signmask(const v_uint64x2& a)
{
v2u64 v0 = msa_shrq_n_u64(a.val, 63);
return (int)msa_getq_lane_u64(v0, 0) + ((int)msa_getq_lane_u64(v0, 1) << 1);
}
inline int v_signmask(const v_int64x2& a)
{ return v_signmask(v_reinterpret_as_u64(a)); }
inline int v_signmask(const v_float64x2& a)
{ return v_signmask(v_reinterpret_as_u64(a)); }
inline int v_scan_forward(const v_int8x16& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_uint8x16& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_int16x8& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_uint16x8& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_int32x4& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_uint32x4& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_float32x4& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_int64x2& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_uint64x2& a) { return trailingZeros32(v_signmask(a)); }
inline int v_scan_forward(const v_float64x2& a) { return trailingZeros32(v_signmask(a)); }
#define OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(_Tpvec, _Tpvec2, suffix, shift) \
inline bool v_check_all(const v_##_Tpvec& a) \
{ \
_Tpvec2 v0 = msa_shrq_n_##suffix(msa_mvnq_##suffix(a.val), shift); \
v2u64 v1 = MSA_TPV_REINTERPRET(v2u64, v0); \
return (msa_getq_lane_u64(v1, 0) | msa_getq_lane_u64(v1, 1)) == 0; \
} \
inline bool v_check_any(const v_##_Tpvec& a) \
{ \
_Tpvec2 v0 = msa_shrq_n_##suffix(a.val, shift); \
v2u64 v1 = MSA_TPV_REINTERPRET(v2u64, v0); \
return (msa_getq_lane_u64(v1, 0) | msa_getq_lane_u64(v1, 1)) != 0; \
}
OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint8x16, v16u8, u8, 7)
OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint16x8, v8u16, u16, 15)
OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint32x4, v4u32, u32, 31)
OPENCV_HAL_IMPL_MSA_CHECK_ALLANY(uint64x2, v2u64, u64, 63)
inline bool v_check_all(const v_int8x16& a)
{ return v_check_all(v_reinterpret_as_u8(a)); }
inline bool v_check_all(const v_int16x8& a)
{ return v_check_all(v_reinterpret_as_u16(a)); }
inline bool v_check_all(const v_int32x4& a)
{ return v_check_all(v_reinterpret_as_u32(a)); }
inline bool v_check_all(const v_float32x4& a)
{ return v_check_all(v_reinterpret_as_u32(a)); }
inline bool v_check_any(const v_int8x16& a)
{ return v_check_any(v_reinterpret_as_u8(a)); }
inline bool v_check_any(const v_int16x8& a)
{ return v_check_any(v_reinterpret_as_u16(a)); }
inline bool v_check_any(const v_int32x4& a)
{ return v_check_any(v_reinterpret_as_u32(a)); }
inline bool v_check_any(const v_float32x4& a)
{ return v_check_any(v_reinterpret_as_u32(a)); }
inline bool v_check_all(const v_int64x2& a)
{ return v_check_all(v_reinterpret_as_u64(a)); }
inline bool v_check_all(const v_float64x2& a)
{ return v_check_all(v_reinterpret_as_u64(a)); }
inline bool v_check_any(const v_int64x2& a)
{ return v_check_any(v_reinterpret_as_u64(a)); }
inline bool v_check_any(const v_float64x2& a)
{ return v_check_any(v_reinterpret_as_u64(a)); }
/* v_select */
#define OPENCV_HAL_IMPL_MSA_SELECT(_Tpvec, _Tpv, _Tpvu) \
inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_bslq_u8(MSA_TPV_REINTERPRET(_Tpvu, mask.val), \
MSA_TPV_REINTERPRET(_Tpvu, b.val), MSA_TPV_REINTERPRET(_Tpvu, a.val)))); \
}
OPENCV_HAL_IMPL_MSA_SELECT(v_uint8x16, v16u8, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_int8x16, v16i8, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_uint16x8, v8u16, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_int16x8, v8i16, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_uint32x4, v4u32, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_int32x4, v4i32, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_float32x4, v4f32, v16u8)
OPENCV_HAL_IMPL_MSA_SELECT(v_float64x2, v2f64, v16u8)
#define OPENCV_HAL_IMPL_MSA_EXPAND(_Tpvec, _Tpwvec, _Tp, suffix, ssuffix, _Tpv, _Tpvs) \
inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \
{ \
_Tpv a_lo = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \
_Tpv a_hi = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \
b0.val = msa_paddlq_##suffix(a_lo); \
b1.val = msa_paddlq_##suffix(a_hi); \
} \
inline _Tpwvec v_expand_low(const _Tpvec& a) \
{ \
_Tpv a_lo = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \
return _Tpwvec(msa_paddlq_##suffix(a_lo)); \
} \
inline _Tpwvec v_expand_high(const _Tpvec& a) \
{ \
_Tpv a_hi = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), msa_dupq_n_##ssuffix(0))); \
return _Tpwvec(msa_paddlq_##suffix(a_hi)); \
} \
inline _Tpwvec v_load_expand(const _Tp* ptr) \
{ \
return _Tpwvec(msa_movl_##suffix(msa_ld1_##suffix(ptr))); \
}
OPENCV_HAL_IMPL_MSA_EXPAND(v_uint8x16, v_uint16x8, uchar, u8, s8, v16u8, v16i8)
OPENCV_HAL_IMPL_MSA_EXPAND(v_int8x16, v_int16x8, schar, s8, s8, v16i8, v16i8)
OPENCV_HAL_IMPL_MSA_EXPAND(v_uint16x8, v_uint32x4, ushort, u16, s16, v8u16, v8i16)
OPENCV_HAL_IMPL_MSA_EXPAND(v_int16x8, v_int32x4, short, s16, s16, v8i16, v8i16)
OPENCV_HAL_IMPL_MSA_EXPAND(v_uint32x4, v_uint64x2, uint, u32, s32, v4u32, v4i32)
OPENCV_HAL_IMPL_MSA_EXPAND(v_int32x4, v_int64x2, int, s32, s32, v4i32, v4i32)
inline v_uint32x4 v_load_expand_q(const uchar* ptr)
{
return v_uint32x4((v4u32){ptr[0], ptr[1], ptr[2], ptr[3]});
}
inline v_int32x4 v_load_expand_q(const schar* ptr)
{
return v_int32x4((v4i32){ptr[0], ptr[1], ptr[2], ptr[3]});
}
/* v_zip, v_combine_low, v_combine_high, v_recombine */
#define OPENCV_HAL_IMPL_MSA_UNPACKS(_Tpvec, _Tpv, _Tpvs, ssuffix) \
inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, _Tpvec& b0, _Tpvec& b1) \
{ \
b0.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \
b1.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \
} \
inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val)))); \
} \
inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val)))); \
} \
inline void v_recombine(const _Tpvec& a, const _Tpvec& b, _Tpvec& c, _Tpvec& d) \
{ \
c.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val))); \
d.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, b.val), MSA_TPV_REINTERPRET(v2i64, a.val))); \
}
OPENCV_HAL_IMPL_MSA_UNPACKS(v_uint8x16, v16u8, v16i8, s8)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_int8x16, v16i8, v16i8, s8)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_uint16x8, v8u16, v8i16, s16)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_int16x8, v8i16, v8i16, s16)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_uint32x4, v4u32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_int32x4, v4i32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_float32x4, v4f32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_UNPACKS(v_float64x2, v2f64, v2i64, s64)
/* v_extract */
#define OPENCV_HAL_IMPL_MSA_EXTRACT(_Tpvec, _Tpv, _Tpvs, suffix) \
template <int s> \
inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \
{ \
return _Tpvec(MSA_TPV_REINTERPRET(_Tpv, msa_extq_##suffix(MSA_TPV_REINTERPRET(_Tpvs, a.val), MSA_TPV_REINTERPRET(_Tpvs, b.val), s))); \
}
OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint8x16, v16u8, v16i8, s8)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_int8x16, v16i8, v16i8, s8)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint16x8, v8u16, v8i16, s16)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_int16x8, v8i16, v8i16, s16)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint32x4, v4u32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_int32x4, v4i32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_uint64x2, v2u64, v2i64, s64)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_int64x2, v2i64, v2i64, s64)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_float32x4, v4f32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_EXTRACT(v_float64x2, v2f64, v2i64, s64)
/* v_round, v_floor, v_ceil, v_trunc */
inline v_int32x4 v_round(const v_float32x4& a)
{
return v_int32x4(msa_cvttintq_s32_f32(a.val));
}
inline v_int32x4 v_floor(const v_float32x4& a)
{
v4i32 a1 = msa_cvttintq_s32_f32(a.val);
return v_int32x4(msa_addq_s32(a1, MSA_TPV_REINTERPRET(v4i32, msa_cgtq_f32(msa_cvtfintq_f32_s32(a1), a.val))));
}
inline v_int32x4 v_ceil(const v_float32x4& a)
{
v4i32 a1 = msa_cvttintq_s32_f32(a.val);
return v_int32x4(msa_subq_s32(a1, MSA_TPV_REINTERPRET(v4i32, msa_cgtq_f32(a.val, msa_cvtfintq_f32_s32(a1)))));
}
inline v_int32x4 v_trunc(const v_float32x4& a)
{
return v_int32x4(msa_cvttruncq_s32_f32(a.val));
}
inline v_int32x4 v_round(const v_float64x2& a)
{
return v_int32x4(msa_pack_s64(msa_cvttintq_s64_f64(a.val), msa_dupq_n_s64(0)));
}
inline v_int32x4 v_round(const v_float64x2& a, const v_float64x2& b)
{
return v_int32x4(msa_pack_s64(msa_cvttintq_s64_f64(a.val), msa_cvttintq_s64_f64(b.val)));
}
inline v_int32x4 v_floor(const v_float64x2& a)
{
v2f64 a1 = msa_cvtrintq_f64(a.val);
return v_int32x4(msa_pack_s64(msa_addq_s64(msa_cvttruncq_s64_f64(a1), MSA_TPV_REINTERPRET(v2i64, msa_cgtq_f64(a1, a.val))), msa_dupq_n_s64(0)));
}
inline v_int32x4 v_ceil(const v_float64x2& a)
{
v2f64 a1 = msa_cvtrintq_f64(a.val);
return v_int32x4(msa_pack_s64(msa_subq_s64(msa_cvttruncq_s64_f64(a1), MSA_TPV_REINTERPRET(v2i64, msa_cgtq_f64(a.val, a1))), msa_dupq_n_s64(0)));
}
inline v_int32x4 v_trunc(const v_float64x2& a)
{
return v_int32x4(msa_pack_s64(msa_cvttruncq_s64_f64(a.val), msa_dupq_n_s64(0)));
}
#define OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(_Tpvec, _Tpv, _Tpvs, ssuffix) \
inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \
const _Tpvec& a2, const _Tpvec& a3, \
_Tpvec& b0, _Tpvec& b1, \
_Tpvec& b2, _Tpvec& b3) \
{ \
_Tpv t00 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \
_Tpv t01 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a1.val), MSA_TPV_REINTERPRET(_Tpvs, a0.val))); \
_Tpv t10 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a3.val), MSA_TPV_REINTERPRET(_Tpvs, a2.val))); \
_Tpv t11 = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_##ssuffix(MSA_TPV_REINTERPRET(_Tpvs, a3.val), MSA_TPV_REINTERPRET(_Tpvs, a2.val))); \
b0.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, t10), MSA_TPV_REINTERPRET(v2i64, t00))); \
b1.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, t10), MSA_TPV_REINTERPRET(v2i64, t00))); \
b2.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvrq_s64(MSA_TPV_REINTERPRET(v2i64, t11), MSA_TPV_REINTERPRET(v2i64, t01))); \
b3.val = MSA_TPV_REINTERPRET(_Tpv, msa_ilvlq_s64(MSA_TPV_REINTERPRET(v2i64, t11), MSA_TPV_REINTERPRET(v2i64, t01))); \
}
OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(v_uint32x4, v4u32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(v_int32x4, v4i32, v4i32, s32)
OPENCV_HAL_IMPL_MSA_TRANSPOSE4x4(v_float32x4, v4f32, v4i32, s32)
#define OPENCV_HAL_IMPL_MSA_INTERLEAVED(_Tpvec, _Tp, suffix) \
inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b) \
{ \
msa_ld2q_##suffix(ptr, &a.val, &b.val); \
} \
inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, v_##_Tpvec& c) \
{ \
msa_ld3q_##suffix(ptr, &a.val, &b.val, &c.val); \
} \
inline void v_load_deinterleave(const _Tp* ptr, v_##_Tpvec& a, v_##_Tpvec& b, \
v_##_Tpvec& c, v_##_Tpvec& d) \
{ \
msa_ld4q_##suffix(ptr, &a.val, &b.val, &c.val, &d.val); \
} \
inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \
hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
{ \
msa_st2q_##suffix(ptr, a.val, b.val); \
} \
inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \
const v_##_Tpvec& c, hal::StoreMode /*mode*/=hal::STORE_UNALIGNED) \
{ \
msa_st3q_##suffix(ptr, a.val, b.val, c.val); \
} \
inline void v_store_interleave( _Tp* ptr, const v_##_Tpvec& a, const v_##_Tpvec& b, \
const v_##_Tpvec& c, const v_##_Tpvec& d, \
hal::StoreMode /*mode*/=hal::STORE_UNALIGNED ) \
{ \
msa_st4q_##suffix(ptr, a.val, b.val, c.val, d.val); \
}
OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint8x16, uchar, u8)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(int8x16, schar, s8)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint16x8, ushort, u16)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(int16x8, short, s16)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint32x4, unsigned, u32)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(int32x4, int, s32)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(float32x4, float, f32)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(uint64x2, uint64, u64)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(int64x2, int64, s64)
OPENCV_HAL_IMPL_MSA_INTERLEAVED(float64x2, double, f64)
/* v_cvt_f32, v_cvt_f64, v_cvt_f64_high */
inline v_float32x4 v_cvt_f32(const v_int32x4& a)
{
return v_float32x4(msa_cvtfintq_f32_s32(a.val));
}
inline v_float32x4 v_cvt_f32(const v_float64x2& a)
{
return v_float32x4(msa_cvtfq_f32_f64(a.val, msa_dupq_n_f64(0.0f)));
}
inline v_float32x4 v_cvt_f32(const v_float64x2& a, const v_float64x2& b)
{
return v_float32x4(msa_cvtfq_f32_f64(a.val, b.val));
}
inline v_float64x2 v_cvt_f64(const v_int32x4& a)
{
return v_float64x2(msa_cvtflq_f64_f32(msa_cvtfintq_f32_s32(a.val)));
}
inline v_float64x2 v_cvt_f64_high(const v_int32x4& a)
{
return v_float64x2(msa_cvtfhq_f64_f32(msa_cvtfintq_f32_s32(a.val)));
}
inline v_float64x2 v_cvt_f64(const v_float32x4& a)
{
return v_float64x2(msa_cvtflq_f64_f32(a.val));
}
inline v_float64x2 v_cvt_f64_high(const v_float32x4& a)
{
return v_float64x2(msa_cvtfhq_f64_f32(a.val));
}
inline v_float64x2 v_cvt_f64(const v_int64x2& a)
{
return v_float64x2(msa_cvtfintq_f64_s64(a.val));
}
////////////// Lookup table access ////////////////////
inline v_int8x16 v_lut(const schar* tab, const int* idx)
{
schar CV_DECL_ALIGNED(32) elems[16] =
{
tab[idx[ 0]],
tab[idx[ 1]],
tab[idx[ 2]],
tab[idx[ 3]],
tab[idx[ 4]],
tab[idx[ 5]],
tab[idx[ 6]],
tab[idx[ 7]],
tab[idx[ 8]],
tab[idx[ 9]],
tab[idx[10]],
tab[idx[11]],
tab[idx[12]],
tab[idx[13]],
tab[idx[14]],
tab[idx[15]]
};
return v_int8x16(msa_ld1q_s8(elems));
}
inline v_int8x16 v_lut_pairs(const schar* tab, const int* idx)
{
schar CV_DECL_ALIGNED(32) elems[16] =
{
tab[idx[0]],
tab[idx[0] + 1],
tab[idx[1]],
tab[idx[1] + 1],
tab[idx[2]],
tab[idx[2] + 1],
tab[idx[3]],
tab[idx[3] + 1],
tab[idx[4]],
tab[idx[4] + 1],
tab[idx[5]],
tab[idx[5] + 1],
tab[idx[6]],
tab[idx[6] + 1],
tab[idx[7]],
tab[idx[7] + 1]
};
return v_int8x16(msa_ld1q_s8(elems));
}
inline v_int8x16 v_lut_quads(const schar* tab, const int* idx)
{
schar CV_DECL_ALIGNED(32) elems[16] =
{
tab[idx[0]],
tab[idx[0] + 1],
tab[idx[0] + 2],
tab[idx[0] + 3],
tab[idx[1]],
tab[idx[1] + 1],
tab[idx[1] + 2],
tab[idx[1] + 3],
tab[idx[2]],
tab[idx[2] + 1],
tab[idx[2] + 2],
tab[idx[2] + 3],
tab[idx[3]],
tab[idx[3] + 1],
tab[idx[3] + 2],
tab[idx[3] + 3]
};
return v_int8x16(msa_ld1q_s8(elems));
}
inline v_uint8x16 v_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut((schar*)tab, idx)); }
inline v_uint8x16 v_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_pairs((schar*)tab, idx)); }
inline v_uint8x16 v_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v_lut_quads((schar*)tab, idx)); }
inline v_int16x8 v_lut(const short* tab, const int* idx)
{
short CV_DECL_ALIGNED(32) elems[8] =
{
tab[idx[0]],
tab[idx[1]],
tab[idx[2]],
tab[idx[3]],
tab[idx[4]],
tab[idx[5]],
tab[idx[6]],
tab[idx[7]]
};
return v_int16x8(msa_ld1q_s16(elems));
}
inline v_int16x8 v_lut_pairs(const short* tab, const int* idx)
{
short CV_DECL_ALIGNED(32) elems[8] =
{
tab[idx[0]],
tab[idx[0] + 1],
tab[idx[1]],
tab[idx[1] + 1],
tab[idx[2]],
tab[idx[2] + 1],
tab[idx[3]],
tab[idx[3] + 1]
};
return v_int16x8(msa_ld1q_s16(elems));
}
inline v_int16x8 v_lut_quads(const short* tab, const int* idx)
{
return v_int16x8(msa_combine_s16(msa_ld1_s16(tab + idx[0]), msa_ld1_s16(tab + idx[1])));
}
inline v_uint16x8 v_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut((short*)tab, idx)); }
inline v_uint16x8 v_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_pairs((short*)tab, idx)); }
inline v_uint16x8 v_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v_lut_quads((short*)tab, idx)); }
inline v_int32x4 v_lut(const int* tab, const int* idx)
{
int CV_DECL_ALIGNED(32) elems[4] =
{
tab[idx[0]],
tab[idx[1]],
tab[idx[2]],
tab[idx[3]]
};
return v_int32x4(msa_ld1q_s32(elems));
}
inline v_int32x4 v_lut_pairs(const int* tab, const int* idx)
{
return v_int32x4(msa_combine_s32(msa_ld1_s32(tab + idx[0]), msa_ld1_s32(tab + idx[1])));
}
inline v_int32x4 v_lut_quads(const int* tab, const int* idx)
{
return v_int32x4(msa_ld1q_s32(tab + idx[0]));
}
inline v_uint32x4 v_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut((int*)tab, idx)); }
inline v_uint32x4 v_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_pairs((int*)tab, idx)); }
inline v_uint32x4 v_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v_lut_quads((int*)tab, idx)); }
inline v_int64x2 v_lut(const int64_t* tab, const int* idx)
{
return v_int64x2(msa_combine_s64(msa_create_s64(tab[idx[0]]), msa_create_s64(tab[idx[1]])));
}
inline v_int64x2 v_lut_pairs(const int64_t* tab, const int* idx)
{
return v_int64x2(msa_ld1q_s64(tab + idx[0]));
}
inline v_uint64x2 v_lut(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut((const int64_t *)tab, idx)); }
inline v_uint64x2 v_lut_pairs(const uint64_t* tab, const int* idx) { return v_reinterpret_as_u64(v_lut_pairs((const int64_t *)tab, idx)); }
inline v_float32x4 v_lut(const float* tab, const int* idx)
{
float CV_DECL_ALIGNED(32) elems[4] =
{
tab[idx[0]],
tab[idx[1]],
tab[idx[2]],
tab[idx[3]]
};
return v_float32x4(msa_ld1q_f32(elems));
}
inline v_float32x4 v_lut_pairs(const float* tab, const int* idx)
{
uint64 CV_DECL_ALIGNED(32) elems[2] =
{
*(uint64*)(tab + idx[0]),
*(uint64*)(tab + idx[1])
};
return v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ld1q_u64(elems)));
}
inline v_float32x4 v_lut_quads(const float* tab, const int* idx)
{
return v_float32x4(msa_ld1q_f32(tab + idx[0]));
}
inline v_int32x4 v_lut(const int* tab, const v_int32x4& idxvec)
{
int CV_DECL_ALIGNED(32) idx[4];
v_store_aligned(idx, idxvec);
return v_int32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]);
}
inline v_uint32x4 v_lut(const unsigned* tab, const v_int32x4& idxvec)
{
unsigned CV_DECL_ALIGNED(32) elems[4] =
{
tab[msa_getq_lane_s32(idxvec.val, 0)],
tab[msa_getq_lane_s32(idxvec.val, 1)],
tab[msa_getq_lane_s32(idxvec.val, 2)],
tab[msa_getq_lane_s32(idxvec.val, 3)]
};
return v_uint32x4(msa_ld1q_u32(elems));
}
inline v_float32x4 v_lut(const float* tab, const v_int32x4& idxvec)
{
int CV_DECL_ALIGNED(32) idx[4];
v_store_aligned(idx, idxvec);
return v_float32x4(tab[idx[0]], tab[idx[1]], tab[idx[2]], tab[idx[3]]);
}
inline void v_lut_deinterleave(const float* tab, const v_int32x4& idxvec, v_float32x4& x, v_float32x4& y)
{
int CV_DECL_ALIGNED(32) idx[4];
v_store_aligned(idx, idxvec);
v4f32 xy02 = msa_combine_f32(msa_ld1_f32(tab + idx[0]), msa_ld1_f32(tab + idx[2]));
v4f32 xy13 = msa_combine_f32(msa_ld1_f32(tab + idx[1]), msa_ld1_f32(tab + idx[3]));
x = v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ilvevq_s32(MSA_TPV_REINTERPRET(v4i32, xy13), MSA_TPV_REINTERPRET(v4i32, xy02))));
y = v_float32x4(MSA_TPV_REINTERPRET(v4f32, msa_ilvodq_s32(MSA_TPV_REINTERPRET(v4i32, xy13), MSA_TPV_REINTERPRET(v4i32, xy02))));
}
inline v_int8x16 v_interleave_pairs(const v_int8x16& vec)
{
v_int8x16 c = v_int8x16(__builtin_msa_vshf_b((v16i8)((v2i64){0x0705060403010200, 0x0F0D0E0C0B090A08}), msa_dupq_n_s8(0), vec.val));
return c;
}
inline v_uint8x16 v_interleave_pairs(const v_uint8x16& vec)
{ return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); }
inline v_int8x16 v_interleave_quads(const v_int8x16& vec)
{
v_int8x16 c = v_int8x16(__builtin_msa_vshf_b((v16i8)((v2i64){0x0703060205010400, 0x0F0B0E0A0D090C08}), msa_dupq_n_s8(0), vec.val));
return c;
}
inline v_uint8x16 v_interleave_quads(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); }
inline v_int16x8 v_interleave_pairs(const v_int16x8& vec)
{
v_int16x8 c = v_int16x8(__builtin_msa_vshf_h((v8i16)((v2i64){0x0003000100020000, 0x0007000500060004}), msa_dupq_n_s16(0), vec.val));
return c;
}
inline v_uint16x8 v_interleave_pairs(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); }
inline v_int16x8 v_interleave_quads(const v_int16x8& vec)
{
v_int16x8 c = v_int16x8(__builtin_msa_vshf_h((v8i16)((v2i64){0x0005000100040000, 0x0007000300060002}), msa_dupq_n_s16(0), vec.val));
return c;
}
inline v_uint16x8 v_interleave_quads(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); }
inline v_int32x4 v_interleave_pairs(const v_int32x4& vec)
{
v_int32x4 c;
c.val[0] = vec.val[0];
c.val[1] = vec.val[2];
c.val[2] = vec.val[1];
c.val[3] = vec.val[3];
return c;
}
inline v_uint32x4 v_interleave_pairs(const v_uint32x4& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
inline v_float32x4 v_interleave_pairs(const v_float32x4& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
inline v_int8x16 v_pack_triplets(const v_int8x16& vec)
{
v_int8x16 c = v_int8x16(__builtin_msa_vshf_b((v16i8)((v2i64){0x0908060504020100, 0x131211100E0D0C0A}), msa_dupq_n_s8(0), vec.val));
return c;
}
inline v_uint8x16 v_pack_triplets(const v_uint8x16& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); }
inline v_int16x8 v_pack_triplets(const v_int16x8& vec)
{
v_int16x8 c = v_int16x8(__builtin_msa_vshf_h((v8i16)((v2i64){0x0004000200010000, 0x0009000800060005}), msa_dupq_n_s16(0), vec.val));
return c;
}
inline v_uint16x8 v_pack_triplets(const v_uint16x8& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); }
inline v_int32x4 v_pack_triplets(const v_int32x4& vec) { return vec; }
inline v_uint32x4 v_pack_triplets(const v_uint32x4& vec) { return vec; }
inline v_float32x4 v_pack_triplets(const v_float32x4& vec) { return vec; }
inline v_float64x2 v_lut(const double* tab, const int* idx)
{
double CV_DECL_ALIGNED(32) elems[2] =
{
tab[idx[0]],
tab[idx[1]]
};
return v_float64x2(msa_ld1q_f64(elems));
}
inline v_float64x2 v_lut_pairs(const double* tab, const int* idx)
{
return v_float64x2(msa_ld1q_f64(tab + idx[0]));
}
inline v_float64x2 v_lut(const double* tab, const v_int32x4& idxvec)
{
int CV_DECL_ALIGNED(32) idx[4];
v_store_aligned(idx, idxvec);
return v_float64x2(tab[idx[0]], tab[idx[1]]);
}
inline void v_lut_deinterleave(const double* tab, const v_int32x4& idxvec, v_float64x2& x, v_float64x2& y)
{
int CV_DECL_ALIGNED(32) idx[4];
v_store_aligned(idx, idxvec);
v2f64 xy0 = msa_ld1q_f64(tab + idx[0]);
v2f64 xy1 = msa_ld1q_f64(tab + idx[1]);
x = v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_ilvevq_s64(MSA_TPV_REINTERPRET(v2i64, xy1), MSA_TPV_REINTERPRET(v2i64, xy0))));
y = v_float64x2(MSA_TPV_REINTERPRET(v2f64, msa_ilvodq_s64(MSA_TPV_REINTERPRET(v2i64, xy1), MSA_TPV_REINTERPRET(v2i64, xy0))));
}
template<int i, typename _Tp>
inline typename _Tp::lane_type v_extract_n(const _Tp& a)
{
return v_rotate_right<i>(a).get0();
}
template<int i>
inline v_uint32x4 v_broadcast_element(const v_uint32x4& a)
{
return v_setall_u32(v_extract_n<i>(a));
}
template<int i>
inline v_int32x4 v_broadcast_element(const v_int32x4& a)
{
return v_setall_s32(v_extract_n<i>(a));
}
template<int i>
inline v_float32x4 v_broadcast_element(const v_float32x4& a)
{
return v_setall_f32(v_extract_n<i>(a));
}
////// FP16 support ///////
#if CV_FP16
inline v_float32x4 v_load_expand(const float16_t* ptr)
{
#ifndef msa_ld1_f16
v4f16 v = (v4f16)msa_ld1_s16((const short*)ptr);
#else
v4f16 v = msa_ld1_f16((const __fp16*)ptr);
#endif
return v_float32x4(msa_cvt_f32_f16(v));
}
inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
{
v4f16 hv = msa_cvt_f16_f32(v.val);
#ifndef msa_st1_f16
msa_st1_s16((short*)ptr, (int16x4_t)hv);
#else
msa_st1_f16((__fp16*)ptr, hv);
#endif
}
#else
inline v_float32x4 v_load_expand(const float16_t* ptr)
{
float buf[4];
for( int i = 0; i < 4; i++ )
buf[i] = (float)ptr[i];
return v_load(buf);
}
inline void v_pack_store(float16_t* ptr, const v_float32x4& v)
{
float buf[4];
v_store(buf, v);
for( int i = 0; i < 4; i++ )
ptr[i] = (float16_t)buf[i];
}
#endif
inline void v_cleanup() {}
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
//! @endcond
}
#endif
| 72,633 | intrin_msa | hpp | en | cpp | code | {"qsc_code_num_words": 12510, "qsc_code_num_chars": 72633.0, "qsc_code_mean_word_length": 3.78936851, "qsc_code_frac_words_unique": 0.03884892, "qsc_code_frac_chars_top_2grams": 0.03518616, "qsc_code_frac_chars_top_3grams": 0.07349436, "qsc_code_frac_chars_top_4grams": 0.09045459, "qsc_code_frac_chars_dupe_5grams": 0.79141441, "qsc_code_frac_chars_dupe_6grams": 0.71815209, "qsc_code_frac_chars_dupe_7grams": 0.63356186, "qsc_code_frac_chars_dupe_8grams": 0.55008965, "qsc_code_frac_chars_dupe_9grams": 0.50412404, "qsc_code_frac_chars_dupe_10grams": 0.39422002, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.10138862, "qsc_code_frac_chars_whitespace": 0.15129487, "qsc_code_size_file_byte": 72633.0, "qsc_code_num_lines": 1872.0, "qsc_code_num_chars_line_max": 170.0, "qsc_code_num_chars_line_mean": 38.79967949, "qsc_code_frac_chars_alphabet": 0.66762378, "qsc_code_frac_chars_comments": 0.01815979, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.20861961, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00033654, "qsc_code_frac_chars_long_word_length": 0.00033654, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00479569, "qsc_code_frac_lines_prompt_comments": 0.00053419, "qsc_code_frac_lines_assert": 0.0, "qsc_codecpp_frac_lines_preprocessor_directives": null, "qsc_codecpp_frac_lines_func_ratio": 0.32792005, "qsc_codecpp_cate_bitsstdc": 0.0, "qsc_codecpp_nums_lines_main": 0.0, "qsc_codecpp_frac_lines_goto": 0.0, "qsc_codecpp_cate_var_zero": 0.0, "qsc_codecpp_score_lines_no_logic": 0.33603998, "qsc_codecpp_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 1, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codecpp_frac_lines_func_ratio": 1, "qsc_codecpp_nums_lines_main": 0, "qsc_codecpp_score_lines_no_logic": 0, "qsc_codecpp_frac_lines_preprocessor_directives": 0, "qsc_codecpp_frac_lines_print": 0} |
00Julian00/Nova2 | external/zonos/sampling.py | import torch
def multinomial(input: torch.Tensor, num_samples: int, replacement=False, *, generator=None):
"""torch.multinomial with arbitrary number of dimensions, and number of candidates on the last dimension.
Args:
input (torch.Tensor): The input tensor containing probabilities.
num_samples (int): Number of samples to draw.
replacement (bool): Whether to draw with replacement or not.
Keywords args:
generator (torch.Generator): A pseudorandom number generator for sampling.
Returns:
torch.Tensor: Last dimension contains num_samples indices
sampled from the multinomial probability distribution
located in the last dimension of tensor input.
"""
if num_samples == 1:
q = torch.empty_like(input).exponential_(1, generator=generator)
return torch.argmax(input / q, dim=-1, keepdim=True).to(torch.int64)
input_ = input.reshape(-1, input.shape[-1])
output_ = torch.multinomial(input_, num_samples=num_samples, replacement=replacement, generator=generator)
output = output_.reshape(*list(input.shape[:-1]), -1)
return output
def apply_top_k(
probs: torch.Tensor,
k: int,
) -> torch.Tensor:
"""Sample next token from top K values along the last dimension of the input probs tensor.
Args:
probs (torch.Tensor): Input probabilities with token candidates on the last dimension.
k (int): The k in “top-k”.
Returns:
torch.Tensor: Sampled tokens.
"""
v, _ = torch.topk(probs, min(k, probs.size(-1)))
pivot = v.select(-1, -1).unsqueeze(-1)
probs = torch.where(probs < pivot, 0.0, probs)
probs.div_(probs.sum(dim=-1, keepdim=True))
return probs
def apply_top_p(probs: torch.Tensor, p: float) -> torch.Tensor:
"""Sample next token from top P probabilities along the last dimension of the input probs tensor.
Args:
probs (torch.Tensor): Input probabilities with token candidates on the last dimension.
p (int): The p in “top-p”.
Returns:
torch.Tensor: Sampled tokens.
"""
probs_sort, probs_idx = torch.sort(probs, dim=-1, descending=True)
probs_sum = torch.cumsum(probs_sort, dim=-1)
mask = probs_sum - probs_sort > p
probs_sort *= (~mask).float()
probs = probs.scatter(-1, probs_idx, probs_sort)
probs.div_(probs.sum(dim=-1, keepdim=True))
return probs
def apply_min_p(probs: torch.Tensor, min_p: float) -> torch.Tensor:
"""Sample next token using min-p sampling.
Args:
scores (torch.FloatTensor): Input logits with token candidates on the last dimension.
min_p (float): Minimum token probability, scaled by the probability of the most likely token.
Must be between 0 and 1. Typical values are in the 0.01-0.2 range.
Returns:
torch.Tensor: Sampled tokens.
"""
top_probs, _ = probs.max(dim=-1, keepdim=True)
tokens_to_remove = probs < (min_p * top_probs)
probs = probs.masked_fill(tokens_to_remove, 0.0)
probs.div_(probs.sum(dim=-1, keepdim=True))
return probs
def modify_logit_for_repetition_penalty(
logits: torch.Tensor,
generated_tokens: torch.Tensor,
repetition_penalty: float,
repetition_penalty_window: int,
):
"""See https://arxiv.org/abs/1909.05858
Apply repetition penalty over a sliding window of the last `repetition_penalty_window` tokens.
logits: (batch_size, n_codebooks, vocab_size)
generated_tokens: (batch_size, n_codebooks, seq_len)
"""
generated_tokens = generated_tokens[..., -repetition_penalty_window:]
generated_tokens = generated_tokens.clamp_max(logits.shape[-1] - 1).to(torch.int64)
rp = torch.full_like(logits, repetition_penalty)
factors = torch.ones_like(logits).scatter_reduce(2, generated_tokens, rp, reduce="prod")
return torch.where(logits <= 0, logits * factors, logits / factors)
def sample_from_logits(
logits: torch.Tensor,
temperature: float = 1.0,
top_p: float = 0.0,
top_k: int = 0,
min_p: float = 0.0,
generated_tokens: torch.Tensor | None = None,
repetition_penalty: float = 3.0,
repetition_penalty_window: float = 2,
) -> torch.Tensor:
"""Sample next token from logits using temperature, top-p, top-k, or min-p sampling.
Args:
logits (torch.Tensor): Input logits with token candidates on the last dimension.
temperature (float): Sampling temperature. Lower temperature results in more deterministic samples.
top_p (float): The p in “top-p”.
top_k (int): The k in “top-k”.
min_p (float): Minimum token probability, scaled by the probability of the most likely token.
Must be between 0 and 1. Typical values are in the 0.01-0.2 range.
Returns:
torch.Tensor: Sampled tokens.
"""
if repetition_penalty != 1.0 and generated_tokens is not None:
logits = modify_logit_for_repetition_penalty(logits, generated_tokens, repetition_penalty, repetition_penalty_window)
if temperature > 0:
probs = torch.softmax(logits / temperature, dim=-1)
if top_p > 0:
probs = apply_top_p(probs, top_p)
if top_k > 0:
probs = apply_top_k(probs, top_k)
if min_p > 0:
probs = apply_min_p(probs, min_p)
next_token = multinomial(probs, num_samples=1)
else:
next_token = torch.argmax(logits, dim=-1, keepdim=True)
return next_token # [batch_size, num_codebooks, 1]
| 5,515 | sampling | py | en | python | code | {"qsc_code_num_words": 763, "qsc_code_num_chars": 5515.0, "qsc_code_mean_word_length": 4.74311927, "qsc_code_frac_words_unique": 0.1965924, "qsc_code_frac_chars_top_2grams": 0.06382979, "qsc_code_frac_chars_top_3grams": 0.03536889, "qsc_code_frac_chars_top_4grams": 0.02486875, "qsc_code_frac_chars_dupe_5grams": 0.31776734, "qsc_code_frac_chars_dupe_6grams": 0.28156949, "qsc_code_frac_chars_dupe_7grams": 0.25283227, "qsc_code_frac_chars_dupe_8grams": 0.21635811, "qsc_code_frac_chars_dupe_9grams": 0.21635811, "qsc_code_frac_chars_dupe_10grams": 0.18983145, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01700443, "qsc_code_frac_chars_whitespace": 0.22157752, "qsc_code_size_file_byte": 5515.0, "qsc_code_num_lines": 141.0, "qsc_code_num_chars_line_max": 126.0, "qsc_code_num_chars_line_mean": 39.11347518, "qsc_code_frac_chars_alphabet": 0.82599581, "qsc_code_frac_chars_comments": 0.41831369, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.14925373, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00133556, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.08955224, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.01492537, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.20895522, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00Julian00/Nova2 | external/zonos/speaker_cloning.py | import math
from functools import cache
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchaudio
from huggingface_hub import hf_hub_download
import os
class logFbankCal(nn.Module):
def __init__(
self,
sample_rate: int = 16_000,
n_fft: int = 512,
win_length: float = 0.025,
hop_length: float = 0.01,
n_mels: int = 80,
):
super().__init__()
self.fbankCal = torchaudio.transforms.MelSpectrogram(
sample_rate=sample_rate,
n_fft=n_fft,
win_length=int(win_length * sample_rate),
hop_length=int(hop_length * sample_rate),
n_mels=n_mels,
)
def forward(self, x):
out = self.fbankCal(x)
out = torch.log(out + 1e-6)
out = out - out.mean(axis=2).unsqueeze(dim=2)
return out
class ASP(nn.Module):
# Attentive statistics pooling
def __init__(self, in_planes, acoustic_dim):
super(ASP, self).__init__()
outmap_size = int(acoustic_dim / 8)
self.out_dim = in_planes * 8 * outmap_size * 2
self.attention = nn.Sequential(
nn.Conv1d(in_planes * 8 * outmap_size, 128, kernel_size=1),
nn.ReLU(),
nn.BatchNorm1d(128),
nn.Conv1d(128, in_planes * 8 * outmap_size, kernel_size=1),
nn.Softmax(dim=2),
)
def forward(self, x):
x = x.reshape(x.size()[0], -1, x.size()[-1])
w = self.attention(x)
mu = torch.sum(x * w, dim=2)
sg = torch.sqrt((torch.sum((x**2) * w, dim=2) - mu**2).clamp(min=1e-5))
x = torch.cat((mu, sg), 1)
x = x.view(x.size()[0], -1)
return x
class SimAMBasicBlock(nn.Module):
expansion = 1
def __init__(self, ConvLayer, NormLayer, in_planes, planes, stride=1, block_id=1):
super(SimAMBasicBlock, self).__init__()
self.conv1 = ConvLayer(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn1 = NormLayer(planes)
self.conv2 = ConvLayer(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
self.bn2 = NormLayer(planes)
self.relu = nn.ReLU(inplace=True)
self.sigmoid = nn.Sigmoid()
self.downsample = nn.Sequential()
if stride != 1 or in_planes != self.expansion * planes:
self.downsample = nn.Sequential(
ConvLayer(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias=False),
NormLayer(self.expansion * planes),
)
def forward(self, x):
out = self.relu(self.bn1(self.conv1(x)))
out = self.bn2(self.conv2(out))
out = self.SimAM(out)
out += self.downsample(x)
out = self.relu(out)
return out
def SimAM(self, X, lambda_p=1e-4):
n = X.shape[2] * X.shape[3] - 1
d = (X - X.mean(dim=[2, 3], keepdim=True)).pow(2)
v = d.sum(dim=[2, 3], keepdim=True) / n
E_inv = d / (4 * (v + lambda_p)) + 0.5
return X * self.sigmoid(E_inv)
class BasicBlock(nn.Module):
expansion = 1
def __init__(self, ConvLayer, NormLayer, in_planes, planes, stride=1, block_id=1):
super(BasicBlock, self).__init__()
self.conv1 = ConvLayer(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn1 = NormLayer(planes)
self.conv2 = ConvLayer(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
self.bn2 = NormLayer(planes)
self.relu = nn.ReLU(inplace=True)
self.downsample = nn.Sequential()
if stride != 1 or in_planes != self.expansion * planes:
self.downsample = nn.Sequential(
ConvLayer(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias=False),
NormLayer(self.expansion * planes),
)
def forward(self, x):
out = self.relu(self.bn1(self.conv1(x)))
out = self.bn2(self.conv2(out))
out += self.downsample(x)
out = self.relu(out)
return out
class Bottleneck(nn.Module):
expansion = 4
def __init__(self, ConvLayer, NormLayer, in_planes, planes, stride=1, block_id=1):
super(Bottleneck, self).__init__()
self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False)
self.bn1 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(planes)
self.conv3 = nn.Conv2d(planes, self.expansion * planes, kernel_size=1, bias=False)
self.bn3 = nn.BatchNorm2d(self.expansion * planes)
self.shortcut = nn.Sequential()
if stride != 1 or in_planes != self.expansion * planes:
self.shortcut = nn.Sequential(
nn.Conv2d(in_planes, self.expansion * planes, kernel_size=1, stride=stride, bias=False),
nn.BatchNorm2d(self.expansion * planes),
)
def forward(self, x):
out = F.relu(self.bn1(self.conv1(x)))
out = F.relu(self.bn2(self.conv2(out)))
out = self.bn3(self.conv3(out))
out += self.shortcut(x)
out = F.relu(out)
return out
class ResNet(nn.Module):
def __init__(self, in_planes, block, num_blocks, in_ch=1, feat_dim="2d", **kwargs):
super(ResNet, self).__init__()
if feat_dim == "1d":
self.NormLayer = nn.BatchNorm1d
self.ConvLayer = nn.Conv1d
elif feat_dim == "2d":
self.NormLayer = nn.BatchNorm2d
self.ConvLayer = nn.Conv2d
elif feat_dim == "3d":
self.NormLayer = nn.BatchNorm3d
self.ConvLayer = nn.Conv3d
else:
print("error")
self.in_planes = in_planes
self.conv1 = self.ConvLayer(in_ch, in_planes, kernel_size=3, stride=1, padding=1, bias=False)
self.bn1 = self.NormLayer(in_planes)
self.relu = nn.ReLU(inplace=True)
self.layer1 = self._make_layer(block, in_planes, num_blocks[0], stride=1, block_id=1)
self.layer2 = self._make_layer(block, in_planes * 2, num_blocks[1], stride=2, block_id=2)
self.layer3 = self._make_layer(block, in_planes * 4, num_blocks[2], stride=2, block_id=3)
self.layer4 = self._make_layer(block, in_planes * 8, num_blocks[3], stride=2, block_id=4)
def _make_layer(self, block, planes, num_blocks, stride, block_id=1):
strides = [stride] + [1] * (num_blocks - 1)
layers = []
for stride in strides:
layers.append(block(self.ConvLayer, self.NormLayer, self.in_planes, planes, stride, block_id))
self.in_planes = planes * block.expansion
return nn.Sequential(*layers)
def forward(self, x):
x = self.relu(self.bn1(self.conv1(x)))
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
return x
def ResNet293(in_planes: int, **kwargs):
return ResNet(in_planes, SimAMBasicBlock, [10, 20, 64, 3], **kwargs)
class ResNet293_based(nn.Module):
def __init__(
self,
in_planes: int = 64,
embd_dim: int = 256,
acoustic_dim: int = 80,
featCal=None,
dropout: float = 0,
**kwargs,
):
super(ResNet293_based, self).__init__()
self.featCal = featCal
self.front = ResNet293(in_planes)
block_expansion = SimAMBasicBlock.expansion
self.pooling = ASP(in_planes * block_expansion, acoustic_dim)
self.bottleneck = nn.Linear(self.pooling.out_dim, embd_dim)
self.drop = nn.Dropout(dropout) if dropout else None
def forward(self, x):
x = self.featCal(x)
x = self.front(x.unsqueeze(dim=1))
x = self.pooling(x)
if self.drop:
x = self.drop(x)
x = self.bottleneck(x)
return x
class SEModule(nn.Module):
def __init__(self, channels, bottleneck=128):
super(SEModule, self).__init__()
self.se = nn.Sequential(
nn.AdaptiveAvgPool1d(1),
nn.Conv1d(channels, bottleneck, kernel_size=1, padding=0),
nn.ReLU(),
# nn.BatchNorm1d(bottleneck), # Removed
nn.Conv1d(bottleneck, channels, kernel_size=1, padding=0),
nn.Sigmoid(),
)
def forward(self, input):
x = self.se(input)
return input * x
class Bottle2neck(nn.Module):
def __init__(self, inplanes, planes, kernel_size=None, dilation=None, scale=8):
super(Bottle2neck, self).__init__()
width = int(math.floor(planes / scale))
self.conv1 = nn.Conv1d(inplanes, width * scale, kernel_size=1)
self.bn1 = nn.BatchNorm1d(width * scale)
self.nums = scale - 1
convs = []
bns = []
num_pad = math.floor(kernel_size / 2) * dilation
for i in range(self.nums):
convs.append(nn.Conv1d(width, width, kernel_size=kernel_size, dilation=dilation, padding=num_pad))
bns.append(nn.BatchNorm1d(width))
self.convs = nn.ModuleList(convs)
self.bns = nn.ModuleList(bns)
self.conv3 = nn.Conv1d(width * scale, planes, kernel_size=1)
self.bn3 = nn.BatchNorm1d(planes)
self.relu = nn.ReLU()
self.width = width
self.se = SEModule(planes)
def forward(self, x):
residual = x
out = self.conv1(x)
out = self.relu(out)
out = self.bn1(out)
spx = torch.split(out, self.width, 1)
for i in range(self.nums):
if i == 0:
sp = spx[i]
else:
sp = sp + spx[i]
sp = self.convs[i](sp)
sp = self.relu(sp)
sp = self.bns[i](sp)
if i == 0:
out = sp
else:
out = torch.cat((out, sp), 1)
out = torch.cat((out, spx[self.nums]), 1)
out = self.conv3(out)
out = self.relu(out)
out = self.bn3(out)
out = self.se(out)
out += residual
return out
class ECAPA_TDNN(nn.Module):
def __init__(self, C, featCal):
super(ECAPA_TDNN, self).__init__()
self.featCal = featCal
self.conv1 = nn.Conv1d(80, C, kernel_size=5, stride=1, padding=2)
self.relu = nn.ReLU()
self.bn1 = nn.BatchNorm1d(C)
self.layer1 = Bottle2neck(C, C, kernel_size=3, dilation=2, scale=8)
self.layer2 = Bottle2neck(C, C, kernel_size=3, dilation=3, scale=8)
self.layer3 = Bottle2neck(C, C, kernel_size=3, dilation=4, scale=8)
# I fixed the shape of the output from MFA layer, that is close to the setting from ECAPA paper.
self.layer4 = nn.Conv1d(3 * C, 1536, kernel_size=1)
self.attention = nn.Sequential(
nn.Conv1d(4608, 256, kernel_size=1),
nn.ReLU(),
nn.BatchNorm1d(256),
nn.Tanh(), # Added
nn.Conv1d(256, 1536, kernel_size=1),
nn.Softmax(dim=2),
)
self.bn5 = nn.BatchNorm1d(3072)
self.fc6 = nn.Linear(3072, 192)
self.bn6 = nn.BatchNorm1d(192)
def forward(self, x):
x = self.featCal(x)
x = self.conv1(x)
x = self.relu(x)
x = self.bn1(x)
x1 = self.layer1(x)
x2 = self.layer2(x + x1)
x3 = self.layer3(x + x1 + x2)
x = self.layer4(torch.cat((x1, x2, x3), dim=1))
x = self.relu(x)
t = x.size()[-1]
global_x = torch.cat(
(
x,
torch.mean(x, dim=2, keepdim=True).repeat(1, 1, t),
torch.sqrt(torch.var(x, dim=2, keepdim=True).clamp(min=1e-4)).repeat(1, 1, t),
),
dim=1,
)
w = self.attention(global_x)
mu = torch.sum(x * w, dim=2)
sg = torch.sqrt((torch.sum((x**2) * w, dim=2) - mu**2).clamp(min=1e-4))
x = torch.cat((mu, sg), 1)
x = self.bn5(x)
x = self.fc6(x)
x = self.bn6(x)
return x
class SpeakerEmbedding(nn.Module):
def __init__(self, ckpt_path: str = "ResNet293_SimAM_ASP_base.pt", device: str = "cuda"):
super().__init__()
self.device = device
with torch.device(device):
self.model = ResNet293_based()
self.model.load_state_dict(torch.load(ckpt_path, weights_only=True, mmap=True))
self.model.featCal = logFbankCal()
self.requires_grad_(False).eval()
@property
def dtype(self):
return next(self.parameters()).dtype
@cache
def _get_resampler(self, orig_sample_rate: int):
return torchaudio.transforms.Resample(orig_sample_rate, 16_000).to(self.device)
def prepare_input(self, wav: torch.Tensor, sample_rate: int) -> torch.Tensor:
assert wav.ndim < 3
if wav.ndim == 2:
wav = wav.mean(0, keepdim=True)
wav = self._get_resampler(sample_rate)(wav)
return wav
def forward(self, wav: torch.Tensor, sample_rate: int):
wav = self.prepare_input(wav, sample_rate).to(self.device, self.dtype)
return self.model(wav).to(wav.device)
class SpeakerEmbeddingLDA(nn.Module):
def __init__(
self,
device: str = "cuda",
):
super().__init__()
spk_model_path = hf_hub_download(repo_id="Zyphra/Zonos-v0.1-speaker-embedding", filename="ResNet293_SimAM_ASP_base.pt")
lda_spk_model_path = hf_hub_download(repo_id="Zyphra/Zonos-v0.1-speaker-embedding", filename="ResNet293_SimAM_ASP_base_LDA-128.pt")
self.device = device
with torch.device(device):
self.model = SpeakerEmbedding(spk_model_path, device)
lda_sd = torch.load(lda_spk_model_path, weights_only=True)
out_features, in_features = lda_sd["weight"].shape
self.lda = nn.Linear(in_features, out_features, bias=True, dtype=torch.float32)
self.lda.load_state_dict(lda_sd)
self.requires_grad_(False).eval()
def forward(self, wav: torch.Tensor, sample_rate: int):
emb = self.model(wav, sample_rate).to(torch.float32)
return emb, self.lda(emb) | 14,176 | speaker_cloning | py | en | python | code | {"qsc_code_num_words": 1910, "qsc_code_num_chars": 14176.0, "qsc_code_mean_word_length": 4.19319372, "qsc_code_frac_words_unique": 0.13717277, "qsc_code_frac_chars_top_2grams": 0.03196404, "qsc_code_frac_chars_top_3grams": 0.01922837, "qsc_code_frac_chars_top_4grams": 0.01685604, "qsc_code_frac_chars_dupe_5grams": 0.44724685, "qsc_code_frac_chars_dupe_6grams": 0.37320514, "qsc_code_frac_chars_dupe_7grams": 0.32376077, "qsc_code_frac_chars_dupe_8grams": 0.25833437, "qsc_code_frac_chars_dupe_9grams": 0.24934449, "qsc_code_frac_chars_dupe_10grams": 0.22761893, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.03765773, "qsc_code_frac_chars_whitespace": 0.28442438, "qsc_code_size_file_byte": 14176.0, "qsc_code_num_lines": 406.0, "qsc_code_num_chars_line_max": 140.0, "qsc_code_num_chars_line_mean": 34.91625616, "qsc_code_frac_chars_alphabet": 0.75187303, "qsc_code_frac_chars_comments": 0.01170993, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.30059524, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01328097, "qsc_code_frac_chars_long_word_length": 0.01135309, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.00297619, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.08928571, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.02380952, "qsc_codepython_frac_lines_simplefunc": 0.008928571428571428, "qsc_codepython_score_lines_no_logic": 0.21130952, "qsc_codepython_frac_lines_print": 0.00297619} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0015/ESP32-OpenCV-Projects | esp32/examples/color_code/main/opencv/opencv2/core/hal/intrin_avx.hpp | // This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#ifndef OPENCV_HAL_INTRIN_AVX_HPP
#define OPENCV_HAL_INTRIN_AVX_HPP
#define CV_SIMD256 1
#define CV_SIMD256_64F 1
#define CV_SIMD256_FP16 0 // no native operations with FP16 type. Only load/store from float32x8 are available (if CV_FP16 == 1)
namespace cv
{
//! @cond IGNORED
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
///////// Utils ////////////
inline __m256i _v256_combine(const __m128i& lo, const __m128i& hi)
{ return _mm256_inserti128_si256(_mm256_castsi128_si256(lo), hi, 1); }
inline __m256 _v256_combine(const __m128& lo, const __m128& hi)
{ return _mm256_insertf128_ps(_mm256_castps128_ps256(lo), hi, 1); }
inline __m256d _v256_combine(const __m128d& lo, const __m128d& hi)
{ return _mm256_insertf128_pd(_mm256_castpd128_pd256(lo), hi, 1); }
inline int _v_cvtsi256_si32(const __m256i& a)
{ return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); }
inline __m256i _v256_shuffle_odd_64(const __m256i& v)
{ return _mm256_permute4x64_epi64(v, _MM_SHUFFLE(3, 1, 2, 0)); }
inline __m256d _v256_shuffle_odd_64(const __m256d& v)
{ return _mm256_permute4x64_pd(v, _MM_SHUFFLE(3, 1, 2, 0)); }
template<int imm>
inline __m256i _v256_permute2x128(const __m256i& a, const __m256i& b)
{ return _mm256_permute2x128_si256(a, b, imm); }
template<int imm>
inline __m256 _v256_permute2x128(const __m256& a, const __m256& b)
{ return _mm256_permute2f128_ps(a, b, imm); }
template<int imm>
inline __m256d _v256_permute2x128(const __m256d& a, const __m256d& b)
{ return _mm256_permute2f128_pd(a, b, imm); }
template<int imm, typename _Tpvec>
inline _Tpvec v256_permute2x128(const _Tpvec& a, const _Tpvec& b)
{ return _Tpvec(_v256_permute2x128<imm>(a.val, b.val)); }
template<int imm>
inline __m256i _v256_permute4x64(const __m256i& a)
{ return _mm256_permute4x64_epi64(a, imm); }
template<int imm>
inline __m256d _v256_permute4x64(const __m256d& a)
{ return _mm256_permute4x64_pd(a, imm); }
template<int imm, typename _Tpvec>
inline _Tpvec v256_permute4x64(const _Tpvec& a)
{ return _Tpvec(_v256_permute4x64<imm>(a.val)); }
inline __m128i _v256_extract_high(const __m256i& v)
{ return _mm256_extracti128_si256(v, 1); }
inline __m128 _v256_extract_high(const __m256& v)
{ return _mm256_extractf128_ps(v, 1); }
inline __m128d _v256_extract_high(const __m256d& v)
{ return _mm256_extractf128_pd(v, 1); }
inline __m128i _v256_extract_low(const __m256i& v)
{ return _mm256_castsi256_si128(v); }
inline __m128 _v256_extract_low(const __m256& v)
{ return _mm256_castps256_ps128(v); }
inline __m128d _v256_extract_low(const __m256d& v)
{ return _mm256_castpd256_pd128(v); }
inline __m256i _v256_packs_epu32(const __m256i& a, const __m256i& b)
{
const __m256i m = _mm256_set1_epi32(65535);
__m256i am = _mm256_min_epu32(a, m);
__m256i bm = _mm256_min_epu32(b, m);
return _mm256_packus_epi32(am, bm);
}
template<int i>
inline int _v256_extract_epi8(const __m256i& a)
{
#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/))
return _mm256_extract_epi8(a, i);
#else
__m128i b = _mm256_extractf128_si256(a, ((i) >> 4));
return _mm_extract_epi8(b, i & 15); // SSE4.1
#endif
}
template<int i>
inline int _v256_extract_epi16(const __m256i& a)
{
#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/))
return _mm256_extract_epi16(a, i);
#else
__m128i b = _mm256_extractf128_si256(a, ((i) >> 3));
return _mm_extract_epi16(b, i & 7); // SSE2
#endif
}
template<int i>
inline int _v256_extract_epi32(const __m256i& a)
{
#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/))
return _mm256_extract_epi32(a, i);
#else
__m128i b = _mm256_extractf128_si256(a, ((i) >> 2));
return _mm_extract_epi32(b, i & 3); // SSE4.1
#endif
}
template<int i>
inline int64 _v256_extract_epi64(const __m256i& a)
{
#if defined(CV__SIMD_HAVE_mm256_extract_epi8) || (CV_AVX2 && (!defined(_MSC_VER) || _MSC_VER >= 1910/*MSVS 2017*/))
return _mm256_extract_epi64(a, i);
#else
__m128i b = _mm256_extractf128_si256(a, ((i) >> 1));
return _mm_extract_epi64(b, i & 1); // SSE4.1
#endif
}
///////// Types ////////////
struct v_uint8x32
{
typedef uchar lane_type;
enum { nlanes = 32 };
__m256i val;
explicit v_uint8x32(__m256i v) : val(v) {}
v_uint8x32(uchar v0, uchar v1, uchar v2, uchar v3,
uchar v4, uchar v5, uchar v6, uchar v7,
uchar v8, uchar v9, uchar v10, uchar v11,
uchar v12, uchar v13, uchar v14, uchar v15,
uchar v16, uchar v17, uchar v18, uchar v19,
uchar v20, uchar v21, uchar v22, uchar v23,
uchar v24, uchar v25, uchar v26, uchar v27,
uchar v28, uchar v29, uchar v30, uchar v31)
{
val = _mm256_setr_epi8((char)v0, (char)v1, (char)v2, (char)v3,
(char)v4, (char)v5, (char)v6 , (char)v7, (char)v8, (char)v9,
(char)v10, (char)v11, (char)v12, (char)v13, (char)v14, (char)v15,
(char)v16, (char)v17, (char)v18, (char)v19, (char)v20, (char)v21,
(char)v22, (char)v23, (char)v24, (char)v25, (char)v26, (char)v27,
(char)v28, (char)v29, (char)v30, (char)v31);
}
v_uint8x32() : val(_mm256_setzero_si256()) {}
uchar get0() const { return (uchar)_v_cvtsi256_si32(val); }
};
struct v_int8x32
{
typedef schar lane_type;
enum { nlanes = 32 };
__m256i val;
explicit v_int8x32(__m256i v) : val(v) {}
v_int8x32(schar v0, schar v1, schar v2, schar v3,
schar v4, schar v5, schar v6, schar v7,
schar v8, schar v9, schar v10, schar v11,
schar v12, schar v13, schar v14, schar v15,
schar v16, schar v17, schar v18, schar v19,
schar v20, schar v21, schar v22, schar v23,
schar v24, schar v25, schar v26, schar v27,
schar v28, schar v29, schar v30, schar v31)
{
val = _mm256_setr_epi8(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9,
v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20,
v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31);
}
v_int8x32() : val(_mm256_setzero_si256()) {}
schar get0() const { return (schar)_v_cvtsi256_si32(val); }
};
struct v_uint16x16
{
typedef ushort lane_type;
enum { nlanes = 16 };
__m256i val;
explicit v_uint16x16(__m256i v) : val(v) {}
v_uint16x16(ushort v0, ushort v1, ushort v2, ushort v3,
ushort v4, ushort v5, ushort v6, ushort v7,
ushort v8, ushort v9, ushort v10, ushort v11,
ushort v12, ushort v13, ushort v14, ushort v15)
{
val = _mm256_setr_epi16((short)v0, (short)v1, (short)v2, (short)v3,
(short)v4, (short)v5, (short)v6, (short)v7, (short)v8, (short)v9,
(short)v10, (short)v11, (short)v12, (short)v13, (short)v14, (short)v15);
}
v_uint16x16() : val(_mm256_setzero_si256()) {}
ushort get0() const { return (ushort)_v_cvtsi256_si32(val); }
};
struct v_int16x16
{
typedef short lane_type;
enum { nlanes = 16 };
__m256i val;
explicit v_int16x16(__m256i v) : val(v) {}
v_int16x16(short v0, short v1, short v2, short v3,
short v4, short v5, short v6, short v7,
short v8, short v9, short v10, short v11,
short v12, short v13, short v14, short v15)
{
val = _mm256_setr_epi16(v0, v1, v2, v3, v4, v5, v6, v7,
v8, v9, v10, v11, v12, v13, v14, v15);
}
v_int16x16() : val(_mm256_setzero_si256()) {}
short get0() const { return (short)_v_cvtsi256_si32(val); }
};
struct v_uint32x8
{
typedef unsigned lane_type;
enum { nlanes = 8 };
__m256i val;
explicit v_uint32x8(__m256i v) : val(v) {}
v_uint32x8(unsigned v0, unsigned v1, unsigned v2, unsigned v3,
unsigned v4, unsigned v5, unsigned v6, unsigned v7)
{
val = _mm256_setr_epi32((unsigned)v0, (unsigned)v1, (unsigned)v2,
(unsigned)v3, (unsigned)v4, (unsigned)v5, (unsigned)v6, (unsigned)v7);
}
v_uint32x8() : val(_mm256_setzero_si256()) {}
unsigned get0() const { return (unsigned)_v_cvtsi256_si32(val); }
};
struct v_int32x8
{
typedef int lane_type;
enum { nlanes = 8 };
__m256i val;
explicit v_int32x8(__m256i v) : val(v) {}
v_int32x8(int v0, int v1, int v2, int v3,
int v4, int v5, int v6, int v7)
{
val = _mm256_setr_epi32(v0, v1, v2, v3, v4, v5, v6, v7);
}
v_int32x8() : val(_mm256_setzero_si256()) {}
int get0() const { return _v_cvtsi256_si32(val); }
};
struct v_float32x8
{
typedef float lane_type;
enum { nlanes = 8 };
__m256 val;
explicit v_float32x8(__m256 v) : val(v) {}
v_float32x8(float v0, float v1, float v2, float v3,
float v4, float v5, float v6, float v7)
{
val = _mm256_setr_ps(v0, v1, v2, v3, v4, v5, v6, v7);
}
v_float32x8() : val(_mm256_setzero_ps()) {}
float get0() const { return _mm_cvtss_f32(_mm256_castps256_ps128(val)); }
};
struct v_uint64x4
{
typedef uint64 lane_type;
enum { nlanes = 4 };
__m256i val;
explicit v_uint64x4(__m256i v) : val(v) {}
v_uint64x4(uint64 v0, uint64 v1, uint64 v2, uint64 v3)
{ val = _mm256_setr_epi64x((int64)v0, (int64)v1, (int64)v2, (int64)v3); }
v_uint64x4() : val(_mm256_setzero_si256()) {}
uint64 get0() const
{
#if defined __x86_64__ || defined _M_X64
return (uint64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val));
#else
int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val));
int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32)));
return (unsigned)a | ((uint64)(unsigned)b << 32);
#endif
}
};
struct v_int64x4
{
typedef int64 lane_type;
enum { nlanes = 4 };
__m256i val;
explicit v_int64x4(__m256i v) : val(v) {}
v_int64x4(int64 v0, int64 v1, int64 v2, int64 v3)
{ val = _mm256_setr_epi64x(v0, v1, v2, v3); }
v_int64x4() : val(_mm256_setzero_si256()) {}
int64 get0() const
{
#if defined __x86_64__ || defined _M_X64
return (int64)_mm_cvtsi128_si64(_mm256_castsi256_si128(val));
#else
int a = _mm_cvtsi128_si32(_mm256_castsi256_si128(val));
int b = _mm_cvtsi128_si32(_mm256_castsi256_si128(_mm256_srli_epi64(val, 32)));
return (int64)((unsigned)a | ((uint64)(unsigned)b << 32));
#endif
}
};
struct v_float64x4
{
typedef double lane_type;
enum { nlanes = 4 };
__m256d val;
explicit v_float64x4(__m256d v) : val(v) {}
v_float64x4(double v0, double v1, double v2, double v3)
{ val = _mm256_setr_pd(v0, v1, v2, v3); }
v_float64x4() : val(_mm256_setzero_pd()) {}
double get0() const { return _mm_cvtsd_f64(_mm256_castpd256_pd128(val)); }
};
//////////////// Load and store operations ///////////////
#define OPENCV_HAL_IMPL_AVX_LOADSTORE(_Tpvec, _Tp) \
inline _Tpvec v256_load(const _Tp* ptr) \
{ return _Tpvec(_mm256_loadu_si256((const __m256i*)ptr)); } \
inline _Tpvec v256_load_aligned(const _Tp* ptr) \
{ return _Tpvec(_mm256_load_si256((const __m256i*)ptr)); } \
inline _Tpvec v256_load_low(const _Tp* ptr) \
{ \
__m128i v128 = _mm_loadu_si128((const __m128i*)ptr); \
return _Tpvec(_mm256_castsi128_si256(v128)); \
} \
inline _Tpvec v256_load_halves(const _Tp* ptr0, const _Tp* ptr1) \
{ \
__m128i vlo = _mm_loadu_si128((const __m128i*)ptr0); \
__m128i vhi = _mm_loadu_si128((const __m128i*)ptr1); \
return _Tpvec(_v256_combine(vlo, vhi)); \
} \
inline void v_store(_Tp* ptr, const _Tpvec& a) \
{ _mm256_storeu_si256((__m256i*)ptr, a.val); } \
inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \
{ _mm256_store_si256((__m256i*)ptr, a.val); } \
inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \
{ _mm256_stream_si256((__m256i*)ptr, a.val); } \
inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \
{ \
if( mode == hal::STORE_UNALIGNED ) \
_mm256_storeu_si256((__m256i*)ptr, a.val); \
else if( mode == hal::STORE_ALIGNED_NOCACHE ) \
_mm256_stream_si256((__m256i*)ptr, a.val); \
else \
_mm256_store_si256((__m256i*)ptr, a.val); \
} \
inline void v_store_low(_Tp* ptr, const _Tpvec& a) \
{ _mm_storeu_si128((__m128i*)ptr, _v256_extract_low(a.val)); } \
inline void v_store_high(_Tp* ptr, const _Tpvec& a) \
{ _mm_storeu_si128((__m128i*)ptr, _v256_extract_high(a.val)); }
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint8x32, uchar)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int8x32, schar)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint16x16, ushort)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int16x16, short)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint32x8, unsigned)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int32x8, int)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_uint64x4, uint64)
OPENCV_HAL_IMPL_AVX_LOADSTORE(v_int64x4, int64)
#define OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(_Tpvec, _Tp, suffix, halfreg) \
inline _Tpvec v256_load(const _Tp* ptr) \
{ return _Tpvec(_mm256_loadu_##suffix(ptr)); } \
inline _Tpvec v256_load_aligned(const _Tp* ptr) \
{ return _Tpvec(_mm256_load_##suffix(ptr)); } \
inline _Tpvec v256_load_low(const _Tp* ptr) \
{ \
return _Tpvec(_mm256_cast##suffix##128_##suffix##256 \
(_mm_loadu_##suffix(ptr))); \
} \
inline _Tpvec v256_load_halves(const _Tp* ptr0, const _Tp* ptr1) \
{ \
halfreg vlo = _mm_loadu_##suffix(ptr0); \
halfreg vhi = _mm_loadu_##suffix(ptr1); \
return _Tpvec(_v256_combine(vlo, vhi)); \
} \
inline void v_store(_Tp* ptr, const _Tpvec& a) \
{ _mm256_storeu_##suffix(ptr, a.val); } \
inline void v_store_aligned(_Tp* ptr, const _Tpvec& a) \
{ _mm256_store_##suffix(ptr, a.val); } \
inline void v_store_aligned_nocache(_Tp* ptr, const _Tpvec& a) \
{ _mm256_stream_##suffix(ptr, a.val); } \
inline void v_store(_Tp* ptr, const _Tpvec& a, hal::StoreMode mode) \
{ \
if( mode == hal::STORE_UNALIGNED ) \
_mm256_storeu_##suffix(ptr, a.val); \
else if( mode == hal::STORE_ALIGNED_NOCACHE ) \
_mm256_stream_##suffix(ptr, a.val); \
else \
_mm256_store_##suffix(ptr, a.val); \
} \
inline void v_store_low(_Tp* ptr, const _Tpvec& a) \
{ _mm_storeu_##suffix(ptr, _v256_extract_low(a.val)); } \
inline void v_store_high(_Tp* ptr, const _Tpvec& a) \
{ _mm_storeu_##suffix(ptr, _v256_extract_high(a.val)); }
OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(v_float32x8, float, ps, __m128)
OPENCV_HAL_IMPL_AVX_LOADSTORE_FLT(v_float64x4, double, pd, __m128d)
#define OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, _Tpvecf, suffix, cast) \
inline _Tpvec v_reinterpret_as_##suffix(const _Tpvecf& a) \
{ return _Tpvec(cast(a.val)); }
#define OPENCV_HAL_IMPL_AVX_INIT(_Tpvec, _Tp, suffix, ssuffix, ctype_s) \
inline _Tpvec v256_setzero_##suffix() \
{ return _Tpvec(_mm256_setzero_si256()); } \
inline _Tpvec v256_setall_##suffix(_Tp v) \
{ return _Tpvec(_mm256_set1_##ssuffix((ctype_s)v)); } \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint8x32, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int8x32, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint16x16, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int16x16, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint32x8, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int32x8, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint64x4, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int64x4, suffix, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_float32x8, suffix, _mm256_castps_si256) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_float64x4, suffix, _mm256_castpd_si256)
OPENCV_HAL_IMPL_AVX_INIT(v_uint8x32, uchar, u8, epi8, char)
OPENCV_HAL_IMPL_AVX_INIT(v_int8x32, schar, s8, epi8, char)
OPENCV_HAL_IMPL_AVX_INIT(v_uint16x16, ushort, u16, epi16, short)
OPENCV_HAL_IMPL_AVX_INIT(v_int16x16, short, s16, epi16, short)
OPENCV_HAL_IMPL_AVX_INIT(v_uint32x8, unsigned, u32, epi32, int)
OPENCV_HAL_IMPL_AVX_INIT(v_int32x8, int, s32, epi32, int)
OPENCV_HAL_IMPL_AVX_INIT(v_uint64x4, uint64, u64, epi64x, int64)
OPENCV_HAL_IMPL_AVX_INIT(v_int64x4, int64, s64, epi64x, int64)
#define OPENCV_HAL_IMPL_AVX_INIT_FLT(_Tpvec, _Tp, suffix, zsuffix, cast) \
inline _Tpvec v256_setzero_##suffix() \
{ return _Tpvec(_mm256_setzero_##zsuffix()); } \
inline _Tpvec v256_setall_##suffix(_Tp v) \
{ return _Tpvec(_mm256_set1_##zsuffix(v)); } \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint8x32, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int8x32, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint16x16, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int16x16, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint32x8, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int32x8, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_uint64x4, suffix, cast) \
OPENCV_HAL_IMPL_AVX_CAST(_Tpvec, v_int64x4, suffix, cast)
OPENCV_HAL_IMPL_AVX_INIT_FLT(v_float32x8, float, f32, ps, _mm256_castsi256_ps)
OPENCV_HAL_IMPL_AVX_INIT_FLT(v_float64x4, double, f64, pd, _mm256_castsi256_pd)
inline v_float32x8 v_reinterpret_as_f32(const v_float32x8& a)
{ return a; }
inline v_float32x8 v_reinterpret_as_f32(const v_float64x4& a)
{ return v_float32x8(_mm256_castpd_ps(a.val)); }
inline v_float64x4 v_reinterpret_as_f64(const v_float64x4& a)
{ return a; }
inline v_float64x4 v_reinterpret_as_f64(const v_float32x8& a)
{ return v_float64x4(_mm256_castps_pd(a.val)); }
/* Recombine */
/*#define OPENCV_HAL_IMPL_AVX_COMBINE(_Tpvec, perm) \
inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(perm(a.val, b.val, 0x20)); } \
inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(perm(a.val, b.val, 0x31)); } \
inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \
_Tpvec& c, _Tpvec& d) \
{ c = v_combine_low(a, b); d = v_combine_high(a, b); }
#define OPENCV_HAL_IMPL_AVX_UNPACKS(_Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_COMBINE(_Tpvec, _mm256_permute2x128_si256) \
inline void v_zip(const _Tpvec& a0, const _Tpvec& a1, \
_Tpvec& b0, _Tpvec& b1) \
{ \
__m256i v0 = _v256_shuffle_odd_64(a0.val); \
__m256i v1 = _v256_shuffle_odd_64(a1.val); \
b0.val = _mm256_unpacklo_##suffix(v0, v1); \
b1.val = _mm256_unpackhi_##suffix(v0, v1); \
}
OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint8x32, epi8)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_int8x32, epi8)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint16x16, epi16)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_int16x16, epi16)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint32x8, epi32)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_int32x8, epi32)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_uint64x4, epi64)
OPENCV_HAL_IMPL_AVX_UNPACKS(v_int64x4, epi64)
OPENCV_HAL_IMPL_AVX_COMBINE(v_float32x8, _mm256_permute2f128_ps)
OPENCV_HAL_IMPL_AVX_COMBINE(v_float64x4, _mm256_permute2f128_pd)
inline void v_zip(const v_float32x8& a0, const v_float32x8& a1, v_float32x8& b0, v_float32x8& b1)
{
__m256 v0 = _mm256_unpacklo_ps(a0.val, a1.val);
__m256 v1 = _mm256_unpackhi_ps(a0.val, a1.val);
v_recombine(v_float32x8(v0), v_float32x8(v1), b0, b1);
}
inline void v_zip(const v_float64x4& a0, const v_float64x4& a1, v_float64x4& b0, v_float64x4& b1)
{
__m256d v0 = _v_shuffle_odd_64(a0.val);
__m256d v1 = _v_shuffle_odd_64(a1.val);
b0.val = _mm256_unpacklo_pd(v0, v1);
b1.val = _mm256_unpackhi_pd(v0, v1);
}*/
//////////////// Variant Value reordering ///////////////
// unpacks
#define OPENCV_HAL_IMPL_AVX_UNPACK(_Tpvec, suffix) \
inline _Tpvec v256_unpacklo(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm256_unpacklo_##suffix(a.val, b.val)); } \
inline _Tpvec v256_unpackhi(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm256_unpackhi_##suffix(a.val, b.val)); }
OPENCV_HAL_IMPL_AVX_UNPACK(v_uint8x32, epi8)
OPENCV_HAL_IMPL_AVX_UNPACK(v_int8x32, epi8)
OPENCV_HAL_IMPL_AVX_UNPACK(v_uint16x16, epi16)
OPENCV_HAL_IMPL_AVX_UNPACK(v_int16x16, epi16)
OPENCV_HAL_IMPL_AVX_UNPACK(v_uint32x8, epi32)
OPENCV_HAL_IMPL_AVX_UNPACK(v_int32x8, epi32)
OPENCV_HAL_IMPL_AVX_UNPACK(v_uint64x4, epi64)
OPENCV_HAL_IMPL_AVX_UNPACK(v_int64x4, epi64)
OPENCV_HAL_IMPL_AVX_UNPACK(v_float32x8, ps)
OPENCV_HAL_IMPL_AVX_UNPACK(v_float64x4, pd)
// blend
#define OPENCV_HAL_IMPL_AVX_BLEND(_Tpvec, suffix) \
template<int m> \
inline _Tpvec v256_blend(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm256_blend_##suffix(a.val, b.val, m)); }
OPENCV_HAL_IMPL_AVX_BLEND(v_uint16x16, epi16)
OPENCV_HAL_IMPL_AVX_BLEND(v_int16x16, epi16)
OPENCV_HAL_IMPL_AVX_BLEND(v_uint32x8, epi32)
OPENCV_HAL_IMPL_AVX_BLEND(v_int32x8, epi32)
OPENCV_HAL_IMPL_AVX_BLEND(v_float32x8, ps)
OPENCV_HAL_IMPL_AVX_BLEND(v_float64x4, pd)
template<int m>
inline v_uint64x4 v256_blend(const v_uint64x4& a, const v_uint64x4& b)
{
enum {M0 = m};
enum {M1 = (M0 | (M0 << 2)) & 0x33};
enum {M2 = (M1 | (M1 << 1)) & 0x55};
enum {MM = M2 | (M2 << 1)};
return v_uint64x4(_mm256_blend_epi32(a.val, b.val, MM));
}
template<int m>
inline v_int64x4 v256_blend(const v_int64x4& a, const v_int64x4& b)
{ return v_int64x4(v256_blend<m>(v_uint64x4(a.val), v_uint64x4(b.val)).val); }
// shuffle
// todo: emulate 64bit
#define OPENCV_HAL_IMPL_AVX_SHUFFLE(_Tpvec, intrin) \
template<int m> \
inline _Tpvec v256_shuffle(const _Tpvec& a) \
{ return _Tpvec(_mm256_##intrin(a.val, m)); }
OPENCV_HAL_IMPL_AVX_SHUFFLE(v_uint32x8, shuffle_epi32)
OPENCV_HAL_IMPL_AVX_SHUFFLE(v_int32x8, shuffle_epi32)
OPENCV_HAL_IMPL_AVX_SHUFFLE(v_float32x8, permute_ps)
OPENCV_HAL_IMPL_AVX_SHUFFLE(v_float64x4, permute_pd)
template<typename _Tpvec>
inline void v256_zip(const _Tpvec& a, const _Tpvec& b, _Tpvec& ab0, _Tpvec& ab1)
{
ab0 = v256_unpacklo(a, b);
ab1 = v256_unpackhi(a, b);
}
template<typename _Tpvec>
inline _Tpvec v256_combine_diagonal(const _Tpvec& a, const _Tpvec& b)
{ return _Tpvec(_mm256_blend_epi32(a.val, b.val, 0xf0)); }
inline v_float32x8 v256_combine_diagonal(const v_float32x8& a, const v_float32x8& b)
{ return v256_blend<0xf0>(a, b); }
inline v_float64x4 v256_combine_diagonal(const v_float64x4& a, const v_float64x4& b)
{ return v256_blend<0xc>(a, b); }
template<typename _Tpvec>
inline _Tpvec v256_alignr_128(const _Tpvec& a, const _Tpvec& b)
{ return v256_permute2x128<0x21>(a, b); }
template<typename _Tpvec>
inline _Tpvec v256_alignr_64(const _Tpvec& a, const _Tpvec& b)
{ return _Tpvec(_mm256_alignr_epi8(a.val, b.val, 8)); }
inline v_float64x4 v256_alignr_64(const v_float64x4& a, const v_float64x4& b)
{ return v_float64x4(_mm256_shuffle_pd(b.val, a.val, _MM_SHUFFLE(0, 0, 1, 1))); }
// todo: emulate float32
template<typename _Tpvec>
inline _Tpvec v256_swap_halves(const _Tpvec& a)
{ return v256_permute2x128<1>(a, a); }
template<typename _Tpvec>
inline _Tpvec v256_reverse_64(const _Tpvec& a)
{ return v256_permute4x64<_MM_SHUFFLE(0, 1, 2, 3)>(a); }
// ZIP
#define OPENCV_HAL_IMPL_AVX_ZIP(_Tpvec) \
inline _Tpvec v_combine_low(const _Tpvec& a, const _Tpvec& b) \
{ return v256_permute2x128<0x20>(a, b); } \
inline _Tpvec v_combine_high(const _Tpvec& a, const _Tpvec& b) \
{ return v256_permute2x128<0x31>(a, b); } \
inline void v_recombine(const _Tpvec& a, const _Tpvec& b, \
_Tpvec& c, _Tpvec& d) \
{ \
_Tpvec a1b0 = v256_alignr_128(a, b); \
c = v256_combine_diagonal(a, a1b0); \
d = v256_combine_diagonal(a1b0, b); \
} \
inline void v_zip(const _Tpvec& a, const _Tpvec& b, \
_Tpvec& ab0, _Tpvec& ab1) \
{ \
_Tpvec ab0ab2, ab1ab3; \
v256_zip(a, b, ab0ab2, ab1ab3); \
v_recombine(ab0ab2, ab1ab3, ab0, ab1); \
}
OPENCV_HAL_IMPL_AVX_ZIP(v_uint8x32)
OPENCV_HAL_IMPL_AVX_ZIP(v_int8x32)
OPENCV_HAL_IMPL_AVX_ZIP(v_uint16x16)
OPENCV_HAL_IMPL_AVX_ZIP(v_int16x16)
OPENCV_HAL_IMPL_AVX_ZIP(v_uint32x8)
OPENCV_HAL_IMPL_AVX_ZIP(v_int32x8)
OPENCV_HAL_IMPL_AVX_ZIP(v_uint64x4)
OPENCV_HAL_IMPL_AVX_ZIP(v_int64x4)
OPENCV_HAL_IMPL_AVX_ZIP(v_float32x8)
OPENCV_HAL_IMPL_AVX_ZIP(v_float64x4)
////////// Arithmetic, bitwise and comparison operations /////////
/* Element-wise binary and unary operations */
/** Arithmetics **/
#define OPENCV_HAL_IMPL_AVX_BIN_OP(bin_op, _Tpvec, intrin) \
inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(intrin(a.val, b.val)); } \
inline _Tpvec& operator bin_op##= (_Tpvec& a, const _Tpvec& b) \
{ a.val = intrin(a.val, b.val); return a; }
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint8x32, _mm256_adds_epu8)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint8x32, _mm256_subs_epu8)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int8x32, _mm256_adds_epi8)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int8x32, _mm256_subs_epi8)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint16x16, _mm256_adds_epu16)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint16x16, _mm256_subs_epu16)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int16x16, _mm256_adds_epi16)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int16x16, _mm256_subs_epi16)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint32x8, _mm256_add_epi32)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint32x8, _mm256_sub_epi32)
OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_uint32x8, _mm256_mullo_epi32)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int32x8, _mm256_add_epi32)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int32x8, _mm256_sub_epi32)
OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_int32x8, _mm256_mullo_epi32)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_uint64x4, _mm256_add_epi64)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_uint64x4, _mm256_sub_epi64)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_int64x4, _mm256_add_epi64)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_int64x4, _mm256_sub_epi64)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_float32x8, _mm256_add_ps)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_float32x8, _mm256_sub_ps)
OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_float32x8, _mm256_mul_ps)
OPENCV_HAL_IMPL_AVX_BIN_OP(/, v_float32x8, _mm256_div_ps)
OPENCV_HAL_IMPL_AVX_BIN_OP(+, v_float64x4, _mm256_add_pd)
OPENCV_HAL_IMPL_AVX_BIN_OP(-, v_float64x4, _mm256_sub_pd)
OPENCV_HAL_IMPL_AVX_BIN_OP(*, v_float64x4, _mm256_mul_pd)
OPENCV_HAL_IMPL_AVX_BIN_OP(/, v_float64x4, _mm256_div_pd)
// saturating multiply 8-bit, 16-bit
inline v_uint8x32 operator * (const v_uint8x32& a, const v_uint8x32& b)
{
v_uint16x16 c, d;
v_mul_expand(a, b, c, d);
return v_pack(c, d);
}
inline v_int8x32 operator * (const v_int8x32& a, const v_int8x32& b)
{
v_int16x16 c, d;
v_mul_expand(a, b, c, d);
return v_pack(c, d);
}
inline v_uint16x16 operator * (const v_uint16x16& a, const v_uint16x16& b)
{
__m256i pl = _mm256_mullo_epi16(a.val, b.val);
__m256i ph = _mm256_mulhi_epu16(a.val, b.val);
__m256i p0 = _mm256_unpacklo_epi16(pl, ph);
__m256i p1 = _mm256_unpackhi_epi16(pl, ph);
return v_uint16x16(_v256_packs_epu32(p0, p1));
}
inline v_int16x16 operator * (const v_int16x16& a, const v_int16x16& b)
{
__m256i pl = _mm256_mullo_epi16(a.val, b.val);
__m256i ph = _mm256_mulhi_epi16(a.val, b.val);
__m256i p0 = _mm256_unpacklo_epi16(pl, ph);
__m256i p1 = _mm256_unpackhi_epi16(pl, ph);
return v_int16x16(_mm256_packs_epi32(p0, p1));
}
inline v_uint8x32& operator *= (v_uint8x32& a, const v_uint8x32& b)
{ a = a * b; return a; }
inline v_int8x32& operator *= (v_int8x32& a, const v_int8x32& b)
{ a = a * b; return a; }
inline v_uint16x16& operator *= (v_uint16x16& a, const v_uint16x16& b)
{ a = a * b; return a; }
inline v_int16x16& operator *= (v_int16x16& a, const v_int16x16& b)
{ a = a * b; return a; }
/** Non-saturating arithmetics **/
#define OPENCV_HAL_IMPL_AVX_BIN_FUNC(func, _Tpvec, intrin) \
inline _Tpvec func(const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(intrin(a.val, b.val)); }
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_uint8x32, _mm256_add_epi8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_int8x32, _mm256_add_epi8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_uint16x16, _mm256_add_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_add_wrap, v_int16x16, _mm256_add_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_uint8x32, _mm256_sub_epi8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_int8x32, _mm256_sub_epi8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_uint16x16, _mm256_sub_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_sub_wrap, v_int16x16, _mm256_sub_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_mul_wrap, v_uint16x16, _mm256_mullo_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_mul_wrap, v_int16x16, _mm256_mullo_epi16)
inline v_uint8x32 v_mul_wrap(const v_uint8x32& a, const v_uint8x32& b)
{
__m256i ad = _mm256_srai_epi16(a.val, 8);
__m256i bd = _mm256_srai_epi16(b.val, 8);
__m256i p0 = _mm256_mullo_epi16(a.val, b.val); // even
__m256i p1 = _mm256_slli_epi16(_mm256_mullo_epi16(ad, bd), 8); // odd
const __m256i b01 = _mm256_set1_epi32(0xFF00FF00);
return v_uint8x32(_mm256_blendv_epi8(p0, p1, b01));
}
inline v_int8x32 v_mul_wrap(const v_int8x32& a, const v_int8x32& b)
{
return v_reinterpret_as_s8(v_mul_wrap(v_reinterpret_as_u8(a), v_reinterpret_as_u8(b)));
}
// Multiply and expand
inline void v_mul_expand(const v_uint8x32& a, const v_uint8x32& b,
v_uint16x16& c, v_uint16x16& d)
{
v_uint16x16 a0, a1, b0, b1;
v_expand(a, a0, a1);
v_expand(b, b0, b1);
c = v_mul_wrap(a0, b0);
d = v_mul_wrap(a1, b1);
}
inline void v_mul_expand(const v_int8x32& a, const v_int8x32& b,
v_int16x16& c, v_int16x16& d)
{
v_int16x16 a0, a1, b0, b1;
v_expand(a, a0, a1);
v_expand(b, b0, b1);
c = v_mul_wrap(a0, b0);
d = v_mul_wrap(a1, b1);
}
inline void v_mul_expand(const v_int16x16& a, const v_int16x16& b,
v_int32x8& c, v_int32x8& d)
{
v_int16x16 vhi = v_int16x16(_mm256_mulhi_epi16(a.val, b.val));
v_int16x16 v0, v1;
v_zip(v_mul_wrap(a, b), vhi, v0, v1);
c = v_reinterpret_as_s32(v0);
d = v_reinterpret_as_s32(v1);
}
inline void v_mul_expand(const v_uint16x16& a, const v_uint16x16& b,
v_uint32x8& c, v_uint32x8& d)
{
v_uint16x16 vhi = v_uint16x16(_mm256_mulhi_epu16(a.val, b.val));
v_uint16x16 v0, v1;
v_zip(v_mul_wrap(a, b), vhi, v0, v1);
c = v_reinterpret_as_u32(v0);
d = v_reinterpret_as_u32(v1);
}
inline void v_mul_expand(const v_uint32x8& a, const v_uint32x8& b,
v_uint64x4& c, v_uint64x4& d)
{
__m256i v0 = _mm256_mul_epu32(a.val, b.val);
__m256i v1 = _mm256_mul_epu32(_mm256_srli_epi64(a.val, 32), _mm256_srli_epi64(b.val, 32));
v_zip(v_uint64x4(v0), v_uint64x4(v1), c, d);
}
inline v_int16x16 v_mul_hi(const v_int16x16& a, const v_int16x16& b) { return v_int16x16(_mm256_mulhi_epi16(a.val, b.val)); }
inline v_uint16x16 v_mul_hi(const v_uint16x16& a, const v_uint16x16& b) { return v_uint16x16(_mm256_mulhi_epu16(a.val, b.val)); }
/** Bitwise shifts **/
#define OPENCV_HAL_IMPL_AVX_SHIFT_OP(_Tpuvec, _Tpsvec, suffix, srai) \
inline _Tpuvec operator << (const _Tpuvec& a, int imm) \
{ return _Tpuvec(_mm256_slli_##suffix(a.val, imm)); } \
inline _Tpsvec operator << (const _Tpsvec& a, int imm) \
{ return _Tpsvec(_mm256_slli_##suffix(a.val, imm)); } \
inline _Tpuvec operator >> (const _Tpuvec& a, int imm) \
{ return _Tpuvec(_mm256_srli_##suffix(a.val, imm)); } \
inline _Tpsvec operator >> (const _Tpsvec& a, int imm) \
{ return _Tpsvec(srai(a.val, imm)); } \
template<int imm> \
inline _Tpuvec v_shl(const _Tpuvec& a) \
{ return _Tpuvec(_mm256_slli_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpsvec v_shl(const _Tpsvec& a) \
{ return _Tpsvec(_mm256_slli_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpuvec v_shr(const _Tpuvec& a) \
{ return _Tpuvec(_mm256_srli_##suffix(a.val, imm)); } \
template<int imm> \
inline _Tpsvec v_shr(const _Tpsvec& a) \
{ return _Tpsvec(srai(a.val, imm)); }
OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint16x16, v_int16x16, epi16, _mm256_srai_epi16)
OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint32x8, v_int32x8, epi32, _mm256_srai_epi32)
inline __m256i _mm256_srai_epi64xx(const __m256i a, int imm)
{
__m256i d = _mm256_set1_epi64x((int64)1 << 63);
__m256i r = _mm256_srli_epi64(_mm256_add_epi64(a, d), imm);
return _mm256_sub_epi64(r, _mm256_srli_epi64(d, imm));
}
OPENCV_HAL_IMPL_AVX_SHIFT_OP(v_uint64x4, v_int64x4, epi64, _mm256_srai_epi64xx)
/** Bitwise logic **/
#define OPENCV_HAL_IMPL_AVX_LOGIC_OP(_Tpvec, suffix, not_const) \
OPENCV_HAL_IMPL_AVX_BIN_OP(&, _Tpvec, _mm256_and_##suffix) \
OPENCV_HAL_IMPL_AVX_BIN_OP(|, _Tpvec, _mm256_or_##suffix) \
OPENCV_HAL_IMPL_AVX_BIN_OP(^, _Tpvec, _mm256_xor_##suffix) \
inline _Tpvec operator ~ (const _Tpvec& a) \
{ return _Tpvec(_mm256_xor_##suffix(a.val, not_const)); }
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint8x32, si256, _mm256_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int8x32, si256, _mm256_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint16x16, si256, _mm256_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int16x16, si256, _mm256_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint32x8, si256, _mm256_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int32x8, si256, _mm256_set1_epi32(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_uint64x4, si256, _mm256_set1_epi64x(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_int64x4, si256, _mm256_set1_epi64x(-1))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_float32x8, ps, _mm256_castsi256_ps(_mm256_set1_epi32(-1)))
OPENCV_HAL_IMPL_AVX_LOGIC_OP(v_float64x4, pd, _mm256_castsi256_pd(_mm256_set1_epi32(-1)))
/** Select **/
#define OPENCV_HAL_IMPL_AVX_SELECT(_Tpvec, suffix) \
inline _Tpvec v_select(const _Tpvec& mask, const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm256_blendv_##suffix(b.val, a.val, mask.val)); }
OPENCV_HAL_IMPL_AVX_SELECT(v_uint8x32, epi8)
OPENCV_HAL_IMPL_AVX_SELECT(v_int8x32, epi8)
OPENCV_HAL_IMPL_AVX_SELECT(v_uint16x16, epi8)
OPENCV_HAL_IMPL_AVX_SELECT(v_int16x16, epi8)
OPENCV_HAL_IMPL_AVX_SELECT(v_uint32x8, epi8)
OPENCV_HAL_IMPL_AVX_SELECT(v_int32x8, epi8)
OPENCV_HAL_IMPL_AVX_SELECT(v_float32x8, ps)
OPENCV_HAL_IMPL_AVX_SELECT(v_float64x4, pd)
/** Comparison **/
#define OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpvec) \
inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \
{ return ~(a == b); } \
inline _Tpvec operator < (const _Tpvec& a, const _Tpvec& b) \
{ return b > a; } \
inline _Tpvec operator >= (const _Tpvec& a, const _Tpvec& b) \
{ return ~(a < b); } \
inline _Tpvec operator <= (const _Tpvec& a, const _Tpvec& b) \
{ return b >= a; }
#define OPENCV_HAL_IMPL_AVX_CMP_OP_INT(_Tpuvec, _Tpsvec, suffix, sbit) \
inline _Tpuvec operator == (const _Tpuvec& a, const _Tpuvec& b) \
{ return _Tpuvec(_mm256_cmpeq_##suffix(a.val, b.val)); } \
inline _Tpuvec operator > (const _Tpuvec& a, const _Tpuvec& b) \
{ \
__m256i smask = _mm256_set1_##suffix(sbit); \
return _Tpuvec(_mm256_cmpgt_##suffix( \
_mm256_xor_si256(a.val, smask), \
_mm256_xor_si256(b.val, smask))); \
} \
inline _Tpsvec operator == (const _Tpsvec& a, const _Tpsvec& b) \
{ return _Tpsvec(_mm256_cmpeq_##suffix(a.val, b.val)); } \
inline _Tpsvec operator > (const _Tpsvec& a, const _Tpsvec& b) \
{ return _Tpsvec(_mm256_cmpgt_##suffix(a.val, b.val)); } \
OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpuvec) \
OPENCV_HAL_IMPL_AVX_CMP_OP_OV(_Tpsvec)
OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint8x32, v_int8x32, epi8, (char)-128)
OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint16x16, v_int16x16, epi16, (short)-32768)
OPENCV_HAL_IMPL_AVX_CMP_OP_INT(v_uint32x8, v_int32x8, epi32, (int)0x80000000)
#define OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(_Tpvec) \
inline _Tpvec operator == (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm256_cmpeq_epi64(a.val, b.val)); } \
inline _Tpvec operator != (const _Tpvec& a, const _Tpvec& b) \
{ return ~(a == b); }
OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_uint64x4)
OPENCV_HAL_IMPL_AVX_CMP_OP_64BIT(v_int64x4)
#define OPENCV_HAL_IMPL_AVX_CMP_FLT(bin_op, imm8, _Tpvec, suffix) \
inline _Tpvec operator bin_op (const _Tpvec& a, const _Tpvec& b) \
{ return _Tpvec(_mm256_cmp_##suffix(a.val, b.val, imm8)); }
#define OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(_Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_CMP_FLT(==, _CMP_EQ_OQ, _Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_CMP_FLT(!=, _CMP_NEQ_OQ, _Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_CMP_FLT(<, _CMP_LT_OQ, _Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_CMP_FLT(>, _CMP_GT_OQ, _Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_CMP_FLT(<=, _CMP_LE_OQ, _Tpvec, suffix) \
OPENCV_HAL_IMPL_AVX_CMP_FLT(>=, _CMP_GE_OQ, _Tpvec, suffix)
OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(v_float32x8, ps)
OPENCV_HAL_IMPL_AVX_CMP_OP_FLT(v_float64x4, pd)
inline v_float32x8 v_not_nan(const v_float32x8& a)
{ return v_float32x8(_mm256_cmp_ps(a.val, a.val, _CMP_ORD_Q)); }
inline v_float64x4 v_not_nan(const v_float64x4& a)
{ return v_float64x4(_mm256_cmp_pd(a.val, a.val, _CMP_ORD_Q)); }
/** min/max **/
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint8x32, _mm256_min_epu8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint8x32, _mm256_max_epu8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int8x32, _mm256_min_epi8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int8x32, _mm256_max_epi8)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint16x16, _mm256_min_epu16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint16x16, _mm256_max_epu16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int16x16, _mm256_min_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int16x16, _mm256_max_epi16)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_uint32x8, _mm256_min_epu32)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_uint32x8, _mm256_max_epu32)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_int32x8, _mm256_min_epi32)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_int32x8, _mm256_max_epi32)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_float32x8, _mm256_min_ps)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_float32x8, _mm256_max_ps)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_min, v_float64x4, _mm256_min_pd)
OPENCV_HAL_IMPL_AVX_BIN_FUNC(v_max, v_float64x4, _mm256_max_pd)
/** Rotate **/
template<int imm>
inline v_uint8x32 v_rotate_left(const v_uint8x32& a, const v_uint8x32& b)
{
enum {IMM_R = (16 - imm) & 0xFF};
enum {IMM_R2 = (32 - imm) & 0xFF};
if (imm == 0) return a;
if (imm == 32) return b;
if (imm > 32) return v_uint8x32();
__m256i swap = _mm256_permute2x128_si256(a.val, b.val, 0x03);
if (imm == 16) return v_uint8x32(swap);
if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(a.val, swap, IMM_R));
return v_uint8x32(_mm256_alignr_epi8(swap, b.val, IMM_R2)); // imm < 32
}
template<int imm>
inline v_uint8x32 v_rotate_right(const v_uint8x32& a, const v_uint8x32& b)
{
enum {IMM_L = (imm - 16) & 0xFF};
if (imm == 0) return a;
if (imm == 32) return b;
if (imm > 32) return v_uint8x32();
__m256i swap = _mm256_permute2x128_si256(a.val, b.val, 0x21);
if (imm == 16) return v_uint8x32(swap);
if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(swap, a.val, imm));
return v_uint8x32(_mm256_alignr_epi8(b.val, swap, IMM_L));
}
template<int imm>
inline v_uint8x32 v_rotate_left(const v_uint8x32& a)
{
enum {IMM_L = (imm - 16) & 0xFF};
enum {IMM_R = (16 - imm) & 0xFF};
if (imm == 0) return a;
if (imm > 32) return v_uint8x32();
// ESAC control[3] ? [127:0] = 0
__m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(0, 0, 2, 0));
if (imm == 16) return v_uint8x32(swapz);
if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(a.val, swapz, IMM_R));
return v_uint8x32(_mm256_slli_si256(swapz, IMM_L));
}
template<int imm>
inline v_uint8x32 v_rotate_right(const v_uint8x32& a)
{
enum {IMM_L = (imm - 16) & 0xFF};
if (imm == 0) return a;
if (imm > 32) return v_uint8x32();
// ESAC control[3] ? [127:0] = 0
__m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(2, 0, 0, 1));
if (imm == 16) return v_uint8x32(swapz);
if (imm < 16) return v_uint8x32(_mm256_alignr_epi8(swapz, a.val, imm));
return v_uint8x32(_mm256_srli_si256(swapz, IMM_L));
}
#define OPENCV_HAL_IMPL_AVX_ROTATE_CAST(intrin, _Tpvec, cast) \
template<int imm> \
inline _Tpvec intrin(const _Tpvec& a, const _Tpvec& b) \
{ \
enum {IMMxW = imm * sizeof(typename _Tpvec::lane_type)}; \
v_uint8x32 ret = intrin<IMMxW>(v_reinterpret_as_u8(a), \
v_reinterpret_as_u8(b)); \
return _Tpvec(cast(ret.val)); \
} \
template<int imm> \
inline _Tpvec intrin(const _Tpvec& a) \
{ \
enum {IMMxW = imm * sizeof(typename _Tpvec::lane_type)}; \
v_uint8x32 ret = intrin<IMMxW>(v_reinterpret_as_u8(a)); \
return _Tpvec(cast(ret.val)); \
}
#define OPENCV_HAL_IMPL_AVX_ROTATE(_Tpvec) \
OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, _Tpvec, OPENCV_HAL_NOP) \
OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, _Tpvec, OPENCV_HAL_NOP)
OPENCV_HAL_IMPL_AVX_ROTATE(v_int8x32)
OPENCV_HAL_IMPL_AVX_ROTATE(v_uint16x16)
OPENCV_HAL_IMPL_AVX_ROTATE(v_int16x16)
OPENCV_HAL_IMPL_AVX_ROTATE(v_uint32x8)
OPENCV_HAL_IMPL_AVX_ROTATE(v_int32x8)
OPENCV_HAL_IMPL_AVX_ROTATE(v_uint64x4)
OPENCV_HAL_IMPL_AVX_ROTATE(v_int64x4)
OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, v_float32x8, _mm256_castsi256_ps)
OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, v_float32x8, _mm256_castsi256_ps)
OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_left, v_float64x4, _mm256_castsi256_pd)
OPENCV_HAL_IMPL_AVX_ROTATE_CAST(v_rotate_right, v_float64x4, _mm256_castsi256_pd)
/** Reverse **/
inline v_uint8x32 v_reverse(const v_uint8x32 &a)
{
static const __m256i perm = _mm256_setr_epi8(
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
__m256i vec = _mm256_shuffle_epi8(a.val, perm);
return v_uint8x32(_mm256_permute2x128_si256(vec, vec, 1));
}
inline v_int8x32 v_reverse(const v_int8x32 &a)
{ return v_reinterpret_as_s8(v_reverse(v_reinterpret_as_u8(a))); }
inline v_uint16x16 v_reverse(const v_uint16x16 &a)
{
static const __m256i perm = _mm256_setr_epi8(
14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1,
14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1);
__m256i vec = _mm256_shuffle_epi8(a.val, perm);
return v_uint16x16(_mm256_permute2x128_si256(vec, vec, 1));
}
inline v_int16x16 v_reverse(const v_int16x16 &a)
{ return v_reinterpret_as_s16(v_reverse(v_reinterpret_as_u16(a))); }
inline v_uint32x8 v_reverse(const v_uint32x8 &a)
{
static const __m256i perm = _mm256_setr_epi32(7, 6, 5, 4, 3, 2, 1, 0);
return v_uint32x8(_mm256_permutevar8x32_epi32(a.val, perm));
}
inline v_int32x8 v_reverse(const v_int32x8 &a)
{ return v_reinterpret_as_s32(v_reverse(v_reinterpret_as_u32(a))); }
inline v_float32x8 v_reverse(const v_float32x8 &a)
{ return v_reinterpret_as_f32(v_reverse(v_reinterpret_as_u32(a))); }
inline v_uint64x4 v_reverse(const v_uint64x4 &a)
{
return v_uint64x4(_mm256_permute4x64_epi64(a.val, _MM_SHUFFLE(0, 1, 2, 3)));
}
inline v_int64x4 v_reverse(const v_int64x4 &a)
{ return v_reinterpret_as_s64(v_reverse(v_reinterpret_as_u64(a))); }
inline v_float64x4 v_reverse(const v_float64x4 &a)
{ return v_reinterpret_as_f64(v_reverse(v_reinterpret_as_u64(a))); }
////////// Reduce and mask /////////
/** Reduce **/
inline unsigned v_reduce_sum(const v_uint8x32& a)
{
__m256i half = _mm256_sad_epu8(a.val, _mm256_setzero_si256());
__m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half));
return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter)));
}
inline int v_reduce_sum(const v_int8x32& a)
{
__m256i half = _mm256_sad_epu8(_mm256_xor_si256(a.val, _mm256_set1_epi8((schar)-128)), _mm256_setzero_si256());
__m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half));
return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter))) - 4096;
}
#define OPENCV_HAL_IMPL_AVX_REDUCE_32(_Tpvec, sctype, func, intrin) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ \
__m128i val = intrin(_v256_extract_low(a.val), _v256_extract_high(a.val)); \
val = intrin(val, _mm_srli_si128(val,8)); \
val = intrin(val, _mm_srli_si128(val,4)); \
val = intrin(val, _mm_srli_si128(val,2)); \
val = intrin(val, _mm_srli_si128(val,1)); \
return (sctype)_mm_cvtsi128_si32(val); \
}
OPENCV_HAL_IMPL_AVX_REDUCE_32(v_uint8x32, uchar, min, _mm_min_epu8)
OPENCV_HAL_IMPL_AVX_REDUCE_32(v_int8x32, schar, min, _mm_min_epi8)
OPENCV_HAL_IMPL_AVX_REDUCE_32(v_uint8x32, uchar, max, _mm_max_epu8)
OPENCV_HAL_IMPL_AVX_REDUCE_32(v_int8x32, schar, max, _mm_max_epi8)
#define OPENCV_HAL_IMPL_AVX_REDUCE_16(_Tpvec, sctype, func, intrin) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ \
__m128i v0 = _v256_extract_low(a.val); \
__m128i v1 = _v256_extract_high(a.val); \
v0 = intrin(v0, v1); \
v0 = intrin(v0, _mm_srli_si128(v0, 8)); \
v0 = intrin(v0, _mm_srli_si128(v0, 4)); \
v0 = intrin(v0, _mm_srli_si128(v0, 2)); \
return (sctype) _mm_cvtsi128_si32(v0); \
}
OPENCV_HAL_IMPL_AVX_REDUCE_16(v_uint16x16, ushort, min, _mm_min_epu16)
OPENCV_HAL_IMPL_AVX_REDUCE_16(v_int16x16, short, min, _mm_min_epi16)
OPENCV_HAL_IMPL_AVX_REDUCE_16(v_uint16x16, ushort, max, _mm_max_epu16)
OPENCV_HAL_IMPL_AVX_REDUCE_16(v_int16x16, short, max, _mm_max_epi16)
#define OPENCV_HAL_IMPL_AVX_REDUCE_8(_Tpvec, sctype, func, intrin) \
inline sctype v_reduce_##func(const _Tpvec& a) \
{ \
__m128i v0 = _v256_extract_low(a.val); \
__m128i v1 = _v256_extract_high(a.val); \
v0 = intrin(v0, v1); \
v0 = intrin(v0, _mm_srli_si128(v0, 8)); \
v0 = intrin(v0, _mm_srli_si128(v0, 4)); \
return (sctype) _mm_cvtsi128_si32(v0); \
}
OPENCV_HAL_IMPL_AVX_REDUCE_8(v_uint32x8, unsigned, min, _mm_min_epu32)
OPENCV_HAL_IMPL_AVX_REDUCE_8(v_int32x8, int, min, _mm_min_epi32)
OPENCV_HAL_IMPL_AVX_REDUCE_8(v_uint32x8, unsigned, max, _mm_max_epu32)
OPENCV_HAL_IMPL_AVX_REDUCE_8(v_int32x8, int, max, _mm_max_epi32)
#define OPENCV_HAL_IMPL_AVX_REDUCE_FLT(func, intrin) \
inline float v_reduce_##func(const v_float32x8& a) \
{ \
__m128 v0 = _v256_extract_low(a.val); \
__m128 v1 = _v256_extract_high(a.val); \
v0 = intrin(v0, v1); \
v0 = intrin(v0, _mm_permute_ps(v0, _MM_SHUFFLE(0, 0, 3, 2))); \
v0 = intrin(v0, _mm_permute_ps(v0, _MM_SHUFFLE(0, 0, 0, 1))); \
return _mm_cvtss_f32(v0); \
}
OPENCV_HAL_IMPL_AVX_REDUCE_FLT(min, _mm_min_ps)
OPENCV_HAL_IMPL_AVX_REDUCE_FLT(max, _mm_max_ps)
inline int v_reduce_sum(const v_int32x8& a)
{
__m256i s0 = _mm256_hadd_epi32(a.val, a.val);
s0 = _mm256_hadd_epi32(s0, s0);
__m128i s1 = _v256_extract_high(s0);
s1 = _mm_add_epi32(_v256_extract_low(s0), s1);
return _mm_cvtsi128_si32(s1);
}
inline unsigned v_reduce_sum(const v_uint32x8& a)
{ return v_reduce_sum(v_reinterpret_as_s32(a)); }
inline int v_reduce_sum(const v_int16x16& a)
{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); }
inline unsigned v_reduce_sum(const v_uint16x16& a)
{ return v_reduce_sum(v_expand_low(a) + v_expand_high(a)); }
inline float v_reduce_sum(const v_float32x8& a)
{
__m256 s0 = _mm256_hadd_ps(a.val, a.val);
s0 = _mm256_hadd_ps(s0, s0);
__m128 s1 = _v256_extract_high(s0);
s1 = _mm_add_ps(_v256_extract_low(s0), s1);
return _mm_cvtss_f32(s1);
}
inline uint64 v_reduce_sum(const v_uint64x4& a)
{
uint64 CV_DECL_ALIGNED(32) idx[2];
_mm_store_si128((__m128i*)idx, _mm_add_epi64(_v256_extract_low(a.val), _v256_extract_high(a.val)));
return idx[0] + idx[1];
}
inline int64 v_reduce_sum(const v_int64x4& a)
{
int64 CV_DECL_ALIGNED(32) idx[2];
_mm_store_si128((__m128i*)idx, _mm_add_epi64(_v256_extract_low(a.val), _v256_extract_high(a.val)));
return idx[0] + idx[1];
}
inline double v_reduce_sum(const v_float64x4& a)
{
__m256d s0 = _mm256_hadd_pd(a.val, a.val);
return _mm_cvtsd_f64(_mm_add_pd(_v256_extract_low(s0), _v256_extract_high(s0)));
}
inline v_float32x8 v_reduce_sum4(const v_float32x8& a, const v_float32x8& b,
const v_float32x8& c, const v_float32x8& d)
{
__m256 ab = _mm256_hadd_ps(a.val, b.val);
__m256 cd = _mm256_hadd_ps(c.val, d.val);
return v_float32x8(_mm256_hadd_ps(ab, cd));
}
inline unsigned v_reduce_sad(const v_uint8x32& a, const v_uint8x32& b)
{
__m256i half = _mm256_sad_epu8(a.val, b.val);
__m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half));
return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter)));
}
inline unsigned v_reduce_sad(const v_int8x32& a, const v_int8x32& b)
{
__m256i half = _mm256_set1_epi8(0x7f);
half = _mm256_sad_epu8(_mm256_add_epi8(a.val, half), _mm256_add_epi8(b.val, half));
__m128i quarter = _mm_add_epi32(_v256_extract_low(half), _v256_extract_high(half));
return (unsigned)_mm_cvtsi128_si32(_mm_add_epi32(quarter, _mm_unpackhi_epi64(quarter, quarter)));
}
inline unsigned v_reduce_sad(const v_uint16x16& a, const v_uint16x16& b)
{
v_uint32x8 l, h;
v_expand(v_add_wrap(a - b, b - a), l, h);
return v_reduce_sum(l + h);
}
inline unsigned v_reduce_sad(const v_int16x16& a, const v_int16x16& b)
{
v_uint32x8 l, h;
v_expand(v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))), l, h);
return v_reduce_sum(l + h);
}
inline unsigned v_reduce_sad(const v_uint32x8& a, const v_uint32x8& b)
{
return v_reduce_sum(v_max(a, b) - v_min(a, b));
}
inline unsigned v_reduce_sad(const v_int32x8& a, const v_int32x8& b)
{
v_int32x8 m = a < b;
return v_reduce_sum(v_reinterpret_as_u32(((a - b) ^ m) - m));
}
inline float v_reduce_sad(const v_float32x8& a, const v_float32x8& b)
{
return v_reduce_sum((a - b) & v_float32x8(_mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff))));
}
/** Popcount **/
inline v_uint8x32 v_popcount(const v_uint8x32& a)
{
__m256i _popcnt_table = _mm256_setr_epi8(0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4);
__m256i _popcnt_mask = _mm256_set1_epi8(0x0F);
return v_uint8x32(_mm256_add_epi8(_mm256_shuffle_epi8(_popcnt_table, _mm256_and_si256( a.val , _popcnt_mask)),
_mm256_shuffle_epi8(_popcnt_table, _mm256_and_si256(_mm256_srli_epi16(a.val, 4), _popcnt_mask))));
}
inline v_uint16x16 v_popcount(const v_uint16x16& a)
{
v_uint8x32 p = v_popcount(v_reinterpret_as_u8(a));
p += v_rotate_right<1>(p);
return v_reinterpret_as_u16(p) & v256_setall_u16(0x00ff);
}
inline v_uint32x8 v_popcount(const v_uint32x8& a)
{
v_uint8x32 p = v_popcount(v_reinterpret_as_u8(a));
p += v_rotate_right<1>(p);
p += v_rotate_right<2>(p);
return v_reinterpret_as_u32(p) & v256_setall_u32(0x000000ff);
}
inline v_uint64x4 v_popcount(const v_uint64x4& a)
{
return v_uint64x4(_mm256_sad_epu8(v_popcount(v_reinterpret_as_u8(a)).val, _mm256_setzero_si256()));
}
inline v_uint8x32 v_popcount(const v_int8x32& a)
{ return v_popcount(v_reinterpret_as_u8(a)); }
inline v_uint16x16 v_popcount(const v_int16x16& a)
{ return v_popcount(v_reinterpret_as_u16(a)); }
inline v_uint32x8 v_popcount(const v_int32x8& a)
{ return v_popcount(v_reinterpret_as_u32(a)); }
inline v_uint64x4 v_popcount(const v_int64x4& a)
{ return v_popcount(v_reinterpret_as_u64(a)); }
/** Mask **/
inline int v_signmask(const v_int8x32& a)
{ return _mm256_movemask_epi8(a.val); }
inline int v_signmask(const v_uint8x32& a)
{ return v_signmask(v_reinterpret_as_s8(a)); }
inline int v_signmask(const v_int16x16& a)
{ return v_signmask(v_pack(a, a)) & 0xFFFF; }
inline int v_signmask(const v_uint16x16& a)
{ return v_signmask(v_reinterpret_as_s16(a)); }
inline int v_signmask(const v_float32x8& a)
{ return _mm256_movemask_ps(a.val); }
inline int v_signmask(const v_float64x4& a)
{ return _mm256_movemask_pd(a.val); }
inline int v_signmask(const v_int32x8& a)
{ return v_signmask(v_reinterpret_as_f32(a)); }
inline int v_signmask(const v_uint32x8& a)
{ return v_signmask(v_reinterpret_as_f32(a)); }
inline int v_signmask(const v_int64x4& a)
{ return v_signmask(v_reinterpret_as_f64(a)); }
inline int v_signmask(const v_uint64x4& a)
{ return v_signmask(v_reinterpret_as_f64(a)); }
inline int v_scan_forward(const v_int8x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); }
inline int v_scan_forward(const v_uint8x32& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))); }
inline int v_scan_forward(const v_int16x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; }
inline int v_scan_forward(const v_uint16x16& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 2; }
inline int v_scan_forward(const v_int32x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; }
inline int v_scan_forward(const v_uint32x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; }
inline int v_scan_forward(const v_float32x8& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 4; }
inline int v_scan_forward(const v_int64x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; }
inline int v_scan_forward(const v_uint64x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; }
inline int v_scan_forward(const v_float64x4& a) { return trailingZeros32(v_signmask(v_reinterpret_as_s8(a))) / 8; }
/** Checks **/
#define OPENCV_HAL_IMPL_AVX_CHECK(_Tpvec, allmask) \
inline bool v_check_all(const _Tpvec& a) { return v_signmask(a) == allmask; } \
inline bool v_check_any(const _Tpvec& a) { return v_signmask(a) != 0; }
OPENCV_HAL_IMPL_AVX_CHECK(v_uint8x32, -1)
OPENCV_HAL_IMPL_AVX_CHECK(v_int8x32, -1)
OPENCV_HAL_IMPL_AVX_CHECK(v_uint32x8, 255)
OPENCV_HAL_IMPL_AVX_CHECK(v_int32x8, 255)
OPENCV_HAL_IMPL_AVX_CHECK(v_uint64x4, 15)
OPENCV_HAL_IMPL_AVX_CHECK(v_int64x4, 15)
OPENCV_HAL_IMPL_AVX_CHECK(v_float32x8, 255)
OPENCV_HAL_IMPL_AVX_CHECK(v_float64x4, 15)
#define OPENCV_HAL_IMPL_AVX_CHECK_SHORT(_Tpvec) \
inline bool v_check_all(const _Tpvec& a) { return (v_signmask(v_reinterpret_as_s8(a)) & 0xaaaaaaaa) == 0xaaaaaaaa; } \
inline bool v_check_any(const _Tpvec& a) { return (v_signmask(v_reinterpret_as_s8(a)) & 0xaaaaaaaa) != 0; }
OPENCV_HAL_IMPL_AVX_CHECK_SHORT(v_uint16x16)
OPENCV_HAL_IMPL_AVX_CHECK_SHORT(v_int16x16)
////////// Other math /////////
/** Some frequent operations **/
#define OPENCV_HAL_IMPL_AVX_MULADD(_Tpvec, suffix) \
inline _Tpvec v_fma(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \
{ return _Tpvec(_mm256_fmadd_##suffix(a.val, b.val, c.val)); } \
inline _Tpvec v_muladd(const _Tpvec& a, const _Tpvec& b, const _Tpvec& c) \
{ return _Tpvec(_mm256_fmadd_##suffix(a.val, b.val, c.val)); } \
inline _Tpvec v_sqrt(const _Tpvec& x) \
{ return _Tpvec(_mm256_sqrt_##suffix(x.val)); } \
inline _Tpvec v_sqr_magnitude(const _Tpvec& a, const _Tpvec& b) \
{ return v_fma(a, a, b * b); } \
inline _Tpvec v_magnitude(const _Tpvec& a, const _Tpvec& b) \
{ return v_sqrt(v_fma(a, a, b*b)); }
OPENCV_HAL_IMPL_AVX_MULADD(v_float32x8, ps)
OPENCV_HAL_IMPL_AVX_MULADD(v_float64x4, pd)
inline v_int32x8 v_fma(const v_int32x8& a, const v_int32x8& b, const v_int32x8& c)
{
return a * b + c;
}
inline v_int32x8 v_muladd(const v_int32x8& a, const v_int32x8& b, const v_int32x8& c)
{
return v_fma(a, b, c);
}
inline v_float32x8 v_invsqrt(const v_float32x8& x)
{
v_float32x8 half = x * v256_setall_f32(0.5);
v_float32x8 t = v_float32x8(_mm256_rsqrt_ps(x.val));
// todo: _mm256_fnmsub_ps
t *= v256_setall_f32(1.5) - ((t * t) * half);
return t;
}
inline v_float64x4 v_invsqrt(const v_float64x4& x)
{
return v256_setall_f64(1.) / v_sqrt(x);
}
/** Absolute values **/
#define OPENCV_HAL_IMPL_AVX_ABS(_Tpvec, suffix) \
inline v_u##_Tpvec v_abs(const v_##_Tpvec& x) \
{ return v_u##_Tpvec(_mm256_abs_##suffix(x.val)); }
OPENCV_HAL_IMPL_AVX_ABS(int8x32, epi8)
OPENCV_HAL_IMPL_AVX_ABS(int16x16, epi16)
OPENCV_HAL_IMPL_AVX_ABS(int32x8, epi32)
inline v_float32x8 v_abs(const v_float32x8& x)
{ return x & v_float32x8(_mm256_castsi256_ps(_mm256_set1_epi32(0x7fffffff))); }
inline v_float64x4 v_abs(const v_float64x4& x)
{ return x & v_float64x4(_mm256_castsi256_pd(_mm256_srli_epi64(_mm256_set1_epi64x(-1), 1))); }
/** Absolute difference **/
inline v_uint8x32 v_absdiff(const v_uint8x32& a, const v_uint8x32& b)
{ return v_add_wrap(a - b, b - a); }
inline v_uint16x16 v_absdiff(const v_uint16x16& a, const v_uint16x16& b)
{ return v_add_wrap(a - b, b - a); }
inline v_uint32x8 v_absdiff(const v_uint32x8& a, const v_uint32x8& b)
{ return v_max(a, b) - v_min(a, b); }
inline v_uint8x32 v_absdiff(const v_int8x32& a, const v_int8x32& b)
{
v_int8x32 d = v_sub_wrap(a, b);
v_int8x32 m = a < b;
return v_reinterpret_as_u8(v_sub_wrap(d ^ m, m));
}
inline v_uint16x16 v_absdiff(const v_int16x16& a, const v_int16x16& b)
{ return v_reinterpret_as_u16(v_sub_wrap(v_max(a, b), v_min(a, b))); }
inline v_uint32x8 v_absdiff(const v_int32x8& a, const v_int32x8& b)
{
v_int32x8 d = a - b;
v_int32x8 m = a < b;
return v_reinterpret_as_u32((d ^ m) - m);
}
inline v_float32x8 v_absdiff(const v_float32x8& a, const v_float32x8& b)
{ return v_abs(a - b); }
inline v_float64x4 v_absdiff(const v_float64x4& a, const v_float64x4& b)
{ return v_abs(a - b); }
/** Saturating absolute difference **/
inline v_int8x32 v_absdiffs(const v_int8x32& a, const v_int8x32& b)
{
v_int8x32 d = a - b;
v_int8x32 m = a < b;
return (d ^ m) - m;
}
inline v_int16x16 v_absdiffs(const v_int16x16& a, const v_int16x16& b)
{ return v_max(a, b) - v_min(a, b); }
////////// Conversions /////////
/** Rounding **/
inline v_int32x8 v_round(const v_float32x8& a)
{ return v_int32x8(_mm256_cvtps_epi32(a.val)); }
inline v_int32x8 v_round(const v_float64x4& a)
{ return v_int32x8(_mm256_castsi128_si256(_mm256_cvtpd_epi32(a.val))); }
inline v_int32x8 v_round(const v_float64x4& a, const v_float64x4& b)
{
__m128i ai = _mm256_cvtpd_epi32(a.val), bi = _mm256_cvtpd_epi32(b.val);
return v_int32x8(_v256_combine(ai, bi));
}
inline v_int32x8 v_trunc(const v_float32x8& a)
{ return v_int32x8(_mm256_cvttps_epi32(a.val)); }
inline v_int32x8 v_trunc(const v_float64x4& a)
{ return v_int32x8(_mm256_castsi128_si256(_mm256_cvttpd_epi32(a.val))); }
inline v_int32x8 v_floor(const v_float32x8& a)
{ return v_int32x8(_mm256_cvttps_epi32(_mm256_floor_ps(a.val))); }
inline v_int32x8 v_floor(const v_float64x4& a)
{ return v_trunc(v_float64x4(_mm256_floor_pd(a.val))); }
inline v_int32x8 v_ceil(const v_float32x8& a)
{ return v_int32x8(_mm256_cvttps_epi32(_mm256_ceil_ps(a.val))); }
inline v_int32x8 v_ceil(const v_float64x4& a)
{ return v_trunc(v_float64x4(_mm256_ceil_pd(a.val))); }
/** To float **/
inline v_float32x8 v_cvt_f32(const v_int32x8& a)
{ return v_float32x8(_mm256_cvtepi32_ps(a.val)); }
inline v_float32x8 v_cvt_f32(const v_float64x4& a)
{ return v_float32x8(_mm256_castps128_ps256(_mm256_cvtpd_ps(a.val))); }
inline v_float32x8 v_cvt_f32(const v_float64x4& a, const v_float64x4& b)
{
__m128 af = _mm256_cvtpd_ps(a.val), bf = _mm256_cvtpd_ps(b.val);
return v_float32x8(_v256_combine(af, bf));
}
inline v_float64x4 v_cvt_f64(const v_int32x8& a)
{ return v_float64x4(_mm256_cvtepi32_pd(_v256_extract_low(a.val))); }
inline v_float64x4 v_cvt_f64_high(const v_int32x8& a)
{ return v_float64x4(_mm256_cvtepi32_pd(_v256_extract_high(a.val))); }
inline v_float64x4 v_cvt_f64(const v_float32x8& a)
{ return v_float64x4(_mm256_cvtps_pd(_v256_extract_low(a.val))); }
inline v_float64x4 v_cvt_f64_high(const v_float32x8& a)
{ return v_float64x4(_mm256_cvtps_pd(_v256_extract_high(a.val))); }
// from (Mysticial and wim) https://stackoverflow.com/q/41144668
inline v_float64x4 v_cvt_f64(const v_int64x4& v)
{
// constants encoded as floating-point
__m256i magic_i_lo = _mm256_set1_epi64x(0x4330000000000000); // 2^52
__m256i magic_i_hi32 = _mm256_set1_epi64x(0x4530000080000000); // 2^84 + 2^63
__m256i magic_i_all = _mm256_set1_epi64x(0x4530000080100000); // 2^84 + 2^63 + 2^52
__m256d magic_d_all = _mm256_castsi256_pd(magic_i_all);
// Blend the 32 lowest significant bits of v with magic_int_lo
__m256i v_lo = _mm256_blend_epi32(magic_i_lo, v.val, 0x55);
// Extract the 32 most significant bits of v
__m256i v_hi = _mm256_srli_epi64(v.val, 32);
// Flip the msb of v_hi and blend with 0x45300000
v_hi = _mm256_xor_si256(v_hi, magic_i_hi32);
// Compute in double precision
__m256d v_hi_dbl = _mm256_sub_pd(_mm256_castsi256_pd(v_hi), magic_d_all);
// (v_hi - magic_d_all) + v_lo Do not assume associativity of floating point addition
__m256d result = _mm256_add_pd(v_hi_dbl, _mm256_castsi256_pd(v_lo));
return v_float64x4(result);
}
////////////// Lookup table access ////////////////////
inline v_int8x32 v256_lut(const schar* tab, const int* idx)
{
return v_int8x32(_mm256_setr_epi8(tab[idx[ 0]], tab[idx[ 1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]],
tab[idx[ 8]], tab[idx[ 9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]],
tab[idx[16]], tab[idx[17]], tab[idx[18]], tab[idx[19]], tab[idx[20]], tab[idx[21]], tab[idx[22]], tab[idx[23]],
tab[idx[24]], tab[idx[25]], tab[idx[26]], tab[idx[27]], tab[idx[28]], tab[idx[29]], tab[idx[30]], tab[idx[31]]));
}
inline v_int8x32 v256_lut_pairs(const schar* tab, const int* idx)
{
return v_int8x32(_mm256_setr_epi16(*(const short*)(tab + idx[ 0]), *(const short*)(tab + idx[ 1]), *(const short*)(tab + idx[ 2]), *(const short*)(tab + idx[ 3]),
*(const short*)(tab + idx[ 4]), *(const short*)(tab + idx[ 5]), *(const short*)(tab + idx[ 6]), *(const short*)(tab + idx[ 7]),
*(const short*)(tab + idx[ 8]), *(const short*)(tab + idx[ 9]), *(const short*)(tab + idx[10]), *(const short*)(tab + idx[11]),
*(const short*)(tab + idx[12]), *(const short*)(tab + idx[13]), *(const short*)(tab + idx[14]), *(const short*)(tab + idx[15])));
}
inline v_int8x32 v256_lut_quads(const schar* tab, const int* idx)
{
return v_int8x32(_mm256_i32gather_epi32((const int*)tab, _mm256_loadu_si256((const __m256i*)idx), 1));
}
inline v_uint8x32 v256_lut(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut((const schar *)tab, idx)); }
inline v_uint8x32 v256_lut_pairs(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut_pairs((const schar *)tab, idx)); }
inline v_uint8x32 v256_lut_quads(const uchar* tab, const int* idx) { return v_reinterpret_as_u8(v256_lut_quads((const schar *)tab, idx)); }
inline v_int16x16 v256_lut(const short* tab, const int* idx)
{
return v_int16x16(_mm256_setr_epi16(tab[idx[0]], tab[idx[1]], tab[idx[ 2]], tab[idx[ 3]], tab[idx[ 4]], tab[idx[ 5]], tab[idx[ 6]], tab[idx[ 7]],
tab[idx[8]], tab[idx[9]], tab[idx[10]], tab[idx[11]], tab[idx[12]], tab[idx[13]], tab[idx[14]], tab[idx[15]]));
}
inline v_int16x16 v256_lut_pairs(const short* tab, const int* idx)
{
return v_int16x16(_mm256_i32gather_epi32((const int*)tab, _mm256_loadu_si256((const __m256i*)idx), 2));
}
inline v_int16x16 v256_lut_quads(const short* tab, const int* idx)
{
#if defined(__GNUC__)
return v_int16x16(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 2));//Looks like intrinsic has wrong definition
#else
return v_int16x16(_mm256_i32gather_epi64((const int64*)tab, _mm_loadu_si128((const __m128i*)idx), 2));
#endif
}
inline v_uint16x16 v256_lut(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut((const short *)tab, idx)); }
inline v_uint16x16 v256_lut_pairs(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut_pairs((const short *)tab, idx)); }
inline v_uint16x16 v256_lut_quads(const ushort* tab, const int* idx) { return v_reinterpret_as_u16(v256_lut_quads((const short *)tab, idx)); }
inline v_int32x8 v256_lut(const int* tab, const int* idx)
{
return v_int32x8(_mm256_i32gather_epi32(tab, _mm256_loadu_si256((const __m256i*)idx), 4));
}
inline v_int32x8 v256_lut_pairs(const int* tab, const int* idx)
{
#if defined(__GNUC__)
return v_int32x8(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 4));
#else
return v_int32x8(_mm256_i32gather_epi64((const int64*)tab, _mm_loadu_si128((const __m128i*)idx), 4));
#endif
}
inline v_int32x8 v256_lut_quads(const int* tab, const int* idx)
{
return v_int32x8(_v256_combine(_mm_loadu_si128((const __m128i*)(tab + idx[0])), _mm_loadu_si128((const __m128i*)(tab + idx[1]))));
}
inline v_uint32x8 v256_lut(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut((const int *)tab, idx)); }
inline v_uint32x8 v256_lut_pairs(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut_pairs((const int *)tab, idx)); }
inline v_uint32x8 v256_lut_quads(const unsigned* tab, const int* idx) { return v_reinterpret_as_u32(v256_lut_quads((const int *)tab, idx)); }
inline v_int64x4 v256_lut(const int64* tab, const int* idx)
{
#if defined(__GNUC__)
return v_int64x4(_mm256_i32gather_epi64((const long long int*)tab, _mm_loadu_si128((const __m128i*)idx), 8));
#else
return v_int64x4(_mm256_i32gather_epi64(tab, _mm_loadu_si128((const __m128i*)idx), 8));
#endif
}
inline v_int64x4 v256_lut_pairs(const int64* tab, const int* idx)
{
return v_int64x4(_v256_combine(_mm_loadu_si128((const __m128i*)(tab + idx[0])), _mm_loadu_si128((const __m128i*)(tab + idx[1]))));
}
inline v_uint64x4 v256_lut(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v256_lut((const int64 *)tab, idx)); }
inline v_uint64x4 v256_lut_pairs(const uint64* tab, const int* idx) { return v_reinterpret_as_u64(v256_lut_pairs((const int64 *)tab, idx)); }
inline v_float32x8 v256_lut(const float* tab, const int* idx)
{
return v_float32x8(_mm256_i32gather_ps(tab, _mm256_loadu_si256((const __m256i*)idx), 4));
}
inline v_float32x8 v256_lut_pairs(const float* tab, const int* idx) { return v_reinterpret_as_f32(v256_lut_pairs((const int *)tab, idx)); }
inline v_float32x8 v256_lut_quads(const float* tab, const int* idx) { return v_reinterpret_as_f32(v256_lut_quads((const int *)tab, idx)); }
inline v_float64x4 v256_lut(const double* tab, const int* idx)
{
return v_float64x4(_mm256_i32gather_pd(tab, _mm_loadu_si128((const __m128i*)idx), 8));
}
inline v_float64x4 v256_lut_pairs(const double* tab, const int* idx) { return v_float64x4(_v256_combine(_mm_loadu_pd(tab + idx[0]), _mm_loadu_pd(tab + idx[1]))); }
inline v_int32x8 v_lut(const int* tab, const v_int32x8& idxvec)
{
return v_int32x8(_mm256_i32gather_epi32(tab, idxvec.val, 4));
}
inline v_uint32x8 v_lut(const unsigned* tab, const v_int32x8& idxvec)
{
return v_reinterpret_as_u32(v_lut((const int *)tab, idxvec));
}
inline v_float32x8 v_lut(const float* tab, const v_int32x8& idxvec)
{
return v_float32x8(_mm256_i32gather_ps(tab, idxvec.val, 4));
}
inline v_float64x4 v_lut(const double* tab, const v_int32x8& idxvec)
{
return v_float64x4(_mm256_i32gather_pd(tab, _mm256_castsi256_si128(idxvec.val), 8));
}
inline void v_lut_deinterleave(const float* tab, const v_int32x8& idxvec, v_float32x8& x, v_float32x8& y)
{
int CV_DECL_ALIGNED(32) idx[8];
v_store_aligned(idx, idxvec);
__m128 z = _mm_setzero_ps();
__m128 xy01, xy45, xy23, xy67;
xy01 = _mm_loadl_pi(z, (const __m64*)(tab + idx[0]));
xy01 = _mm_loadh_pi(xy01, (const __m64*)(tab + idx[1]));
xy45 = _mm_loadl_pi(z, (const __m64*)(tab + idx[4]));
xy45 = _mm_loadh_pi(xy45, (const __m64*)(tab + idx[5]));
__m256 xy0145 = _v256_combine(xy01, xy45);
xy23 = _mm_loadl_pi(z, (const __m64*)(tab + idx[2]));
xy23 = _mm_loadh_pi(xy23, (const __m64*)(tab + idx[3]));
xy67 = _mm_loadl_pi(z, (const __m64*)(tab + idx[6]));
xy67 = _mm_loadh_pi(xy67, (const __m64*)(tab + idx[7]));
__m256 xy2367 = _v256_combine(xy23, xy67);
__m256 xxyy0145 = _mm256_unpacklo_ps(xy0145, xy2367);
__m256 xxyy2367 = _mm256_unpackhi_ps(xy0145, xy2367);
x = v_float32x8(_mm256_unpacklo_ps(xxyy0145, xxyy2367));
y = v_float32x8(_mm256_unpackhi_ps(xxyy0145, xxyy2367));
}
inline void v_lut_deinterleave(const double* tab, const v_int32x8& idxvec, v_float64x4& x, v_float64x4& y)
{
int CV_DECL_ALIGNED(32) idx[4];
v_store_low(idx, idxvec);
__m128d xy0 = _mm_loadu_pd(tab + idx[0]);
__m128d xy2 = _mm_loadu_pd(tab + idx[2]);
__m128d xy1 = _mm_loadu_pd(tab + idx[1]);
__m128d xy3 = _mm_loadu_pd(tab + idx[3]);
__m256d xy02 = _v256_combine(xy0, xy2);
__m256d xy13 = _v256_combine(xy1, xy3);
x = v_float64x4(_mm256_unpacklo_pd(xy02, xy13));
y = v_float64x4(_mm256_unpackhi_pd(xy02, xy13));
}
inline v_int8x32 v_interleave_pairs(const v_int8x32& vec)
{
return v_int8x32(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0d0e0c0b090a08, 0x0705060403010200, 0x0f0d0e0c0b090a08, 0x0705060403010200)));
}
inline v_uint8x32 v_interleave_pairs(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_interleave_pairs(v_reinterpret_as_s8(vec))); }
inline v_int8x32 v_interleave_quads(const v_int8x32& vec)
{
return v_int8x32(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0b0e0a0d090c08, 0x0703060205010400, 0x0f0b0e0a0d090c08, 0x0703060205010400)));
}
inline v_uint8x32 v_interleave_quads(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_interleave_quads(v_reinterpret_as_s8(vec))); }
inline v_int16x16 v_interleave_pairs(const v_int16x16& vec)
{
return v_int16x16(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0e0b0a0d0c0908, 0x0706030205040100, 0x0f0e0b0a0d0c0908, 0x0706030205040100)));
}
inline v_uint16x16 v_interleave_pairs(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_interleave_pairs(v_reinterpret_as_s16(vec))); }
inline v_int16x16 v_interleave_quads(const v_int16x16& vec)
{
return v_int16x16(_mm256_shuffle_epi8(vec.val, _mm256_set_epi64x(0x0f0e07060d0c0504, 0x0b0a030209080100, 0x0f0e07060d0c0504, 0x0b0a030209080100)));
}
inline v_uint16x16 v_interleave_quads(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_interleave_quads(v_reinterpret_as_s16(vec))); }
inline v_int32x8 v_interleave_pairs(const v_int32x8& vec)
{
return v_int32x8(_mm256_shuffle_epi32(vec.val, _MM_SHUFFLE(3, 1, 2, 0)));
}
inline v_uint32x8 v_interleave_pairs(const v_uint32x8& vec) { return v_reinterpret_as_u32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
inline v_float32x8 v_interleave_pairs(const v_float32x8& vec) { return v_reinterpret_as_f32(v_interleave_pairs(v_reinterpret_as_s32(vec))); }
inline v_int8x32 v_pack_triplets(const v_int8x32& vec)
{
return v_int8x32(_mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(vec.val, _mm256_broadcastsi128_si256(_mm_set_epi64x(0xffffff0f0e0d0c0a, 0x0908060504020100))),
_mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000)));
}
inline v_uint8x32 v_pack_triplets(const v_uint8x32& vec) { return v_reinterpret_as_u8(v_pack_triplets(v_reinterpret_as_s8(vec))); }
inline v_int16x16 v_pack_triplets(const v_int16x16& vec)
{
return v_int16x16(_mm256_permutevar8x32_epi32(_mm256_shuffle_epi8(vec.val, _mm256_broadcastsi128_si256(_mm_set_epi64x(0xffff0f0e0d0c0b0a, 0x0908050403020100))),
_mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000)));
}
inline v_uint16x16 v_pack_triplets(const v_uint16x16& vec) { return v_reinterpret_as_u16(v_pack_triplets(v_reinterpret_as_s16(vec))); }
inline v_int32x8 v_pack_triplets(const v_int32x8& vec)
{
return v_int32x8(_mm256_permutevar8x32_epi32(vec.val, _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000)));
}
inline v_uint32x8 v_pack_triplets(const v_uint32x8& vec) { return v_reinterpret_as_u32(v_pack_triplets(v_reinterpret_as_s32(vec))); }
inline v_float32x8 v_pack_triplets(const v_float32x8& vec)
{
return v_float32x8(_mm256_permutevar8x32_ps(vec.val, _mm256_set_epi64x(0x0000000700000007, 0x0000000600000005, 0x0000000400000002, 0x0000000100000000)));
}
////////// Matrix operations /////////
//////// Dot Product ////////
// 16 >> 32
inline v_int32x8 v_dotprod(const v_int16x16& a, const v_int16x16& b)
{ return v_int32x8(_mm256_madd_epi16(a.val, b.val)); }
inline v_int32x8 v_dotprod(const v_int16x16& a, const v_int16x16& b, const v_int32x8& c)
{ return v_dotprod(a, b) + c; }
// 32 >> 64
inline v_int64x4 v_dotprod(const v_int32x8& a, const v_int32x8& b)
{
__m256i even = _mm256_mul_epi32(a.val, b.val);
__m256i odd = _mm256_mul_epi32(_mm256_srli_epi64(a.val, 32), _mm256_srli_epi64(b.val, 32));
return v_int64x4(_mm256_add_epi64(even, odd));
}
inline v_int64x4 v_dotprod(const v_int32x8& a, const v_int32x8& b, const v_int64x4& c)
{ return v_dotprod(a, b) + c; }
// 8 >> 32
inline v_uint32x8 v_dotprod_expand(const v_uint8x32& a, const v_uint8x32& b)
{
__m256i even_m = _mm256_set1_epi32(0xFF00FF00);
__m256i even_a = _mm256_blendv_epi8(a.val, _mm256_setzero_si256(), even_m);
__m256i odd_a = _mm256_srli_epi16(a.val, 8);
__m256i even_b = _mm256_blendv_epi8(b.val, _mm256_setzero_si256(), even_m);
__m256i odd_b = _mm256_srli_epi16(b.val, 8);
__m256i prod0 = _mm256_madd_epi16(even_a, even_b);
__m256i prod1 = _mm256_madd_epi16(odd_a, odd_b);
return v_uint32x8(_mm256_add_epi32(prod0, prod1));
}
inline v_uint32x8 v_dotprod_expand(const v_uint8x32& a, const v_uint8x32& b, const v_uint32x8& c)
{ return v_dotprod_expand(a, b) + c; }
inline v_int32x8 v_dotprod_expand(const v_int8x32& a, const v_int8x32& b)
{
__m256i even_a = _mm256_srai_epi16(_mm256_bslli_epi128(a.val, 1), 8);
__m256i odd_a = _mm256_srai_epi16(a.val, 8);
__m256i even_b = _mm256_srai_epi16(_mm256_bslli_epi128(b.val, 1), 8);
__m256i odd_b = _mm256_srai_epi16(b.val, 8);
__m256i prod0 = _mm256_madd_epi16(even_a, even_b);
__m256i prod1 = _mm256_madd_epi16(odd_a, odd_b);
return v_int32x8(_mm256_add_epi32(prod0, prod1));
}
inline v_int32x8 v_dotprod_expand(const v_int8x32& a, const v_int8x32& b, const v_int32x8& c)
{ return v_dotprod_expand(a, b) + c; }
// 16 >> 64
inline v_uint64x4 v_dotprod_expand(const v_uint16x16& a, const v_uint16x16& b)
{
__m256i mullo = _mm256_mullo_epi16(a.val, b.val);
__m256i mulhi = _mm256_mulhi_epu16(a.val, b.val);
__m256i mul0 = _mm256_unpacklo_epi16(mullo, mulhi);
__m256i mul1 = _mm256_unpackhi_epi16(mullo, mulhi);
__m256i p02 = _mm256_blend_epi32(mul0, _mm256_setzero_si256(), 0xAA);
__m256i p13 = _mm256_srli_epi64(mul0, 32);
__m256i p46 = _mm256_blend_epi32(mul1, _mm256_setzero_si256(), 0xAA);
__m256i p57 = _mm256_srli_epi64(mul1, 32);
__m256i p15_ = _mm256_add_epi64(p02, p13);
__m256i p9d_ = _mm256_add_epi64(p46, p57);
return v_uint64x4(_mm256_add_epi64(
_mm256_unpacklo_epi64(p15_, p9d_),
_mm256_unpackhi_epi64(p15_, p9d_)
));
}
inline v_uint64x4 v_dotprod_expand(const v_uint16x16& a, const v_uint16x16& b, const v_uint64x4& c)
{ return v_dotprod_expand(a, b) + c; }
inline v_int64x4 v_dotprod_expand(const v_int16x16& a, const v_int16x16& b)
{
__m256i prod = _mm256_madd_epi16(a.val, b.val);
__m256i sign = _mm256_srai_epi32(prod, 31);
__m256i lo = _mm256_unpacklo_epi32(prod, sign);
__m256i hi = _mm256_unpackhi_epi32(prod, sign);
return v_int64x4(_mm256_add_epi64(
_mm256_unpacklo_epi64(lo, hi),
_mm256_unpackhi_epi64(lo, hi)
));
}
inline v_int64x4 v_dotprod_expand(const v_int16x16& a, const v_int16x16& b, const v_int64x4& c)
{ return v_dotprod_expand(a, b) + c; }
// 32 >> 64f
inline v_float64x4 v_dotprod_expand(const v_int32x8& a, const v_int32x8& b)
{ return v_cvt_f64(v_dotprod(a, b)); }
inline v_float64x4 v_dotprod_expand(const v_int32x8& a, const v_int32x8& b, const v_float64x4& c)
{ return v_dotprod_expand(a, b) + c; }
//////// Fast Dot Product ////////
// 16 >> 32
inline v_int32x8 v_dotprod_fast(const v_int16x16& a, const v_int16x16& b)
{ return v_dotprod(a, b); }
inline v_int32x8 v_dotprod_fast(const v_int16x16& a, const v_int16x16& b, const v_int32x8& c)
{ return v_dotprod(a, b, c); }
// 32 >> 64
inline v_int64x4 v_dotprod_fast(const v_int32x8& a, const v_int32x8& b)
{ return v_dotprod(a, b); }
inline v_int64x4 v_dotprod_fast(const v_int32x8& a, const v_int32x8& b, const v_int64x4& c)
{ return v_dotprod(a, b, c); }
// 8 >> 32
inline v_uint32x8 v_dotprod_expand_fast(const v_uint8x32& a, const v_uint8x32& b)
{ return v_dotprod_expand(a, b); }
inline v_uint32x8 v_dotprod_expand_fast(const v_uint8x32& a, const v_uint8x32& b, const v_uint32x8& c)
{ return v_dotprod_expand(a, b, c); }
inline v_int32x8 v_dotprod_expand_fast(const v_int8x32& a, const v_int8x32& b)
{ return v_dotprod_expand(a, b); }
inline v_int32x8 v_dotprod_expand_fast(const v_int8x32& a, const v_int8x32& b, const v_int32x8& c)
{ return v_dotprod_expand(a, b, c); }
// 16 >> 64
inline v_uint64x4 v_dotprod_expand_fast(const v_uint16x16& a, const v_uint16x16& b)
{
__m256i mullo = _mm256_mullo_epi16(a.val, b.val);
__m256i mulhi = _mm256_mulhi_epu16(a.val, b.val);
__m256i mul0 = _mm256_unpacklo_epi16(mullo, mulhi);
__m256i mul1 = _mm256_unpackhi_epi16(mullo, mulhi);
__m256i p02 = _mm256_blend_epi32(mul0, _mm256_setzero_si256(), 0xAA);
__m256i p13 = _mm256_srli_epi64(mul0, 32);
__m256i p46 = _mm256_blend_epi32(mul1, _mm256_setzero_si256(), 0xAA);
__m256i p57 = _mm256_srli_epi64(mul1, 32);
__m256i p15_ = _mm256_add_epi64(p02, p13);
__m256i p9d_ = _mm256_add_epi64(p46, p57);
return v_uint64x4(_mm256_add_epi64(p15_, p9d_));
}
inline v_uint64x4 v_dotprod_expand_fast(const v_uint16x16& a, const v_uint16x16& b, const v_uint64x4& c)
{ return v_dotprod_expand_fast(a, b) + c; }
inline v_int64x4 v_dotprod_expand_fast(const v_int16x16& a, const v_int16x16& b)
{
__m256i prod = _mm256_madd_epi16(a.val, b.val);
__m256i sign = _mm256_srai_epi32(prod, 31);
__m256i lo = _mm256_unpacklo_epi32(prod, sign);
__m256i hi = _mm256_unpackhi_epi32(prod, sign);
return v_int64x4(_mm256_add_epi64(lo, hi));
}
inline v_int64x4 v_dotprod_expand_fast(const v_int16x16& a, const v_int16x16& b, const v_int64x4& c)
{ return v_dotprod_expand_fast(a, b) + c; }
// 32 >> 64f
inline v_float64x4 v_dotprod_expand_fast(const v_int32x8& a, const v_int32x8& b)
{ return v_dotprod_expand(a, b); }
inline v_float64x4 v_dotprod_expand_fast(const v_int32x8& a, const v_int32x8& b, const v_float64x4& c)
{ return v_dotprod_expand(a, b, c); }
#define OPENCV_HAL_AVX_SPLAT2_PS(a, im) \
v_float32x8(_mm256_permute_ps(a.val, _MM_SHUFFLE(im, im, im, im)))
inline v_float32x8 v_matmul(const v_float32x8& v, const v_float32x8& m0,
const v_float32x8& m1, const v_float32x8& m2,
const v_float32x8& m3)
{
v_float32x8 v04 = OPENCV_HAL_AVX_SPLAT2_PS(v, 0);
v_float32x8 v15 = OPENCV_HAL_AVX_SPLAT2_PS(v, 1);
v_float32x8 v26 = OPENCV_HAL_AVX_SPLAT2_PS(v, 2);
v_float32x8 v37 = OPENCV_HAL_AVX_SPLAT2_PS(v, 3);
return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, v37 * m3)));
}
inline v_float32x8 v_matmuladd(const v_float32x8& v, const v_float32x8& m0,
const v_float32x8& m1, const v_float32x8& m2,
const v_float32x8& a)
{
v_float32x8 v04 = OPENCV_HAL_AVX_SPLAT2_PS(v, 0);
v_float32x8 v15 = OPENCV_HAL_AVX_SPLAT2_PS(v, 1);
v_float32x8 v26 = OPENCV_HAL_AVX_SPLAT2_PS(v, 2);
return v_fma(v04, m0, v_fma(v15, m1, v_fma(v26, m2, a)));
}
#define OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(_Tpvec, suffix, cast_from, cast_to) \
inline void v_transpose4x4(const _Tpvec& a0, const _Tpvec& a1, \
const _Tpvec& a2, const _Tpvec& a3, \
_Tpvec& b0, _Tpvec& b1, _Tpvec& b2, _Tpvec& b3) \
{ \
__m256i t0 = cast_from(_mm256_unpacklo_##suffix(a0.val, a1.val)); \
__m256i t1 = cast_from(_mm256_unpacklo_##suffix(a2.val, a3.val)); \
__m256i t2 = cast_from(_mm256_unpackhi_##suffix(a0.val, a1.val)); \
__m256i t3 = cast_from(_mm256_unpackhi_##suffix(a2.val, a3.val)); \
b0.val = cast_to(_mm256_unpacklo_epi64(t0, t1)); \
b1.val = cast_to(_mm256_unpackhi_epi64(t0, t1)); \
b2.val = cast_to(_mm256_unpacklo_epi64(t2, t3)); \
b3.val = cast_to(_mm256_unpackhi_epi64(t2, t3)); \
}
OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_uint32x8, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_int32x8, epi32, OPENCV_HAL_NOP, OPENCV_HAL_NOP)
OPENCV_HAL_IMPL_AVX_TRANSPOSE4x4(v_float32x8, ps, _mm256_castps_si256, _mm256_castsi256_ps)
//////////////// Value reordering ///////////////
/* Expand */
#define OPENCV_HAL_IMPL_AVX_EXPAND(_Tpvec, _Tpwvec, _Tp, intrin) \
inline void v_expand(const _Tpvec& a, _Tpwvec& b0, _Tpwvec& b1) \
{ \
b0.val = intrin(_v256_extract_low(a.val)); \
b1.val = intrin(_v256_extract_high(a.val)); \
} \
inline _Tpwvec v_expand_low(const _Tpvec& a) \
{ return _Tpwvec(intrin(_v256_extract_low(a.val))); } \
inline _Tpwvec v_expand_high(const _Tpvec& a) \
{ return _Tpwvec(intrin(_v256_extract_high(a.val))); } \
inline _Tpwvec v256_load_expand(const _Tp* ptr) \
{ \
__m128i a = _mm_loadu_si128((const __m128i*)ptr); \
return _Tpwvec(intrin(a)); \
}
OPENCV_HAL_IMPL_AVX_EXPAND(v_uint8x32, v_uint16x16, uchar, _mm256_cvtepu8_epi16)
OPENCV_HAL_IMPL_AVX_EXPAND(v_int8x32, v_int16x16, schar, _mm256_cvtepi8_epi16)
OPENCV_HAL_IMPL_AVX_EXPAND(v_uint16x16, v_uint32x8, ushort, _mm256_cvtepu16_epi32)
OPENCV_HAL_IMPL_AVX_EXPAND(v_int16x16, v_int32x8, short, _mm256_cvtepi16_epi32)
OPENCV_HAL_IMPL_AVX_EXPAND(v_uint32x8, v_uint64x4, unsigned, _mm256_cvtepu32_epi64)
OPENCV_HAL_IMPL_AVX_EXPAND(v_int32x8, v_int64x4, int, _mm256_cvtepi32_epi64)
#define OPENCV_HAL_IMPL_AVX_EXPAND_Q(_Tpvec, _Tp, intrin) \
inline _Tpvec v256_load_expand_q(const _Tp* ptr) \
{ \
__m128i a = _mm_loadl_epi64((const __m128i*)ptr); \
return _Tpvec(intrin(a)); \
}
OPENCV_HAL_IMPL_AVX_EXPAND_Q(v_uint32x8, uchar, _mm256_cvtepu8_epi32)
OPENCV_HAL_IMPL_AVX_EXPAND_Q(v_int32x8, schar, _mm256_cvtepi8_epi32)
/* pack */
// 16
inline v_int8x32 v_pack(const v_int16x16& a, const v_int16x16& b)
{ return v_int8x32(_v256_shuffle_odd_64(_mm256_packs_epi16(a.val, b.val))); }
inline v_uint8x32 v_pack(const v_uint16x16& a, const v_uint16x16& b)
{
__m256i t = _mm256_set1_epi16(255);
__m256i a1 = _mm256_min_epu16(a.val, t);
__m256i b1 = _mm256_min_epu16(b.val, t);
return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a1, b1)));
}
inline v_uint8x32 v_pack_u(const v_int16x16& a, const v_int16x16& b)
{
return v_uint8x32(_v256_shuffle_odd_64(_mm256_packus_epi16(a.val, b.val)));
}
inline void v_pack_store(schar* ptr, const v_int16x16& a)
{ v_store_low(ptr, v_pack(a, a)); }
inline void v_pack_store(uchar* ptr, const v_uint16x16& a)
{
const __m256i m = _mm256_set1_epi16(255);
__m256i am = _mm256_min_epu16(a.val, m);
am = _v256_shuffle_odd_64(_mm256_packus_epi16(am, am));
v_store_low(ptr, v_uint8x32(am));
}
inline void v_pack_u_store(uchar* ptr, const v_int16x16& a)
{ v_store_low(ptr, v_pack_u(a, a)); }
template<int n> inline
v_uint8x32 v_rshr_pack(const v_uint16x16& a, const v_uint16x16& b)
{
// we assume that n > 0, and so the shifted 16-bit values can be treated as signed numbers.
v_uint16x16 delta = v256_setall_u16((short)(1 << (n-1)));
return v_pack_u(v_reinterpret_as_s16((a + delta) >> n),
v_reinterpret_as_s16((b + delta) >> n));
}
template<int n> inline
void v_rshr_pack_store(uchar* ptr, const v_uint16x16& a)
{
v_uint16x16 delta = v256_setall_u16((short)(1 << (n-1)));
v_pack_u_store(ptr, v_reinterpret_as_s16((a + delta) >> n));
}
template<int n> inline
v_uint8x32 v_rshr_pack_u(const v_int16x16& a, const v_int16x16& b)
{
v_int16x16 delta = v256_setall_s16((short)(1 << (n-1)));
return v_pack_u((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_u_store(uchar* ptr, const v_int16x16& a)
{
v_int16x16 delta = v256_setall_s16((short)(1 << (n-1)));
v_pack_u_store(ptr, (a + delta) >> n);
}
template<int n> inline
v_int8x32 v_rshr_pack(const v_int16x16& a, const v_int16x16& b)
{
v_int16x16 delta = v256_setall_s16((short)(1 << (n-1)));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(schar* ptr, const v_int16x16& a)
{
v_int16x16 delta = v256_setall_s16((short)(1 << (n-1)));
v_pack_store(ptr, (a + delta) >> n);
}
// 32
inline v_int16x16 v_pack(const v_int32x8& a, const v_int32x8& b)
{ return v_int16x16(_v256_shuffle_odd_64(_mm256_packs_epi32(a.val, b.val))); }
inline v_uint16x16 v_pack(const v_uint32x8& a, const v_uint32x8& b)
{ return v_uint16x16(_v256_shuffle_odd_64(_v256_packs_epu32(a.val, b.val))); }
inline v_uint16x16 v_pack_u(const v_int32x8& a, const v_int32x8& b)
{ return v_uint16x16(_v256_shuffle_odd_64(_mm256_packus_epi32(a.val, b.val))); }
inline void v_pack_store(short* ptr, const v_int32x8& a)
{ v_store_low(ptr, v_pack(a, a)); }
inline void v_pack_store(ushort* ptr, const v_uint32x8& a)
{
const __m256i m = _mm256_set1_epi32(65535);
__m256i am = _mm256_min_epu32(a.val, m);
am = _v256_shuffle_odd_64(_mm256_packus_epi32(am, am));
v_store_low(ptr, v_uint16x16(am));
}
inline void v_pack_u_store(ushort* ptr, const v_int32x8& a)
{ v_store_low(ptr, v_pack_u(a, a)); }
template<int n> inline
v_uint16x16 v_rshr_pack(const v_uint32x8& a, const v_uint32x8& b)
{
// we assume that n > 0, and so the shifted 32-bit values can be treated as signed numbers.
v_uint32x8 delta = v256_setall_u32(1 << (n-1));
return v_pack_u(v_reinterpret_as_s32((a + delta) >> n),
v_reinterpret_as_s32((b + delta) >> n));
}
template<int n> inline
void v_rshr_pack_store(ushort* ptr, const v_uint32x8& a)
{
v_uint32x8 delta = v256_setall_u32(1 << (n-1));
v_pack_u_store(ptr, v_reinterpret_as_s32((a + delta) >> n));
}
template<int n> inline
v_uint16x16 v_rshr_pack_u(const v_int32x8& a, const v_int32x8& b)
{
v_int32x8 delta = v256_setall_s32(1 << (n-1));
return v_pack_u((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_u_store(ushort* ptr, const v_int32x8& a)
{
v_int32x8 delta = v256_setall_s32(1 << (n-1));
v_pack_u_store(ptr, (a + delta) >> n);
}
template<int n> inline
v_int16x16 v_rshr_pack(const v_int32x8& a, const v_int32x8& b)
{
v_int32x8 delta = v256_setall_s32(1 << (n-1));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(short* ptr, const v_int32x8& a)
{
v_int32x8 delta = v256_setall_s32(1 << (n-1));
v_pack_store(ptr, (a + delta) >> n);
}
// 64
// Non-saturating pack
inline v_uint32x8 v_pack(const v_uint64x4& a, const v_uint64x4& b)
{
__m256i a0 = _mm256_shuffle_epi32(a.val, _MM_SHUFFLE(0, 0, 2, 0));
__m256i b0 = _mm256_shuffle_epi32(b.val, _MM_SHUFFLE(0, 0, 2, 0));
__m256i ab = _mm256_unpacklo_epi64(a0, b0); // a0, a1, b0, b1, a2, a3, b2, b3
return v_uint32x8(_v256_shuffle_odd_64(ab));
}
inline v_int32x8 v_pack(const v_int64x4& a, const v_int64x4& b)
{ return v_reinterpret_as_s32(v_pack(v_reinterpret_as_u64(a), v_reinterpret_as_u64(b))); }
inline void v_pack_store(unsigned* ptr, const v_uint64x4& a)
{
__m256i a0 = _mm256_shuffle_epi32(a.val, _MM_SHUFFLE(0, 0, 2, 0));
v_store_low(ptr, v_uint32x8(_v256_shuffle_odd_64(a0)));
}
inline void v_pack_store(int* ptr, const v_int64x4& b)
{ v_pack_store((unsigned*)ptr, v_reinterpret_as_u64(b)); }
template<int n> inline
v_uint32x8 v_rshr_pack(const v_uint64x4& a, const v_uint64x4& b)
{
v_uint64x4 delta = v256_setall_u64((uint64)1 << (n-1));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(unsigned* ptr, const v_uint64x4& a)
{
v_uint64x4 delta = v256_setall_u64((uint64)1 << (n-1));
v_pack_store(ptr, (a + delta) >> n);
}
template<int n> inline
v_int32x8 v_rshr_pack(const v_int64x4& a, const v_int64x4& b)
{
v_int64x4 delta = v256_setall_s64((int64)1 << (n-1));
return v_pack((a + delta) >> n, (b + delta) >> n);
}
template<int n> inline
void v_rshr_pack_store(int* ptr, const v_int64x4& a)
{
v_int64x4 delta = v256_setall_s64((int64)1 << (n-1));
v_pack_store(ptr, (a + delta) >> n);
}
// pack boolean
inline v_uint8x32 v_pack_b(const v_uint16x16& a, const v_uint16x16& b)
{
__m256i ab = _mm256_packs_epi16(a.val, b.val);
return v_uint8x32(_v256_shuffle_odd_64(ab));
}
inline v_uint8x32 v_pack_b(const v_uint32x8& a, const v_uint32x8& b,
const v_uint32x8& c, const v_uint32x8& d)
{
__m256i ab = _mm256_packs_epi32(a.val, b.val);
__m256i cd = _mm256_packs_epi32(c.val, d.val);
__m256i abcd = _v256_shuffle_odd_64(_mm256_packs_epi16(ab, cd));
return v_uint8x32(_mm256_shuffle_epi32(abcd, _MM_SHUFFLE(3, 1, 2, 0)));
}
inline v_uint8x32 v_pack_b(const v_uint64x4& a, const v_uint64x4& b, const v_uint64x4& c,
const v_uint64x4& d, const v_uint64x4& e, const v_uint64x4& f,
const v_uint64x4& g, const v_uint64x4& h)
{
__m256i ab = _mm256_packs_epi32(a.val, b.val);
__m256i cd = _mm256_packs_epi32(c.val, d.val);
__m256i ef = _mm256_packs_epi32(e.val, f.val);
__m256i gh = _mm256_packs_epi32(g.val, h.val);
__m256i abcd = _mm256_packs_epi32(ab, cd);
__m256i efgh = _mm256_packs_epi32(ef, gh);
__m256i pkall = _v256_shuffle_odd_64(_mm256_packs_epi16(abcd, efgh));
__m256i rev = _mm256_alignr_epi8(pkall, pkall, 8);
return v_uint8x32(_mm256_unpacklo_epi16(pkall, rev));
}
/* Recombine */
// its up there with load and store operations
/* Extract */
#define OPENCV_HAL_IMPL_AVX_EXTRACT(_Tpvec) \
template<int s> \
inline _Tpvec v_extract(const _Tpvec& a, const _Tpvec& b) \
{ return v_rotate_right<s>(a, b); }
OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint8x32)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_int8x32)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint16x16)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_int16x16)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint32x8)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_int32x8)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_uint64x4)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_int64x4)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_float32x8)
OPENCV_HAL_IMPL_AVX_EXTRACT(v_float64x4)
template<int i>
inline uchar v_extract_n(v_uint8x32 a)
{
return (uchar)_v256_extract_epi8<i>(a.val);
}
template<int i>
inline schar v_extract_n(v_int8x32 a)
{
return (schar)v_extract_n<i>(v_reinterpret_as_u8(a));
}
template<int i>
inline ushort v_extract_n(v_uint16x16 a)
{
return (ushort)_v256_extract_epi16<i>(a.val);
}
template<int i>
inline short v_extract_n(v_int16x16 a)
{
return (short)v_extract_n<i>(v_reinterpret_as_u16(a));
}
template<int i>
inline uint v_extract_n(v_uint32x8 a)
{
return (uint)_v256_extract_epi32<i>(a.val);
}
template<int i>
inline int v_extract_n(v_int32x8 a)
{
return (int)v_extract_n<i>(v_reinterpret_as_u32(a));
}
template<int i>
inline uint64 v_extract_n(v_uint64x4 a)
{
return (uint64)_v256_extract_epi64<i>(a.val);
}
template<int i>
inline int64 v_extract_n(v_int64x4 v)
{
return (int64)v_extract_n<i>(v_reinterpret_as_u64(v));
}
template<int i>
inline float v_extract_n(v_float32x8 v)
{
union { uint iv; float fv; } d;
d.iv = v_extract_n<i>(v_reinterpret_as_u32(v));
return d.fv;
}
template<int i>
inline double v_extract_n(v_float64x4 v)
{
union { uint64 iv; double dv; } d;
d.iv = v_extract_n<i>(v_reinterpret_as_u64(v));
return d.dv;
}
template<int i>
inline v_uint32x8 v_broadcast_element(v_uint32x8 a)
{
static const __m256i perm = _mm256_set1_epi32((char)i);
return v_uint32x8(_mm256_permutevar8x32_epi32(a.val, perm));
}
template<int i>
inline v_int32x8 v_broadcast_element(const v_int32x8 &a)
{ return v_reinterpret_as_s32(v_broadcast_element<i>(v_reinterpret_as_u32(a))); }
template<int i>
inline v_float32x8 v_broadcast_element(const v_float32x8 &a)
{ return v_reinterpret_as_f32(v_broadcast_element<i>(v_reinterpret_as_u32(a))); }
///////////////////// load deinterleave /////////////////////////////
inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b )
{
__m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 32));
const __m256i sh = _mm256_setr_epi8(0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15,
0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15);
__m256i p0 = _mm256_shuffle_epi8(ab0, sh);
__m256i p1 = _mm256_shuffle_epi8(ab1, sh);
__m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16);
__m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16);
__m256i a0 = _mm256_unpacklo_epi64(pl, ph);
__m256i b0 = _mm256_unpackhi_epi64(pl, ph);
a = v_uint8x32(a0);
b = v_uint8x32(b0);
}
inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b )
{
__m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 16));
const __m256i sh = _mm256_setr_epi8(0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15,
0, 1, 4, 5, 8, 9, 12, 13, 2, 3, 6, 7, 10, 11, 14, 15);
__m256i p0 = _mm256_shuffle_epi8(ab0, sh);
__m256i p1 = _mm256_shuffle_epi8(ab1, sh);
__m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16);
__m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16);
__m256i a0 = _mm256_unpacklo_epi64(pl, ph);
__m256i b0 = _mm256_unpackhi_epi64(pl, ph);
a = v_uint16x16(a0);
b = v_uint16x16(b0);
}
inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b )
{
__m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 8));
const int sh = 0+2*4+1*16+3*64;
__m256i p0 = _mm256_shuffle_epi32(ab0, sh);
__m256i p1 = _mm256_shuffle_epi32(ab1, sh);
__m256i pl = _mm256_permute2x128_si256(p0, p1, 0 + 2*16);
__m256i ph = _mm256_permute2x128_si256(p0, p1, 1 + 3*16);
__m256i a0 = _mm256_unpacklo_epi64(pl, ph);
__m256i b0 = _mm256_unpackhi_epi64(pl, ph);
a = v_uint32x8(a0);
b = v_uint32x8(b0);
}
inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b )
{
__m256i ab0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i ab1 = _mm256_loadu_si256((const __m256i*)(ptr + 4));
__m256i pl = _mm256_permute2x128_si256(ab0, ab1, 0 + 2*16);
__m256i ph = _mm256_permute2x128_si256(ab0, ab1, 1 + 3*16);
__m256i a0 = _mm256_unpacklo_epi64(pl, ph);
__m256i b0 = _mm256_unpackhi_epi64(pl, ph);
a = v_uint64x4(a0);
b = v_uint64x4(b0);
}
inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b, v_uint8x32& c )
{
__m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 32));
__m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 64));
__m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16);
__m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16);
const __m256i m0 = _mm256_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0,
0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0);
const __m256i m1 = _mm256_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0,
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1);
__m256i b0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_low, s02_high, m0), bgr1, m1);
__m256i g0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_high, s02_low, m1), bgr1, m0);
__m256i r0 = _mm256_blendv_epi8(_mm256_blendv_epi8(bgr1, s02_low, m0), s02_high, m1);
const __m256i
sh_b = _mm256_setr_epi8(0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13,
0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14, 1, 4, 7, 10, 13),
sh_g = _mm256_setr_epi8(1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14,
1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, 5, 8, 11, 14),
sh_r = _mm256_setr_epi8(2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15,
2, 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15);
b0 = _mm256_shuffle_epi8(b0, sh_b);
g0 = _mm256_shuffle_epi8(g0, sh_g);
r0 = _mm256_shuffle_epi8(r0, sh_r);
a = v_uint8x32(b0);
b = v_uint8x32(g0);
c = v_uint8x32(r0);
}
inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b, v_uint16x16& c )
{
__m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 16));
__m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 32));
__m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16);
__m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16);
const __m256i m0 = _mm256_setr_epi8(0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1,
0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0);
const __m256i m1 = _mm256_setr_epi8(0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0,
-1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0);
__m256i b0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_low, s02_high, m0), bgr1, m1);
__m256i g0 = _mm256_blendv_epi8(_mm256_blendv_epi8(bgr1, s02_low, m0), s02_high, m1);
__m256i r0 = _mm256_blendv_epi8(_mm256_blendv_epi8(s02_high, s02_low, m1), bgr1, m0);
const __m256i sh_b = _mm256_setr_epi8(0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11,
0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11);
const __m256i sh_g = _mm256_setr_epi8(2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13,
2, 3, 8, 9, 14, 15, 4, 5, 10, 11, 0, 1, 6, 7, 12, 13);
const __m256i sh_r = _mm256_setr_epi8(4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15,
4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15);
b0 = _mm256_shuffle_epi8(b0, sh_b);
g0 = _mm256_shuffle_epi8(g0, sh_g);
r0 = _mm256_shuffle_epi8(r0, sh_r);
a = v_uint16x16(b0);
b = v_uint16x16(g0);
c = v_uint16x16(r0);
}
inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b, v_uint32x8& c )
{
__m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 8));
__m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 16));
__m256i s02_low = _mm256_permute2x128_si256(bgr0, bgr2, 0 + 2*16);
__m256i s02_high = _mm256_permute2x128_si256(bgr0, bgr2, 1 + 3*16);
__m256i b0 = _mm256_blend_epi32(_mm256_blend_epi32(s02_low, s02_high, 0x24), bgr1, 0x92);
__m256i g0 = _mm256_blend_epi32(_mm256_blend_epi32(s02_high, s02_low, 0x92), bgr1, 0x24);
__m256i r0 = _mm256_blend_epi32(_mm256_blend_epi32(bgr1, s02_low, 0x24), s02_high, 0x92);
b0 = _mm256_shuffle_epi32(b0, 0x6c);
g0 = _mm256_shuffle_epi32(g0, 0xb1);
r0 = _mm256_shuffle_epi32(r0, 0xc6);
a = v_uint32x8(b0);
b = v_uint32x8(g0);
c = v_uint32x8(r0);
}
inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b, v_uint64x4& c )
{
__m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 4));
__m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 8));
__m256i s01 = _mm256_blend_epi32(bgr0, bgr1, 0xf0);
__m256i s12 = _mm256_blend_epi32(bgr1, bgr2, 0xf0);
__m256i s20r = _mm256_permute4x64_epi64(_mm256_blend_epi32(bgr2, bgr0, 0xf0), 0x1b);
__m256i b0 = _mm256_unpacklo_epi64(s01, s20r);
__m256i g0 = _mm256_alignr_epi8(s12, s01, 8);
__m256i r0 = _mm256_unpackhi_epi64(s20r, s12);
a = v_uint64x4(b0);
b = v_uint64x4(g0);
c = v_uint64x4(r0);
}
inline void v_load_deinterleave( const uchar* ptr, v_uint8x32& a, v_uint8x32& b, v_uint8x32& c, v_uint8x32& d )
{
__m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 32));
__m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 64));
__m256i bgr3 = _mm256_loadu_si256((const __m256i*)(ptr + 96));
const __m256i sh = _mm256_setr_epi8(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15,
0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
__m256i p0 = _mm256_shuffle_epi8(bgr0, sh);
__m256i p1 = _mm256_shuffle_epi8(bgr1, sh);
__m256i p2 = _mm256_shuffle_epi8(bgr2, sh);
__m256i p3 = _mm256_shuffle_epi8(bgr3, sh);
__m256i p01l = _mm256_unpacklo_epi32(p0, p1);
__m256i p01h = _mm256_unpackhi_epi32(p0, p1);
__m256i p23l = _mm256_unpacklo_epi32(p2, p3);
__m256i p23h = _mm256_unpackhi_epi32(p2, p3);
__m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16);
__m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16);
__m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16);
__m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16);
__m256i b0 = _mm256_unpacklo_epi32(pll, plh);
__m256i g0 = _mm256_unpackhi_epi32(pll, plh);
__m256i r0 = _mm256_unpacklo_epi32(phl, phh);
__m256i a0 = _mm256_unpackhi_epi32(phl, phh);
a = v_uint8x32(b0);
b = v_uint8x32(g0);
c = v_uint8x32(r0);
d = v_uint8x32(a0);
}
inline void v_load_deinterleave( const ushort* ptr, v_uint16x16& a, v_uint16x16& b, v_uint16x16& c, v_uint16x16& d )
{
__m256i bgr0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgr1 = _mm256_loadu_si256((const __m256i*)(ptr + 16));
__m256i bgr2 = _mm256_loadu_si256((const __m256i*)(ptr + 32));
__m256i bgr3 = _mm256_loadu_si256((const __m256i*)(ptr + 48));
const __m256i sh = _mm256_setr_epi8(0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15,
0, 1, 8, 9, 2, 3, 10, 11, 4, 5, 12, 13, 6, 7, 14, 15);
__m256i p0 = _mm256_shuffle_epi8(bgr0, sh);
__m256i p1 = _mm256_shuffle_epi8(bgr1, sh);
__m256i p2 = _mm256_shuffle_epi8(bgr2, sh);
__m256i p3 = _mm256_shuffle_epi8(bgr3, sh);
__m256i p01l = _mm256_unpacklo_epi32(p0, p1);
__m256i p01h = _mm256_unpackhi_epi32(p0, p1);
__m256i p23l = _mm256_unpacklo_epi32(p2, p3);
__m256i p23h = _mm256_unpackhi_epi32(p2, p3);
__m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16);
__m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16);
__m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16);
__m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16);
__m256i b0 = _mm256_unpacklo_epi32(pll, plh);
__m256i g0 = _mm256_unpackhi_epi32(pll, plh);
__m256i r0 = _mm256_unpacklo_epi32(phl, phh);
__m256i a0 = _mm256_unpackhi_epi32(phl, phh);
a = v_uint16x16(b0);
b = v_uint16x16(g0);
c = v_uint16x16(r0);
d = v_uint16x16(a0);
}
inline void v_load_deinterleave( const unsigned* ptr, v_uint32x8& a, v_uint32x8& b, v_uint32x8& c, v_uint32x8& d )
{
__m256i p0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i p1 = _mm256_loadu_si256((const __m256i*)(ptr + 8));
__m256i p2 = _mm256_loadu_si256((const __m256i*)(ptr + 16));
__m256i p3 = _mm256_loadu_si256((const __m256i*)(ptr + 24));
__m256i p01l = _mm256_unpacklo_epi32(p0, p1);
__m256i p01h = _mm256_unpackhi_epi32(p0, p1);
__m256i p23l = _mm256_unpacklo_epi32(p2, p3);
__m256i p23h = _mm256_unpackhi_epi32(p2, p3);
__m256i pll = _mm256_permute2x128_si256(p01l, p23l, 0 + 2*16);
__m256i plh = _mm256_permute2x128_si256(p01l, p23l, 1 + 3*16);
__m256i phl = _mm256_permute2x128_si256(p01h, p23h, 0 + 2*16);
__m256i phh = _mm256_permute2x128_si256(p01h, p23h, 1 + 3*16);
__m256i b0 = _mm256_unpacklo_epi32(pll, plh);
__m256i g0 = _mm256_unpackhi_epi32(pll, plh);
__m256i r0 = _mm256_unpacklo_epi32(phl, phh);
__m256i a0 = _mm256_unpackhi_epi32(phl, phh);
a = v_uint32x8(b0);
b = v_uint32x8(g0);
c = v_uint32x8(r0);
d = v_uint32x8(a0);
}
inline void v_load_deinterleave( const uint64* ptr, v_uint64x4& a, v_uint64x4& b, v_uint64x4& c, v_uint64x4& d )
{
__m256i bgra0 = _mm256_loadu_si256((const __m256i*)ptr);
__m256i bgra1 = _mm256_loadu_si256((const __m256i*)(ptr + 4));
__m256i bgra2 = _mm256_loadu_si256((const __m256i*)(ptr + 8));
__m256i bgra3 = _mm256_loadu_si256((const __m256i*)(ptr + 12));
__m256i l02 = _mm256_permute2x128_si256(bgra0, bgra2, 0 + 2*16);
__m256i h02 = _mm256_permute2x128_si256(bgra0, bgra2, 1 + 3*16);
__m256i l13 = _mm256_permute2x128_si256(bgra1, bgra3, 0 + 2*16);
__m256i h13 = _mm256_permute2x128_si256(bgra1, bgra3, 1 + 3*16);
__m256i b0 = _mm256_unpacklo_epi64(l02, l13);
__m256i g0 = _mm256_unpackhi_epi64(l02, l13);
__m256i r0 = _mm256_unpacklo_epi64(h02, h13);
__m256i a0 = _mm256_unpackhi_epi64(h02, h13);
a = v_uint64x4(b0);
b = v_uint64x4(g0);
c = v_uint64x4(r0);
d = v_uint64x4(a0);
}
///////////////////////////// store interleave /////////////////////////////////////
inline void v_store_interleave( uchar* ptr, const v_uint8x32& x, const v_uint8x32& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i xy_l = _mm256_unpacklo_epi8(x.val, y.val);
__m256i xy_h = _mm256_unpackhi_epi8(x.val, y.val);
__m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16);
__m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, xy0);
_mm256_stream_si256((__m256i*)(ptr + 32), xy1);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, xy0);
_mm256_store_si256((__m256i*)(ptr + 32), xy1);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, xy0);
_mm256_storeu_si256((__m256i*)(ptr + 32), xy1);
}
}
inline void v_store_interleave( ushort* ptr, const v_uint16x16& x, const v_uint16x16& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i xy_l = _mm256_unpacklo_epi16(x.val, y.val);
__m256i xy_h = _mm256_unpackhi_epi16(x.val, y.val);
__m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16);
__m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, xy0);
_mm256_stream_si256((__m256i*)(ptr + 16), xy1);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, xy0);
_mm256_store_si256((__m256i*)(ptr + 16), xy1);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, xy0);
_mm256_storeu_si256((__m256i*)(ptr + 16), xy1);
}
}
inline void v_store_interleave( unsigned* ptr, const v_uint32x8& x, const v_uint32x8& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i xy_l = _mm256_unpacklo_epi32(x.val, y.val);
__m256i xy_h = _mm256_unpackhi_epi32(x.val, y.val);
__m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16);
__m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, xy0);
_mm256_stream_si256((__m256i*)(ptr + 8), xy1);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, xy0);
_mm256_store_si256((__m256i*)(ptr + 8), xy1);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, xy0);
_mm256_storeu_si256((__m256i*)(ptr + 8), xy1);
}
}
inline void v_store_interleave( uint64* ptr, const v_uint64x4& x, const v_uint64x4& y,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i xy_l = _mm256_unpacklo_epi64(x.val, y.val);
__m256i xy_h = _mm256_unpackhi_epi64(x.val, y.val);
__m256i xy0 = _mm256_permute2x128_si256(xy_l, xy_h, 0 + 2*16);
__m256i xy1 = _mm256_permute2x128_si256(xy_l, xy_h, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, xy0);
_mm256_stream_si256((__m256i*)(ptr + 4), xy1);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, xy0);
_mm256_store_si256((__m256i*)(ptr + 4), xy1);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, xy0);
_mm256_storeu_si256((__m256i*)(ptr + 4), xy1);
}
}
inline void v_store_interleave( uchar* ptr, const v_uint8x32& a, const v_uint8x32& b, const v_uint8x32& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
const __m256i sh_b = _mm256_setr_epi8(
0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5,
0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10, 5);
const __m256i sh_g = _mm256_setr_epi8(
5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10,
5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10);
const __m256i sh_r = _mm256_setr_epi8(
10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15,
10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15);
__m256i b0 = _mm256_shuffle_epi8(a.val, sh_b);
__m256i g0 = _mm256_shuffle_epi8(b.val, sh_g);
__m256i r0 = _mm256_shuffle_epi8(c.val, sh_r);
const __m256i m0 = _mm256_setr_epi8(0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0,
0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0);
const __m256i m1 = _mm256_setr_epi8(0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0,
0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0);
__m256i p0 = _mm256_blendv_epi8(_mm256_blendv_epi8(b0, g0, m0), r0, m1);
__m256i p1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g0, r0, m0), b0, m1);
__m256i p2 = _mm256_blendv_epi8(_mm256_blendv_epi8(r0, b0, m0), g0, m1);
__m256i bgr0 = _mm256_permute2x128_si256(p0, p1, 0 + 2*16);
__m256i bgr1 = _mm256_permute2x128_si256(p2, p0, 0 + 3*16);
__m256i bgr2 = _mm256_permute2x128_si256(p1, p2, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgr0);
_mm256_stream_si256((__m256i*)(ptr + 32), bgr1);
_mm256_stream_si256((__m256i*)(ptr + 64), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgr0);
_mm256_store_si256((__m256i*)(ptr + 32), bgr1);
_mm256_store_si256((__m256i*)(ptr + 64), bgr2);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgr0);
_mm256_storeu_si256((__m256i*)(ptr + 32), bgr1);
_mm256_storeu_si256((__m256i*)(ptr + 64), bgr2);
}
}
inline void v_store_interleave( ushort* ptr, const v_uint16x16& a, const v_uint16x16& b, const v_uint16x16& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
const __m256i sh_b = _mm256_setr_epi8(
0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11,
0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11);
const __m256i sh_g = _mm256_setr_epi8(
10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5,
10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5);
const __m256i sh_r = _mm256_setr_epi8(
4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15,
4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15);
__m256i b0 = _mm256_shuffle_epi8(a.val, sh_b);
__m256i g0 = _mm256_shuffle_epi8(b.val, sh_g);
__m256i r0 = _mm256_shuffle_epi8(c.val, sh_r);
const __m256i m0 = _mm256_setr_epi8(0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1,
0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0);
const __m256i m1 = _mm256_setr_epi8(0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0,
-1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0);
__m256i p0 = _mm256_blendv_epi8(_mm256_blendv_epi8(b0, g0, m0), r0, m1);
__m256i p1 = _mm256_blendv_epi8(_mm256_blendv_epi8(g0, r0, m0), b0, m1);
__m256i p2 = _mm256_blendv_epi8(_mm256_blendv_epi8(r0, b0, m0), g0, m1);
__m256i bgr0 = _mm256_permute2x128_si256(p0, p2, 0 + 2*16);
//__m256i bgr1 = p1;
__m256i bgr2 = _mm256_permute2x128_si256(p0, p2, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgr0);
_mm256_stream_si256((__m256i*)(ptr + 16), p1);
_mm256_stream_si256((__m256i*)(ptr + 32), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgr0);
_mm256_store_si256((__m256i*)(ptr + 16), p1);
_mm256_store_si256((__m256i*)(ptr + 32), bgr2);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgr0);
_mm256_storeu_si256((__m256i*)(ptr + 16), p1);
_mm256_storeu_si256((__m256i*)(ptr + 32), bgr2);
}
}
inline void v_store_interleave( unsigned* ptr, const v_uint32x8& a, const v_uint32x8& b, const v_uint32x8& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i b0 = _mm256_shuffle_epi32(a.val, 0x6c);
__m256i g0 = _mm256_shuffle_epi32(b.val, 0xb1);
__m256i r0 = _mm256_shuffle_epi32(c.val, 0xc6);
__m256i p0 = _mm256_blend_epi32(_mm256_blend_epi32(b0, g0, 0x92), r0, 0x24);
__m256i p1 = _mm256_blend_epi32(_mm256_blend_epi32(g0, r0, 0x92), b0, 0x24);
__m256i p2 = _mm256_blend_epi32(_mm256_blend_epi32(r0, b0, 0x92), g0, 0x24);
__m256i bgr0 = _mm256_permute2x128_si256(p0, p1, 0 + 2*16);
//__m256i bgr1 = p2;
__m256i bgr2 = _mm256_permute2x128_si256(p0, p1, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgr0);
_mm256_stream_si256((__m256i*)(ptr + 8), p2);
_mm256_stream_si256((__m256i*)(ptr + 16), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgr0);
_mm256_store_si256((__m256i*)(ptr + 8), p2);
_mm256_store_si256((__m256i*)(ptr + 16), bgr2);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgr0);
_mm256_storeu_si256((__m256i*)(ptr + 8), p2);
_mm256_storeu_si256((__m256i*)(ptr + 16), bgr2);
}
}
inline void v_store_interleave( uint64* ptr, const v_uint64x4& a, const v_uint64x4& b, const v_uint64x4& c,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i s01 = _mm256_unpacklo_epi64(a.val, b.val);
__m256i s12 = _mm256_unpackhi_epi64(b.val, c.val);
__m256i s20 = _mm256_blend_epi32(c.val, a.val, 0xcc);
__m256i bgr0 = _mm256_permute2x128_si256(s01, s20, 0 + 2*16);
__m256i bgr1 = _mm256_blend_epi32(s01, s12, 0x0f);
__m256i bgr2 = _mm256_permute2x128_si256(s20, s12, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgr0);
_mm256_stream_si256((__m256i*)(ptr + 4), bgr1);
_mm256_stream_si256((__m256i*)(ptr + 8), bgr2);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgr0);
_mm256_store_si256((__m256i*)(ptr + 4), bgr1);
_mm256_store_si256((__m256i*)(ptr + 8), bgr2);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgr0);
_mm256_storeu_si256((__m256i*)(ptr + 4), bgr1);
_mm256_storeu_si256((__m256i*)(ptr + 8), bgr2);
}
}
inline void v_store_interleave( uchar* ptr, const v_uint8x32& a, const v_uint8x32& b,
const v_uint8x32& c, const v_uint8x32& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i bg0 = _mm256_unpacklo_epi8(a.val, b.val);
__m256i bg1 = _mm256_unpackhi_epi8(a.val, b.val);
__m256i ra0 = _mm256_unpacklo_epi8(c.val, d.val);
__m256i ra1 = _mm256_unpackhi_epi8(c.val, d.val);
__m256i bgra0_ = _mm256_unpacklo_epi16(bg0, ra0);
__m256i bgra1_ = _mm256_unpackhi_epi16(bg0, ra0);
__m256i bgra2_ = _mm256_unpacklo_epi16(bg1, ra1);
__m256i bgra3_ = _mm256_unpackhi_epi16(bg1, ra1);
__m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16);
__m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16);
__m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16);
__m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgra0);
_mm256_stream_si256((__m256i*)(ptr + 32), bgra1);
_mm256_stream_si256((__m256i*)(ptr + 64), bgra2);
_mm256_stream_si256((__m256i*)(ptr + 96), bgra3);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgra0);
_mm256_store_si256((__m256i*)(ptr + 32), bgra1);
_mm256_store_si256((__m256i*)(ptr + 64), bgra2);
_mm256_store_si256((__m256i*)(ptr + 96), bgra3);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgra0);
_mm256_storeu_si256((__m256i*)(ptr + 32), bgra1);
_mm256_storeu_si256((__m256i*)(ptr + 64), bgra2);
_mm256_storeu_si256((__m256i*)(ptr + 96), bgra3);
}
}
inline void v_store_interleave( ushort* ptr, const v_uint16x16& a, const v_uint16x16& b,
const v_uint16x16& c, const v_uint16x16& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i bg0 = _mm256_unpacklo_epi16(a.val, b.val);
__m256i bg1 = _mm256_unpackhi_epi16(a.val, b.val);
__m256i ra0 = _mm256_unpacklo_epi16(c.val, d.val);
__m256i ra1 = _mm256_unpackhi_epi16(c.val, d.val);
__m256i bgra0_ = _mm256_unpacklo_epi32(bg0, ra0);
__m256i bgra1_ = _mm256_unpackhi_epi32(bg0, ra0);
__m256i bgra2_ = _mm256_unpacklo_epi32(bg1, ra1);
__m256i bgra3_ = _mm256_unpackhi_epi32(bg1, ra1);
__m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16);
__m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16);
__m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16);
__m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgra0);
_mm256_stream_si256((__m256i*)(ptr + 16), bgra1);
_mm256_stream_si256((__m256i*)(ptr + 32), bgra2);
_mm256_stream_si256((__m256i*)(ptr + 48), bgra3);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgra0);
_mm256_store_si256((__m256i*)(ptr + 16), bgra1);
_mm256_store_si256((__m256i*)(ptr + 32), bgra2);
_mm256_store_si256((__m256i*)(ptr + 48), bgra3);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgra0);
_mm256_storeu_si256((__m256i*)(ptr + 16), bgra1);
_mm256_storeu_si256((__m256i*)(ptr + 32), bgra2);
_mm256_storeu_si256((__m256i*)(ptr + 48), bgra3);
}
}
inline void v_store_interleave( unsigned* ptr, const v_uint32x8& a, const v_uint32x8& b,
const v_uint32x8& c, const v_uint32x8& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i bg0 = _mm256_unpacklo_epi32(a.val, b.val);
__m256i bg1 = _mm256_unpackhi_epi32(a.val, b.val);
__m256i ra0 = _mm256_unpacklo_epi32(c.val, d.val);
__m256i ra1 = _mm256_unpackhi_epi32(c.val, d.val);
__m256i bgra0_ = _mm256_unpacklo_epi64(bg0, ra0);
__m256i bgra1_ = _mm256_unpackhi_epi64(bg0, ra0);
__m256i bgra2_ = _mm256_unpacklo_epi64(bg1, ra1);
__m256i bgra3_ = _mm256_unpackhi_epi64(bg1, ra1);
__m256i bgra0 = _mm256_permute2x128_si256(bgra0_, bgra1_, 0 + 2*16);
__m256i bgra2 = _mm256_permute2x128_si256(bgra0_, bgra1_, 1 + 3*16);
__m256i bgra1 = _mm256_permute2x128_si256(bgra2_, bgra3_, 0 + 2*16);
__m256i bgra3 = _mm256_permute2x128_si256(bgra2_, bgra3_, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgra0);
_mm256_stream_si256((__m256i*)(ptr + 8), bgra1);
_mm256_stream_si256((__m256i*)(ptr + 16), bgra2);
_mm256_stream_si256((__m256i*)(ptr + 24), bgra3);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgra0);
_mm256_store_si256((__m256i*)(ptr + 8), bgra1);
_mm256_store_si256((__m256i*)(ptr + 16), bgra2);
_mm256_store_si256((__m256i*)(ptr + 24), bgra3);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgra0);
_mm256_storeu_si256((__m256i*)(ptr + 8), bgra1);
_mm256_storeu_si256((__m256i*)(ptr + 16), bgra2);
_mm256_storeu_si256((__m256i*)(ptr + 24), bgra3);
}
}
inline void v_store_interleave( uint64* ptr, const v_uint64x4& a, const v_uint64x4& b,
const v_uint64x4& c, const v_uint64x4& d,
hal::StoreMode mode=hal::STORE_UNALIGNED )
{
__m256i bg0 = _mm256_unpacklo_epi64(a.val, b.val);
__m256i bg1 = _mm256_unpackhi_epi64(a.val, b.val);
__m256i ra0 = _mm256_unpacklo_epi64(c.val, d.val);
__m256i ra1 = _mm256_unpackhi_epi64(c.val, d.val);
__m256i bgra0 = _mm256_permute2x128_si256(bg0, ra0, 0 + 2*16);
__m256i bgra1 = _mm256_permute2x128_si256(bg1, ra1, 0 + 2*16);
__m256i bgra2 = _mm256_permute2x128_si256(bg0, ra0, 1 + 3*16);
__m256i bgra3 = _mm256_permute2x128_si256(bg1, ra1, 1 + 3*16);
if( mode == hal::STORE_ALIGNED_NOCACHE )
{
_mm256_stream_si256((__m256i*)ptr, bgra0);
_mm256_stream_si256((__m256i*)(ptr + 4), bgra1);
_mm256_stream_si256((__m256i*)(ptr + 8), bgra2);
_mm256_stream_si256((__m256i*)(ptr + 12), bgra3);
}
else if( mode == hal::STORE_ALIGNED )
{
_mm256_store_si256((__m256i*)ptr, bgra0);
_mm256_store_si256((__m256i*)(ptr + 4), bgra1);
_mm256_store_si256((__m256i*)(ptr + 8), bgra2);
_mm256_store_si256((__m256i*)(ptr + 12), bgra3);
}
else
{
_mm256_storeu_si256((__m256i*)ptr, bgra0);
_mm256_storeu_si256((__m256i*)(ptr + 4), bgra1);
_mm256_storeu_si256((__m256i*)(ptr + 8), bgra2);
_mm256_storeu_si256((__m256i*)(ptr + 12), bgra3);
}
}
#define OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(_Tpvec0, _Tp0, suffix0, _Tpvec1, _Tp1, suffix1) \
inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0 ) \
{ \
_Tpvec1 a1, b1; \
v_load_deinterleave((const _Tp1*)ptr, a1, b1); \
a0 = v_reinterpret_as_##suffix0(a1); \
b0 = v_reinterpret_as_##suffix0(b1); \
} \
inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0 ) \
{ \
_Tpvec1 a1, b1, c1; \
v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1); \
a0 = v_reinterpret_as_##suffix0(a1); \
b0 = v_reinterpret_as_##suffix0(b1); \
c0 = v_reinterpret_as_##suffix0(c1); \
} \
inline void v_load_deinterleave( const _Tp0* ptr, _Tpvec0& a0, _Tpvec0& b0, _Tpvec0& c0, _Tpvec0& d0 ) \
{ \
_Tpvec1 a1, b1, c1, d1; \
v_load_deinterleave((const _Tp1*)ptr, a1, b1, c1, d1); \
a0 = v_reinterpret_as_##suffix0(a1); \
b0 = v_reinterpret_as_##suffix0(b1); \
c0 = v_reinterpret_as_##suffix0(c1); \
d0 = v_reinterpret_as_##suffix0(d1); \
} \
inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \
hal::StoreMode mode=hal::STORE_UNALIGNED ) \
{ \
_Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
_Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
v_store_interleave((_Tp1*)ptr, a1, b1, mode); \
} \
inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, const _Tpvec0& c0, \
hal::StoreMode mode=hal::STORE_UNALIGNED ) \
{ \
_Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
_Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
_Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \
v_store_interleave((_Tp1*)ptr, a1, b1, c1, mode); \
} \
inline void v_store_interleave( _Tp0* ptr, const _Tpvec0& a0, const _Tpvec0& b0, \
const _Tpvec0& c0, const _Tpvec0& d0, \
hal::StoreMode mode=hal::STORE_UNALIGNED ) \
{ \
_Tpvec1 a1 = v_reinterpret_as_##suffix1(a0); \
_Tpvec1 b1 = v_reinterpret_as_##suffix1(b0); \
_Tpvec1 c1 = v_reinterpret_as_##suffix1(c0); \
_Tpvec1 d1 = v_reinterpret_as_##suffix1(d0); \
v_store_interleave((_Tp1*)ptr, a1, b1, c1, d1, mode); \
}
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int8x32, schar, s8, v_uint8x32, uchar, u8)
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int16x16, short, s16, v_uint16x16, ushort, u16)
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int32x8, int, s32, v_uint32x8, unsigned, u32)
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float32x8, float, f32, v_uint32x8, unsigned, u32)
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_int64x4, int64, s64, v_uint64x4, uint64, u64)
OPENCV_HAL_IMPL_AVX_LOADSTORE_INTERLEAVE(v_float64x4, double, f64, v_uint64x4, uint64, u64)
// FP16
inline v_float32x8 v256_load_expand(const float16_t* ptr)
{
return v_float32x8(_mm256_cvtph_ps(_mm_loadu_si128((const __m128i*)ptr)));
}
inline void v_pack_store(float16_t* ptr, const v_float32x8& a)
{
__m128i ah = _mm256_cvtps_ph(a.val, 0);
_mm_storeu_si128((__m128i*)ptr, ah);
}
inline void v256_cleanup() { _mm256_zeroall(); }
CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END
//! @endcond
} // cv::
#endif // OPENCV_HAL_INTRIN_AVX_HPP
| 133,266 | intrin_avx | hpp | en | cpp | code | {"qsc_code_num_words": 20015, "qsc_code_num_chars": 133266.0, "qsc_code_mean_word_length": 3.93789658, "qsc_code_frac_words_unique": 0.0358731, "qsc_code_frac_chars_top_2grams": 0.02877552, "qsc_code_frac_chars_top_3grams": 0.04535823, "qsc_code_frac_chars_top_4grams": 0.05582552, "qsc_code_frac_chars_dupe_5grams": 0.80316429, "qsc_code_frac_chars_dupe_6grams": 0.74576551, "qsc_code_frac_chars_dupe_7grams": 0.66141822, "qsc_code_frac_chars_dupe_8grams": 0.5936029, "qsc_code_frac_chars_dupe_9grams": 0.54150754, "qsc_code_frac_chars_dupe_10grams": 0.46037022, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.15988718, "qsc_code_frac_chars_whitespace": 0.21783501, "qsc_code_size_file_byte": 133266.0, "qsc_code_num_lines": 3125.0, "qsc_code_num_chars_line_max": 169.0, "qsc_code_num_chars_line_mean": 42.64512, "qsc_code_frac_chars_alphabet": 0.59625273, "qsc_code_frac_chars_comments": 0.03855447, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.26831179, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00773445, "qsc_code_frac_lines_prompt_comments": 0.00096, "qsc_code_frac_lines_assert": 0.0, "qsc_codecpp_frac_lines_preprocessor_directives": null, "qsc_codecpp_frac_lines_func_ratio": 0.28946338, "qsc_codecpp_cate_bitsstdc": 0.0, "qsc_codecpp_nums_lines_main": 0.0, "qsc_codecpp_frac_lines_goto": 0.0, "qsc_codecpp_cate_var_zero": 0.0, "qsc_codecpp_score_lines_no_logic": 0.28985507, "qsc_codecpp_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 1, "qsc_code_frac_chars_dupe_6grams": 1, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codecpp_frac_lines_func_ratio": 1, "qsc_codecpp_nums_lines_main": 0, "qsc_codecpp_score_lines_no_logic": 0, "qsc_codecpp_frac_lines_preprocessor_directives": 0, "qsc_codecpp_frac_lines_print": 0} |
00Julian00/Nova2 | external/zonos/conditioning.py | from functools import cache
from typing import Any, Literal, Iterable
import torch
import torch.nn as nn
from .config import PrefixConditionerConfig
class Conditioner(nn.Module):
def __init__(
self,
output_dim: int,
name: str,
cond_dim: int | None = None,
projection: Literal["none", "linear", "mlp"] = "none",
uncond_type: Literal["learned", "none"] = "none",
**kwargs,
):
super().__init__()
self.name = name
self.output_dim = output_dim
self.cond_dim = cond_dim = cond_dim or output_dim
if projection == "linear":
self.project = nn.Linear(cond_dim, output_dim)
elif projection == "mlp":
self.project = nn.Sequential(
nn.Linear(cond_dim, output_dim),
nn.SiLU(),
nn.Linear(output_dim, output_dim),
)
else:
self.project = nn.Identity()
self.uncond_vector = None
if uncond_type == "learned":
self.uncond_vector = nn.Parameter(torch.zeros(output_dim))
def apply_cond(self, *inputs: Any) -> torch.Tensor:
raise NotImplementedError()
def forward(self, inputs: tuple[Any, ...] | None) -> torch.Tensor:
if inputs is None:
assert self.uncond_vector is not None
return self.uncond_vector.data.view(1, 1, -1)
cond = self.apply_cond(*inputs)
cond = self.project(cond)
return cond
# ------- ESPEAK CONTAINMENT ZONE ------------------------------------------------------------------------------------------------------------------------------------------------
import re
import unicodedata
import inflect
import torch
import torch.nn as nn
from kanjize import number2kanji
from phonemizer.backend import EspeakBackend
from sudachipy import Dictionary, SplitMode
# --- Number normalization code from https://github.com/daniilrobnikov/vits2/blob/main/text/normalize_numbers.py ---
_inflect = inflect.engine()
_comma_number_re = re.compile(r"([0-9][0-9\,]+[0-9])")
_decimal_number_re = re.compile(r"([0-9]+\.[0-9]+)")
_pounds_re = re.compile(r"£([0-9\,]*[0-9]+)")
_dollars_re = re.compile(r"\$([0-9\.\,]*[0-9]+)")
_ordinal_re = re.compile(r"[0-9]+(st|nd|rd|th)")
_number_re = re.compile(r"[0-9]+")
def _remove_commas(m: re.Match) -> str:
return m.group(1).replace(",", "")
def _expand_decimal_point(m: re.Match) -> str:
return m.group(1).replace(".", " point ")
def _expand_dollars(m: re.Match) -> str:
match = m.group(1)
parts = match.split(".")
if len(parts) > 2:
return match + " dollars" # Unexpected format
dollars = int(parts[0]) if parts[0] else 0
cents = int(parts[1]) if len(parts) > 1 and parts[1] else 0
if dollars and cents:
dollar_unit = "dollar" if dollars == 1 else "dollars"
cent_unit = "cent" if cents == 1 else "cents"
return "%s %s, %s %s" % (dollars, dollar_unit, cents, cent_unit)
elif dollars:
dollar_unit = "dollar" if dollars == 1 else "dollars"
return "%s %s" % (dollars, dollar_unit)
elif cents:
cent_unit = "cent" if cents == 1 else "cents"
return "%s %s" % (cents, cent_unit)
else:
return "zero dollars"
def _expand_ordinal(m: re.Match) -> str:
return _inflect.number_to_words(m.group(0))
def _expand_number(m: re.Match) -> str:
num = int(m.group(0))
if num > 1000 and num < 3000:
if num == 2000:
return "two thousand"
elif num > 2000 and num < 2010:
return "two thousand " + _inflect.number_to_words(num % 100)
elif num % 100 == 0:
return _inflect.number_to_words(num // 100) + " hundred"
else:
return _inflect.number_to_words(num, andword="", zero="oh", group=2).replace(", ", " ")
else:
return _inflect.number_to_words(num, andword="")
def normalize_numbers(text: str) -> str:
text = re.sub(_comma_number_re, _remove_commas, text)
text = re.sub(_pounds_re, r"\1 pounds", text)
text = re.sub(_dollars_re, _expand_dollars, text)
text = re.sub(_decimal_number_re, _expand_decimal_point, text)
text = re.sub(_ordinal_re, _expand_ordinal, text)
text = re.sub(_number_re, _expand_number, text)
return text
# --- Number normalization code end ---
PAD_ID, UNK_ID, BOS_ID, EOS_ID = 0, 1, 2, 3
SPECIAL_TOKEN_IDS = [PAD_ID, UNK_ID, BOS_ID, EOS_ID]
_punctuation = ';:,.!?¡¿—…"«»“”() *~-/\\&'
_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
_letters_ipa = (
"ɑɐɒæɓʙβɔɕçɗɖðʤəɘɚɛɜɝɞɟʄɡɠɢʛɦɧħɥʜɨɪʝɭɬɫɮʟɱɯɰŋɳɲɴøɵɸθœɶʘɹɺɾɻʀʁɽʂʃʈʧʉʊʋⱱʌɣɤʍχʎʏʑʐʒʔʡʕʢǀǁǂǃˈˌːˑʼʴʰʱʲʷˠˤ˞↓↑→↗↘'̩'ᵻ"
)
symbols = [*_punctuation, *_letters, *_letters_ipa]
_symbol_to_id = {s: i for i, s in enumerate(symbols, start=len(SPECIAL_TOKEN_IDS))}
def _get_symbol_id(s: str) -> int:
return _symbol_to_id.get(s, 1)
def get_symbol_ids(text: str) -> list[int]:
return list(map(_get_symbol_id, text))
def tokenize_phonemes(phonemes: list[str]) -> tuple[torch.Tensor, list[int]]:
phoneme_ids = [[BOS_ID, *get_symbol_ids(phonemes), EOS_ID] for phonemes in phonemes]
lengths = list(map(len, phoneme_ids))
longest = max(lengths)
phoneme_ids = [[PAD_ID] * (longest - len(ids)) + ids for ids in phoneme_ids]
return torch.tensor(phoneme_ids), lengths
def normalize_jp_text(text: str, tokenizer=Dictionary(dict="full").create()) -> str:
text = unicodedata.normalize("NFKC", text)
text = re.sub(r"\d+", lambda m: number2kanji(int(m[0])), text)
final_text = " ".join([x.reading_form() for x in tokenizer.tokenize(text, SplitMode.A)])
return final_text
def clean(texts: list[str], languages: list[str]) -> list[str]:
texts_out = []
for text, language in zip(texts, languages):
if "ja" in language:
text = normalize_jp_text(text)
else:
text = normalize_numbers(text)
texts_out.append(text)
return texts_out
@cache
def get_backend(language: str) -> "EspeakBackend":
import logging
from phonemizer.backend import EspeakBackend
logger = logging.getLogger("phonemizer")
backend = EspeakBackend(
language,
preserve_punctuation=True,
with_stress=True,
punctuation_marks=_punctuation,
logger=logger,
)
logger.setLevel(logging.ERROR)
return backend
def phonemize(texts: list[str], languages: list[str]) -> list[str]:
texts = clean(texts, languages)
batch_phonemes = []
for text, language in zip(texts, languages):
backend = get_backend(language)
phonemes = backend.phonemize([text], strip=True)
batch_phonemes.append(phonemes[0])
return batch_phonemes
class EspeakPhonemeConditioner(Conditioner):
def __init__(self, output_dim: int, **kwargs):
super().__init__(output_dim, **kwargs)
self.phoneme_embedder = nn.Embedding(len(SPECIAL_TOKEN_IDS) + len(symbols), output_dim)
def apply_cond(self, texts: list[str], languages: list[str]) -> torch.Tensor:
"""
Args:
texts: list of texts to convert to phonemes
languages: ISO 639-1 -or otherwise eSpeak compatible- language code
"""
device = self.phoneme_embedder.weight.device
phonemes = phonemize(texts, languages)
phoneme_ids, _ = tokenize_phonemes(phonemes)
phoneme_embeds = self.phoneme_embedder(phoneme_ids.to(device))
return phoneme_embeds
# ------- ESPEAK CONTAINMENT ZONE ------------------------------------------------------------------------------------------------------------------------------------------------
class FourierConditioner(Conditioner):
def __init__(
self,
output_dim: int,
input_dim: int = 1,
std: float = 1.0,
min_val: float = 0.0,
max_val: float = 1.0,
**kwargs,
):
assert output_dim % 2 == 0
super().__init__(output_dim, **kwargs)
self.register_buffer("weight", torch.randn([output_dim // 2, input_dim]) * std)
self.input_dim, self.min_val, self.max_val = input_dim, min_val, max_val
def apply_cond(self, x: torch.Tensor) -> torch.Tensor:
assert x.shape[-1] == self.input_dim
x = (x - self.min_val) / (self.max_val - self.min_val) # [batch_size, seq_len, input_dim]
f = 2 * torch.pi * x.to(self.weight.dtype) @ self.weight.T # [batch_size, seq_len, output_dim // 2]
return torch.cat([f.cos(), f.sin()], dim=-1) # [batch_size, seq_len, output_dim]
class IntegerConditioner(Conditioner):
def __init__(self, output_dim: int, min_val: int = 0, max_val: int = 512, **kwargs):
super().__init__(output_dim, **kwargs)
self.min_val = min_val
self.max_val = max_val
self.int_embedder = nn.Embedding(max_val - min_val + 1, output_dim)
def apply_cond(self, x: torch.Tensor) -> torch.Tensor:
assert x.shape[-1] == 1
return self.int_embedder(x.squeeze(-1) - self.min_val) # [batch_size, seq_len, output_dim]
class PassthroughConditioner(Conditioner):
def __init__(self, output_dim: int, **kwargs):
super().__init__(output_dim, **kwargs)
def apply_cond(self, x: torch.Tensor) -> torch.Tensor:
assert x.shape[-1] == self.cond_dim
return x
_cond_cls_map = {
"PassthroughConditioner": PassthroughConditioner,
"EspeakPhonemeConditioner": EspeakPhonemeConditioner,
"FourierConditioner": FourierConditioner,
"IntegerConditioner": IntegerConditioner,
}
def build_conditioners(conditioners: list[dict], output_dim: int) -> list[Conditioner]:
return [_cond_cls_map[config["type"]](output_dim, **config) for config in conditioners]
class PrefixConditioner(Conditioner):
def __init__(self, config: PrefixConditionerConfig, output_dim: int):
super().__init__(output_dim, "prefix", projection=config.projection)
self.conditioners = nn.ModuleList(build_conditioners(config.conditioners, output_dim))
self.norm = nn.LayerNorm(output_dim)
self.required_keys = {c.name for c in self.conditioners if c.uncond_vector is None}
def forward(self, cond_dict: dict) -> torch.Tensor:
if not set(cond_dict).issuperset(self.required_keys):
raise ValueError(f"Missing required keys: {self.required_keys - set(cond_dict)}")
conds = []
for conditioner in self.conditioners:
conds.append(conditioner(cond_dict.get(conditioner.name)))
max_bsz = max(map(len, conds))
assert all(c.shape[0] in (max_bsz, 1) for c in conds)
conds = [c.expand(max_bsz, -1, -1) for c in conds]
return self.norm(self.project(torch.cat(conds, dim=-2)))
supported_language_codes = [
'af', 'am', 'an', 'ar', 'as', 'az', 'ba', 'bg', 'bn', 'bpy', 'bs', 'ca', 'cmn',
'cs', 'cy', 'da', 'de', 'el', 'en-029', 'en-gb', 'en-gb-scotland', 'en-gb-x-gbclan',
'en-gb-x-gbcwmd', 'en-gb-x-rp', 'en-us', 'eo', 'es', 'es-419', 'et', 'eu', 'fa',
'fa-latn', 'fi', 'fr-be', 'fr-ch', 'fr-fr', 'ga', 'gd', 'gn', 'grc', 'gu', 'hak',
'hi', 'hr', 'ht', 'hu', 'hy', 'hyw', 'ia', 'id', 'is', 'it', 'ja', 'jbo', 'ka',
'kk', 'kl', 'kn', 'ko', 'kok', 'ku', 'ky', 'la', 'lfn', 'lt', 'lv', 'mi', 'mk',
'ml', 'mr', 'ms', 'mt', 'my', 'nb', 'nci', 'ne', 'nl', 'om', 'or', 'pa', 'pap',
'pl', 'pt', 'pt-br', 'py', 'quc', 'ro', 'ru', 'ru-lv', 'sd', 'shn', 'si', 'sk',
'sl', 'sq', 'sr', 'sv', 'sw', 'ta', 'te', 'tn', 'tr', 'tt', 'ur', 'uz', 'vi',
'vi-vn-x-central', 'vi-vn-x-south', 'yue'
] # fmt: off
def make_cond_dict(
text: str = "It would be nice to have time for testing, indeed.",
language: str = "en-us",
speaker: torch.Tensor | None = None,
emotion: list[float] = [0.3077, 0.0256, 0.0256, 0.0256, 0.0256, 0.0256, 0.2564, 0.3077],
fmax: float = 22050.0,
pitch_std: float = 20.0,
speaking_rate: float = 15.0,
vqscore_8: list[float] = [0.78] * 8,
ctc_loss: float = 0.0,
dnsmos_ovrl: float = 4.0,
speaker_noised: bool = False,
unconditional_keys: Iterable[str] = {"vqscore_8", "dnsmos_ovrl"},
device: str = "cuda",
) -> dict:
"""
A helper to build the 'cond_dict' that the model expects.
By default, it will generate a random speaker embedding
"""
assert language.lower() in supported_language_codes, "Please pick a supported language"
language_code_to_id = {lang: i for i, lang in enumerate(supported_language_codes)}
cond_dict = {
"espeak": ([text], [language]),
"speaker": speaker,
"emotion": emotion,
"fmax": fmax,
"pitch_std": pitch_std,
"speaking_rate": speaking_rate,
"language_id": language_code_to_id[language],
"vqscore_8": vqscore_8,
"ctc_loss": ctc_loss,
"dnsmos_ovrl": dnsmos_ovrl,
"speaker_noised": int(speaker_noised),
}
for k in unconditional_keys:
cond_dict.pop(k, None)
for k, v in cond_dict.items():
if isinstance(v, (float, int, list)):
v = torch.tensor(v)
if isinstance(v, torch.Tensor):
cond_dict[k] = v.view(1, 1, -1).to(device)
if k == "emotion":
cond_dict[k] /= cond_dict[k].sum(dim=-1)
return cond_dict | 13,285 | conditioning | py | en | python | code | {"qsc_code_num_words": 1749, "qsc_code_num_chars": 13285.0, "qsc_code_mean_word_length": 4.45454545, "qsc_code_frac_words_unique": 0.24128073, "qsc_code_frac_chars_top_2grams": 0.03465537, "qsc_code_frac_chars_top_3grams": 0.01078167, "qsc_code_frac_chars_top_4grams": 0.00924143, "qsc_code_frac_chars_dupe_5grams": 0.21255295, "qsc_code_frac_chars_dupe_6grams": 0.18752407, "qsc_code_frac_chars_dupe_7grams": 0.14619433, "qsc_code_frac_chars_dupe_8grams": 0.10935695, "qsc_code_frac_chars_dupe_9grams": 0.07418817, "qsc_code_frac_chars_dupe_10grams": 0.04697728, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01831678, "qsc_code_frac_chars_whitespace": 0.21919458, "qsc_code_size_file_byte": 13285.0, "qsc_code_num_lines": 373.0, "qsc_code_num_chars_line_max": 179.0, "qsc_code_num_chars_line_mean": 35.61662198, "qsc_code_frac_chars_alphabet": 0.7312253, "qsc_code_frac_chars_comments": 0.0687994, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.1299639, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.09915475, "qsc_code_frac_chars_long_word_length": 0.0168238, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.02527076, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.10108303, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.00722022, "qsc_codepython_frac_lines_import": 0.05415162, "qsc_codepython_frac_lines_simplefunc": 0.021660649819494584, "qsc_codepython_score_lines_no_logic": 0.28519856, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00Julian00/Nova2 | external/zonos/backbone.py | import torch
import torch.nn as nn
from mamba_ssm.models.mixer_seq_simple import create_block
from mamba_ssm.ops.triton.layer_norm import layer_norm_fn
from mamba_ssm.utils.generation import InferenceParams
from .config import BackboneConfig
class ZonosBackbone(nn.Module):
def __init__(self, config: BackboneConfig):
super().__init__()
self.config = config
self.layers = nn.ModuleList(
[
create_block(
d_model=config.d_model,
d_intermediate=config.d_intermediate
if (i not in config.attn_layer_idx)
else config.attn_mlp_d_intermediate,
ssm_cfg=config.ssm_cfg,
layer_idx=i,
attn_layer_idx=config.attn_layer_idx,
attn_cfg=config.attn_cfg,
norm_epsilon=config.norm_epsilon,
residual_in_fp32=config.residual_in_fp32,
fused_add_norm=True,
rms_norm=config.rms_norm,
)
for i in range(config.n_layer)
]
)
self.norm_f = nn.LayerNorm(config.d_model, eps=config.norm_epsilon)
def forward(self, hidden_states: torch.Tensor, inference_params: InferenceParams | None = None):
residual = None
for layer in self.layers:
hidden_states, residual = layer(hidden_states, residual, inference_params)
return layer_norm_fn(
hidden_states,
self.norm_f.weight,
self.norm_f.bias,
residual,
eps=self.norm_f.eps,
residual_in_fp32=self.config.residual_in_fp32,
is_rms_norm=self.config.rms_norm,
) | 1,763 | backbone | py | en | python | code | {"qsc_code_num_words": 206, "qsc_code_num_chars": 1763.0, "qsc_code_mean_word_length": 4.77669903, "qsc_code_frac_words_unique": 0.33009709, "qsc_code_frac_chars_top_2grams": 0.04065041, "qsc_code_frac_chars_top_3grams": 0.05691057, "qsc_code_frac_chars_top_4grams": 0.03658537, "qsc_code_frac_chars_dupe_5grams": 0.0, "qsc_code_frac_chars_dupe_6grams": 0.0, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00683177, "qsc_code_frac_chars_whitespace": 0.33579126, "qsc_code_size_file_byte": 1763.0, "qsc_code_num_lines": 50.0, "qsc_code_num_chars_line_max": 101.0, "qsc_code_num_chars_line_mean": 35.26, "qsc_code_frac_chars_alphabet": 0.83347566, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.04651163, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.13953488, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.23255814, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00Julian00/Nova2 | external/zonos/model.py | import json
import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download
from mamba_ssm.utils.generation import InferenceParams
from safetensors.torch import load_model
from .autoencoder import DACAutoencoder
from .backbone import ZonosBackbone
from .codebook_pattern import apply_delay_pattern, revert_delay_pattern
from .conditioning import PrefixConditioner
from .config import ZonosConfig
from .sampling import sample_from_logits
from .speaker_cloning import SpeakerEmbeddingLDA
class Zonos(nn.Module):
def __init__(self, config: ZonosConfig):
super().__init__()
self.config = config
dim = config.backbone.d_model
self.eos_token_id = config.eos_token_id
self.masked_token_id = config.masked_token_id
self.autoencoder = DACAutoencoder()
self.backbone = ZonosBackbone(config.backbone)
self.prefix_conditioner = PrefixConditioner(config.prefix_conditioner, dim)
self.spk_clone_model = None
# TODO: pad to multiple of at least 8
self.embeddings = nn.ModuleList([nn.Embedding(1026, dim) for _ in range(self.autoencoder.num_codebooks)])
self.heads = nn.ModuleList([nn.Linear(dim, 1025, bias=False) for _ in range(self.autoencoder.num_codebooks)])
self._cg_graph = None
self._cg_batch_size = None
self._cg_input_ids = None
self._cg_logits = None
self._cg_inference_params = None
self._cg_scale = None
@classmethod
def from_pretrained(cls, repo_id: str, revision: str | None = None, device: str = "cuda") -> "Zonos":
config_path = hf_hub_download(repo_id=repo_id, filename="config.json", revision=revision)
model_path = hf_hub_download(repo_id=repo_id, filename="model.safetensors", revision=revision)
return cls.from_local(config_path, model_path, device)
@classmethod
def from_local(cls, config_path: str, model_path: str, device: str = "cuda") -> "Zonos":
config = ZonosConfig.from_dict(json.load(open(config_path)))
with torch.device(device):
model = cls(config)
load_model(model, model_path, device=device)
return model.bfloat16()
def make_speaker_embedding(self, wav: torch.Tensor, sr: int) -> torch.Tensor:
"""Generate a speaker embedding from an audio clip."""
if self.spk_clone_model is None:
self.spk_clone_model = SpeakerEmbeddingLDA()
_, spk_embedding = self.spk_clone_model(wav.to(self.spk_clone_model.device), sr)
return spk_embedding.unsqueeze(0).bfloat16()
def embed_codes(self, codes: torch.Tensor) -> torch.Tensor:
return sum(emb(codes[:, i]) for i, emb in enumerate(self.embeddings))
def apply_heads(self, hidden_states: torch.Tensor) -> torch.Tensor:
return torch.stack([head(hidden_states) for head in self.heads], dim=1)
def _compute_logits(
self, hidden_states: torch.Tensor, inference_params: InferenceParams, cfg_scale: float
) -> torch.Tensor:
"""
Pass `hidden_states` into `backbone` and `multi_head`, applying
classifier-free guidance if `cfg_scale != 1.0`.
"""
last_hidden_states = self.backbone(hidden_states, inference_params)[:, -1, :].unsqueeze(1)
logits = self.apply_heads(last_hidden_states).squeeze(2).float()
if cfg_scale != 1.0:
cond_logits, uncond_logits = logits.chunk(2)
logits = uncond_logits + (cond_logits - uncond_logits) * cfg_scale
return logits
def _decode_one_token(
self,
input_ids: torch.Tensor,
inference_params: InferenceParams,
cfg_scale: float,
) -> torch.Tensor:
"""
Single-step decode. Prepares the hidden states, possibly replicates them
for CFG, and then delegates to `_compute_logits`.
Below we wrap this function with a simple CUDA Graph capturing mechanism,
doing 3 warmup steps if needed and then capturing or replaying the graph.
We only recapture if the batch size changes.
"""
# TODO: support cfg_scale==1
if cfg_scale == 1.0:
hidden_states = self.embed_codes(input_ids)
return self._compute_logits(hidden_states, inference_params, cfg_scale)
bsz = input_ids.size(0)
need_capture = (self._cg_graph is None) or (self._cg_batch_size != bsz)
if need_capture:
self._cg_graph = None
self._cg_batch_size = bsz
self._cg_inference_params = inference_params
self._cg_scale = cfg_scale
for _ in range(3):
hidden_states = self.embed_codes(input_ids)
hidden_states = hidden_states.repeat(2, 1, 1) # because cfg != 1.0
logits = self._compute_logits(hidden_states, inference_params, cfg_scale)
self._cg_input_ids = input_ids.clone()
self._cg_logits = torch.empty_like(logits)
g = torch.cuda.CUDAGraph()
def capture_region():
hidden_states_local = self.embed_codes(self._cg_input_ids)
hidden_states_local = hidden_states_local.repeat(2, 1, 1)
self._cg_logits = self._compute_logits(hidden_states_local, self._cg_inference_params, self._cg_scale)
with torch.cuda.graph(g):
capture_region()
self._cg_graph = g
else:
self._cg_input_ids.copy_(input_ids)
self._cg_graph.replay()
return self._cg_logits
def _prefill(
self,
prefix_hidden_states: torch.Tensor,
input_ids: torch.Tensor,
inference_params: InferenceParams,
cfg_scale: float,
) -> torch.Tensor:
"""
"Prefill" mode: we already have `prefix_hidden_states`, and we want
to append new embeddings, then compute the logits.
"""
# Replicate input_ids if CFG is enabled
if cfg_scale != 1.0:
input_ids = input_ids.expand(prefix_hidden_states.shape[0], -1, -1)
hidden_states = torch.cat([prefix_hidden_states, self.embed_codes(input_ids)], dim=1)
return self._compute_logits(hidden_states, inference_params, cfg_scale)
def setup_cache(self, batch_size: int, max_seqlen: int, dtype: torch.dtype = torch.bfloat16) -> InferenceParams:
key_value_memory_dict = {
i: layer.allocate_inference_cache(batch_size, max_seqlen, dtype=dtype)
for i, layer in enumerate(self.backbone.layers)
}
lengths_per_sample = torch.full((batch_size,), 0, dtype=torch.int32, device="cuda")
return InferenceParams(max_seqlen, batch_size, 0, 0, key_value_memory_dict, lengths_per_sample)
def prepare_conditioning(self, cond_dict: dict, uncond_dict: dict | None = None, device: str = "cuda") -> torch.Tensor:
if uncond_dict is None:
uncond_dict = {k: cond_dict[k] for k in self.prefix_conditioner.required_keys}
return torch.cat(
[
self.prefix_conditioner(cond_dict),
self.prefix_conditioner(uncond_dict),
]
)
def _disallow_cb_not_zero_eos(self, logits):
eos_bias = torch.zeros_like(logits)
eos_bias[:, 1:, self.eos_token_id] = -1e9
return logits + eos_bias
@torch.inference_mode()
def generate(
self,
prefix_conditioning: torch.Tensor, # [bsz, cond_seq_len, d_model]
audio_prefix_codes: torch.Tensor | None = None, # [bsz, 9, prefix_audio_seq_len]
max_new_tokens: int = 86 * 30,
cfg_scale: float = 2.0,
batch_size: int = 1,
sampling_params: dict = dict(min_p=0.1),
):
assert cfg_scale != 1, "TODO: add support for cfg_scale=1"
prefix_audio_len = 0 if audio_prefix_codes is None else audio_prefix_codes.shape[2]
unknown_token = -1
seq_len = prefix_conditioning.shape[1] + prefix_audio_len + max_new_tokens
inference_params = self.setup_cache(batch_size=batch_size * 2, max_seqlen=seq_len)
codes = torch.full((batch_size, 9, seq_len), unknown_token, device="cuda")
if audio_prefix_codes is not None:
codes[..., :prefix_audio_len] = audio_prefix_codes
delayed_codes = apply_delay_pattern(codes, self.masked_token_id)
delayed_prefix_audio_codes = delayed_codes[..., : prefix_audio_len + 1]
logits = self._prefill(prefix_conditioning, delayed_prefix_audio_codes, inference_params, cfg_scale)
next_token = sample_from_logits(logits, **sampling_params)
offset = delayed_prefix_audio_codes.shape[2]
frame = delayed_codes[..., offset : offset + 1]
frame.masked_scatter_(frame == unknown_token, next_token)
prefix_length = prefix_conditioning.shape[1] + prefix_audio_len + 1
inference_params.seqlen_offset += prefix_length
inference_params.lengths_per_sample[:] += prefix_length
for offset in range(offset + 1, delayed_codes.shape[2]):
input_ids = delayed_codes[..., offset - 1 : offset]
logits = self._decode_one_token(input_ids, inference_params, cfg_scale)
logits = self._disallow_cb_not_zero_eos(logits)
next_token = sample_from_logits(logits, generated_tokens=delayed_codes[..., :offset], **sampling_params)
if offset > 8 and (next_token == self.eos_token_id).any():
break
frame = delayed_codes[..., offset : offset + 1]
frame.masked_scatter_(frame == unknown_token, next_token)
inference_params.seqlen_offset += 1
inference_params.lengths_per_sample[:] += 1
out_codes = revert_delay_pattern(delayed_codes)
out_codes.masked_fill_(out_codes >= 1024, 0)
out_codes = out_codes[..., : offset - 9]
self._cg_graph = None # reset cuda graph to avoid cache changes
return out_codes
| 9,944 | model | py | en | python | code | {"qsc_code_num_words": 1279, "qsc_code_num_chars": 9944.0, "qsc_code_mean_word_length": 4.85613761, "qsc_code_frac_words_unique": 0.19468335, "qsc_code_frac_chars_top_2grams": 0.04636934, "qsc_code_frac_chars_top_3grams": 0.01014329, "qsc_code_frac_chars_top_4grams": 0.0136854, "qsc_code_frac_chars_dupe_5grams": 0.23844791, "qsc_code_frac_chars_dupe_6grams": 0.16422476, "qsc_code_frac_chars_dupe_7grams": 0.14764128, "qsc_code_frac_chars_dupe_8grams": 0.11898245, "qsc_code_frac_chars_dupe_9grams": 0.09676381, "qsc_code_frac_chars_dupe_10grams": 0.07647722, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01182253, "qsc_code_frac_chars_whitespace": 0.24296058, "qsc_code_size_file_byte": 9944.0, "qsc_code_num_lines": 236.0, "qsc_code_num_chars_line_max": 124.0, "qsc_code_num_chars_line_mean": 42.13559322, "qsc_code_frac_chars_alphabet": 0.81323061, "qsc_code_frac_chars_comments": 0.0821601, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.15789474, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01011336, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00847458, "qsc_code_frac_lines_assert": 0.00584795, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.08187135, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.07602339, "qsc_codepython_frac_lines_simplefunc": 0.011695906432748537, "qsc_codepython_score_lines_no_logic": 0.23976608, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/ItemSlot.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.Key;
import com.shatteredpixel.shatteredpixeldungeon.items.keys.SkeletonKey;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic.ExoticPotion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ExoticScroll;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
public class ItemSlot extends Button<GameAction> {
public static final int DEGRADED = 0xFF4444;
public static final int UPGRADED = 0x44FF44;
public static final int FADED = 0x999999;
public static final int WARNING = 0xFF8800;
private static final float ENABLED = 1.0f;
private static final float DISABLED = 0.3f;
protected ItemSprite icon;
protected Item item;
protected BitmapText topLeft;
protected BitmapText topRight;
protected BitmapText bottomRight;
protected Image bottomRightIcon;
protected boolean iconVisible = true;
private static final String TXT_STRENGTH = ":%d";
private static final String TXT_TYPICAL_STR = "%d?";
private static final String TXT_KEY_DEPTH = "\u007F%d";
private static final String TXT_LEVEL = "%+d";
private static final String TXT_CURSED = "";//"-";
// Special "virtual items"
public static final Item CHEST = new Item() {
public int image() { return ItemSpriteSheet.CHEST; }
};
public static final Item LOCKED_CHEST = new Item() {
public int image() { return ItemSpriteSheet.LOCKED_CHEST; }
};
public static final Item CRYSTAL_CHEST = new Item() {
public int image() { return ItemSpriteSheet.CRYSTAL_CHEST; }
};
public static final Item TOMB = new Item() {
public int image() { return ItemSpriteSheet.TOMB; }
};
public static final Item SKELETON = new Item() {
public int image() { return ItemSpriteSheet.BONES; }
};
public static final Item REMAINS = new Item() {
public int image() { return ItemSpriteSheet.REMAINS; }
};
public ItemSlot() {
super();
icon.visible(false);
enable(false);
}
public ItemSlot( Item item ) {
this();
item( item );
}
@Override
protected void createChildren() {
super.createChildren();
icon = new ItemSprite();
add( icon );
topLeft = new BitmapText( PixelScene.pixelFont);
add( topLeft );
topRight = new BitmapText( PixelScene.pixelFont);
add( topRight );
bottomRight = new BitmapText( PixelScene.pixelFont);
add( bottomRight );
}
@Override
protected void layout() {
super.layout();
icon.x = x + (width - icon.width) / 2f;
icon.y = y + (height - icon.height) / 2f;
PixelScene.align(icon);
if (topLeft != null) {
topLeft.measure();
if (topLeft.width > width){
topLeft.scale.set(PixelScene.align(0.8f));
} else {
topLeft.scale.set(1f);
}
topLeft.x = x;
topLeft.y = y;
PixelScene.align(topLeft);
}
if (topRight != null) {
topRight.x = x + (width - topRight.width());
topRight.y = y;
PixelScene.align(topRight);
}
if (bottomRight != null) {
bottomRight.x = x + (width - bottomRight.width());
bottomRight.y = y + (height - bottomRight.height());
PixelScene.align(bottomRight);
}
if (bottomRightIcon != null) {
bottomRightIcon.x = x + (width - bottomRightIcon.width()) -1;
bottomRightIcon.y = y + (height - bottomRightIcon.height());
PixelScene.align(bottomRightIcon);
}
}
public void item( Item item ) {
if (this.item == item) {
if (item != null) {
icon.frame(item.image());
icon.glow(item.glowing());
}
updateText();
return;
}
this.item = item;
if (item == null) {
enable(false);
icon.visible(false);
updateText();
} else {
enable(true);
icon.visible(true);
icon.view( item );
updateText();
}
}
private void updateText(){
if (bottomRightIcon != null){
remove(bottomRightIcon);
bottomRightIcon = null;
}
if (item == null){
topLeft.visible = topRight.visible = bottomRight.visible = false;
return;
} else {
topLeft.visible = topRight.visible = bottomRight.visible = true;
}
topLeft.text( item.status() );
boolean isArmor = item instanceof Armor;
boolean isWeapon = item instanceof Weapon;
if (isArmor || isWeapon) {
if (item.levelKnown || (isWeapon && !(item instanceof MeleeWeapon))) {
int str = isArmor ? ((Armor)item).STRReq() : ((Weapon)item).STRReq();
topRight.text( Messages.format( TXT_STRENGTH, str ) );
if (str > Dungeon.hero.STR()) {
topRight.hardlight( DEGRADED );
} else {
topRight.resetColor();
}
} else {
topRight.text( Messages.format( TXT_TYPICAL_STR, isArmor ?
((Armor)item).STRReq(0) :
((Weapon)item).STRReq(0) ) );
topRight.hardlight( WARNING );
}
topRight.measure();
} else if (item instanceof Key && !(item instanceof SkeletonKey)) {
topRight.text(Messages.format(TXT_KEY_DEPTH, ((Key) item).depth));
topRight.measure();
} else {
topRight.text( null );
}
int level = item.visiblyUpgraded();
if (level != 0) {
bottomRight.text( item.levelKnown ? Messages.format( TXT_LEVEL, level ) : TXT_CURSED );
bottomRight.measure();
bottomRight.hardlight( level > 0 ? UPGRADED : DEGRADED );
} else if (item instanceof Scroll || item instanceof Potion) {
bottomRight.text( null );
Integer iconInt;
if (item instanceof Scroll){
iconInt = ((Scroll) item).initials();
} else {
iconInt = ((Potion) item).initials();
}
if (iconInt != null && iconVisible) {
bottomRightIcon = new Image(Assets.CONS_ICONS);
int left = iconInt*7;
int top;
if (item instanceof Potion){
if (item instanceof ExoticPotion){
top = 8;
} else {
top = 0;
}
} else {
if (item instanceof ExoticScroll){
top = 24;
} else {
top = 16;
}
}
bottomRightIcon.frame(left, top, 7, 8);
add(bottomRightIcon);
}
} else {
bottomRight.text( null );
}
layout();
}
public void enable( boolean value ) {
active = value;
float alpha = value ? ENABLED : DISABLED;
icon.alpha( alpha );
topLeft.alpha( alpha );
topRight.alpha( alpha );
bottomRight.alpha( alpha );
if (bottomRightIcon != null) bottomRightIcon.alpha( alpha );
}
public void showParams( boolean TL, boolean TR, boolean BR ) {
if (TL) add( topLeft );
else remove( topLeft );
if (TR) add( topRight );
else remove( topRight );
if (BR) add( bottomRight );
else remove( bottomRight );
iconVisible = BR;
}
}
| 8,201 | ItemSlot | java | en | java | code | {"qsc_code_num_words": 930, "qsc_code_num_chars": 8201.0, "qsc_code_mean_word_length": 6.06451613, "qsc_code_frac_words_unique": 0.24193548, "qsc_code_frac_chars_top_2grams": 0.03191489, "qsc_code_frac_chars_top_3grams": 0.1212766, "qsc_code_frac_chars_top_4grams": 0.13262411, "qsc_code_frac_chars_dupe_5grams": 0.28120567, "qsc_code_frac_chars_dupe_6grams": 0.17960993, "qsc_code_frac_chars_dupe_7grams": 0.04734043, "qsc_code_frac_chars_dupe_8grams": 0.025, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0098128, "qsc_code_frac_chars_whitespace": 0.19229362, "qsc_code_size_file_byte": 8201.0, "qsc_code_num_lines": 301.0, "qsc_code_num_chars_line_max": 91.0, "qsc_code_num_chars_line_mean": 27.24584718, "qsc_code_frac_chars_alphabet": 0.84163647, "qsc_code_frac_chars_comments": 0.09913425, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.15929204, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00230103, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00433135, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05309735, "qsc_codejava_score_lines_no_logic": 0.19026549, "qsc_codejava_frac_words_no_modifier": 0.92307692, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/HealthBar.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.ui.Component;
public class HealthBar extends Component {
private static final int COLOR_BG = 0xFFCC0000;
private static final int COLOR_HP = 0xFF00EE00;
private static final int COLOR_SHLD = 0xFFBBEEBB;
private static final int HEIGHT = 2;
private ColorBlock Bg;
private ColorBlock Shld;
private ColorBlock Hp;
private float health;
private float shield;
@Override
protected void createChildren() {
Bg = new ColorBlock( 1, 1, COLOR_BG );
add( Bg );
Shld = new ColorBlock( 1, 1, COLOR_SHLD );
add( Shld );
Hp = new ColorBlock( 1, 1, COLOR_HP );
add( Hp );
height = HEIGHT;
}
@Override
protected void layout() {
Bg.x = Shld.x = Hp.x = x;
Bg.y = Shld.y = Hp.y = y;
Bg.size( width, height );
//logic here rounds up to the nearest pixel
float pixelWidth = width;
if (camera() != null) pixelWidth *= camera().zoom;
Shld.size( width * (float)Math.ceil(shield * pixelWidth)/pixelWidth, height );
Hp.size( width * (float)Math.ceil(health * pixelWidth)/pixelWidth, height );
}
public void level( float value ) {
level( value, 0f );
}
public void level( float health, float shield ){
this.health = health;
this.shield = shield;
layout();
}
public void level(Char c){
float health = c.HP;
float shield = c.shielding();
float max = Math.max(health+shield, c.HT);
level(health/max, (health+shield)/max);
}
}
| 2,281 | HealthBar | java | en | java | code | {"qsc_code_num_words": 322, "qsc_code_num_chars": 2281.0, "qsc_code_mean_word_length": 4.96273292, "qsc_code_frac_words_unique": 0.41614907, "qsc_code_frac_chars_top_2grams": 0.03254068, "qsc_code_frac_chars_top_3grams": 0.04505632, "qsc_code_frac_chars_top_4grams": 0.05256571, "qsc_code_frac_chars_dupe_5grams": 0.16520651, "qsc_code_frac_chars_dupe_6grams": 0.0350438, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01528384, "qsc_code_frac_chars_whitespace": 0.19684349, "qsc_code_size_file_byte": 2281.0, "qsc_code_num_lines": 85.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 26.83529412, "qsc_code_frac_chars_alphabet": 0.8569869, "qsc_code_frac_chars_comments": 0.32967996, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04081633, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.01962067, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.10204082, "qsc_codejava_score_lines_no_logic": 0.28571429, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/ScrollPane.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Point;
import com.watabou.utils.PointF;
public class ScrollPane extends Component {
protected static final int THUMB_COLOR = 0xFF7b8073;
protected static final float THUMB_ALPHA = 0.5f;
protected TouchController controller;
protected Component content;
protected ColorBlock thumb;
protected float minX;
protected float minY;
protected float maxX;
protected float maxY;
public ScrollPane( Component content ) {
super();
this.content = content;
addToBack( content );
width = content.width();
height = content.height();
content.camera = new Camera( 0, 0, 1, 1, PixelScene.defaultZoom );
Camera.add( content.camera );
}
@Override
public void destroy() {
super.destroy();
Camera.remove( content.camera );
}
public void scrollTo( float x, float y ) {
content.camera.scroll.set( x, y );
}
@Override
protected void createChildren() {
controller = new TouchController();
add( controller );
thumb = new ColorBlock( 1, 1, THUMB_COLOR );
thumb.am = THUMB_ALPHA;
add( thumb );
}
@Override
protected void layout() {
content.setPos( 0, 0 );
controller.x = x;
controller.y = y;
controller.width = width;
controller.height = height;
Point p = camera().cameraToScreen( x, y );
Camera cs = content.camera;
cs.x = p.x;
cs.y = p.y;
cs.resize( (int)width, (int)height );
thumb.visible = height < content.height();
if (thumb.visible) {
thumb.scale.set( 2, height * height / content.height() );
thumb.x = right() - thumb.width();
thumb.y = y;
}
}
public Component content() {
return content;
}
public void onClick( float x, float y ) {
}
public class TouchController extends TouchArea {
private float dragThreshold;
public TouchController() {
super( 0, 0, 0, 0 );
dragThreshold = PixelScene.defaultZoom * 8;
}
@Override
protected void onTouchUp( NoosaInputProcessor.Touch touch ) {
if (dragging) {
dragging = false;
thumb.am = THUMB_ALPHA;
} else {
PointF p = content.camera.screenToCamera( (int)touch.current.x, (int)touch.current.y );
ScrollPane.this.onClick( p.x, p.y );
}
}
private boolean dragging = false;
private PointF lastPos = new PointF();
@Override
protected void onDrag( NoosaInputProcessor.Touch t ) {
if (dragging) {
doScroll(t.current);
} else if (PointF.distance( t.current, t.start ) > dragThreshold) {
dragging = true;
lastPos.set( t.current );
thumb.am = 1;
}
}
@Override
public boolean onMouseScroll(int scroll) {
PointF newPt = new PointF(lastPos);
newPt.y -= scroll * content.camera.zoom * 4;
doScroll(newPt);
return true;
}
private void doScroll(PointF current) {
final Camera c = content.camera;
c.shift( PointF.diff(lastPos, current).invScale( c.zoom ) );
if (c.scroll.x + width > content.width()) {
c.scroll.x = content.width() - width;
}
if (c.scroll.x < 0) {
c.scroll.x = 0;
}
if (c.scroll.y + height > content.height()) {
c.scroll.y = content.height() - height;
}
if (c.scroll.y < 0) {
c.scroll.y = 0;
}
thumb.y = y + height * c.scroll.y / content.height();
lastPos.set(current);
}
}
}
| 4,296 | ScrollPane | java | en | java | code | {"qsc_code_num_words": 555, "qsc_code_num_chars": 4296.0, "qsc_code_mean_word_length": 5.27387387, "qsc_code_frac_words_unique": 0.31351351, "qsc_code_frac_chars_top_2grams": 0.02152374, "qsc_code_frac_chars_top_3grams": 0.03826443, "qsc_code_frac_chars_top_4grams": 0.02869833, "qsc_code_frac_chars_dupe_5grams": 0.04646396, "qsc_code_frac_chars_dupe_6grams": 0.03758114, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01311953, "qsc_code_frac_chars_whitespace": 0.20158287, "qsc_code_size_file_byte": 4296.0, "qsc_code_num_lines": 181.0, "qsc_code_num_chars_line_max": 92.0, "qsc_code_num_chars_line_mean": 23.73480663, "qsc_code_frac_chars_alphabet": 0.84023324, "qsc_code_frac_chars_comments": 0.18179702, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.08130081, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00284495, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08130081, "qsc_codejava_score_lines_no_logic": 0.24390244, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickSlotButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.PathFinder;
public class QuickSlotButton extends Button<GameAction> implements WndBag.Listener {
private static QuickSlotButton[] instance = new QuickSlotButton[4];
private int slotNum;
private ItemSlot slot;
private static Image crossB;
private static Image crossM;
private static boolean targeting = false;
public static Char lastTarget = null;
public QuickSlotButton( int slotNum, GameAction hotKey ) {
super();
this.slotNum = slotNum;
item( select( slotNum ) );
instance[slotNum] = this;
slot.hotKey = this.hotKey = hotKey;
}
@Override
public void destroy() {
super.destroy();
reset();
}
public static void reset() {
instance = new QuickSlotButton[4];
lastTarget = null;
}
@Override
protected void createChildren() {
super.createChildren();
slot = new ItemSlot() {
@Override
protected void onClick() {
if (!Dungeon.hero.isAlive())
return;
if (NoosaInputProcessor.modifier) {
onLongClick();
return;
}
if (targeting) {
int cell = autoAim(lastTarget, select(slotNum));
if (cell != -1){
GameScene.handleCell(cell);
} else {
//couldn't auto-aim, just target the position and hope for the best.
GameScene.handleCell( lastTarget.pos );
}
} else {
Item item = select(slotNum);
if (item.usesTargeting)
useTargeting();
item.execute( Dungeon.hero );
}
}
@Override
protected boolean onLongClick() {
return QuickSlotButton.this.onLongClick();
}
@Override
protected void onTouchDown() {
icon.lightness( 0.7f );
}
@Override
protected void onTouchUp() {
icon.resetColor();
}
};
slot.showParams( true, false, true );
add( slot );
crossB = Icons.TARGET.get();
crossB.visible = false;
add( crossB );
crossM = new Image();
crossM.copy( crossB );
}
@Override
protected void layout() {
super.layout();
slot.fill( this );
crossB.x = x + (width - crossB.width) / 2;
crossB.y = y + (height - crossB.height) / 2;
PixelScene.align(crossB);
}
@Override
protected void onClick() {
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, Messages.get(this, "select_item") );
}
@Override
protected boolean onLongClick() {
GameScene.selectItem( this, WndBag.Mode.QUICKSLOT, Messages.get(this, "select_item") );
return true;
}
private static Item select(int slotNum){
return Dungeon.quickslot.getItem( slotNum );
}
@Override
public void onSelect( Item item ) {
if (item != null) {
Dungeon.quickslot.setSlot( slotNum , item );
refresh();
}
}
public void item( Item item ) {
slot.item( item );
enableSlot();
}
public void enable( boolean value ) {
active = value;
if (value) {
enableSlot();
} else {
slot.enable( false );
}
}
private void enableSlot() {
slot.enable(Dungeon.quickslot.isNonePlaceholder( slotNum ));
}
private void useTargeting() {
if (lastTarget != null &&
Actor.chars().contains( lastTarget ) &&
lastTarget.isAlive() &&
Dungeon.level.heroFOV[lastTarget.pos]) {
targeting = true;
CharSprite sprite = lastTarget.sprite;
sprite.parent.addToFront( crossM );
crossM.point(sprite.center(crossM));
crossB.point(slot.icon.center(crossB));
crossB.visible = true;
} else {
lastTarget = null;
targeting = false;
}
}
public static int autoAim(Char target){
//will use generic projectile logic if no item is specified
return autoAim(target, new Item());
}
//FIXME: this is currently very expensive, should either optimize ballistica or this, or both
public static int autoAim(Char target, Item item){
//first try to directly target
if (item.throwPos(Dungeon.hero, target.pos) == target.pos) {
return target.pos;
}
//Otherwise pick nearby tiles to try and 'angle' the shot, auto-aim basically.
PathFinder.buildDistanceMap( target.pos, BArray.not( new boolean[Dungeon.level.length()], null ), 2 );
for (int i = 0; i < PathFinder.distance.length; i++) {
if (PathFinder.distance[i] < Integer.MAX_VALUE
&& item.throwPos(Dungeon.hero, i) == target.pos)
return i;
}
//couldn't find a cell, give up.
return -1;
}
public static void refresh() {
for (int i = 0; i < instance.length; i++) {
if (instance[i] != null) {
instance[i].item(select(i));
}
}
}
public static void target( Char target ) {
if (target != null && target.alignment != Char.Alignment.ALLY) {
lastTarget = target;
TargetHealthIndicator.instance.target( target );
}
}
public static void cancel() {
if (targeting) {
crossB.visible = false;
crossM.remove();
targeting = false;
}
}
}
| 6,328 | QuickSlotButton | java | en | java | code | {"qsc_code_num_words": 738, "qsc_code_num_chars": 6328.0, "qsc_code_mean_word_length": 5.98238482, "qsc_code_frac_words_unique": 0.32655827, "qsc_code_frac_chars_top_2grams": 0.03057758, "qsc_code_frac_chars_top_3grams": 0.10328426, "qsc_code_frac_chars_top_4grams": 0.10962627, "qsc_code_frac_chars_dupe_5grams": 0.11279728, "qsc_code_frac_chars_dupe_6grams": 0.05753114, "qsc_code_frac_chars_dupe_7grams": 0.03035108, "qsc_code_frac_chars_dupe_8grams": 0.03035108, "qsc_code_frac_chars_dupe_9grams": 0.03035108, "qsc_code_frac_chars_dupe_10grams": 0.03035108, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00545065, "qsc_code_frac_chars_whitespace": 0.18821113, "qsc_code_size_file_byte": 6328.0, "qsc_code_num_lines": 254.0, "qsc_code_num_chars_line_max": 105.0, "qsc_code_num_chars_line_mean": 24.91338583, "qsc_code_frac_chars_alphabet": 0.85400039, "qsc_code_frac_chars_comments": 0.18030973, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.17679558, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00424137, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00393701, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.12154696, "qsc_codejava_score_lines_no_logic": 0.25414365, "qsc_codejava_frac_words_no_modifier": 0.91304348, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/StyledButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
//simple button which support a background chrome, text, and an icon.
public class StyledButton extends Button<GameAction> {
protected NinePatch bg;
protected RenderedTextBlock text;
protected Image icon;
public StyledButton(Chrome.Type type, String label ) {
this(type, label, 9);
}
public StyledButton(Chrome.Type type, String label, int size ){
super();
bg = Chrome.get( type );
addToBack( bg );
text = PixelScene.renderTextBlock( size );
text.text( label );
add( text );
}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
float componentWidth = 0;
if (icon != null) componentWidth += icon.width() + 2;
if (text != null && !text.text().equals("")){
componentWidth += text.width() + 2;
text.setPos(
x + (width() + componentWidth)/2f - text.width() - 1,
y + (height() - text.height()) / 2f
);
PixelScene.align(text);
}
if (icon != null) {
icon.x = x + (width() - componentWidth)/2f + 1;
icon.y = y + (height() - icon.height()) / 2f;
PixelScene.align(icon);
}
}
@Override
protected void onTouchDown() {
bg.brightness( 1.2f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
bg.resetColor();
}
public void enable( boolean value ) {
active = value;
text.alpha( value ? 1.0f : 0.3f );
}
public void text( String value ) {
text.text( value );
layout();
}
public void textColor( int value ) {
text.hardlight( value );
}
public void icon( Image icon ) {
if (this.icon != null) {
remove( this.icon );
}
this.icon = icon;
if (this.icon != null) {
add( this.icon );
layout();
}
}
public Image icon(){
return icon;
}
public float reqWidth() {
float reqWidth = 0;
if (icon != null){
reqWidth += icon.width() + 2;
}
if (text != null && !text.text().equals("")){
reqWidth += text.width() + 2;
}
return reqWidth;
}
public float reqHeight() {
float reqHeight = 0;
if (icon != null){
reqHeight = Math.max(icon.height() + 4, reqHeight);
}
if (text != null && !text.text().equals("")){
reqHeight = Math.max(text.height() + 4, reqHeight);
}
return reqHeight;
}
}
| 3,486 | StyledButton | java | en | java | code | {"qsc_code_num_words": 440, "qsc_code_num_chars": 3486.0, "qsc_code_mean_word_length": 5.23863636, "qsc_code_frac_words_unique": 0.36818182, "qsc_code_frac_chars_top_2grams": 0.03123644, "qsc_code_frac_chars_top_3grams": 0.0824295, "qsc_code_frac_chars_top_4grams": 0.07635575, "qsc_code_frac_chars_dupe_5grams": 0.12841649, "qsc_code_frac_chars_dupe_6grams": 0.10151844, "qsc_code_frac_chars_dupe_7grams": 0.06681128, "qsc_code_frac_chars_dupe_8grams": 0.02950108, "qsc_code_frac_chars_dupe_9grams": 0.02950108, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01413043, "qsc_code_frac_chars_whitespace": 0.20826162, "qsc_code_size_file_byte": 3486.0, "qsc_code_num_lines": 149.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 23.39597315, "qsc_code_frac_chars_alphabet": 0.82101449, "qsc_code_frac_chars_comments": 0.24354561, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.1, "qsc_codejava_score_lines_no_logic": 0.25, "qsc_codejava_frac_words_no_modifier": 0.90909091, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/LanguageButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndLangs;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class LanguageButton extends Button {
private Image image;
@Override
protected void createChildren() {
super.createChildren();
image = Icons.get(Icons.LANGS);
add( image );
updateIcon();
}
private boolean flashing;
private float time = 0;
@Override
public void update() {
super.update();
if (flashing){
image.am = (float)Math.abs(Math.cos( (time += Game.elapsed) ));
if (time >= Math.PI) {
time = 0;
}
}
}
private void updateIcon(){
image.resetColor();
flashing = false;
switch(Messages.lang().status()){
case INCOMPLETE:
image.tint(1, 0, 0, .5f);
flashing = true;
break;
case UNREVIEWED:
image.tint(1, .5f, 0, .5f);
break;
}
}
@Override
protected void layout() {
super.layout();
image.x = x + (width - image.width)/2f;
image.y = y + (height - image.height)/2f;
PixelScene.align(image);
}
@Override
protected void onTouchDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
image.resetColor();
updateIcon();
}
@Override
protected void onClick() {
//TODO fix this when language support is added
parent.add(new WndLangs());
}
}
| 2,454 | LanguageButton | java | en | java | code | {"qsc_code_num_words": 315, "qsc_code_num_chars": 2454.0, "qsc_code_mean_word_length": 5.51746032, "qsc_code_frac_words_unique": 0.5047619, "qsc_code_frac_chars_top_2grams": 0.04142693, "qsc_code_frac_chars_top_3grams": 0.10932106, "qsc_code_frac_chars_top_4grams": 0.10126582, "qsc_code_frac_chars_dupe_5grams": 0.04718067, "qsc_code_frac_chars_dupe_6grams": 0.03222094, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01542289, "qsc_code_frac_chars_whitespace": 0.1809291, "qsc_code_size_file_byte": 2454.0, "qsc_code_num_lines": 102.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 24.05882353, "qsc_code_frac_chars_alphabet": 0.84925373, "qsc_code_frac_chars_comments": 0.33700081, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.18461538, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00980392, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.10769231, "qsc_codejava_score_lines_no_logic": 0.27692308, "qsc_codejava_frac_words_no_modifier": 0.875, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/GridTileMap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
public class GridTileMap extends DungeonTilemap {
public GridTileMap() {
super("visual_grid.png");
map( Dungeon.level.map, Dungeon.level.width() );
}
private int gridSetting = -1;
@Override
public synchronized void updateMap() {
gridSetting = SPDSettings.visualGrid();
super.updateMap();
}
@Override
protected int getTileVisual(int pos, int tile, boolean flat) {
if (gridSetting == -1 || (pos % mapWidth) % 2 != (pos / mapWidth) % 2){
return -1;
} else if (DungeonTileSheet.floorTile(tile) || tile == Terrain.HIGH_GRASS || tile == Terrain.FURROWED_GRASS) {
return gridSetting;
} else if (DungeonTileSheet.doorTile(tile)){
if (DungeonTileSheet.wallStitcheable(map[pos - mapWidth])){
return 12 + gridSetting;
} else if ( tile == Terrain.OPEN_DOOR){
return 8 + gridSetting;
} else {
return 4 + gridSetting;
}
} else {
return -1;
}
}
}
| 1,920 | GridTileMap | java | en | java | code | {"qsc_code_num_words": 240, "qsc_code_num_chars": 1920.0, "qsc_code_mean_word_length": 5.7625, "qsc_code_frac_words_unique": 0.5375, "qsc_code_frac_chars_top_2grams": 0.04916847, "qsc_code_frac_chars_top_3grams": 0.109906, "qsc_code_frac_chars_top_4grams": 0.04121475, "qsc_code_frac_chars_dupe_5grams": 0.0592914, "qsc_code_frac_chars_dupe_6grams": 0.04049168, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01714286, "qsc_code_frac_chars_whitespace": 0.1796875, "qsc_code_size_file_byte": 1920.0, "qsc_code_num_lines": 63.0, "qsc_code_num_chars_line_max": 113.0, "qsc_code_num_chars_line_mean": 30.47619048, "qsc_code_frac_chars_alphabet": 0.86095238, "qsc_code_frac_chars_comments": 0.40625, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.17647059, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01315789, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02941176, "qsc_codejava_score_lines_no_logic": 0.17647059, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTerrainTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.watabou.noosa.Image;
import com.watabou.utils.PathFinder;
public class DungeonTerrainTilemap extends DungeonTilemap {
static DungeonTerrainTilemap instance;
public DungeonTerrainTilemap(){
super(Dungeon.level.tilesTex());
map( Dungeon.level.map, Dungeon.level.width() );
instance = this;
}
@Override
protected int getTileVisual(int pos, int tile, boolean flat) {
int visual = DungeonTileSheet.directVisuals.get(tile, -1);
if (visual != -1) return DungeonTileSheet.getVisualWithAlts(visual, pos);
if (tile == Terrain.WATER) {
return DungeonTileSheet.stitchWaterTile(
map[pos + PathFinder.CIRCLE4[0]],
map[pos + PathFinder.CIRCLE4[1]],
map[pos + PathFinder.CIRCLE4[2]],
map[pos + PathFinder.CIRCLE4[3]]
);
} else if (tile == Terrain.CHASM) {
return DungeonTileSheet.stitchChasmTile( pos > mapWidth ? map[pos - mapWidth] : -1);
}
if (!flat) {
if ((DungeonTileSheet.doorTile(tile))) {
return DungeonTileSheet.getRaisedDoorTile(tile, map[pos - mapWidth]);
} else if (DungeonTileSheet.wallStitcheable(tile)){
return DungeonTileSheet.getRaisedWallTile(
tile,
pos,
(pos+1) % mapWidth != 0 ? map[pos + 1] : -1,
pos + mapWidth < size ? map[pos + mapWidth] : -1,
pos % mapWidth != 0 ? map[pos - 1] : -1
);
} else if (tile == Terrain.SIGN) {
return DungeonTileSheet.RAISED_SIGN;
} else if (tile == Terrain.STATUE) {
return DungeonTileSheet.RAISED_STATUE;
} else if (tile == Terrain.STATUE_SP) {
return DungeonTileSheet.RAISED_STATUE_SP;
} else if (tile == Terrain.ALCHEMY) {
return DungeonTileSheet.RAISED_ALCHEMY_POT;
} else if (tile == Terrain.BARRICADE) {
return DungeonTileSheet.RAISED_BARRICADE;
} else if (tile == Terrain.HIGH_GRASS) {
return DungeonTileSheet.getVisualWithAlts(
DungeonTileSheet.RAISED_HIGH_GRASS,
pos);
} else if (tile == Terrain.FURROWED_GRASS) {
return DungeonTileSheet.getVisualWithAlts(
DungeonTileSheet.RAISED_FURROWED_GRASS,
pos);
} else {
return DungeonTileSheet.NULL_TILE;
}
} else {
return DungeonTileSheet.getVisualWithAlts(
DungeonTileSheet.directFlatVisuals.get(tile),
pos);
}
}
public static Image tile(int pos, int tile ) {
Image img = new Image( instance.texture );
img.frame( instance.tileset.get( instance.getTileVisual( pos, tile, true ) ) );
return img;
}
@Override
protected boolean needsRender(int pos) {
return super.needsRender(pos) && data[pos] != DungeonTileSheet.WATER;
}
}
| 3,523 | DungeonTerrainTilemap | java | en | java | code | {"qsc_code_num_words": 411, "qsc_code_num_chars": 3523.0, "qsc_code_mean_word_length": 6.01703163, "qsc_code_frac_words_unique": 0.36739659, "qsc_code_frac_chars_top_2grams": 0.12454509, "qsc_code_frac_chars_top_3grams": 0.04731096, "qsc_code_frac_chars_top_4grams": 0.05499393, "qsc_code_frac_chars_dupe_5grams": 0.11888395, "qsc_code_frac_chars_dupe_6grams": 0.08976951, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01259622, "qsc_code_frac_chars_whitespace": 0.18875958, "qsc_code_size_file_byte": 3523.0, "qsc_code_num_lines": 107.0, "qsc_code_num_chars_line_max": 88.0, "qsc_code_num_chars_line_mean": 32.92523364, "qsc_code_frac_chars_alphabet": 0.85269419, "qsc_code_frac_chars_comments": 0.22168606, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.16216216, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04054054, "qsc_codejava_score_lines_no_logic": 0.13513514, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/Tag.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.watabou.noosa.Game;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.ui.Button;
public class Tag extends Button<GameAction> {
private float r;
private float g;
private float b;
protected NinePatch bg;
protected float lightness = 0;
public Tag( int color ) {
super();
this.r = (color >> 16) / 255f;
this.g = ((color >> 8) & 0xFF) / 255f;
this.b = (color & 0xFF) / 255f;
}
@Override
protected void createChildren() {
super.createChildren();
bg = Chrome.get( Chrome.Type.TAG );
bg.hardlight( r, g, b );
add( bg );
}
@Override
protected void layout() {
super.layout();
bg.x = x;
bg.y = y;
bg.size( width, height );
}
public void flash() {
lightness = 1f;
}
public void flip(boolean value){
bg.flipHorizontal(value);
}
@Override
public void update() {
super.update();
if (visible && lightness > 0.5) {
if ((lightness -= Game.elapsed) > 0.5) {
bg.ra = bg.ga = bg.ba = 2 * lightness - 1;
bg.rm = 2 * r * (1 - lightness);
bg.gm = 2 * g * (1 - lightness);
bg.bm = 2 * b * (1 - lightness);
} else {
bg.hardlight( r, g, b );
}
}
}
}
| 2,119 | Tag | java | en | java | code | {"qsc_code_num_words": 294, "qsc_code_num_chars": 2119.0, "qsc_code_mean_word_length": 4.80272109, "qsc_code_frac_words_unique": 0.48639456, "qsc_code_frac_chars_top_2grams": 0.03186969, "qsc_code_frac_chars_top_3grams": 0.0276204, "qsc_code_frac_chars_top_4grams": 0.04036827, "qsc_code_frac_chars_dupe_5grams": 0.07790368, "qsc_code_frac_chars_dupe_6grams": 0.03966006, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02712477, "qsc_code_frac_chars_whitespace": 0.21708353, "qsc_code_size_file_byte": 2119.0, "qsc_code_num_lines": 89.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 23.80898876, "qsc_code_frac_chars_alphabet": 0.82399036, "qsc_code_frac_chars_comments": 0.36857008, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.09433962, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00597907, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09433962, "qsc_codejava_score_lines_no_logic": 0.28301887, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/LootIndicator.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
public class LootIndicator extends Tag {
private ItemSlot slot;
private Item lastItem = null;
private int lastQuantity = 0;
public LootIndicator() {
super( 0x1F75CC );
setSize( 24, 24 );
visible = false;
}
@Override
protected void createChildren() {
super.createChildren();
slot = new ItemSlot() {
protected void onClick() {
if (Dungeon.hero.handle(Dungeon.hero.pos)){
Dungeon.hero.next();
}
}
};
slot.showParams( true, false, false );
add( slot );
}
@Override
protected void layout() {
super.layout();
slot.setRect( x + 2, y + 3, width - 2, height - 6 );
}
@Override
public void update() {
if (Dungeon.hero.ready) {
Heap heap = Dungeon.level.heaps.get( Dungeon.hero.pos );
if (heap != null) {
Item item =
heap.type == Heap.Type.CHEST || heap.type == Heap.Type.MIMIC ? ItemSlot.CHEST :
heap.type == Heap.Type.LOCKED_CHEST ? ItemSlot.LOCKED_CHEST :
heap.type == Heap.Type.CRYSTAL_CHEST ? ItemSlot.CRYSTAL_CHEST :
heap.type == Heap.Type.TOMB ? ItemSlot.TOMB :
heap.type == Heap.Type.SKELETON ? ItemSlot.SKELETON :
heap.type == Heap.Type.REMAINS ? ItemSlot.REMAINS :
heap.peek();
if (item != lastItem || item.quantity() != lastQuantity) {
lastItem = item;
lastQuantity = item.quantity();
slot.item( item );
flash();
}
visible = true;
} else {
lastItem = null;
visible = false;
}
}
slot.enable( visible && Dungeon.hero.ready );
super.update();
}
}
| 2,570 | LootIndicator | java | en | java | code | {"qsc_code_num_words": 318, "qsc_code_num_chars": 2570.0, "qsc_code_mean_word_length": 5.39308176, "qsc_code_frac_words_unique": 0.45283019, "qsc_code_frac_chars_top_2grams": 0.06530612, "qsc_code_frac_chars_top_3grams": 0.04897959, "qsc_code_frac_chars_top_4grams": 0.06530612, "qsc_code_frac_chars_dupe_5grams": 0.15393586, "qsc_code_frac_chars_dupe_6grams": 0.03265306, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01497753, "qsc_code_frac_chars_whitespace": 0.22062257, "qsc_code_size_file_byte": 2570.0, "qsc_code_num_lines": 101.0, "qsc_code_num_chars_line_max": 85.0, "qsc_code_num_chars_line_mean": 25.44554455, "qsc_code_frac_chars_alphabet": 0.84123814, "qsc_code_frac_chars_comments": 0.30389105, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.08333333, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00447177, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06666667, "qsc_codejava_score_lines_no_logic": 0.15, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
public class ExitButton extends Button {
protected Image image;
public ExitButton() {
super();
width = 20;
height = 20;
}
@Override
protected void createChildren() {
super.createChildren();
image = Icons.EXIT.get();
add( image );
}
@Override
protected void layout() {
super.layout();
image.x = x + (width - image.width)/2f;
image.y = y + (height - image.height)/2f;
PixelScene.align(image);
}
@Override
protected void onTouchDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
image.resetColor();
}
@Override
protected void onClick() {
if (Game.scene() instanceof TitleScene) {
Game.instance.finish();
} else {
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
}
}
}
| 2,041 | ExitButton | java | en | java | code | {"qsc_code_num_words": 257, "qsc_code_num_chars": 2041.0, "qsc_code_mean_word_length": 5.84435798, "qsc_code_frac_words_unique": 0.50972763, "qsc_code_frac_chars_top_2grams": 0.04793609, "qsc_code_frac_chars_top_3grams": 0.126498, "qsc_code_frac_chars_top_4grams": 0.1171771, "qsc_code_frac_chars_dupe_5grams": 0.12117177, "qsc_code_frac_chars_dupe_6grams": 0.03728362, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01466276, "qsc_code_frac_chars_whitespace": 0.16462518, "qsc_code_size_file_byte": 2041.0, "qsc_code_num_lines": 79.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 25.83544304, "qsc_code_frac_chars_alphabet": 0.86627566, "qsc_code_frac_chars_comments": 0.38265556, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10638298, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.10638298, "qsc_codejava_score_lines_no_logic": 0.31914894, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/QuickRecipe.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.Recipe;
import com.shatteredpixel.shatteredpixeldungeon.items.bombs.Bomb;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
import com.shatteredpixel.shatteredpixeldungeon.items.food.MeatPie;
import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Pasty;
import com.shatteredpixel.shatteredpixeldungeon.items.food.StewedMeat;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.AlchemicalCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.BlizzardBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.CausticBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.InfernalBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.ShockingBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfAquaticRejuvenation;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfArcaneArmor;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfDragonsBlood;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfHoneyedHealing;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfIcyTouch;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfMight;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfToxicEssence;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic.ExoticPotion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ExoticScroll;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.Alchemize;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.AquaBlast;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.ArcaneCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.BeaconOfReturning;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.CurseInfusion;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.FeatherFall;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.MagicalInfusion;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.MagicalPorter;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.PhaseShift;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.ReclaimTrap;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.Recycle;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.WildEnergy;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.scenes.AlchemyScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Reflection;
import java.util.ArrayList;
import java.util.Arrays;
public class QuickRecipe extends Component {
private ArrayList<Item> ingredients;
private ArrayList<ItemSlot> inputs;
private QuickRecipe.arrow arrow;
private ItemSlot output;
public QuickRecipe(Recipe.SimpleRecipe r){
this(r, r.getIngredients(), r.sampleOutput(null));
}
public QuickRecipe(Recipe r, ArrayList<Item> inputs, final Item output) {
ingredients = inputs;
int cost = r.cost(inputs);
boolean hasInputs = true;
this.inputs = new ArrayList<>();
for (final Item in : inputs) {
anonymize(in);
ItemSlot curr;
curr = new ItemSlot(in) {
@Override
protected void onClick() {
ShatteredPixelDungeon.scene().addToFront(new WndInfoItem(in));
}
};
ArrayList<Item> similar = Dungeon.hero.belongings.getAllSimilar(in);
int quantity = 0;
for (Item sim : similar) {
//if we are looking for a specific item, it must be IDed
if (sim.getClass() != in.getClass() || sim.isIdentified()) quantity += sim.quantity();
}
if (quantity < in.quantity()) {
curr.icon.alpha(0.3f);
hasInputs = false;
}
curr.showParams(true, false, true);
add(curr);
this.inputs.add(curr);
}
if (cost > 0) {
arrow = new arrow(Icons.get(Icons.ARROW), cost);
arrow.hardlightText(0x00CCFF);
} else {
arrow = new arrow(Icons.get(Icons.ARROW));
}
if (hasInputs) {
arrow.icon.tint(1, 1, 0, 1);
if (!(ShatteredPixelDungeon.scene() instanceof AlchemyScene)) {
arrow.enable(false);
}
} else {
arrow.icon.color(0, 0, 0);
arrow.enable(false);
}
add(arrow);
anonymize(output);
this.output = new ItemSlot(output){
@Override
protected void onClick() {
ShatteredPixelDungeon.scene().addToFront(new WndInfoItem(output));
}
};
if (!hasInputs){
this.output.icon.alpha(0.3f);
}
this.output.showParams(true, false, true);
add(this.output);
layout();
}
@Override
protected void layout() {
height = 16;
width = 0;
for (ItemSlot item : inputs){
item.setRect(x + width, y, 16, 16);
width += 16;
}
arrow.setRect(x + width, y, 14, 16);
width += 14;
output.setRect(x + width, y, 16, 16);
width += 16;
}
//used to ensure that un-IDed items are not spoiled
private void anonymize(Item item){
if (item instanceof Potion){
((Potion) item).anonymize();
} else if (item instanceof Scroll){
((Scroll) item).anonymize();
}
}
public class arrow extends IconButton {
BitmapText text;
public arrow(){
super();
}
public arrow( Image icon ){
super( icon );
}
public arrow( Image icon, int count ){
super( icon );
text = new BitmapText( Integer.toString(count), PixelScene.pixelFont);
text.measure();
add(text);
}
@Override
protected void layout() {
super.layout();
if (text != null){
text.x = x;
text.y = y;
PixelScene.align(text);
}
}
@Override
protected void onClick() {
super.onClick();
//find the window this is inside of and close it
Group parent = this.parent;
while (parent != null){
if (parent instanceof Window){
((Window) parent).hide();
break;
} else {
parent = parent.parent;
}
}
((AlchemyScene)ShatteredPixelDungeon.scene()).populate(ingredients, Dungeon.hero.belongings);
}
public void hardlightText(int color ){
if (text != null) text.hardlight(color);
}
}
//gets recipes for a particular alchemy guide page
//a null entry indicates a break in section
public static ArrayList<QuickRecipe> getRecipes( int pageIdx ){
ArrayList<QuickRecipe> result = new ArrayList<>();
switch (pageIdx){
case 0: default:
result.add(new QuickRecipe( new Potion.SeedToPotion(), new ArrayList<>(Arrays.asList(new Plant.Seed.PlaceHolder().quantity(3))), new WndBag.Placeholder(ItemSpriteSheet.POTION_HOLDER){
{
name = Messages.get(Potion.SeedToPotion.class, "name");
}
@Override
public String info() {
return "";
}
}));
return result;
case 1:
Recipe r = new Scroll.ScrollToStone();
for (Class<?> cls : Generator.Category.SCROLL.classes){
Scroll scroll = (Scroll) Reflection.newInstance(cls);
if (!scroll.isKnown()) scroll.anonymize();
ArrayList<Item> in = new ArrayList<Item>(Arrays.asList(scroll));
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
}
return result;
case 2:
result.add(new QuickRecipe( new StewedMeat.oneMeat() ));
result.add(new QuickRecipe( new StewedMeat.twoMeat() ));
result.add(new QuickRecipe( new StewedMeat.threeMeat() ));
result.add(null);
result.add(null);
result.add(new QuickRecipe( new MeatPie.Recipe(),
new ArrayList<Item>(Arrays.asList(new Pasty(), new Food(), new MysteryMeat.PlaceHolder())),
new MeatPie()));
result.add(null);
result.add(null);
result.add(new QuickRecipe( new Blandfruit.CookFruit(),
new ArrayList<>(Arrays.asList(new Blandfruit(), new Plant.Seed.PlaceHolder())),
new Blandfruit(){
{
name = Messages.get(Blandfruit.class, "cooked");
}
@Override
public String info() {
return "";
}
}));
return result;
case 3:
r = new Bomb.EnhanceBomb();
int i = 0;
for (Class<?> cls : Bomb.EnhanceBomb.validIngredients.keySet()){
if (i == 2){
result.add(null);
i = 0;
}
Item item = (Item) Reflection.newInstance(cls);
ArrayList<Item> in = new ArrayList<>(Arrays.asList(new Bomb(), item));
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
i++;
}
return result;
case 4:
r = new ExoticPotion.PotionToExotic();
for (Class<?> cls : Generator.Category.POTION.classes){
Potion pot = (Potion) Reflection.newInstance(cls);
ArrayList<Item> in = new ArrayList<>(Arrays.asList(pot, new Plant.Seed.PlaceHolder().quantity(2)));
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
}
return result;
case 5:
r = new ExoticScroll.ScrollToExotic();
for (Class<?> cls : Generator.Category.SCROLL.classes){
Scroll scroll = (Scroll) Reflection.newInstance(cls);
ArrayList<Item> in = new ArrayList<>(Arrays.asList(scroll, new Runestone.PlaceHolder().quantity(2)));
result.add(new QuickRecipe( r, in, r.sampleOutput(in)));
}
return result;
case 6:
result.add(new QuickRecipe(new AlchemicalCatalyst.Recipe(), new ArrayList<>(Arrays.asList(new Potion.PlaceHolder(), new Plant.Seed.PlaceHolder())), new AlchemicalCatalyst()));
result.add(new QuickRecipe(new AlchemicalCatalyst.Recipe(), new ArrayList<>(Arrays.asList(new Potion.PlaceHolder(), new Runestone.PlaceHolder())), new AlchemicalCatalyst()));
result.add(null);
result.add(null);
result.add(new QuickRecipe(new ArcaneCatalyst.Recipe(), new ArrayList<>(Arrays.asList(new Scroll.PlaceHolder(), new Runestone.PlaceHolder())), new ArcaneCatalyst()));
result.add(new QuickRecipe(new ArcaneCatalyst.Recipe(), new ArrayList<>(Arrays.asList(new Scroll.PlaceHolder(), new Plant.Seed.PlaceHolder())), new ArcaneCatalyst()));
return result;
case 7:
result.add(new QuickRecipe(new CausticBrew.Recipe()));
result.add(new QuickRecipe(new InfernalBrew.Recipe()));
result.add(new QuickRecipe(new BlizzardBrew.Recipe()));
result.add(new QuickRecipe(new ShockingBrew.Recipe()));
result.add(null);
result.add(null);
result.add(new QuickRecipe(new ElixirOfHoneyedHealing.Recipe()));
result.add(new QuickRecipe(new ElixirOfMight.Recipe()));
result.add(new QuickRecipe(new ElixirOfAquaticRejuvenation.Recipe()));
result.add(new QuickRecipe(new ElixirOfDragonsBlood.Recipe()));
result.add(new QuickRecipe(new ElixirOfIcyTouch.Recipe()));
result.add(new QuickRecipe(new ElixirOfToxicEssence.Recipe()));
result.add(new QuickRecipe(new ElixirOfArcaneArmor.Recipe()));
return result;
case 8:
result.add(new QuickRecipe(new MagicalPorter.Recipe()));
result.add(new QuickRecipe(new PhaseShift.Recipe()));
result.add(new QuickRecipe(new WildEnergy.Recipe()));
result.add(new QuickRecipe(new BeaconOfReturning.Recipe()));
result.add(null);
result.add(null);
result.add(new QuickRecipe(new AquaBlast.Recipe()));
result.add(new QuickRecipe(new FeatherFall.Recipe()));
result.add(new QuickRecipe(new ReclaimTrap.Recipe()));
result.add(null);
result.add(null);
result.add(new QuickRecipe(new CurseInfusion.Recipe()));
result.add(new QuickRecipe(new MagicalInfusion.Recipe()));
result.add(new QuickRecipe(new Alchemize.Recipe()));
result.add(new QuickRecipe(new Recycle.Recipe()));
return result;
}
}
}
| 13,361 | QuickRecipe | java | en | java | code | {"qsc_code_num_words": 1506, "qsc_code_num_chars": 13361.0, "qsc_code_mean_word_length": 6.47875166, "qsc_code_frac_words_unique": 0.19588313, "qsc_code_frac_chars_top_2grams": 0.04888798, "qsc_code_frac_chars_top_3grams": 0.19083735, "qsc_code_frac_chars_top_4grams": 0.21645998, "qsc_code_frac_chars_dupe_5grams": 0.5362304, "qsc_code_frac_chars_dupe_6grams": 0.44316901, "qsc_code_frac_chars_dupe_7grams": 0.23695808, "qsc_code_frac_chars_dupe_8grams": 0.16039766, "qsc_code_frac_chars_dupe_9grams": 0.14584401, "qsc_code_frac_chars_dupe_10grams": 0.12565338, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00606167, "qsc_code_frac_chars_whitespace": 0.14804281, "qsc_code_size_file_byte": 13361.0, "qsc_code_num_lines": 361.0, "qsc_code_num_chars_line_max": 188.0, "qsc_code_num_chars_line_mean": 37.01108033, "qsc_code_frac_chars_alphabet": 0.85109374, "qsc_code_frac_chars_comments": 0.07694035, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.19601329, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00081083, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00064867, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03654485, "qsc_codejava_score_lines_no_logic": 0.27906977, "qsc_codejava_frac_words_no_modifier": 0.69230769, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 0.5, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/GameLog.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.Signal;
import java.util.ArrayList;
import java.util.regex.Pattern;
public class GameLog extends Component implements Signal.Listener<String> {
private static final int MAX_LINES = 3;
private static final Pattern PUNCTUATION = Pattern.compile( ".*[.,;?! ]$" );
private RenderedTextBlock lastEntry;
private int lastColor;
private static ArrayList<Entry> entries = new ArrayList<>();
public GameLog() {
super();
GLog.update.replace( this );
recreateLines();
}
private static ArrayList<String> textsToAdd = new ArrayList<>();
@Override
public synchronized void update() {
for (String text : textsToAdd){
if (length != entries.size()){
clear();
recreateLines();
}
int color = CharSprite.DEFAULT;
if (text.startsWith( GLog.POSITIVE )) {
text = text.substring( GLog.POSITIVE.length() );
color = CharSprite.POSITIVE;
} else
if (text.startsWith( GLog.NEGATIVE )) {
text = text.substring( GLog.NEGATIVE.length() );
color = CharSprite.NEGATIVE;
} else
if (text.startsWith( GLog.WARNING )) {
text = text.substring( GLog.WARNING.length() );
color = CharSprite.WARNING;
} else
if (text.startsWith( GLog.HIGHLIGHT )) {
text = text.substring( GLog.HIGHLIGHT.length() );
color = CharSprite.NEUTRAL;
}
if (lastEntry != null && color == lastColor && lastEntry.nLines < MAX_LINES) {
String lastMessage = lastEntry.text();
lastEntry.text( lastMessage.length() == 0 ? text : lastMessage + " " + text );
entries.get( entries.size() - 1 ).text = lastEntry.text();
} else {
lastEntry = PixelScene.renderTextBlock( text, 6 );
lastEntry.setHightlighting( false );
lastEntry.hardlight( color );
lastColor = color;
add( lastEntry );
entries.add( new Entry( text, color ) );
}
if (length > 0) {
int nLines;
do {
nLines = 0;
for (int i = 0; i < length-1; i++) {
nLines += ((RenderedTextBlock) members.get(i)).nLines;
}
if (nLines > MAX_LINES) {
RenderedTextBlock r = ((RenderedTextBlock) members.get(0));
remove(r);
r.destroy();
entries.remove( 0 );
}
} while (nLines > MAX_LINES);
if (entries.isEmpty()) {
lastEntry = null;
}
}
}
if (!textsToAdd.isEmpty()){
layout();
textsToAdd.clear();
}
super.update();
}
private synchronized void recreateLines() {
for (Entry entry : entries) {
lastEntry = PixelScene.renderTextBlock( entry.text, 6 );
lastEntry.hardlight( lastColor = entry.color );
add( lastEntry );
}
}
public synchronized void newLine() {
lastEntry = null;
}
@Override
public synchronized void onSignal( String text ) {
textsToAdd.add(text);
}
@Override
protected void layout() {
float pos = y;
for (int i=length-1; i >= 0; i--) {
RenderedTextBlock entry = (RenderedTextBlock)members.get( i );
entry.maxWidth((int)width);
entry.setPos(x, pos-entry.height());
pos -= entry.height()+2;
}
}
@Override
public void destroy() {
GLog.update.remove( this );
super.destroy();
}
private static class Entry {
public String text;
public int color;
public Entry( String text, int color ) {
this.text = text;
this.color = color;
}
}
public static void wipe() {
entries.clear();
}
}
| 4,441 | GameLog | java | en | java | code | {"qsc_code_num_words": 510, "qsc_code_num_chars": 4441.0, "qsc_code_mean_word_length": 5.75686275, "qsc_code_frac_words_unique": 0.34313725, "qsc_code_frac_chars_top_2grams": 0.01532698, "qsc_code_frac_chars_top_3grams": 0.05177112, "qsc_code_frac_chars_top_4grams": 0.02724796, "qsc_code_frac_chars_dupe_5grams": 0.05245232, "qsc_code_frac_chars_dupe_6grams": 0.01907357, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00891061, "qsc_code_frac_chars_whitespace": 0.21661788, "qsc_code_size_file_byte": 4441.0, "qsc_code_num_lines": 173.0, "qsc_code_num_chars_line_max": 83.0, "qsc_code_num_chars_line_mean": 25.67052023, "qsc_code_frac_chars_alphabet": 0.83501006, "qsc_code_frac_chars_comments": 0.17563612, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10655738, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00327779, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02459016, "qsc_codejava_score_lines_no_logic": 0.13114754, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/RenderedTextBlock.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText;
import com.watabou.noosa.ui.Component;
import java.util.ArrayList;
import java.util.regex.Pattern;
public class RenderedTextBlock extends Component {
private int maxWidth = Integer.MAX_VALUE;
public int nLines;
private static final RenderedText SPACE = new RenderedText();
private static final RenderedText NEWLINE = new RenderedText();
protected String text;
protected String[] tokens = null;
protected ArrayList<RenderedText> words = new ArrayList<>();
protected boolean multiline = false;
private int size;
private float zoom;
private int color = -1;
private int hightlightColor = Window.TITLE_COLOR;
private boolean highlightingEnabled = true;
public RenderedTextBlock(int size){
this.size = size;
}
public RenderedTextBlock(String text, int size){
this.size = size;
text(text);
}
//splits on newlines, underscores, and chinese/japaneses characters
private Pattern regularsplitter = Pattern.compile(
"(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})|" +
"(?<=\\p{InHalfwidth_and_Fullwidth_Forms})|(?=\\p{InHalfwidth_and_Fullwidth_Forms})");
//additionally splits on words, so that each word can be arranged individually
private Pattern regularsplitterMultiline = Pattern.compile(
"(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" +
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" +
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" +
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" +
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})|" +
"(?<=\\p{InHalfwidth_and_Fullwidth_Forms})|(?=\\p{InHalfwidth_and_Fullwidth_Forms})");
public void text(String text){
this.text = text;
if (text != null && !text.equals("")) {
if (multiline){
tokens = regularsplitterMultiline.split(text);
} else {
tokens = regularsplitter.split(text);
}
build();
}
}
public void text(String text, int maxWidth){
this.maxWidth = maxWidth;
multiline = true;
text(text);
}
public String text(){
return text;
}
public void maxWidth(int maxWidth){
if (this.maxWidth != maxWidth){
this.maxWidth = maxWidth;
multiline = true;
text(text);
}
}
public int maxWidth(){
return maxWidth;
}
private synchronized void build(){
if (tokens == null) return;
clear();
words = new ArrayList<>();
boolean highlighting = false;
for (String str : tokens){
if (str.equals("_") && highlightingEnabled){
highlighting = !highlighting;
} else if (str.equals("\n")){
words.add(NEWLINE);
} else if (str.equals(" ")){
words.add(SPACE);
} else {
RenderedText word = new RenderedText(str, size);
if (highlighting) word.hardlight(hightlightColor);
else if (color != -1) word.hardlight(color);
word.scale.set(zoom);
words.add(word);
add(word);
if (height < word.height()) height = word.height();
}
}
layout();
}
public synchronized void zoom(float zoom){
this.zoom = zoom;
for (RenderedText word : words) {
if (word != null) word.scale.set(zoom);
}
layout();
}
public synchronized void hardlight(int color){
this.color = color;
for (RenderedText word : words) {
if (word != null) word.hardlight( color );
}
}
public synchronized void resetColor(){
this.color = -1;
for (RenderedText word : words) {
if (word != null) word.resetColor();
}
}
public synchronized void alpha(float value){
for (RenderedText word : words) {
if (word != null) word.alpha( value );
}
}
public synchronized void setHightlighting(boolean enabled){
setHightlighting(enabled, Window.TITLE_COLOR);
}
public synchronized void setHightlighting(boolean enabled, int color){
if (enabled != highlightingEnabled || color != hightlightColor) {
hightlightColor = color;
highlightingEnabled = enabled;
build();
}
}
public synchronized void invert(){
if (words != null) {
for (RenderedText word : words) {
if (word != null) {
word.ra = 0.77f;
word.ga = 0.73f;
word.ba = 0.62f;
word.rm = -0.77f;
word.gm = -0.73f;
word.bm = -0.62f;
}
}
}
}
@Override
protected synchronized void layout() {
super.layout();
float x = this.x;
float y = this.y;
float height = 0;
nLines = 1;
width = 0;
for (RenderedText word : words){
if (word == SPACE){
x += 1.5f;
} else if (word == NEWLINE) {
//newline
y += height+2f;
x = this.x;
nLines++;
} else {
if (word.height() > height) height = word.height();
if ((x - this.x) + word.width() > maxWidth){
y += height+2f;
x = this.x;
nLines++;
}
word.x = x;
word.y = y;
PixelScene.align(word);
x += word.width();
if ((x - this.x) > width) width = (x - this.x);
//TODO spacing currently doesn't factor in halfwidth and fullwidth characters
//(e.g. Ideographic full stop)
x -= 0.5f;
}
}
this.height = (y - this.y) + height;
}
}
| 6,238 | RenderedTextBlock | java | en | java | code | {"qsc_code_num_words": 738, "qsc_code_num_chars": 6238.0, "qsc_code_mean_word_length": 5.38753388, "qsc_code_frac_words_unique": 0.28319783, "qsc_code_frac_chars_top_2grams": 0.0362173, "qsc_code_frac_chars_top_3grams": 0.03873239, "qsc_code_frac_chars_top_4grams": 0.0362173, "qsc_code_frac_chars_dupe_5grams": 0.27162978, "qsc_code_frac_chars_dupe_6grams": 0.24346076, "qsc_code_frac_chars_dupe_7grams": 0.19567404, "qsc_code_frac_chars_dupe_8grams": 0.18511066, "qsc_code_frac_chars_dupe_9grams": 0.13732394, "qsc_code_frac_chars_dupe_10grams": 0.10965795, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00949879, "qsc_code_frac_chars_whitespace": 0.20679705, "qsc_code_size_file_byte": 6238.0, "qsc_code_num_lines": 242.0, "qsc_code_num_chars_line_max": 92.0, "qsc_code_num_chars_line_mean": 25.7768595, "qsc_code_frac_chars_alphabet": 0.79405821, "qsc_code_frac_chars_comments": 0.16688041, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.21590909, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.13411584, "qsc_code_frac_chars_long_word_length": 0.13122956, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00413223, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02840909, "qsc_codejava_score_lines_no_logic": 0.10227273, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/OptionSlider.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.GameMath;
import com.watabou.utils.PointF;
public abstract class OptionSlider extends Component {
private TouchArea touchArea;
private RenderedTextBlock title;
private RenderedTextBlock minTxt;
private RenderedTextBlock maxTxt;
//values are expressed internally as ints, but they can easily be interpreted as something else externally.
private int minVal;
private int maxVal;
private int selectedVal;
private NinePatch sliderNode;
private NinePatch BG;
private ColorBlock sliderBG;
private ColorBlock[] sliderTicks;
private float tickDist;
public OptionSlider(String title, String minTxt, String maxTxt, int minVal, int maxVal){
super();
//shouldn't function if this happens.
if (minVal > maxVal){
minVal = maxVal;
active = false;
}
this.title.text(title);
this.minTxt.text(minTxt);
this.maxTxt.text(maxTxt);
this.minVal = minVal;
this.maxVal = maxVal;
sliderTicks = new ColorBlock[(maxVal - minVal) + 1];
for (int i = 0; i < sliderTicks.length; i++){
add(sliderTicks[i] = new ColorBlock(1, 11, 0xFF222222));
}
add(sliderNode);
}
protected abstract void onChange();
public int getSelectedValue(){
return selectedVal;
}
public void setSelectedValue(int val) {
this.selectedVal = val;
sliderNode.x = (int)(x + tickDist*(selectedVal-minVal));
sliderNode.y = sliderBG.y-4;
}
@Override
protected void createChildren() {
super.createChildren();
add( BG = Chrome.get(Chrome.Type.RED_BUTTON));
BG.alpha(0.5f);
add(title = PixelScene.renderTextBlock(9));
add(this.minTxt = PixelScene.renderTextBlock(6));
add(this.maxTxt = PixelScene.renderTextBlock(6));
add(sliderBG = new ColorBlock(1, 1, 0xFF222222));
sliderNode = Chrome.get(Chrome.Type.RED_BUTTON);
sliderNode.size(5, 9);
touchArea = new TouchArea(0, 0, 0, 0){
boolean pressed = false;
@Override
protected void onTouchDown(NoosaInputProcessor.Touch touch) {
pressed = true;
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x-2, p.x, sliderBG.x+sliderBG.width()-2);
sliderNode.brightness(1.5f);
}
@Override
protected void onDrag(NoosaInputProcessor.Touch touch) {
if (pressed) {
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
}
}
@Override
protected void onTouchUp(NoosaInputProcessor.Touch touch) {
if (pressed) {
PointF p = camera().screenToCamera((int) touch.current.x, (int) touch.current.y);
sliderNode.x = GameMath.gate(sliderBG.x - 2, p.x, sliderBG.x + sliderBG.width() - 2);
sliderNode.resetColor();
//sets the selected value
selectedVal = minVal + Math.round(sliderNode.x / tickDist);
sliderNode.x = (int) (x + tickDist * (selectedVal - minVal));
onChange();
pressed = false;
}
}
};
add(touchArea);
}
@Override
protected void layout() {
title.setPos(
x + (width-title.width())/2,
y+2
);
PixelScene.align(title);
sliderBG.y = y + height() - 8;
sliderBG.x = x+2;
sliderBG.size(width-5, 1);
tickDist = sliderBG.width()/(maxVal - minVal);
for (int i = 0; i < sliderTicks.length; i++){
sliderTicks[i].y = sliderBG.y-5;
sliderTicks[i].x = (int)(x + 2 + (tickDist*i));
}
minTxt.setPos(
x+1,
sliderBG.y-6-minTxt.height()
);
maxTxt.setPos(
x+width()-maxTxt.width()-1,
sliderBG.y-6-minTxt.height()
);
sliderNode.x = (int)(x + tickDist*(selectedVal-minVal));
sliderNode.y = sliderBG.y-4;
touchArea.x = x;
touchArea.y = y;
touchArea.width = width();
touchArea.height = height();
BG.size(width(), height());
BG.x = x;
BG.y = y;
}
}
| 4,952 | OptionSlider | java | en | java | code | {"qsc_code_num_words": 637, "qsc_code_num_chars": 4952.0, "qsc_code_mean_word_length": 5.41915228, "qsc_code_frac_words_unique": 0.30455259, "qsc_code_frac_chars_top_2grams": 0.02346466, "qsc_code_frac_chars_top_3grams": 0.03244496, "qsc_code_frac_chars_top_4grams": 0.02433372, "qsc_code_frac_chars_dupe_5grams": 0.24536501, "qsc_code_frac_chars_dupe_6grams": 0.23783314, "qsc_code_frac_chars_dupe_7grams": 0.19206257, "qsc_code_frac_chars_dupe_8grams": 0.18047509, "qsc_code_frac_chars_dupe_9grams": 0.16483198, "qsc_code_frac_chars_dupe_10grams": 0.16483198, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01765571, "qsc_code_frac_chars_whitespace": 0.17649435, "qsc_code_size_file_byte": 4952.0, "qsc_code_num_lines": 179.0, "qsc_code_num_chars_line_max": 109.0, "qsc_code_num_chars_line_mean": 27.66480447, "qsc_code_frac_chars_alphabet": 0.82883767, "qsc_code_frac_chars_comments": 0.19184168, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.2, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0049975, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.056, "qsc_codejava_score_lines_no_logic": 0.232, "qsc_codejava_frac_words_no_modifier": 0.875, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/ui/StatusPane.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.ui;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.input.GameAction;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.NinePatch;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.ui.Button;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.ColorMath;
public class StatusPane extends Component {
private NinePatch bg;
private Image avatar;
private float warning;
private int lastTier = 0;
private Image rawShielding;
private Image shieldedHP;
private Image hp;
private Image exp;
private BossHealthBar bossHP;
private int lastLvl = -1;
private BitmapText level;
private BitmapText depth;
private DangerIndicator danger;
private BuffIndicator buffs;
private Compass compass;
private JournalButton btnJournal;
private MenuButton btnMenu;
private Toolbar.PickedUpItem pickedUp;
private BitmapText version;
@Override
protected void createChildren() {
bg = new NinePatch( Assets.STATUS, 0, 0, 128, 36, 85, 0, 45, 0 );
add( bg );
add( new TouchArea<GameAction>( 0, 1, 31, 31 ) {
@Override
protected void onClick( NoosaInputProcessor.Touch touch ) {
Image sprite = Dungeon.hero.sprite;
Camera.main.panTo( sprite.center(), 5f );
GameScene.show( new WndHero() );
}
@Override
public boolean onKeyUp(NoosaInputProcessor.Key<GameAction> key) {
boolean handled = true;
switch (key.action) {
case HERO_INFO:
onClick( null );
break;
case JOURNAL:
GameScene.show( new WndJournal() );
break;
default:
handled = false;
break;
}
return handled;
}
} );
btnJournal = new JournalButton();
add( btnJournal );
btnMenu = new MenuButton();
add( btnMenu );
avatar = HeroSprite.avatar( Dungeon.hero.heroClass, lastTier );
add( avatar );
compass = new Compass( Statistics.amuletObtained ? Dungeon.level.entrance : Dungeon.level.exit );
add( compass );
rawShielding = new Image( Assets.SHLD_BAR );
rawShielding.alpha(0.5f);
add(rawShielding);
shieldedHP = new Image( Assets.SHLD_BAR );
add(shieldedHP);
hp = new Image( Assets.HP_BAR );
add( hp );
exp = new Image( Assets.XP_BAR );
add( exp );
bossHP = new BossHealthBar();
add( bossHP );
level = new BitmapText( PixelScene.pixelFont);
level.hardlight( 0xFFEBA4 );
add( level );
depth = new BitmapText( Integer.toString( Dungeon.depth ), PixelScene.pixelFont);
depth.hardlight( 0xCACFC2 );
depth.measure();
add( depth );
danger = new DangerIndicator();
add( danger );
buffs = new BuffIndicator( Dungeon.hero );
add( buffs );
add( pickedUp = new Toolbar.PickedUpItem());
version = new BitmapText( "v" + Game.version, PixelScene.pixelFont);
version.alpha( 0.5f );
add(version);
}
@Override
protected void layout() {
height = 32;
bg.size( width, bg.height );
avatar.x = bg.x + 15 - avatar.width / 2f;
avatar.y = bg.y + 16 - avatar.height / 2f;
PixelScene.align(avatar);
compass.x = avatar.x + avatar.width / 2f - compass.origin.x;
compass.y = avatar.y + avatar.height / 2f - compass.origin.y;
PixelScene.align(compass);
hp.x = shieldedHP.x = rawShielding.x = 30;
hp.y = shieldedHP.y = rawShielding.y = 3;
bossHP.setPos( 6 + (width - bossHP.width())/2, 20);
depth.x = width - 35.5f - depth.width() / 2f;
depth.y = 8f - depth.baseLine() / 2f;
PixelScene.align(depth);
danger.setPos( width - danger.width(), 20 );
buffs.setPos( 31, 9 );
btnJournal.setPos( width - 42, 1 );
btnMenu.setPos( width - btnMenu.width(), 1 );
version.scale.set(PixelScene.align(0.5f));
version.measure();
version.x = width - version.width();
version.y = btnMenu.bottom() + (4 - version.baseLine());
PixelScene.align(version);
}
private static final int[] warningColors = new int[]{0x660000, 0xCC0000, 0x660000};
@Override
public void update() {
super.update();
float health = Dungeon.hero.HP;
float shield = Dungeon.hero.shielding();
float max = Dungeon.hero.HT;
if (!Dungeon.hero.isAlive()) {
avatar.tint(0x000000, 0.5f);
} else if ((health/max) < 0.3f) {
warning += Game.elapsed * 5f *(0.4f - (health/max));
warning %= 1f;
avatar.tint(ColorMath.interpolate(warning, warningColors), 0.5f );
} else {
avatar.resetColor();
}
hp.scale.x = Math.max( 0, (health-shield)/max);
shieldedHP.scale.x = health/max;
rawShielding.scale.x = shield/max;
exp.scale.x = (width / exp.width) * Dungeon.hero.exp / Dungeon.hero.maxExp();
if (Dungeon.hero.lvl != lastLvl) {
if (lastLvl != -1) {
Emitter emitter = (Emitter)recycle( Emitter.class );
emitter.revive();
emitter.pos( 27, 27 );
emitter.burst( Speck.factory( Speck.STAR ), 12 );
}
lastLvl = Dungeon.hero.lvl;
level.text( Integer.toString( lastLvl ) );
level.measure();
level.x = 27.5f - level.width() / 2f;
level.y = 28.0f - level.baseLine() / 2f;
PixelScene.align(level);
}
int tier = Dungeon.hero.tier();
if (tier != lastTier) {
lastTier = tier;
avatar.copy( HeroSprite.avatar( Dungeon.hero.heroClass, tier ) );
}
}
public void pickup( Item item, int cell) {
pickedUp.reset( item,
cell,
btnJournal.journalIcon.x + btnJournal.journalIcon.width()/2f,
btnJournal.journalIcon.y + btnJournal.journalIcon.height()/2f);
}
public void flash(){
btnJournal.flashing = true;
}
public void updateKeys(){
btnJournal.updateKeyDisplay();
}
private static class JournalButton extends Button {
private Image bg;
private Image journalIcon;
private KeyDisplay keyIcon;
private boolean flashing;
public JournalButton() {
super();
width = bg.width + 13; //includes the depth display to the left
height = bg.height + 4;
}
@Override
protected void createChildren() {
super.createChildren();
bg = new Image( Assets.MENU, 2, 2, 13, 11 );
add( bg );
journalIcon = new Image( Assets.MENU, 31, 0, 11, 7);
add( journalIcon );
keyIcon = new KeyDisplay();
add(keyIcon);
updateKeyDisplay();
}
@Override
protected void layout() {
super.layout();
bg.x = x + 13;
bg.y = y + 2;
journalIcon.x = bg.x + (bg.width() - journalIcon.width())/2f;
journalIcon.y = bg.y + (bg.height() - journalIcon.height())/2f;
PixelScene.align(journalIcon);
keyIcon.x = bg.x + 1;
keyIcon.y = bg.y + 1;
keyIcon.width = bg.width - 2;
keyIcon.height = bg.height - 2;
PixelScene.align(keyIcon);
}
private float time;
@Override
public void update() {
super.update();
if (flashing){
journalIcon.am = (float)Math.abs(Math.cos( 3 * (time += Game.elapsed) ));
keyIcon.am = journalIcon.am;
if (time >= 0.333f*Math.PI) {
time = 0;
}
}
}
public void updateKeyDisplay() {
keyIcon.updateKeys();
keyIcon.visible = keyIcon.keyCount() > 0;
journalIcon.visible = !keyIcon.visible;
if (keyIcon.keyCount() > 0) {
bg.brightness(.8f - (Math.min(6, keyIcon.keyCount()) / 20f));
} else {
bg.resetColor();
}
}
@Override
protected void onTouchDown() {
bg.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
if (keyIcon.keyCount() > 0) {
bg.brightness(.8f - (Math.min(6, keyIcon.keyCount()) / 20f));
} else {
bg.resetColor();
}
}
@Override
protected void onClick() {
flashing = false;
time = 0;
keyIcon.am = journalIcon.am = 1;
GameScene.show( new WndJournal() );
}
}
private static class MenuButton extends Button {
private Image image;
public MenuButton() {
super();
width = image.width + 4;
height = image.height + 4;
}
@Override
protected void createChildren() {
super.createChildren();
image = new Image( Assets.MENU, 17, 2, 12, 11 );
add( image );
}
@Override
protected void layout() {
super.layout();
image.x = x + 2;
image.y = y + 2;
}
@Override
protected void onTouchDown() {
image.brightness( 1.5f );
Sample.INSTANCE.play( Assets.SND_CLICK );
}
@Override
protected void onTouchUp() {
image.resetColor();
}
@Override
protected void onClick() {
GameScene.show( new WndGame() );
}
}
}
| 9,939 | StatusPane | java | en | java | code | {"qsc_code_num_words": 1202, "qsc_code_num_chars": 9939.0, "qsc_code_mean_word_length": 5.60648918, "qsc_code_frac_words_unique": 0.25124792, "qsc_code_frac_chars_top_2grams": 0.03205223, "qsc_code_frac_chars_top_3grams": 0.07330464, "qsc_code_frac_chars_top_4grams": 0.0783499, "qsc_code_frac_chars_dupe_5grams": 0.17035168, "qsc_code_frac_chars_dupe_6grams": 0.09853094, "qsc_code_frac_chars_dupe_7grams": 0.06855617, "qsc_code_frac_chars_dupe_8grams": 0.06855617, "qsc_code_frac_chars_dupe_9grams": 0.05045259, "qsc_code_frac_chars_dupe_10grams": 0.05045259, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02417747, "qsc_code_frac_chars_whitespace": 0.19267532, "qsc_code_size_file_byte": 9939.0, "qsc_code_num_lines": 407.0, "qsc_code_num_chars_line_max": 100.0, "qsc_code_num_chars_line_mean": 24.42014742, "qsc_code_frac_chars_alphabet": 0.81567797, "qsc_code_frac_chars_comments": 0.08260388, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.19463087, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00010967, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00526431, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06711409, "qsc_codejava_score_lines_no_logic": 0.22818792, "qsc_codejava_frac_words_no_modifier": 0.95238095, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/Recipe.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.AlchemistsToolkit;
import com.shatteredpixel.shatteredpixeldungeon.items.bombs.Bomb;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit;
import com.shatteredpixel.shatteredpixeldungeon.items.food.MeatPie;
import com.shatteredpixel.shatteredpixeldungeon.items.food.StewedMeat;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.AlchemicalCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.BlizzardBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.CausticBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.InfernalBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.ShockingBrew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfAquaticRejuvenation;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfArcaneArmor;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfDragonsBlood;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfHoneyedHealing;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfIcyTouch;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfMight;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.ElixirOfToxicEssence;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic.ExoticPotion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.Scroll;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ExoticScroll;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.Alchemize;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.AquaBlast;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.ArcaneCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.BeaconOfReturning;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.CurseInfusion;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.FeatherFall;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.MagicalInfusion;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.MagicalPorter;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.PhaseShift;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.ReclaimTrap;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.Recycle;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.WildEnergy;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart;
import com.watabou.utils.Reflection;
import java.util.ArrayList;
public abstract class Recipe {
public abstract boolean testIngredients(ArrayList<Item> ingredients);
public abstract int cost(ArrayList<Item> ingredients);
public abstract Item brew(ArrayList<Item> ingredients);
public abstract Item sampleOutput(ArrayList<Item> ingredients);
//subclass for the common situation of a recipe with static inputs and outputs
public static abstract class SimpleRecipe extends Recipe {
//*** These elements must be filled in by subclasses
protected Class<?extends Item>[] inputs; //each class should be unique
protected int[] inQuantity;
protected int cost;
protected Class<?extends Item> output;
protected int outQuantity;
//***
//gets a simple list of items based on inputs
public ArrayList<Item> getIngredients() {
ArrayList<Item> result = new ArrayList<>();
for (int i = 0; i < inputs.length; i++) {
Item ingredient = Reflection.newInstance(inputs[i]);
ingredient.quantity(inQuantity[i]);
result.add(ingredient);
}
return result;
}
@Override
public final boolean testIngredients(ArrayList<Item> ingredients) {
int[] needed = inQuantity.clone();
for (Item ingredient : ingredients){
if (!ingredient.isIdentified()) return false;
for (int i = 0; i < inputs.length; i++){
if (ingredient.getClass() == inputs[i]){
needed[i] -= ingredient.quantity();
break;
}
}
}
for (int i : needed){
if (i > 0){
return false;
}
}
return true;
}
public final int cost(ArrayList<Item> ingredients){
return cost;
}
@Override
public final Item brew(ArrayList<Item> ingredients) {
if (!testIngredients(ingredients)) return null;
int[] needed = inQuantity.clone();
for (Item ingredient : ingredients){
for (int i = 0; i < inputs.length; i++) {
if (ingredient.getClass() == inputs[i] && needed[i] > 0) {
if (needed[i] <= ingredient.quantity()) {
ingredient.quantity(ingredient.quantity() - needed[i]);
needed[i] = 0;
} else {
needed[i] -= ingredient.quantity();
ingredient.quantity(0);
}
}
}
}
//sample output and real output are identical in this case.
return sampleOutput(null);
}
//ingredients are ignored, as output doesn't vary
public final Item sampleOutput(ArrayList<Item> ingredients){
try {
Item result = Reflection.newInstance(output);
result.quantity(outQuantity);
return result;
} catch (Exception e) {
ShatteredPixelDungeon.reportException( e );
return null;
}
}
}
//*******
// Static members
//*******
private static Recipe[] oneIngredientRecipes = new Recipe[]{
new AlchemistsToolkit.upgradeKit(),
new Scroll.ScrollToStone(),
new StewedMeat.oneMeat()
};
private static Recipe[] twoIngredientRecipes = new Recipe[]{
new Blandfruit.CookFruit(),
new Bomb.EnhanceBomb(),
new AlchemicalCatalyst.Recipe(),
new ArcaneCatalyst.Recipe(),
new ElixirOfArcaneArmor.Recipe(),
new ElixirOfAquaticRejuvenation.Recipe(),
new ElixirOfDragonsBlood.Recipe(),
new ElixirOfIcyTouch.Recipe(),
new ElixirOfMight.Recipe(),
new ElixirOfHoneyedHealing.Recipe(),
new ElixirOfToxicEssence.Recipe(),
new BlizzardBrew.Recipe(),
new InfernalBrew.Recipe(),
new ShockingBrew.Recipe(),
new CausticBrew.Recipe(),
new Alchemize.Recipe(),
new AquaBlast.Recipe(),
new BeaconOfReturning.Recipe(),
new CurseInfusion.Recipe(),
new FeatherFall.Recipe(),
new MagicalInfusion.Recipe(),
new MagicalPorter.Recipe(),
new PhaseShift.Recipe(),
new ReclaimTrap.Recipe(),
new Recycle.Recipe(),
new WildEnergy.Recipe(),
new StewedMeat.twoMeat()
};
private static Recipe[] threeIngredientRecipes = new Recipe[]{
new Potion.SeedToPotion(),
new ExoticPotion.PotionToExotic(),
new ExoticScroll.ScrollToExotic(),
new StewedMeat.threeMeat(),
new MeatPie.Recipe()
};
public static Recipe findRecipe(ArrayList<Item> ingredients){
if (ingredients.size() == 1){
for (Recipe recipe : oneIngredientRecipes){
if (recipe.testIngredients(ingredients)){
return recipe;
}
}
} else if (ingredients.size() == 2){
for (Recipe recipe : twoIngredientRecipes){
if (recipe.testIngredients(ingredients)){
return recipe;
}
}
} else if (ingredients.size() == 3){
for (Recipe recipe : threeIngredientRecipes){
if (recipe.testIngredients(ingredients)){
return recipe;
}
}
}
return null;
}
public static boolean usableInRecipe(Item item){
return !item.cursed
&& (!(item instanceof EquipableItem) || item instanceof Dart || item instanceof AlchemistsToolkit)
&& !(item instanceof Wand);
}
}
| 8,469 | Recipe | java | en | java | code | {"qsc_code_num_words": 889, "qsc_code_num_chars": 8469.0, "qsc_code_mean_word_length": 7.1856018, "qsc_code_frac_words_unique": 0.26096738, "qsc_code_frac_chars_top_2grams": 0.09846587, "qsc_code_frac_chars_top_3grams": 0.22010019, "qsc_code_frac_chars_top_4grams": 0.24232937, "qsc_code_frac_chars_dupe_5grams": 0.45491547, "qsc_code_frac_chars_dupe_6grams": 0.38008766, "qsc_code_frac_chars_dupe_7grams": 0.1654665, "qsc_code_frac_chars_dupe_8grams": 0.05823419, "qsc_code_frac_chars_dupe_9grams": 0.03850971, "qsc_code_frac_chars_dupe_10grams": 0.03850971, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00372055, "qsc_code_frac_chars_whitespace": 0.14311017, "qsc_code_size_file_byte": 8469.0, "qsc_code_num_lines": 246.0, "qsc_code_num_chars_line_max": 103.0, "qsc_code_num_chars_line_mean": 34.42682927, "qsc_code_frac_chars_alphabet": 0.876533, "qsc_code_frac_chars_comments": 0.13378203, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13333333, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.01666667, "qsc_codejava_score_lines_no_logic": 0.3, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/ArmorKit.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.ClassArmor;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.audio.Sample;
import java.util.ArrayList;
public class ArmorKit extends Item {
private static final String TXT_UPGRADED = "you applied the armor kit to upgrade your %s";
private static final float TIME_TO_UPGRADE = 2;
private static final String AC_APPLY = "APPLY";
{
image = ItemSpriteSheet.KIT;
unique = true;
}
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
actions.add( AC_APPLY );
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute( hero, action );
if (action.equals(AC_APPLY)) {
curUser = hero;
GameScene.selectItem( itemSelector, WndBag.Mode.ARMOR, Messages.get(this, "prompt") );
}
}
@Override
public boolean isUpgradable() {
return false;
}
@Override
public boolean isIdentified() {
return true;
}
private void upgrade( Armor armor ) {
detach( curUser.belongings.backpack );
curUser.sprite.centerEmitter().start( Speck.factory( Speck.KIT ), 0.05f, 10 );
curUser.spend( TIME_TO_UPGRADE );
curUser.busy();
GLog.w( Messages.get(this, "upgraded", armor.name()) );
ClassArmor classArmor = ClassArmor.upgrade( curUser, armor );
if (curUser.belongings.armor == armor) {
curUser.belongings.armor = classArmor;
((HeroSprite)curUser.sprite).updateArmor();
classArmor.activate(curUser);
} else {
armor.detach( curUser.belongings.backpack );
classArmor.collect( curUser.belongings.backpack );
}
curUser.sprite.operate( curUser.pos );
Sample.INSTANCE.play( Assets.SND_EVOKE );
}
private final WndBag.Listener itemSelector = new WndBag.Listener() {
@Override
public void onSelect( Item item ) {
if (item != null) {
ArmorKit.this.upgrade( (Armor)item );
}
}
};
}
| 3,409 | ArmorKit | java | en | java | code | {"qsc_code_num_words": 405, "qsc_code_num_chars": 3409.0, "qsc_code_mean_word_length": 6.23209877, "qsc_code_frac_words_unique": 0.43950617, "qsc_code_frac_chars_top_2grams": 0.08082409, "qsc_code_frac_chars_top_3grams": 0.18066561, "qsc_code_frac_chars_top_4grams": 0.19175911, "qsc_code_frac_chars_dupe_5grams": 0.16442155, "qsc_code_frac_chars_dupe_6grams": 0.06497623, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00802512, "qsc_code_frac_chars_whitespace": 0.15928425, "qsc_code_size_file_byte": 3409.0, "qsc_code_num_lines": 118.0, "qsc_code_num_chars_line_max": 93.0, "qsc_code_num_chars_line_mean": 28.88983051, "qsc_code_frac_chars_alphabet": 0.8726448, "qsc_code_frac_chars_comments": 0.22909944, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.07042254, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0239726, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07042254, "qsc_codejava_score_lines_no_logic": 0.30985915, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/Gold.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.MasterThievesArmband;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class Gold extends Item {
private static final String TXT_VALUE = "%+d";
{
image = ItemSpriteSheet.GOLD;
stackable = true;
}
public Gold() {
this( 1 );
}
public Gold( int value ) {
this.quantity = value;
}
@Override
public ArrayList<String> actions( Hero hero ) {
return new ArrayList<>();
}
@Override
public boolean doPickUp( Hero hero ) {
Dungeon.gold += quantity;
Statistics.goldCollected += quantity;
Badges.validateGoldCollected();
MasterThievesArmband.Thievery thievery = hero.buff(MasterThievesArmband.Thievery.class);
if (thievery != null)
thievery.collect(quantity);
GameScene.pickUp( this, hero.pos );
hero.sprite.showStatus( CharSprite.NEUTRAL, TXT_VALUE, quantity );
hero.spendAndNext( TIME_TO_PICK_UP );
Sample.INSTANCE.play( Assets.SND_GOLD, 1, 1, Random.Float( 0.9f, 1.1f ) );
return true;
}
@Override
public boolean isUpgradable() {
return false;
}
@Override
public boolean isIdentified() {
return true;
}
@Override
public Item random() {
quantity = Random.Int( 30 + Dungeon.depth * 10, 60 + Dungeon.depth * 20 );
return this;
}
private static final String VALUE = "value";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( VALUE, quantity );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle(bundle);
quantity = bundle.getInt( VALUE );
}
}
| 3,021 | Gold | java | en | java | code | {"qsc_code_num_words": 360, "qsc_code_num_chars": 3021.0, "qsc_code_mean_word_length": 6.27222222, "qsc_code_frac_words_unique": 0.46111111, "qsc_code_frac_chars_top_2grams": 0.04782994, "qsc_code_frac_chars_top_3grams": 0.16829052, "qsc_code_frac_chars_top_4grams": 0.17537644, "qsc_code_frac_chars_dupe_5grams": 0.08148804, "qsc_code_frac_chars_dupe_6grams": 0.02480071, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0125638, "qsc_code_frac_chars_whitespace": 0.15690169, "qsc_code_size_file_byte": 3021.0, "qsc_code_num_lines": 109.0, "qsc_code_num_chars_line_max": 91.0, "qsc_code_num_chars_line_mean": 27.71559633, "qsc_code_frac_chars_alphabet": 0.87396938, "qsc_code_frac_chars_comments": 0.25852367, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13043478, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00357143, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08695652, "qsc_codejava_score_lines_no_logic": 0.34782609, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/BrokenSeal.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.ShieldBuff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndItem;
import com.watabou.noosa.audio.Sample;
import java.util.ArrayList;
public class BrokenSeal extends Item {
public static final String AC_AFFIX = "AFFIX";
//only to be used from the quickslot, for tutorial purposes mostly.
public static final String AC_INFO = "INFO_WINDOW";
{
image = ItemSpriteSheet.SEAL;
cursedKnown = levelKnown = true;
unique = true;
bones = false;
defaultAction = AC_INFO;
}
@Override
public ArrayList<String> actions(Hero hero) {
ArrayList<String> actions = super.actions(hero);
actions.add(AC_AFFIX);
return actions;
}
@Override
public void execute(Hero hero, String action) {
super.execute(hero, action);
if (action.equals(AC_AFFIX)){
curItem = this;
GameScene.selectItem(armorSelector, WndBag.Mode.ARMOR, Messages.get(this, "prompt"));
} else if (action.equals(AC_INFO)) {
GameScene.show(new WndItem(null, this, true));
}
}
@Override
//scroll of upgrade can be used directly once, same as upgrading armor the seal is affixed to then removing it.
public boolean isUpgradable() {
return level() == 0;
}
protected static WndBag.Listener armorSelector = new WndBag.Listener() {
@Override
public void onSelect( Item item ) {
if (item != null && item instanceof Armor) {
Armor armor = (Armor)item;
if (!armor.levelKnown){
GLog.w(Messages.get(BrokenSeal.class, "unknown_armor"));
} else if (armor.cursed || armor.level() < 0){
GLog.w(Messages.get(BrokenSeal.class, "degraded_armor"));
} else {
GLog.p(Messages.get(BrokenSeal.class, "affix"));
Dungeon.hero.sprite.operate(Dungeon.hero.pos);
Sample.INSTANCE.play(Assets.SND_UNLOCK);
armor.affixSeal((BrokenSeal)curItem);
curItem.detach(Dungeon.hero.belongings.backpack);
}
}
}
};
public static class WarriorShield extends ShieldBuff {
private Armor armor;
private float partialShield;
@Override
public synchronized boolean act() {
if (shielding() < maxShield()) {
partialShield += 1/30f;
}
while (partialShield >= 1){
incShield();
partialShield--;
}
if (shielding() <= 0 && maxShield() <= 0){
detach();
}
spend(TICK);
return true;
}
public synchronized void supercharge(int maxShield){
if (maxShield > shielding()){
setShield(maxShield);
}
}
public synchronized void setArmor(Armor arm){
armor = arm;
}
public synchronized int maxShield() {
if (armor != null && armor.isEquipped((Hero)target)) {
return 1 + armor.tier + armor.level();
} else {
return 0;
}
}
@Override
//logic edited slightly as buff should not detach
public int absorbDamage(int dmg) {
if (shielding() >= dmg){
decShield(dmg);
dmg = 0;
} else {
dmg -= shielding();
setShield(0);
}
return dmg;
}
}
}
| 4,370 | BrokenSeal | java | en | java | code | {"qsc_code_num_words": 521, "qsc_code_num_chars": 4370.0, "qsc_code_mean_word_length": 5.97696737, "qsc_code_frac_words_unique": 0.41458733, "qsc_code_frac_chars_top_2grams": 0.0655106, "qsc_code_frac_chars_top_3grams": 0.14643545, "qsc_code_frac_chars_top_4grams": 0.1554271, "qsc_code_frac_chars_dupe_5grams": 0.12716763, "qsc_code_frac_chars_dupe_6grams": 0.03789338, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00808025, "qsc_code_frac_chars_whitespace": 0.17871854, "qsc_code_size_file_byte": 4370.0, "qsc_code_num_lines": 156.0, "qsc_code_num_chars_line_max": 113.0, "qsc_code_num_chars_line_mean": 28.01282051, "qsc_code_frac_chars_alphabet": 0.85957091, "qsc_code_frac_chars_comments": 0.23066362, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.08256881, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01606187, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04587156, "qsc_codejava_score_lines_no_logic": 0.2293578, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/KindofMisc.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
public abstract class KindofMisc extends EquipableItem {
private static final float TIME_TO_EQUIP = 1f;
@Override
public boolean doEquip(final Hero hero) {
if (hero.belongings.misc1 != null && hero.belongings.misc2 != null) {
final KindofMisc m1 = hero.belongings.misc1;
final KindofMisc m2 = hero.belongings.misc2;
GameScene.show(
new WndOptions(Messages.get(KindofMisc.class, "unequip_title"),
Messages.get(KindofMisc.class, "unequip_message"),
Messages.titleCase(m1.toString()),
Messages.titleCase(m2.toString())) {
@Override
protected void onSelect(int index) {
KindofMisc equipped = (index == 0 ? m1 : m2);
//temporarily give 1 extra backpack spot to support swapping with a full inventory
hero.belongings.backpack.size++;
if (equipped.doUnequip(hero, true, false)) {
//fully re-execute rather than just call doEquip as we want to preserve quickslot
execute(hero, AC_EQUIP);
}
hero.belongings.backpack.size--;
}
});
return false;
} else {
if (hero.belongings.misc1 == null) {
hero.belongings.misc1 = this;
} else {
hero.belongings.misc2 = this;
}
detach( hero.belongings.backpack );
activate( hero );
cursedKnown = true;
if (cursed) {
equipCursed( hero );
GLog.n( Messages.get(this, "equip_cursed", this) );
}
hero.spendAndNext( TIME_TO_EQUIP );
return true;
}
}
@Override
public boolean doUnequip(Hero hero, boolean collect, boolean single) {
if (super.doUnequip(hero, collect, single)){
if (hero.belongings.misc1 == this) {
hero.belongings.misc1 = null;
} else {
hero.belongings.misc2 = null;
}
return true;
} else {
return false;
}
}
@Override
public boolean isEquipped( Hero hero ) {
return hero.belongings.misc1 == this || hero.belongings.misc2 == this;
}
}
| 3,072 | KindofMisc | java | en | java | code | {"qsc_code_num_words": 374, "qsc_code_num_chars": 3072.0, "qsc_code_mean_word_length": 5.7513369, "qsc_code_frac_words_unique": 0.45187166, "qsc_code_frac_chars_top_2grams": 0.09762901, "qsc_code_frac_chars_top_3grams": 0.06183171, "qsc_code_frac_chars_top_4grams": 0.10227801, "qsc_code_frac_chars_dupe_5grams": 0.13947001, "qsc_code_frac_chars_dupe_6grams": 0.09669921, "qsc_code_frac_chars_dupe_7grams": 0.0362622, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01545972, "qsc_code_frac_chars_whitespace": 0.19986979, "qsc_code_size_file_byte": 3072.0, "qsc_code_num_lines": 113.0, "qsc_code_num_chars_line_max": 90.0, "qsc_code_num_chars_line_mean": 27.18584071, "qsc_code_frac_chars_alphabet": 0.85964199, "qsc_code_frac_chars_comments": 0.30729167, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.1875, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01879699, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.078125, "qsc_codejava_score_lines_no_logic": 0.234375, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/Dewdrop.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
public class Dewdrop extends Item {
{
image = ItemSpriteSheet.DEWDROP;
stackable = true;
dropsDownHeap = true;
}
@Override
public boolean doPickUp( Hero hero ) {
DewVial vial = hero.belongings.getItem( DewVial.class );
if (vial != null && !vial.isFull()){
vial.collectDew( this );
} else {
//20 drops for a full heal
int heal = Math.round( hero.HT * 0.05f * quantity );
int effect = Math.min( hero.HT - hero.HP, heal );
if (effect > 0) {
hero.HP += effect;
hero.sprite.emitter().burst( Speck.factory( Speck.HEALING ), 1 );
hero.sprite.showStatus( CharSprite.POSITIVE, Messages.get(this, "value", effect) );
} else {
GLog.i( Messages.get(this, "already_full") );
return false;
}
}
Sample.INSTANCE.play( Assets.SND_DEWDROP );
hero.spendAndNext( TIME_TO_PICK_UP );
return true;
}
@Override
//max of one dew in a stack
public Item quantity(int value) {
quantity = Math.min( value, 1);
return this;
}
}
| 2,345 | Dewdrop | java | en | java | code | {"qsc_code_num_words": 301, "qsc_code_num_chars": 2345.0, "qsc_code_mean_word_length": 5.61461794, "qsc_code_frac_words_unique": 0.52491694, "qsc_code_frac_chars_top_2grams": 0.08047337, "qsc_code_frac_chars_top_3grams": 0.17988166, "qsc_code_frac_chars_top_4grams": 0.18224852, "qsc_code_frac_chars_dupe_5grams": 0.10887574, "qsc_code_frac_chars_dupe_6grams": 0.03313609, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01299376, "qsc_code_frac_chars_whitespace": 0.17953092, "qsc_code_size_file_byte": 2345.0, "qsc_code_num_lines": 80.0, "qsc_code_num_chars_line_max": 88.0, "qsc_code_num_chars_line_mean": 29.3125, "qsc_code_frac_chars_alphabet": 0.86538462, "qsc_code_frac_chars_comments": 0.35565032, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0952381, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01125083, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04761905, "qsc_codejava_score_lines_no_logic": 0.33333333, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/Ankh.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite.Glowing;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
public class Ankh extends Item {
public static final String AC_BLESS = "BLESS";
{
image = ItemSpriteSheet.ANKH;
//You tell the ankh no, don't revive me, and then it comes back to revive you again in another run.
//I'm not sure if that's enthusiasm or passive-aggression.
bones = true;
}
private Boolean blessed = false;
@Override
public boolean isUpgradable() {
return false;
}
@Override
public boolean isIdentified() {
return true;
}
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions(hero);
DewVial vial = hero.belongings.getItem(DewVial.class);
if (vial != null && vial.isFull() && !blessed)
actions.add( AC_BLESS );
return actions;
}
@Override
public void execute( final Hero hero, String action ) {
super.execute( hero, action );
if (action.equals( AC_BLESS )) {
DewVial vial = hero.belongings.getItem(DewVial.class);
if (vial != null){
blessed = true;
vial.empty();
GLog.p( Messages.get(this, "bless") );
hero.spend( 1f );
hero.busy();
Sample.INSTANCE.play( Assets.SND_DRINK );
CellEmitter.get(hero.pos).start(Speck.factory(Speck.LIGHT), 0.2f, 3);
hero.sprite.operate( hero.pos );
}
}
}
@Override
public String desc() {
if (blessed)
return Messages.get(this, "desc_blessed");
else
return super.desc();
}
public Boolean isBlessed(){
return blessed;
}
private static final Glowing WHITE = new Glowing( 0xFFFFCC );
@Override
public Glowing glowing() {
return isBlessed() ? WHITE : null;
}
private static final String BLESSED = "blessed";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( BLESSED, blessed );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
blessed = bundle.getBoolean( BLESSED );
}
@Override
public int price() {
return 50 * quantity;
}
}
| 3,428 | Ankh | java | en | java | code | {"qsc_code_num_words": 429, "qsc_code_num_chars": 3428.0, "qsc_code_mean_word_length": 5.82517483, "qsc_code_frac_words_unique": 0.44289044, "qsc_code_frac_chars_top_2grams": 0.03601441, "qsc_code_frac_chars_top_3grams": 0.13685474, "qsc_code_frac_chars_top_4grams": 0.14085634, "qsc_code_frac_chars_dupe_5grams": 0.18327331, "qsc_code_frac_chars_dupe_6grams": 0.06562625, "qsc_code_frac_chars_dupe_7grams": 0.04321729, "qsc_code_frac_chars_dupe_8grams": 0.04321729, "qsc_code_frac_chars_dupe_9grams": 0.04321729, "qsc_code_frac_chars_dupe_10grams": 0.04321729, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00843289, "qsc_code_frac_chars_whitespace": 0.1697783, "qsc_code_size_file_byte": 3428.0, "qsc_code_num_lines": 129.0, "qsc_code_num_chars_line_max": 102.0, "qsc_code_num_chars_line_mean": 26.57364341, "qsc_code_frac_chars_alphabet": 0.8696416, "qsc_code_frac_chars_comments": 0.27362894, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13253012, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01164659, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00321285, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.12048193, "qsc_codejava_score_lines_no_logic": 0.31325301, "qsc_codejava_frac_words_no_modifier": 0.81818182, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/Honeypot.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bee;
import com.shatteredpixel.shatteredpixeldungeon.effects.Pushing;
import com.shatteredpixel.shatteredpixeldungeon.effects.Splash;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.tweeners.AlphaTweener;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class Honeypot extends Item {
public static final String AC_SHATTER = "SHATTER";
{
image = ItemSpriteSheet.HONEYPOT;
defaultAction = AC_THROW;
usesTargeting = true;
stackable = true;
}
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
actions.add( AC_SHATTER );
return actions;
}
@Override
public void execute( final Hero hero, String action ) {
super.execute( hero, action );
if (action.equals( AC_SHATTER )) {
hero.sprite.zap( hero.pos );
detach( hero.belongings.backpack );
Item item = shatter( hero, hero.pos );
if (!item.collect()){
Dungeon.level.drop(item, hero.pos);
if (item instanceof ShatteredPot){
((ShatteredPot) item).dropPot(hero, hero.pos);
}
}
hero.next();
}
}
@Override
protected void onThrow( int cell ) {
if (Dungeon.level.pit[cell]) {
super.onThrow( cell );
} else {
Dungeon.level.drop(shatter( null, cell ), cell);
}
}
public Item shatter( Char owner, int pos ) {
if (Dungeon.level.heroFOV[pos]) {
Sample.INSTANCE.play( Assets.SND_SHATTER );
Splash.at( pos, 0xffd500, 5 );
}
int newPos = pos;
if (Actor.findChar( pos ) != null) {
ArrayList<Integer> candidates = new ArrayList<>();
boolean[] passable = Dungeon.level.passable;
for (int n : PathFinder.NEIGHBOURS4) {
int c = pos + n;
if (passable[c] && Actor.findChar( c ) == null) {
candidates.add( c );
}
}
newPos = candidates.size() > 0 ? Random.element( candidates ) : -1;
}
if (newPos != -1) {
Bee bee = new Bee();
bee.spawn( Dungeon.depth );
bee.setPotInfo( pos, owner );
bee.HP = bee.HT;
bee.pos = newPos;
GameScene.add( bee );
Actor.addDelayed( new Pushing( bee, pos, newPos ), -1f );
bee.sprite.alpha( 0 );
bee.sprite.parent.add( new AlphaTweener( bee.sprite, 1, 0.15f ) );
Sample.INSTANCE.play( Assets.SND_BEE );
return new ShatteredPot();
} else {
return this;
}
}
@Override
public boolean isUpgradable() {
return false;
}
@Override
public boolean isIdentified() {
return true;
}
@Override
public int price() {
return 30 * quantity;
}
//The bee's broken 'home', all this item does is let its bee know where it is, and who owns it (if anyone).
public static class ShatteredPot extends Item {
{
image = ItemSpriteSheet.SHATTPOT;
stackable = true;
}
@Override
public boolean doPickUp(Hero hero) {
if ( super.doPickUp(hero) ){
pickupPot( hero );
return true;
} else {
return false;
}
}
@Override
public void doDrop(Hero hero) {
super.doDrop(hero);
dropPot(hero, hero.pos);
}
@Override
protected void onThrow(int cell) {
super.onThrow(cell);
dropPot(curUser, cell);
}
public void pickupPot(Char holder){
for (Bee bee : findBees(holder.pos)){
updateBee(bee, -1, holder);
}
}
public void dropPot( Char holder, int dropPos ){
for (Bee bee : findBees(holder)){
updateBee(bee, dropPos, null);
}
}
private void updateBee( Bee bee, int cell, Char holder ){
if (bee != null && bee.alignment == Char.Alignment.ENEMY)
bee.setPotInfo( cell, holder );
}
//returns up to quantity bees which match the current pot Pos
private ArrayList<Bee> findBees( int potPos ){
ArrayList<Bee> bees = new ArrayList<>();
for (Char c : Actor.chars()){
if (c instanceof Bee && ((Bee) c).potPos() == potPos){
bees.add((Bee) c);
if (bees.size() >= quantity) {
break;
}
}
}
return bees;
}
//returns up to quantity bees which match the current pot holder
private ArrayList<Bee> findBees( Char potHolder ){
ArrayList<Bee> bees = new ArrayList<>();
for (Char c : Actor.chars()){
if (c instanceof Bee && ((Bee) c).potHolderID() == potHolder.id()){
bees.add((Bee) c);
if (bees.size() >= quantity) {
break;
}
}
}
return bees;
}
@Override
public boolean isUpgradable() {
return false;
}
@Override
public boolean isIdentified() {
return true;
}
@Override
public int price() {
return 5 * quantity;
}
}
}
| 5,790 | Honeypot | java | en | java | code | {"qsc_code_num_words": 707, "qsc_code_num_chars": 5790.0, "qsc_code_mean_word_length": 5.48514851, "qsc_code_frac_words_unique": 0.31541726, "qsc_code_frac_chars_top_2grams": 0.03249097, "qsc_code_frac_chars_top_3grams": 0.10778752, "qsc_code_frac_chars_top_4grams": 0.11346055, "qsc_code_frac_chars_dupe_5grams": 0.28261991, "qsc_code_frac_chars_dupe_6grams": 0.17225374, "qsc_code_frac_chars_dupe_7grams": 0.13976276, "qsc_code_frac_chars_dupe_8grams": 0.13976276, "qsc_code_frac_chars_dupe_9grams": 0.13976276, "qsc_code_frac_chars_dupe_10grams": 0.13976276, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00612826, "qsc_code_frac_chars_whitespace": 0.21088083, "qsc_code_size_file_byte": 5790.0, "qsc_code_num_lines": 239.0, "qsc_code_num_chars_line_max": 109.0, "qsc_code_num_chars_line_mean": 24.22594142, "qsc_code_frac_chars_alphabet": 0.84263515, "qsc_code_frac_chars_comments": 0.16252159, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.25714286, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0014436, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00164982, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08571429, "qsc_codejava_score_lines_no_logic": 0.23428571, "qsc_codejava_frac_words_no_modifier": 0.9375, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/input/GameAction.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.input;
public enum GameAction {
BACK( null ),
HERO_INFO("Hero Info"),
JOURNAL("Journal"),
REST("Wait"),
SEARCH("Search"),
RESUME("Resume motion"),
BACKPACK("Backpack"),
QUICKSLOT_1("Quickslot 1"),
QUICKSLOT_2("Quickslot 2"),
QUICKSLOT_3("Quickslot 3"),
QUICKSLOT_4("Quickslot 4"),
TAG_ATTACK("Attack"),
TAG_DANGER("Visible Enemies"),
ZOOM_IN("Zoom In"),
ZOOM_OUT("Zoom Out"),
ZOOM_DEFAULT("Default Zoom"),
MOVE_UP("Move North"), MOVE_DOWN("Move South"), MOVE_LEFT("Move West"), MOVE_RIGHT("Move East"),
MOVE_TOP_LEFT("Move NW"), MOVE_TOP_RIGHT("Move NE"), MOVE_BOTTOM_LEFT("Move SW"), MOVE_BOTTOM_RIGHT("Move SE"),
OPERATE("Current Cell"),
UNKNOWN(null);
private final String description;
GameAction(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
| 1,684 | GameAction | java | en | java | code | {"qsc_code_num_words": 237, "qsc_code_num_chars": 1684.0, "qsc_code_mean_word_length": 5.05907173, "qsc_code_frac_words_unique": 0.56118143, "qsc_code_frac_chars_top_2grams": 0.02752294, "qsc_code_frac_chars_top_3grams": 0.03252711, "qsc_code_frac_chars_top_4grams": 0.04753962, "qsc_code_frac_chars_dupe_5grams": 0.06839033, "qsc_code_frac_chars_dupe_6grams": 0.04670559, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01765537, "qsc_code_frac_chars_whitespace": 0.15914489, "qsc_code_size_file_byte": 1684.0, "qsc_code_num_lines": 61.0, "qsc_code_num_chars_line_max": 113.0, "qsc_code_num_chars_line_mean": 27.60655738, "qsc_code_frac_chars_alphabet": 0.82909605, "qsc_code_frac_chars_comments": 0.46377672, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.24031008, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03333333, "qsc_codejava_score_lines_no_logic": 0.1, "qsc_codejava_frac_words_no_modifier": 1.0, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": null, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/mechanics/Ballistica.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.mechanics;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import java.util.ArrayList;
import java.util.List;
public class Ballistica {
//note that the path is the FULL path of the projectile, including tiles after collision.
//make sure to generate a subPath for the common case of going source to collision.
public ArrayList<Integer> path = new ArrayList<>();
public Integer sourcePos = null;
public Integer collisionPos = null;
public Integer dist = 0;
//parameters to specify the colliding cell
public static final int STOP_TARGET = 1; //ballistica will stop at the target cell
public static final int STOP_CHARS = 2; //ballistica will stop on first char hit
public static final int STOP_TERRAIN = 4; //ballistica will stop on terrain(LOS blocking, impassable, etc.)
public static final int PROJECTILE = STOP_TARGET | STOP_CHARS | STOP_TERRAIN;
public static final int MAGIC_BOLT = STOP_CHARS | STOP_TERRAIN;
public static final int WONT_STOP = 0;
public Ballistica( int from, int to, int params ){
sourcePos = from;
build(from, to, (params & STOP_TARGET) > 0, (params & STOP_CHARS) > 0, (params & STOP_TERRAIN) > 0);
if (collisionPos != null) {
dist = path.indexOf(collisionPos);
} else if (!path.isEmpty()) {
collisionPos = path.get(dist = path.size() - 1);
} else {
path.add(from);
collisionPos = from;
dist = 0;
}
}
private void build( int from, int to, boolean stopTarget, boolean stopChars, boolean stopTerrain ) {
int w = Dungeon.level.width();
int x0 = from % w;
int x1 = to % w;
int y0 = from / w;
int y1 = to / w;
int dx = x1 - x0;
int dy = y1 - y0;
int stepX = dx > 0 ? +1 : -1;
int stepY = dy > 0 ? +1 : -1;
dx = Math.abs( dx );
dy = Math.abs( dy );
int stepA;
int stepB;
int dA;
int dB;
if (dx > dy) {
stepA = stepX;
stepB = stepY * w;
dA = dx;
dB = dy;
} else {
stepA = stepY * w;
stepB = stepX;
dA = dy;
dB = dx;
}
int cell = from;
int err = dA / 2;
while (Dungeon.level.insideMap(cell)) {
//if we're in a wall, collide with the previous cell along the path.
//we don't use solid here because we don't want to stop short of closed doors
if (stopTerrain && cell != sourcePos && !Dungeon.level.passable[cell] && !Dungeon.level.avoid[cell]) {
collide(path.get(path.size() - 1));
}
path.add(cell);
if ((stopTerrain && cell != sourcePos && Dungeon.level.solid[cell])
|| (cell != sourcePos && stopChars && Actor.findChar( cell ) != null)
|| (cell == to && stopTarget)){
collide(cell);
}
cell += stepA;
err += dB;
if (err >= dA) {
err = err - dA;
cell = cell + stepB;
}
}
}
//we only want to record the first position collision occurs at.
private void collide(int cell){
if (collisionPos == null)
collisionPos = cell;
}
//returns a segment of the path from start to end, inclusive.
//if there is an error, returns an empty arraylist instead.
public List<Integer> subPath(int start, int end){
try {
end = Math.min( end, path.size()-1);
return path.subList(start, end+1);
} catch (Exception e){
ShatteredPixelDungeon.reportException(e);
return new ArrayList<>();
}
}
}
| 4,193 | Ballistica | java | en | java | code | {"qsc_code_num_words": 592, "qsc_code_num_chars": 4193.0, "qsc_code_mean_word_length": 4.75844595, "qsc_code_frac_words_unique": 0.36486486, "qsc_code_frac_chars_top_2grams": 0.02555911, "qsc_code_frac_chars_top_3grams": 0.03620873, "qsc_code_frac_chars_top_4grams": 0.04259851, "qsc_code_frac_chars_dupe_5grams": 0.11288605, "qsc_code_frac_chars_dupe_6grams": 0.09513667, "qsc_code_frac_chars_dupe_7grams": 0.02839901, "qsc_code_frac_chars_dupe_8grams": 0.02839901, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01371115, "qsc_code_frac_chars_whitespace": 0.21726687, "qsc_code_size_file_byte": 4193.0, "qsc_code_num_lines": 149.0, "qsc_code_num_chars_line_max": 109.0, "qsc_code_num_chars_line_mean": 28.1409396, "qsc_code_frac_chars_alphabet": 0.84460695, "qsc_code_frac_chars_comments": 0.35058431, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.02197802, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02197802, "qsc_codejava_score_lines_no_logic": 0.13186813, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/mechanics/ShadowCaster.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.mechanics;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
//based on: http://www.roguebasin.com/index.php?title=FOV_using_recursive_shadowcasting
public final class ShadowCaster {
public static final int MAX_DISTANCE = 12;
//max length of rows as FOV moves out, for each FOV distance
//This is used to make the overall FOV circular, instead of square
public static int[][] rounding;
static {
rounding = new int[MAX_DISTANCE+1][];
for (int i=1; i <= MAX_DISTANCE; i++) {
rounding[i] = new int[i+1];
for (int j=1; j <= i; j++) {
//testing the middle of a cell, so we use i + 0.5
rounding[i][j] = (int)Math.min(
j,
Math.round( (i + 0.5) * Math.cos( Math.asin( j / (i + 0.5) ))));
}
}
}
public static void castShadow( int x, int y, boolean[] fieldOfView, boolean[] blocking, int distance ) {
if (distance >= MAX_DISTANCE){
distance = MAX_DISTANCE;
}
BArray.setFalse(fieldOfView);
//set source cell to true
fieldOfView[y * Dungeon.level.width() + x] = true;
//scans octants, clockwise
try {
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, +1, -1, false);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, -1, +1, true);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, +1, +1, true);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, +1, +1, false);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, -1, +1, false);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, +1, -1, true);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, -1, -1, true);
scanOctant(distance, fieldOfView, blocking, 1, x, y, 0.0, 1.0, -1, -1, false);
} catch (Exception e){
ShatteredPixelDungeon.reportException(e);
BArray.setFalse(fieldOfView);
}
}
//scans a single 45 degree octant of the FOV.
//This can add up to a whole FOV by mirroring in X(mX), Y(mY), and X=Y(mXY)
private static void scanOctant(int distance, boolean[] fov, boolean[] blocking, int row,
int x, int y, double lSlope, double rSlope,
int mX, int mY, boolean mXY){
//if we have negative space to traverse, just quit.
if (rSlope < lSlope) return;
boolean inBlocking = false;
int start, end;
int col;
//calculations are offset by 0.5 because FOV is coming from the center of the source cell
//for each row, starting with the current one
for (; row <= distance; row++){
//we offset by slightly less than 0.5 to account for slopes just touching a cell
if (lSlope == 0) start = 0;
else start = (int)Math.floor((row - 0.5) * lSlope + 0.499);
if (rSlope == 1) end = rounding[distance][row];
else end = Math.min( rounding[distance][row],
(int)Math.ceil((row + 0.5) * rSlope - 0.499));
//coordinates of source
int cell = x + y*Dungeon.level.width();
//plus coordinates of current cell (including mirroring in x, y, and x=y)
if (mXY) cell += mX*start*Dungeon.level.width() + mY*row;
else cell += mX*start + mY*row*Dungeon.level.width();
//for each column in this row, which
for (col = start; col <= end; col++){
fov[cell] = true;
if (blocking[cell]){
if (!inBlocking){
inBlocking = true;
//start a new scan, 1 row deeper, ending at the left side of current cell
if (col != start){
scanOctant(distance, fov, blocking, row+1, x, y, lSlope,
//change in x over change in y
(col - 0.5) / (row + 0.5),
mX, mY, mXY);
}
}
} else {
if (inBlocking){
inBlocking = false;
//restrict current scan to the left side of current cell for future rows
//change in x over change in y
lSlope = (col - 0.5) / (row - 0.5);
}
}
if (!mXY) cell += mX;
else cell += mX*Dungeon.level.width();
}
//if the row ends in a blocking cell, this scan is finished.
if (inBlocking) return;
}
}
}
| 5,100 | ShadowCaster | java | en | java | code | {"qsc_code_num_words": 739, "qsc_code_num_chars": 5100.0, "qsc_code_mean_word_length": 4.32476319, "qsc_code_frac_words_unique": 0.29634641, "qsc_code_frac_chars_top_2grams": 0.01001252, "qsc_code_frac_chars_top_3grams": 0.00844806, "qsc_code_frac_chars_top_4grams": 0.09261577, "qsc_code_frac_chars_dupe_5grams": 0.18710889, "qsc_code_frac_chars_dupe_6grams": 0.17897372, "qsc_code_frac_chars_dupe_7grams": 0.14017522, "qsc_code_frac_chars_dupe_8grams": 0.12640801, "qsc_code_frac_chars_dupe_9grams": 0.12640801, "qsc_code_frac_chars_dupe_10grams": 0.12640801, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.03030303, "qsc_code_frac_chars_whitespace": 0.24941176, "qsc_code_size_file_byte": 5100.0, "qsc_code_num_lines": 147.0, "qsc_code_num_chars_line_max": 106.0, "qsc_code_num_chars_line_mean": 34.69387755, "qsc_code_frac_chars_alphabet": 0.8045977, "qsc_code_frac_chars_comments": 0.36784314, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.02564103, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02564103, "qsc_codejava_score_lines_no_logic": 0.08974359, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00x4/m4rs | src/wma.rs | //! WMA (Weighted Moving Average)
//!
//! # Examples
//! ```rust
//! // Prepare candlesticks in some way
//! let candlesticks = vec![
//! m4rs::Candlestick::new(1719400001, 100.0, 130.0, 90.0, 110.0, 1000.0),
//! m4rs::Candlestick::new(1719400002, 110.0, 140.0, 100.0, 130.0, 1000.0),
//! m4rs::Candlestick::new(1719400003, 130.0, 135.0, 120.0, 120.0, 1000.0),
//! m4rs::Candlestick::new(1719400004, 120.0, 130.0, 80.0, 95.0, 1000.0),
//! m4rs::Candlestick::new(1719400005, 90.0, 100.0, 70.0, 82.0, 1000.0),
//! ];
//!
//! // Get 20WMA calculation result
//! let result = m4rs::wma(&candlesticks, 20);
//! ```
use crate::Error;
use super::{IndexEntry, IndexEntryLike};
/// Returns WMA (Weighted Moving Average) for given IndexEntry list
pub fn wma(entries: &[impl IndexEntryLike], duration: usize) -> Result<Vec<IndexEntry>, Error> {
if duration == 0 || entries.len() < duration {
return Ok(vec![]);
}
IndexEntry::validate_list(entries)?;
let mut sorted = entries.to_owned();
sorted.sort_by_key(|x| x.get_at());
Ok((0..=(sorted.len() - duration))
.map(|i| sorted.iter().skip(i).take(duration).collect::<Vec<_>>())
.map(|xs| {
let at = xs.iter().last().unwrap().get_at();
let weights: Vec<f64> = (1..=duration).map(|x| x as f64).collect();
let weights_sum = weights.iter().fold(0.0, |z, x| z + x);
let value_sum = xs
.iter()
.zip(weights)
.map(|(x, w)| x.get_value() * w)
.fold(0.0, |z, x| z + x);
IndexEntry {
at,
value: value_sum / weights_sum,
}
})
.collect())
}
| 1,722 | wma | rs | en | rust | code | {"qsc_code_num_words": 227, "qsc_code_num_chars": 1722.0, "qsc_code_mean_word_length": 4.0660793, "qsc_code_frac_words_unique": 0.3876652, "qsc_code_frac_chars_top_2grams": 0.08125677, "qsc_code_frac_chars_top_3grams": 0.09750813, "qsc_code_frac_chars_top_4grams": 0.04333694, "qsc_code_frac_chars_dupe_5grams": 0.12567714, "qsc_code_frac_chars_dupe_6grams": 0.12567714, "qsc_code_frac_chars_dupe_7grams": 0.02166847, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.13198758, "qsc_code_frac_chars_whitespace": 0.25203252, "qsc_code_size_file_byte": 1722.0, "qsc_code_num_lines": 49.0, "qsc_code_num_chars_line_max": 97.0, "qsc_code_num_chars_line_mean": 35.14285714, "qsc_code_frac_chars_alphabet": 0.58462733, "qsc_code_frac_chars_comments": 0.40534262, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
00x4/m4rs | src/dema.rs | //! DEMA (Double Exponential Moving Average)
//!
//! # Examples
//! ```rust
//! // Prepare candlesticks in some way
//! let candlesticks = vec![
//! m4rs::Candlestick::new(1719400001, 100.0, 130.0, 90.0, 110.0, 1000.0),
//! m4rs::Candlestick::new(1719400002, 110.0, 140.0, 100.0, 130.0, 1000.0),
//! m4rs::Candlestick::new(1719400003, 130.0, 135.0, 120.0, 120.0, 1000.0),
//! m4rs::Candlestick::new(1719400004, 120.0, 130.0, 80.0, 95.0, 1000.0),
//! m4rs::Candlestick::new(1719400005, 90.0, 100.0, 70.0, 82.0, 1000.0),
//! ];
//!
//! // Get 9DEMA calculation result
//! let result = m4rs::dema(&candlesticks, 9);
//! ```
use crate::{Error, IndexEntry, IndexEntryLike, ema};
/// Returns DEMA (Double Exponential Moving Average) for given IndexEntry list
pub fn dema(entries: &[impl IndexEntryLike], duration: usize) -> Result<Vec<IndexEntry>, Error> {
let ema1 = ema(entries, duration)?;
let ema2 = ema(&ema1, duration)?;
Ok(ema2
.iter()
.filter_map(|e2| {
ema1.iter().find(|e1| e1.at == e2.at).map(|e1| IndexEntry {
at: e1.at,
value: e1.value * 2.0 - e2.value,
})
})
.collect())
}
| 1,203 | dema | rs | en | rust | code | {"qsc_code_num_words": 161, "qsc_code_num_chars": 1203.0, "qsc_code_mean_word_length": 4.34161491, "qsc_code_frac_words_unique": 0.42857143, "qsc_code_frac_chars_top_2grams": 0.10729614, "qsc_code_frac_chars_top_3grams": 0.12875536, "qsc_code_frac_chars_top_4grams": 0.05722461, "qsc_code_frac_chars_dupe_5grams": 0.23462089, "qsc_code_frac_chars_dupe_6grams": 0.13733906, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.18181818, "qsc_code_frac_chars_whitespace": 0.21363259, "qsc_code_size_file_byte": 1203.0, "qsc_code_num_lines": 33.0, "qsc_code_num_chars_line_max": 98.0, "qsc_code_num_chars_line_mean": 36.45454545, "qsc_code_frac_chars_alphabet": 0.55708245, "qsc_code_frac_chars_comments": 0.59850374, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.14285714, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
00x4/m4rs | src/tema.rs | //! TEMA (Triple Exponential Moving Average)
//!
//! # Examples
//! ```rust
//! // Prepare candlesticks in some way
//! let candlesticks = vec![
//! m4rs::Candlestick::new(1719400001, 100.0, 130.0, 90.0, 110.0, 1000.0),
//! m4rs::Candlestick::new(1719400002, 110.0, 140.0, 100.0, 130.0, 1000.0),
//! m4rs::Candlestick::new(1719400003, 130.0, 135.0, 120.0, 120.0, 1000.0),
//! m4rs::Candlestick::new(1719400004, 120.0, 130.0, 80.0, 95.0, 1000.0),
//! m4rs::Candlestick::new(1719400005, 90.0, 100.0, 70.0, 82.0, 1000.0),
//! ];
//!
//! // Get 9TEMA calculation result
//! let result = m4rs::tema(&candlesticks, 9);
//! ```
use crate::{Error, IndexEntry, IndexEntryLike, ema};
/// Returns TEMA (Triple Exponential Moving Average) for given IndexEntry list
pub fn tema(entries: &[impl IndexEntryLike], duration: usize) -> Result<Vec<IndexEntry>, Error> {
let ema1 = ema(entries, duration)?;
let ema2 = ema(&ema1, duration)?;
let ema3 = ema(&ema2, duration)?;
Ok(ema3
.iter()
.filter_map(|e3| {
match (
ema1.iter().find(|x| x.at == e3.at),
ema2.iter().find(|x| x.at == e3.at),
) {
(Some(e1), Some(e2)) => Some(IndexEntry {
at: e1.at,
value: e1.value * 3.0 - e2.value * 3.0 + e3.value,
}),
_ => None,
}
})
.collect())
}
| 1,440 | tema | rs | en | rust | code | {"qsc_code_num_words": 183, "qsc_code_num_chars": 1440.0, "qsc_code_mean_word_length": 4.19672131, "qsc_code_frac_words_unique": 0.40437158, "qsc_code_frac_chars_top_2grams": 0.09765625, "qsc_code_frac_chars_top_3grams": 0.1171875, "qsc_code_frac_chars_top_4grams": 0.05208333, "qsc_code_frac_chars_dupe_5grams": 0.25520833, "qsc_code_frac_chars_dupe_6grams": 0.16666667, "qsc_code_frac_chars_dupe_7grams": 0.04166667, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.16872038, "qsc_code_frac_chars_whitespace": 0.26736111, "qsc_code_size_file_byte": 1440.0, "qsc_code_num_lines": 40.0, "qsc_code_num_chars_line_max": 98.0, "qsc_code_num_chars_line_mean": 36.0, "qsc_code_frac_chars_alphabet": 0.55924171, "qsc_code_frac_chars_comments": 0.5, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/actors/Actor.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.actors;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
import com.watabou.utils.SparseArray;
import java.util.HashSet;
public abstract class Actor implements Bundlable {
public static final float TICK = 1f;
private float time;
private int id = 0;
//default priority values for general actor categories
//note that some specific actors pick more specific values
//e.g. a buff acting after all normal buffs might have priority BUFF_PRIO + 1
protected static final int VFX_PRIO = 100; //visual effects take priority
protected static final int HERO_PRIO = 0; //positive is before hero, negative after
protected static final int BLOB_PRIO = -10; //blobs act after hero, before mobs
protected static final int MOB_PRIO = -20; //mobs act between buffs and blobd
protected static final int BUFF_PRIO = -30; //buffs act last in a turn
private static final int DEFAULT = -100; //if no priority is given, act after all else
//used to determine what order actors act in if their time is equal. Higher values act earlier.
protected int actPriority = DEFAULT;
protected abstract boolean act();
protected void spend( float time ) {
this.time += time;
//if time is very close to a whole number, round to a whole number to fix errors
float ex = Math.abs(this.time % 1f);
if (ex < .001f){
this.time = Math.round(this.time);
}
}
public void spendToWhole(){
time = (float)Math.ceil(time);
}
protected void postpone( float time ) {
if (this.time < now + time) {
this.time = now + time;
//if time is very close to a whole number, round to a whole number to fix errors
float ex = Math.abs(this.time % 1f);
if (ex < .001f){
this.time = Math.round(this.time);
}
}
}
public float cooldown() {
return time - now;
}
protected void diactivate() {
time = Float.MAX_VALUE;
}
protected void onAdd() {}
protected void onRemove() {}
private static final String TIME = "time";
private static final String ID = "id";
@Override
public void storeInBundle( Bundle bundle ) {
bundle.put( TIME, time );
bundle.put( ID, id );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
time = bundle.getFloat( TIME );
id = bundle.getInt( ID );
}
private static int nextID = 1;
public int id() {
if (id > 0) {
return id;
} else {
return (id = nextID++);
}
}
// **********************
// *** Static members ***
private static HashSet<Actor> all = new HashSet<>();
private static HashSet<Char> chars = new HashSet<>();
private static volatile Actor current;
private static SparseArray<Actor> ids = new SparseArray<>();
private static float now = 0;
public static float now(){
return now;
}
public static synchronized void clear() {
now = 0;
all.clear();
chars.clear();
ids.clear();
}
public static synchronized void fixTime() {
if (all.isEmpty()) return;
float min = Float.MAX_VALUE;
for (Actor a : all) {
if (a.time < min) {
min = a.time;
}
}
//Only pull everything back by whole numbers
//So that turns always align with a whole number
min = (int)min;
for (Actor a : all) {
a.time -= min;
}
if (Dungeon.hero != null && all.contains( Dungeon.hero )) {
Statistics.duration += min;
}
now -= min;
}
public static void init() {
add( Dungeon.hero );
for (Mob mob : Dungeon.level.mobs) {
add( mob );
}
for (Blob blob : Dungeon.level.blobs.values()) {
add( blob );
}
current = null;
}
private static final String NEXTID = "nextid";
public static void storeNextID( Bundle bundle){
bundle.put( NEXTID, nextID );
}
public static void restoreNextID( Bundle bundle){
nextID = bundle.getInt( NEXTID );
}
public static void resetNextID(){
nextID = 1;
}
/*protected*/public void next() {
if (current == this) {
current = null;
}
}
public static boolean processing(){
return current != null;
}
public static void process() {
boolean doNext;
boolean interrupted = false;
do {
current = null;
if (!interrupted) {
now = Float.MAX_VALUE;
for (Actor actor : all) {
//some actors will always go before others if time is equal.
if (actor.time < now ||
actor.time == now && (current == null || actor.actPriority > current.actPriority)) {
now = actor.time;
current = actor;
}
}
}
if (current != null) {
Actor acting = current;
if (acting instanceof Char && ((Char) acting).sprite != null) {
// If it's character's turn to act, but its sprite
// is moving, wait till the movement is over
try {
synchronized (((Char)acting).sprite) {
if (((Char)acting).sprite.isMoving) {
((Char) acting).sprite.wait();
}
}
} catch (InterruptedException e) {
interrupted = true;
}
}
interrupted = interrupted || Thread.interrupted();
if (interrupted){
doNext = false;
current = null;
} else {
doNext = acting.act();
if (doNext && (Dungeon.hero == null || !Dungeon.hero.isAlive())) {
doNext = false;
current = null;
}
}
} else {
doNext = false;
}
if (!doNext){
synchronized (Thread.currentThread()) {
interrupted = interrupted || Thread.interrupted();
if (interrupted){
current = null;
interrupted = false;
}
synchronized (GameScene.class){
//signals to the gamescene that actor processing is finished for now
GameScene.class.notify();
}
try {
Thread.currentThread().wait();
} catch (InterruptedException e) {
interrupted = true;
}
}
}
} while (true);
}
public static void add( Actor actor ) {
add( actor, now );
}
public static void addDelayed( Actor actor, float delay ) {
add( actor, now + delay );
}
private static synchronized void add( Actor actor, float time ) {
if (all.contains( actor )) {
return;
}
ids.put( actor.id(), actor );
all.add( actor );
actor.time += time;
actor.onAdd();
if (actor instanceof Char) {
Char ch = (Char)actor;
chars.add( ch );
for (Buff buff : ch.buffs()) {
all.add( buff );
buff.onAdd();
}
}
}
public static synchronized void remove( Actor actor ) {
if (actor != null) {
all.remove( actor );
chars.remove( actor );
actor.onRemove();
if (actor.id > 0) {
ids.remove( actor.id );
}
}
}
public static synchronized Char findChar( int pos ) {
for (Char ch : chars){
if (ch.pos == pos)
return ch;
}
return null;
}
public static synchronized Actor findById( int id ) {
return ids.get( id );
}
public static synchronized HashSet<Actor> all() {
return new HashSet<>(all);
}
public static synchronized HashSet<Char> chars() { return new HashSet<>(chars); }
}
| 8,135 | Actor | java | en | java | code | {"qsc_code_num_words": 1017, "qsc_code_num_chars": 8135.0, "qsc_code_mean_word_length": 5.14749263, "qsc_code_frac_words_unique": 0.2605703, "qsc_code_frac_chars_top_2grams": 0.03896848, "qsc_code_frac_chars_top_3grams": 0.05081184, "qsc_code_frac_chars_top_4grams": 0.0504298, "qsc_code_frac_chars_dupe_5grams": 0.16962751, "qsc_code_frac_chars_dupe_6grams": 0.10888252, "qsc_code_frac_chars_dupe_7grams": 0.04890162, "qsc_code_frac_chars_dupe_8grams": 0.04890162, "qsc_code_frac_chars_dupe_9grams": 0.04890162, "qsc_code_frac_chars_dupe_10grams": 0.04890162, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00761627, "qsc_code_frac_chars_whitespace": 0.24142594, "qsc_code_size_file_byte": 8135.0, "qsc_code_num_lines": 349.0, "qsc_code_num_chars_line_max": 97.0, "qsc_code_num_chars_line_mean": 23.30945559, "qsc_code_frac_chars_alphabet": 0.84070653, "qsc_code_frac_chars_comments": 0.22286417, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.13445378, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00189813, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08403361, "qsc_codejava_score_lines_no_logic": 0.15966387, "qsc_codejava_frac_words_no_modifier": 0.95238095, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00x4/m4rs | src/standard_deviation.rs | //! Standard Deviation
//!
//! # Examples
//! ```rust
//! // Prepare candlesticks in some way
//! let candlesticks = vec![
//! m4rs::Candlestick::new(1719400001, 100.0, 130.0, 90.0, 110.0, 1000.0),
//! m4rs::Candlestick::new(1719400002, 110.0, 140.0, 100.0, 130.0, 1000.0),
//! m4rs::Candlestick::new(1719400003, 130.0, 135.0, 120.0, 120.0, 1000.0),
//! m4rs::Candlestick::new(1719400004, 120.0, 130.0, 80.0, 95.0, 1000.0),
//! m4rs::Candlestick::new(1719400005, 90.0, 100.0, 70.0, 82.0, 1000.0),
//! ];
//!
//! // Get Standard Deviation calculation result
//! let result = m4rs::standard_deviation(&candlesticks, 20);
//! ```
use crate::{Error, IndexEntry, IndexEntryLike};
/// Returns Standard Deviation for given IndexEntry list
pub fn standard_deviation(
entries: &[impl IndexEntryLike],
duration: usize,
) -> Result<Vec<IndexEntry>, Error> {
if duration == 0 || entries.len() < duration {
return Ok(vec![]);
}
IndexEntry::validate_list(entries)?;
let mut sorted = entries.to_owned();
sorted.sort_by_key(|x| x.get_at());
Ok((0..=(sorted.len() - duration))
.map(|i| sorted.iter().skip(i).take(duration).collect::<Vec<_>>())
.map(|xs| {
let d = duration as f64;
let avg = xs.iter().fold(0.0, |z, x| z + x.get_value()) / d;
let value = (xs
.iter()
.fold(0.0, |z, x| z + (x.get_value() - avg).abs().powi(2))
/ d)
.sqrt();
IndexEntry {
at: xs.last().unwrap().get_at(),
value,
}
})
.collect())
}
| 1,646 | standard_deviation | rs | en | rust | code | {"qsc_code_num_words": 210, "qsc_code_num_chars": 1646.0, "qsc_code_mean_word_length": 4.2, "qsc_code_frac_words_unique": 0.4047619, "qsc_code_frac_chars_top_2grams": 0.09637188, "qsc_code_frac_chars_top_3grams": 0.10204082, "qsc_code_frac_chars_top_4grams": 0.04535147, "qsc_code_frac_chars_dupe_5grams": 0.16326531, "qsc_code_frac_chars_dupe_6grams": 0.16326531, "qsc_code_frac_chars_dupe_7grams": 0.05442177, "qsc_code_frac_chars_dupe_8grams": 0.05442177, "qsc_code_frac_chars_dupe_9grams": 0.05442177, "qsc_code_frac_chars_dupe_10grams": 0.05442177, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.13539967, "qsc_code_frac_chars_whitespace": 0.25516403, "qsc_code_size_file_byte": 1646.0, "qsc_code_num_lines": 49.0, "qsc_code_num_chars_line_max": 80.0, "qsc_code_num_chars_line_mean": 33.59183673, "qsc_code_frac_chars_alphabet": 0.58401305, "qsc_code_frac_chars_comments": 0.42770352, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/WallBlockingTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.Tilemap;
public class WallBlockingTilemap extends Tilemap {
public static final int SIZE = 16;
private static final int CLEARED = -2;
private static final int BLOCK_NONE = -1;
private static final int BLOCK_RIGHT = 0;
private static final int BLOCK_LEFT = 1;
private static final int BLOCK_ALL = 2;
private static final int BLOCK_BELOW = 3;
public WallBlockingTilemap() {
super("wall_blocking.png", new TextureFilm( "wall_blocking.png", SIZE, SIZE ) );
map( new int[Dungeon.level.length()], Dungeon.level.width());
}
@Override
public synchronized void updateMap() {
super.updateMap();
data = new int[size]; //clears all values, including cleared tiles
for (int cell = 0; cell < data.length; cell++) {
//force all top/bottom row, and none-discoverable cells to cleared
if (!Dungeon.level.discoverable[cell]
|| (cell - mapWidth) <= 0
|| (cell + mapWidth) >= size){
data[cell] = CLEARED;
} else {
updateMapCell(cell);
}
}
}
private int curr;
@Override
public synchronized void updateMapCell(int cell) {
//TODO should doors be considered? currently the blocking is a bit permissive around doors
//non-wall tiles
if (!wall(cell)) {
//clear empty floor tiles and cells which are visible
if (!fogHidden(cell) || !wall(cell + mapWidth)) {
curr = CLEARED;
//block wall overhang if:
//- There are cells 2x below
//- The cell below is a wall and visible
//- All of left, below-left, right, below-right is either a wall or hidden
} else if ( !fogHidden(cell + mapWidth)
&& (fogHidden(cell - 1) || wall(cell - 1))
&& (fogHidden(cell + 1) || wall(cell + 1))
&& (fogHidden(cell - 1 + mapWidth) || wall(cell - 1 + mapWidth))
&& (fogHidden(cell + 1 + mapWidth) || wall(cell + 1 + mapWidth))) {
curr = BLOCK_BELOW;
} else {
curr = BLOCK_NONE;
}
//wall tiles
} else {
//camera-facing wall tiles
if (!wall(cell + mapWidth)) {
//Block a camera-facing wall if:
//- the cell above, above-left, or above-right is not a wall, visible, and has a wall below
//- none of the remaining 5 neighbour cells are both not a wall and visible
//if all 3 above are wall we can shortcut and just clear the cell
if (wall(cell - 1 - mapWidth) && wall(cell - mapWidth) && wall(cell + 1 - mapWidth)){
curr = CLEARED;
} else if ((!wall(cell - 1 - mapWidth) && !fogHidden(cell - 1 - mapWidth) && wall(cell - 1)) ||
(!wall(cell - mapWidth) && !fogHidden(cell - mapWidth)) ||
(!wall(cell + 1 - mapWidth) && !fogHidden(cell + 1 - mapWidth) && wall(cell+1))){
if ( !fogHidden( cell + mapWidth) ||
(!wall(cell - 1) && !fogHidden(cell - 1)) ||
(!wall(cell - 1 + mapWidth) && !fogHidden(cell - 1 + mapWidth)) ||
(!wall(cell + 1) && !fogHidden(cell + 1)) ||
(!wall(cell + 1 + mapWidth) && !fogHidden(cell + 1 + mapWidth))){
curr = CLEARED;
} else {
curr = BLOCK_ALL;
}
} else {
curr = BLOCK_NONE;
}
//internal wall tiles
} else {
//Block the side of an internal wall if:
//- the cell above, below, or the cell itself is visible
//and all of the following are NOT true:
//- the cell has no neighbours on that side
//- the top-side neighbour is visible and the side neighbour isn't a wall.
//- the side neighbour is both not a wall and visible
//- the bottom-side neighbour is both not a wall and visible
curr = BLOCK_NONE;
if (!fogHidden(cell - mapWidth)
|| !fogHidden(cell)
|| !fogHidden(cell + mapWidth)) {
//right side
if ( ((cell + 1) % mapWidth == 0) ||
(!wall(cell + 1) && !fogHidden(cell + 1 - mapWidth)) ||
(!wall(cell + 1) && !fogHidden(cell + 1)) ||
(!wall(cell + 1 + mapWidth) && !fogHidden(cell + 1 + mapWidth))
){
//do nothing
} else {
curr += 1;
}
//left side
if ( (cell % mapWidth == 0) ||
(!wall(cell - 1) && !fogHidden(cell - 1 - mapWidth)) ||
(!wall(cell - 1) && !fogHidden(cell - 1)) ||
(!wall(cell - 1 + mapWidth) && !fogHidden(cell - 1 + mapWidth))
){
//do nothing
} else {
curr += 2;
}
if (curr == BLOCK_NONE) {
curr = CLEARED;
}
}
}
}
if (data[cell] != curr){
data[cell] = curr;
super.updateMapCell(cell);
}
}
private boolean fogHidden(int cell){
if (!Dungeon.level.visited[cell] && !Dungeon.level.mapped[cell]) {
return true;
} else if (wall(cell) && cell + mapWidth < size && !wall(cell + mapWidth) &&
!Dungeon.level.visited[cell + mapWidth] && !Dungeon.level.mapped[cell + mapWidth]) {
return true;
}
return false;
}
private boolean wall(int cell) {
return DungeonTileSheet.wallStitcheable(Dungeon.level.map[cell]);
}
private boolean door(int cell) {
return DungeonTileSheet.doorTile(Dungeon.level.map[cell]);
}
public synchronized void updateArea(int cell, int radius){
int l = cell%mapWidth - radius;
int t = cell/mapWidth - radius;
int r = cell%mapWidth + radius;
int b = cell/mapWidth + radius;
updateArea(
Math.max(0, l),
Math.max(0, t),
Math.min(mapWidth-1, r - l),
Math.min(mapHeight-1, b - t)
);
}
public synchronized void updateArea(int x, int y, int w, int h) {
int cell;
for (int i = x; i <= x+w; i++){
for (int j = y; j <= y+h; j++){
cell = i + j*mapWidth;
if (cell < data.length && data[cell] != CLEARED)
updateMapCell(cell);
}
}
}
}
| 6,528 | WallBlockingTilemap | java | en | java | code | {"qsc_code_num_words": 857, "qsc_code_num_chars": 6528.0, "qsc_code_mean_word_length": 4.68144691, "qsc_code_frac_words_unique": 0.23687281, "qsc_code_frac_chars_top_2grams": 0.04611167, "qsc_code_frac_chars_top_3grams": 0.06804586, "qsc_code_frac_chars_top_4grams": 0.05483549, "qsc_code_frac_chars_dupe_5grams": 0.3058325, "qsc_code_frac_chars_dupe_6grams": 0.25074776, "qsc_code_frac_chars_dupe_7grams": 0.16749751, "qsc_code_frac_chars_dupe_8grams": 0.16749751, "qsc_code_frac_chars_dupe_9grams": 0.16550349, "qsc_code_frac_chars_dupe_10grams": 0.13783649, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01532489, "qsc_code_frac_chars_whitespace": 0.25030637, "qsc_code_size_file_byte": 6528.0, "qsc_code_num_lines": 218.0, "qsc_code_num_chars_line_max": 100.0, "qsc_code_num_chars_line_mean": 29.94495413, "qsc_code_frac_chars_alphabet": 0.80445443, "qsc_code_frac_chars_comments": 0.29901961, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.20149254, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00743007, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00458716, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02238806, "qsc_codejava_score_lines_no_logic": 0.08955224, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/FogOfWar.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.watabou.gltextures.BufferTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.utils.Rect;
import java.util.ArrayList;
public class FogOfWar extends Image {
//first index is visibility type, second is brightness level
private static final int FOG_COLORS[][] = new int[][]{{
//visible
0x55000000, 0x00000000, //-2 and -1 brightness
0x00000000, //0 brightness
0x00000000, 0x00000000 //1 and 2 brightness
}, {
//visited
0xDD000000, 0xBB000000,
0x99000000,
0x77000000, 0x55000000
}, {
//mapped
0xDD221108, 0xBB442211,
0x99663319,
0x77884411, 0x55AA552A
}, {
//invisible
0xFF000000, 0xFF000000,
0xFF000000,
0xFF000000, 0xFF000000
}};
private static final int VISIBLE = 0;
private static final int VISITED = 1;
private static final int MAPPED = 2;
private static final int INVISIBLE = 3;
private int mapWidth;
private int mapHeight;
private int mapLength;
private int pWidth;
private int pHeight;
//should be divisible by 2
private static final int PIX_PER_TILE = 2;
private int width2;
private int height2;
private volatile ArrayList<Rect> toUpdate;
private volatile ArrayList<Rect> updating;
/*
TODO currently the center of each fox pixel is aligned with the inside of a cell
might be possible to create a better fog effect by aligning them with edges of a cell,
similar to the existing fog effect in vanilla (although probably with more precision)
the advantage here is that it may be possible to totally eliminate the tile blocking map
*/
public FogOfWar( int mapWidth, int mapHeight ) {
super();
this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
mapLength = mapHeight * mapWidth;
pWidth = mapWidth * PIX_PER_TILE;
pHeight = mapHeight * PIX_PER_TILE;
width2 = 1;
while (width2 < pWidth) {
width2 <<= 1;
}
height2 = 1;
while (height2 < pHeight) {
height2 <<= 1;
}
float size = DungeonTilemap.SIZE / PIX_PER_TILE;
width = width2 * size;
height = height2 * size;
BufferTexture tx = new BufferTexture(width2, height2);
TextureCache.add(FogOfWar.class, tx);
texture( tx );
scale.set(
DungeonTilemap.SIZE / PIX_PER_TILE,
DungeonTilemap.SIZE / PIX_PER_TILE);
toUpdate = new ArrayList<>();
toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
public synchronized void updateFog(){
toUpdate.clear();
toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
public synchronized void updateFog(Rect update){
for (Rect r : toUpdate.toArray(new Rect[0])){
if (!r.intersect(update).isEmpty()){
toUpdate.remove(r);
toUpdate.add(r.union(update));
return;
}
}
toUpdate.add(update);
}
public synchronized void updateFog( int cell, int radius ){
Rect update = new Rect(
(cell % mapWidth) - radius,
(cell / mapWidth) - radius,
(cell % mapWidth) - radius + 1 + 2*radius,
(cell / mapWidth) - radius + 1 + 2*radius);
update.left = Math.max(0, update.left);
update.top = Math.max(0, update.top);
update.right = Math.min(mapWidth, update.right);
update.bottom = Math.min(mapHeight, update.bottom);
if (update.isEmpty()) return;
updateFog( update );
}
public synchronized void updateFogArea(int x, int y, int w, int h){
updateFog(new Rect(x, y, x + w, y + h));
}
private synchronized void moveToUpdating(){
updating = toUpdate;
toUpdate = new ArrayList<>();
}
private boolean[] visible;
private boolean[] visited;
private boolean[] mapped;
private int brightness;
private void updateTexture( boolean[] visible, boolean[] visited, boolean[] mapped ) {
this.visible = visible;
this.visited = visited;
this.mapped = mapped;
this.brightness = SPDSettings.brightness() + 2;
moveToUpdating();
boolean fullUpdate = false;
if (updating.size() == 1){
Rect update = updating.get(0);
if (update.height() == mapHeight && update.width() == mapWidth){
fullUpdate = true;
}
}
BufferTexture fog = (BufferTexture) texture;
int cell;
for (Rect update : updating) {
for (int i = update.top; i <= update.bottom; i++) {
cell = mapWidth * i + update.left;
for (int j = update.left; j <= update.right; j++) {
if (cell >= Dungeon.level.length()) continue; //do nothing
if (!Dungeon.level.discoverable[cell]
|| (!visible[cell] && !visited[cell] && !mapped[cell])) {
//we skip filling cells here if it isn't a full update
// because they must already be dark
if (fullUpdate)
fillCell(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
cell++;
continue;
}
//wall tiles
if (wall(cell)) {
//always dark if nothing is beneath them
if (cell + mapWidth >= mapLength) {
fillCell(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
//internal wall tiles, need to check both the left and right side,
// to account for only one half of them being seen
} else if (wall(cell + mapWidth)) {
//left side
if (cell % mapWidth != 0) {
//picks the darkest fog between current tile, left, and below-left(if left is a wall).
if (wall(cell - 1)) {
//if below-left is also a wall, then we should be dark no matter what.
if (wall(cell + mapWidth - 1)) {
fillLeft(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
} else {
fillLeft(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), Math.max(getCellFog(cell + mapWidth - 1), getCellFog(cell - 1)))][brightness]);
}
} else {
fillLeft(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell - 1))][brightness]);
}
} else {
fillLeft(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
}
//right side
if ((cell + 1) % mapWidth != 0) {
//picks the darkest fog between current tile, right, and below-right(if right is a wall).
if (wall(cell + 1)) {
//if below-right is also a wall, then we should be dark no matter what.
if (wall(cell + mapWidth + 1)) {
fillRight(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
} else {
fillRight(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), Math.max(getCellFog(cell + mapWidth + 1), getCellFog(cell + 1)))][brightness]);
}
} else {
fillRight(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell + 1))][brightness]);
}
} else {
fillRight(fog, j, i, FOG_COLORS[INVISIBLE][brightness]);
}
//camera-facing wall tiles
//darkest between themselves and the tile below them
} else {
fillCell(fog, j, i, FOG_COLORS[Math.max(getCellFog(cell), getCellFog(cell + mapWidth))][brightness]);
}
//other tiles, just their direct value
} else {
fillCell(fog, j, i, FOG_COLORS[getCellFog(cell)][brightness]);
}
cell++;
}
}
}
if (updating.size() == 1 && !fullUpdate){
fog.update(updating.get(0).top * PIX_PER_TILE, updating.get(0).bottom * PIX_PER_TILE);
} else {
fog.update();
}
}
private boolean wall(int cell) {
return DungeonTileSheet.wallStitcheable(Dungeon.level.map[cell]);
}
private int getCellFog( int cell ){
if (visible[cell]) {
return VISIBLE;
} else if (visited[cell]) {
return VISITED;
} else if (mapped[cell] ) {
return MAPPED;
} else {
return INVISIBLE;
}
}
private void fillLeft( BufferTexture fog, int x, int y, int color){
for (int i = 0; i < PIX_PER_TILE; i++){
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE);
for (int j = 0; j < PIX_PER_TILE/2; j++) {
fog.pixels.put(color);
}
}
}
private void fillRight( BufferTexture fog, int x, int y, int color){
for (int i = 0; i < PIX_PER_TILE; i++){
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE + PIX_PER_TILE/2);
for (int j = PIX_PER_TILE/2; j < PIX_PER_TILE; j++) {
fog.pixels.put(color);
}
}
}
private void fillCell( BufferTexture fog, int x, int y, int color){
for (int i = 0; i < PIX_PER_TILE; i++){
fog.pixels.position(((y * PIX_PER_TILE)+i)*width2 + x * PIX_PER_TILE);
for (int j = 0; j < PIX_PER_TILE; j++) {
fog.pixels.put(color);
}
}
}
@Override
protected NoosaScript script() {
return NoosaScriptNoLighting.get();
}
@Override
public void draw() {
if (!toUpdate.isEmpty()){
updateTexture(Dungeon.level.heroFOV, Dungeon.level.visited, Dungeon.level.mapped);
}
super.draw();
}
@Override
public void destroy() {
super.destroy();
if (texture != null){
TextureCache.remove(FogOfWar.class);
}
}
}
| 9,725 | FogOfWar | java | en | java | code | {"qsc_code_num_words": 1263, "qsc_code_num_chars": 9725.0, "qsc_code_mean_word_length": 5.00079177, "qsc_code_frac_words_unique": 0.2304038, "qsc_code_frac_chars_top_2grams": 0.0208993, "qsc_code_frac_chars_top_3grams": 0.03483217, "qsc_code_frac_chars_top_4grams": 0.01519949, "qsc_code_frac_chars_dupe_5grams": 0.28974034, "qsc_code_frac_chars_dupe_6grams": 0.26361621, "qsc_code_frac_chars_dupe_7grams": 0.24794174, "qsc_code_frac_chars_dupe_8grams": 0.22640912, "qsc_code_frac_chars_dupe_9grams": 0.19743509, "qsc_code_frac_chars_dupe_10grams": 0.16782774, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0322666, "qsc_code_frac_chars_whitespace": 0.22241645, "qsc_code_size_file_byte": 9725.0, "qsc_code_num_lines": 348.0, "qsc_code_num_chars_line_max": 149.0, "qsc_code_num_chars_line_mean": 27.9454023, "qsc_code_frac_chars_alphabet": 0.80296218, "qsc_code_frac_chars_comments": 0.20956298, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.15189873, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.02601795, "qsc_code_frac_lines_prompt_comments": 0.00287356, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03797468, "qsc_codejava_score_lines_no_logic": 0.13924051, "qsc_codejava_frac_words_no_modifier": 0.9, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTileSheet.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.watabou.utils.Random;
import com.watabou.utils.SparseArray;
import java.util.Arrays;
import java.util.HashSet;
public class DungeonTileSheet {
private static final int WIDTH = 16;
private static int xy(int x, int y){
x -= 1; y -= 1;
return x + WIDTH*y;
}
//used in cases like map-edge decision making.
public static final int NULL_TILE = -1;
/**********************************************************************
* Floor Tiles
**********************************************************************/
private static final int GROUND = xy(1, 1); //32 slots
public static final int FLOOR = GROUND +0;
public static final int FLOOR_DECO = GROUND +1;
public static final int GRASS = GROUND +2;
public static final int EMBERS = GROUND +3;
public static final int FLOOR_SP = GROUND +4;
public static final int FLOOR_ALT_1 = GROUND +6;
public static final int FLOOR_DECO_ALT = GROUND +7;
public static final int GRASS_ALT = GROUND +8;
public static final int EMBERS_ALT = GROUND +9;
public static final int FLOOR_SP_ALT = GROUND +10;
public static final int FLOOR_ALT_2 = GROUND +12;
public static final int ENTRANCE = GROUND +16;
public static final int EXIT = GROUND +17;
public static final int WELL = GROUND +18;
public static final int EMPTY_WELL = GROUND +19;
public static final int PEDESTAL = GROUND +20;
/**********************************************************************
* Water Tiles
**********************************************************************/
public static final int WATER = xy(1, 3); //16 slots
//next 15 slots are all water stitching with ground.
//These tiles can stitch with water
public static HashSet<Integer> waterStitcheable = new HashSet<>(Arrays.asList(
Terrain.EMPTY, Terrain.GRASS, Terrain.EMPTY_WELL,
Terrain.ENTRANCE, Terrain.EXIT, Terrain.EMBERS,
Terrain.BARRICADE, Terrain.HIGH_GRASS, Terrain.FURROWED_GRASS, Terrain.SECRET_TRAP,
Terrain.TRAP, Terrain.INACTIVE_TRAP, Terrain.EMPTY_DECO,
Terrain.SIGN, Terrain.WELL, Terrain.STATUE, Terrain.ALCHEMY,
Terrain.DOOR, Terrain.OPEN_DOOR, Terrain.LOCKED_DOOR
));
//+1 for ground above, +2 for ground right, +4 for ground below, +8 for ground left.
public static int stitchWaterTile(int top, int right, int bottom, int left){
int result = WATER;
if (waterStitcheable.contains(top)) result += 1;
if (waterStitcheable.contains(right)) result += 2;
if (waterStitcheable.contains(bottom)) result += 4;
if (waterStitcheable.contains(left)) result += 8;
return result;
}
public static boolean floorTile(int tile){
return tile == Terrain.WATER || directVisuals.get(tile, CHASM) < CHASM;
}
/**********************************************************************
* Chasm Tiles
**********************************************************************/
public static final int CHASM = xy(1, 4); //16 tiles
//chasm stitching visuals...
public static final int CHASM_FLOOR = CHASM+1;
public static final int CHASM_FLOOR_SP = CHASM+2;
public static final int CHASM_WALL = CHASM+3;
public static final int CHASM_WATER = CHASM+4;
//tiles that can stitch with chasms (from above), and which visual represents the stitching
public static SparseArray<Integer> chasmStitcheable = new SparseArray<>();
static {
//floor
chasmStitcheable.put( Terrain.EMPTY, CHASM_FLOOR );
chasmStitcheable.put( Terrain.GRASS, CHASM_FLOOR );
chasmStitcheable.put( Terrain.EMBERS, CHASM_FLOOR );
chasmStitcheable.put( Terrain.EMPTY_WELL, CHASM_FLOOR );
chasmStitcheable.put( Terrain.HIGH_GRASS, CHASM_FLOOR );
chasmStitcheable.put( Terrain.FURROWED_GRASS,CHASM_FLOOR );
chasmStitcheable.put( Terrain.EMPTY_DECO, CHASM_FLOOR );
chasmStitcheable.put( Terrain.SIGN, CHASM_FLOOR );
chasmStitcheable.put( Terrain.EMPTY_WELL, CHASM_FLOOR );
chasmStitcheable.put( Terrain.WELL, CHASM_FLOOR );
chasmStitcheable.put( Terrain.STATUE, CHASM_FLOOR );
chasmStitcheable.put( Terrain.SECRET_TRAP, CHASM_FLOOR );
chasmStitcheable.put( Terrain.INACTIVE_TRAP,CHASM_FLOOR );
chasmStitcheable.put( Terrain.TRAP, CHASM_FLOOR );
chasmStitcheable.put( Terrain.BOOKSHELF, CHASM_FLOOR );
chasmStitcheable.put( Terrain.BARRICADE, CHASM_FLOOR );
chasmStitcheable.put( Terrain.PEDESTAL, CHASM_FLOOR );
//special floor
chasmStitcheable.put( Terrain.EMPTY_SP, CHASM_FLOOR_SP );
chasmStitcheable.put( Terrain.STATUE_SP, CHASM_FLOOR_SP );
//wall
chasmStitcheable.put( Terrain.WALL, CHASM_WALL );
chasmStitcheable.put( Terrain.DOOR, CHASM_WALL );
chasmStitcheable.put( Terrain.OPEN_DOOR, CHASM_WALL );
chasmStitcheable.put( Terrain.LOCKED_DOOR, CHASM_WALL );
chasmStitcheable.put( Terrain.SECRET_DOOR, CHASM_WALL );
chasmStitcheable.put( Terrain.WALL_DECO, CHASM_WALL );
//water
chasmStitcheable.put( Terrain.WATER, CHASM_WATER );
}
public static int stitchChasmTile(int above){
return chasmStitcheable.get(above, CHASM);
}
/**********************************************************************
Flat Tiles
**********************************************************************/
private static final int FLAT_WALLS = xy(1, 5); //16 slots
public static final int FLAT_WALL = FLAT_WALLS+0;
public static final int FLAT_WALL_DECO = FLAT_WALLS+1;
public static final int FLAT_BOOKSHELF = FLAT_WALLS+2;
public static final int FLAT_WALL_ALT = FLAT_WALLS+4;
public static final int FLAT_WALL_DECO_ALT = FLAT_WALLS+5;
public static final int FLAT_BOOKSHELF_ALT = FLAT_WALLS+6;
private static final int FLAT_DOORS = xy(1, 6); //16 slots
public static final int FLAT_DOOR = FLAT_DOORS+0;
public static final int FLAT_DOOR_OPEN = FLAT_DOORS+1;
public static final int FLAT_DOOR_LOCKED = FLAT_DOORS+2;
public static final int UNLOCKED_EXIT = FLAT_DOORS+3;
public static final int LOCKED_EXIT = FLAT_DOORS+4;
public static final int FLAT_OTHER = xy(1, 7); //16 slots
public static final int FLAT_SIGN = FLAT_OTHER+0;
public static final int FLAT_STATUE = FLAT_OTHER+1;
public static final int FLAT_STATUE_SP = FLAT_OTHER+2;
public static final int FLAT_ALCHEMY_POT = FLAT_OTHER+3;
public static final int FLAT_BARRICADE = FLAT_OTHER+4;
public static final int FLAT_HIGH_GRASS = FLAT_OTHER+5;
public static final int FLAT_FURROWED_GRASS = FLAT_OTHER+6;
public static final int FLAT_HIGH_GRASS_ALT = FLAT_OTHER+8;
public static final int FLAT_FURROWED_ALT = FLAT_OTHER+9;
/**********************************************************************
* Raised Tiles, Lower Layer
**********************************************************************/
private static final int RAISED_WALLS = xy(1, 8); //32 slots
//+1 for open to the right, +2 for open to the left
public static final int RAISED_WALL = RAISED_WALLS+0;
public static final int RAISED_WALL_DECO = RAISED_WALLS+4;
//wall that appears behind a top/bottom doorway
public static final int RAISED_WALL_DOOR = RAISED_WALLS+8;
public static final int RAISED_WALL_BOOKSHELF = RAISED_WALLS+12;
public static final int RAISED_WALL_ALT = RAISED_WALLS+16;
public static final int RAISED_WALL_DECO_ALT = RAISED_WALLS+20;
public static final int RAISED_WALL_BOOKSHELF_ALT = RAISED_WALLS+28;
//we use an array instead of a collection because the small element count
// makes array traversal much faster than something like HashSet.contains.
//These tiles count as wall for the purposes of wall stitching
private static int[] wallStitcheable = new int[]{
Terrain.WALL, Terrain.WALL_DECO, Terrain.SECRET_DOOR,
Terrain.LOCKED_EXIT, Terrain.UNLOCKED_EXIT, Terrain.BOOKSHELF, NULL_TILE
};
public static boolean wallStitcheable(int tile){
for (int i : wallStitcheable)
if (tile == i)
return true;
return false;
}
public static int getRaisedWallTile(int tile, int pos, int right, int below, int left){
int result;
if (below == -1 || wallStitcheable(below)) return -1;
else if (doorTile(below)) result = RAISED_WALL_DOOR;
else if (tile == Terrain.WALL || tile == Terrain.SECRET_DOOR) result = RAISED_WALL;
else if (tile == Terrain.WALL_DECO) result = RAISED_WALL_DECO;
else if (tile == Terrain.BOOKSHELF) result = RAISED_WALL_BOOKSHELF;
else return -1;
result = getVisualWithAlts(result, pos);
if (!wallStitcheable(right)) result += 1;
if (!wallStitcheable(left)) result += 2;
return result;
}
private static final int RAISED_DOORS = xy(1, 10); //16 slots
public static final int RAISED_DOOR = RAISED_DOORS+0;
public static final int RAISED_DOOR_OPEN = RAISED_DOORS+1;
public static final int RAISED_DOOR_LOCKED = RAISED_DOORS+2;
//floor tile that appears on a top/bottom doorway
public static final int RAISED_DOOR_SIDEWAYS = RAISED_DOORS+3;
public static int getRaisedDoorTile(int tile, int below){
if (wallStitcheable(below)) return RAISED_DOOR_SIDEWAYS;
else if (tile == Terrain.DOOR) return DungeonTileSheet.RAISED_DOOR;
else if (tile == Terrain.OPEN_DOOR) return DungeonTileSheet.RAISED_DOOR_OPEN;
else if (tile == Terrain.LOCKED_DOOR) return DungeonTileSheet.RAISED_DOOR_LOCKED;
else return -1;
}
private static int[] doorTiles = new int[]{
Terrain.DOOR, Terrain.LOCKED_DOOR, Terrain.OPEN_DOOR
};
public static boolean doorTile(int tile){
for (int i : doorTiles)
if (tile == i)
return true;
return false;
}
private static final int RAISED_OTHER = xy(1, 11); //16 slots
public static final int RAISED_SIGN = RAISED_OTHER+0;
public static final int RAISED_STATUE = RAISED_OTHER+1;
public static final int RAISED_STATUE_SP = RAISED_OTHER+2;
public static final int RAISED_ALCHEMY_POT = RAISED_OTHER+3;
public static final int RAISED_BARRICADE = RAISED_OTHER+4;
public static final int RAISED_HIGH_GRASS = RAISED_OTHER+5;
public static final int RAISED_FURROWED_GRASS = RAISED_OTHER+6;
public static final int RAISED_HIGH_GRASS_ALT = RAISED_OTHER+9;
public static final int RAISED_FURROWED_ALT = RAISED_OTHER+10;
/**********************************************************************
* Raised Tiles, Upper Layer
**********************************************************************/
//+1 for open right, +2 for open right-below, +4 for open left-below, +8 for open left.
public static final int WALLS_INTERNAL = xy(1, 12); //32 slots
private static final int WALL_INTERNAL = WALLS_INTERNAL+0;
private static final int WALL_INTERNAL_WOODEN = WALLS_INTERNAL+16;
public static int stitchInternalWallTile(int tile, int right, int rightBelow, int below, int leftBelow, int left){
int result;
if (tile == Terrain.BOOKSHELF || below == Terrain.BOOKSHELF) result = WALL_INTERNAL_WOODEN;
else result = WALL_INTERNAL;
if (!wallStitcheable(right)) result += 1;
if (!wallStitcheable(rightBelow)) result += 2;
if (!wallStitcheable(leftBelow)) result += 4;
if (!wallStitcheable(left)) result += 8;
return result;
}
//+1 for open to the down-right, +2 for open to the down-left
private static final int WALLS_OVERHANG = xy(1, 14); //32 slots
public static final int WALL_OVERHANG = WALLS_OVERHANG+0;
public static final int DOOR_SIDEWAYS_OVERHANG = WALLS_OVERHANG+4;
public static final int DOOR_SIDEWAYS_OVERHANG_OPEN = WALLS_OVERHANG+8;
public static final int DOOR_SIDEWAYS_OVERHANG_LOCKED = WALLS_OVERHANG+12;
public static final int WALL_OVERHANG_WOODEN = WALLS_OVERHANG+16;
public static int stitchWallOverhangTile(int tile, int rightBelow, int below, int leftBelow){
int visual;
if (tile == Terrain.DOOR) visual = DOOR_SIDEWAYS_OVERHANG;
else if (tile == Terrain.OPEN_DOOR) visual = DOOR_SIDEWAYS_OVERHANG_OPEN;
else if (tile == Terrain.LOCKED_DOOR) visual = DOOR_SIDEWAYS_OVERHANG_LOCKED;
else if (below == Terrain.BOOKSHELF) visual = WALL_OVERHANG_WOODEN;
else visual = WALL_OVERHANG;
if (!wallStitcheable(rightBelow)) visual += 1;
if (!wallStitcheable(leftBelow)) visual += 2;
return visual;
}
//no attachment to adjacent walls
public static final int DOOR_OVERHANG = WALL_OVERHANG+21;
public static final int DOOR_OVERHANG_OPEN = WALL_OVERHANG+22;
public static final int DOOR_SIDEWAYS = WALL_OVERHANG+23;
public static final int DOOR_SIDEWAYS_LOCKED = WALL_OVERHANG+24;
public static final int STATUE_OVERHANG = WALL_OVERHANG+32;
public static final int ALCHEMY_POT_OVERHANG = WALL_OVERHANG+33;
public static final int BARRICADE_OVERHANG = WALL_OVERHANG+34;
public static final int HIGH_GRASS_OVERHANG = WALL_OVERHANG+35;
public static final int FURROWED_OVERHANG = WALL_OVERHANG+36;
public static final int HIGH_GRASS_OVERHANG_ALT = WALL_OVERHANG+38;
public static final int FURROWED_OVERHANG_ALT = WALL_OVERHANG+39;
/**********************************************************************
* Logic for the selection of tile visuals
**********************************************************************/
//These visuals always directly represent a game tile with no stitching required
public static SparseArray<Integer> directVisuals = new SparseArray<>();
static {
directVisuals.put(Terrain.EMPTY, FLOOR);
directVisuals.put(Terrain.GRASS, GRASS);
directVisuals.put(Terrain.EMPTY_WELL, EMPTY_WELL);
directVisuals.put(Terrain.ENTRANCE, ENTRANCE);
directVisuals.put(Terrain.EXIT, EXIT);
directVisuals.put(Terrain.EMBERS, EMBERS);
directVisuals.put(Terrain.PEDESTAL, PEDESTAL);
directVisuals.put(Terrain.EMPTY_SP, FLOOR_SP);
directVisuals.put(Terrain.SECRET_TRAP, directVisuals.get(Terrain.EMPTY));
directVisuals.put(Terrain.TRAP, directVisuals.get(Terrain.EMPTY));
directVisuals.put(Terrain.INACTIVE_TRAP, directVisuals.get(Terrain.EMPTY));
directVisuals.put(Terrain.EMPTY_DECO, FLOOR_DECO);
directVisuals.put(Terrain.LOCKED_EXIT, LOCKED_EXIT);
directVisuals.put(Terrain.UNLOCKED_EXIT, UNLOCKED_EXIT);
directVisuals.put(Terrain.WELL, WELL);
}
//These visuals directly represent game tiles (no stitching) when terrain is being shown as flat
public static SparseArray<Integer> directFlatVisuals = new SparseArray<>();
static {
directFlatVisuals.put(Terrain.WALL, FLAT_WALL);
directFlatVisuals.put(Terrain.DOOR, FLAT_DOOR);
directFlatVisuals.put(Terrain.OPEN_DOOR, FLAT_DOOR_OPEN);
directFlatVisuals.put(Terrain.LOCKED_DOOR, FLAT_DOOR_LOCKED);
directFlatVisuals.put(Terrain.WALL_DECO, FLAT_WALL_DECO);
directFlatVisuals.put(Terrain.BOOKSHELF, FLAT_BOOKSHELF);
directFlatVisuals.put(Terrain.SIGN, FLAT_SIGN);
directFlatVisuals.put(Terrain.STATUE, FLAT_STATUE);
directFlatVisuals.put(Terrain.STATUE_SP, FLAT_STATUE_SP);
directFlatVisuals.put(Terrain.ALCHEMY, FLAT_ALCHEMY_POT);
directFlatVisuals.put(Terrain.BARRICADE, FLAT_BARRICADE);
directFlatVisuals.put(Terrain.HIGH_GRASS, FLAT_HIGH_GRASS);
directFlatVisuals.put(Terrain.FURROWED_GRASS, FLAT_FURROWED_GRASS);
directFlatVisuals.put(Terrain.SECRET_DOOR, directFlatVisuals.get(Terrain.WALL));
}
/**********************************************************************
* Logic for the selection of alternate tile visuals
**********************************************************************/
public static byte[] tileVariance;
public static void setupVariance(int size, long seed){
Random.seed( seed );
tileVariance = new byte[size];
for (int i = 0; i < tileVariance.length; i++)
tileVariance[i] = (byte)Random.Int(100);
Random.seed();
}
//These alt visuals will trigger 50% of the time (45% of the time if a rare alt is also present)
public static SparseArray<Integer> commonAltVisuals = new SparseArray<>();
static {
commonAltVisuals.put(FLOOR, FLOOR_ALT_1);
commonAltVisuals.put(GRASS, GRASS_ALT);
commonAltVisuals.put(FLAT_WALL, FLAT_WALL_ALT);
commonAltVisuals.put(EMBERS, EMBERS_ALT);
commonAltVisuals.put(FLAT_WALL_DECO, FLAT_WALL_DECO_ALT);
commonAltVisuals.put(FLOOR_SP, FLOOR_SP_ALT);
commonAltVisuals.put(FLOOR_DECO, FLOOR_DECO_ALT);
commonAltVisuals.put(FLAT_BOOKSHELF, FLAT_BOOKSHELF_ALT);
commonAltVisuals.put(FLAT_HIGH_GRASS, FLAT_HIGH_GRASS_ALT);
commonAltVisuals.put(FLAT_FURROWED_GRASS, FLAT_FURROWED_ALT);
commonAltVisuals.put(RAISED_WALL, RAISED_WALL_ALT);
commonAltVisuals.put(RAISED_WALL_DECO, RAISED_WALL_DECO_ALT);
commonAltVisuals.put(RAISED_WALL_BOOKSHELF, RAISED_WALL_BOOKSHELF_ALT);
commonAltVisuals.put(RAISED_HIGH_GRASS, RAISED_HIGH_GRASS_ALT);
commonAltVisuals.put(RAISED_FURROWED_GRASS, RAISED_FURROWED_ALT);
commonAltVisuals.put(HIGH_GRASS_OVERHANG, HIGH_GRASS_OVERHANG_ALT);
commonAltVisuals.put(FURROWED_OVERHANG, FURROWED_OVERHANG_ALT);
}
//These alt visuals trigger 5% of the time (and also override common alts when they show up)
public static SparseArray<Integer> rareAltVisuals = new SparseArray<>();
static {
rareAltVisuals.put(FLOOR, FLOOR_ALT_2);
}
public static int getVisualWithAlts(int visual, int pos){
if (tileVariance[pos] >= 95 && rareAltVisuals.containsKey(visual))
return rareAltVisuals.get(visual);
else if (tileVariance[pos] >= 50 && commonAltVisuals.containsKey(visual))
return commonAltVisuals.get(visual);
else
return visual;
}
}
| 19,731 | DungeonTileSheet | java | en | java | code | {"qsc_code_num_words": 2342, "qsc_code_num_chars": 19731.0, "qsc_code_mean_word_length": 5.31554227, "qsc_code_frac_words_unique": 0.12809564, "qsc_code_frac_chars_top_2grams": 0.09542935, "qsc_code_frac_chars_top_3grams": 0.10233754, "qsc_code_frac_chars_top_4grams": 0.13013093, "qsc_code_frac_chars_dupe_5grams": 0.39922885, "qsc_code_frac_chars_dupe_6grams": 0.26917825, "qsc_code_frac_chars_dupe_7grams": 0.11197687, "qsc_code_frac_chars_dupe_8grams": 0.03317536, "qsc_code_frac_chars_dupe_9grams": 0.01992128, "qsc_code_frac_chars_dupe_10grams": 0.01301309, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01432368, "qsc_code_frac_chars_whitespace": 0.21803254, "qsc_code_size_file_byte": 19731.0, "qsc_code_num_lines": 441.0, "qsc_code_num_chars_line_max": 116.0, "qsc_code_num_chars_line_mean": 44.7414966, "qsc_code_frac_chars_alphabet": 0.79253354, "qsc_code_frac_chars_comments": 0.17951447, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0899654, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04152249, "qsc_codejava_score_lines_no_logic": 0.10380623, "qsc_codejava_frac_words_no_modifier": 0.92307692, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/RaisedTerrainTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
public class RaisedTerrainTilemap extends DungeonTilemap {
public RaisedTerrainTilemap() {
super(Dungeon.level.tilesTex());
map( Dungeon.level.map, Dungeon.level.width() );
}
@Override
protected int getTileVisual(int pos, int tile, boolean flat) {
if (flat) return -1;
if (tile == Terrain.HIGH_GRASS){
return DungeonTileSheet.getVisualWithAlts(
DungeonTileSheet.RAISED_HIGH_GRASS,
pos) + 2;
} else if (tile == Terrain.FURROWED_GRASS){
return DungeonTileSheet.getVisualWithAlts(
DungeonTileSheet.RAISED_FURROWED_GRASS,
pos) + 2;
}
return -1;
}
}
| 1,567 | RaisedTerrainTilemap | java | en | java | code | {"qsc_code_num_words": 200, "qsc_code_num_chars": 1567.0, "qsc_code_mean_word_length": 5.765, "qsc_code_frac_words_unique": 0.565, "qsc_code_frac_chars_top_2grams": 0.02862099, "qsc_code_frac_chars_top_3grams": 0.0338248, "qsc_code_frac_chars_top_4grams": 0.04943625, "qsc_code_frac_chars_dupe_5grams": 0.18560278, "qsc_code_frac_chars_dupe_6grams": 0.16305291, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0163297, "qsc_code_frac_chars_whitespace": 0.17932355, "qsc_code_size_file_byte": 1567.0, "qsc_code_num_lines": 52.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 30.13461538, "qsc_code_frac_chars_alphabet": 0.88024883, "qsc_code_frac_chars_comments": 0.49776643, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.17391304, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.04347826, "qsc_codejava_score_lines_no_logic": 0.17391304, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.watabou.noosa.Image;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.Tilemap;
import com.watabou.noosa.tweeners.AlphaTweener;
import com.watabou.utils.GameMath;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Point;
import com.watabou.utils.PointF;
public abstract class DungeonTilemap extends Tilemap {
public static final int SIZE = 16;
protected int[] map;
public DungeonTilemap(String tex) {
super(tex, new TextureFilm( tex, SIZE, SIZE ) );
}
@Override
//we need to retain two arrays, map is the dungeon tilemap which we can reference.
// Data is our own internal image representation of the tiles, which may differ.
public void map(int[] data, int cols) {
map = data;
super.map(new int[data.length], cols);
}
@Override
public synchronized void updateMap() {
super.updateMap();
for (int i = 0; i < data.length; i++)
data[i] = getTileVisual(i ,map[i], false);
}
@Override
public synchronized void updateMapCell(int cell) {
//update in a 3x3 grid to account for neighbours which might also be affected
if (Dungeon.level.insideMap(cell)) {
super.updateMapCell(cell - mapWidth - 1);
super.updateMapCell(cell + mapWidth + 1);
for (int i : PathFinder.NEIGHBOURS9)
data[cell + i] = getTileVisual(cell + i, map[cell + i], false);
//unless we're at the level's edge, then just do the one tile.
} else {
super.updateMapCell(cell);
data[cell] = getTileVisual(cell, map[cell], false);
}
}
protected abstract int getTileVisual(int pos, int tile, boolean flat);
public int screenToTile(int x, int y ){
return screenToTile(x, y, false);
}
//wall assist is used to make raised perspective tapping a bit easier.
// If the pressed tile is a wall tile, the tap can be 'bumped' down into a none-wall tile.
// currently this happens if the bottom 1/4 of the wall tile is pressed.
public int screenToTile(int x, int y, boolean wallAssist ) {
PointF p = camera().screenToCamera( x, y ).
offset( this.point().negate() ).
invScale( SIZE );
//snap to the edges of the tilemap
p.x = GameMath.gate(0, p.x, Dungeon.level.width()-0.001f);
p.y = GameMath.gate(0, p.y, Dungeon.level.height()-0.001f);
int cell = (int)p.x + (int)p.y * Dungeon.level.width();
if (wallAssist
&& map != null
&& DungeonTileSheet.wallStitcheable(map[cell])){
if (cell + mapWidth < size
&& p.y % 1 >= 0.75f
&& !DungeonTileSheet.wallStitcheable(map[cell + mapWidth])){
cell += mapWidth;
}
}
return cell;
}
@Override
public boolean overlapsPoint( float x, float y ) {
return true;
}
public void discover( int pos, int oldValue ) {
int visual = getTileVisual( pos, oldValue, false);
if (visual < 0) return;
final Image tile = new Image( texture );
tile.frame( tileset.get( getTileVisual( pos, oldValue, false)));
tile.point( tileToWorld( pos ) );
parent.add( tile );
parent.add( new AlphaTweener( tile, 0, 0.6f ) {
protected void onComplete() {
tile.killAndErase();
killAndErase();
}
} );
}
public static PointF tileToWorld( int pos ) {
return new PointF( pos % Dungeon.level.width(), pos / Dungeon.level.width() ).scale( SIZE );
}
public static PointF tileCenterToWorld( int pos ) {
return new PointF(
(pos % Dungeon.level.width() + 0.5f) * SIZE,
(pos / Dungeon.level.width() + 0.5f) * SIZE );
}
public static Point tileToPoint( int pos ) {
return new Point(pos % Dungeon.level.width(), pos / Dungeon.level.width());
}
public static int pointToTile( Point point ) {
return point.y * Dungeon.level.width() + point.x;
}
public static PointF raisedTileCenterToWorld( int pos ) {
return new PointF(
(pos % Dungeon.level.width() + 0.5f) * SIZE,
(pos / Dungeon.level.width() + 0.1f) * SIZE );
}
@Override
public boolean overlapsScreenPoint( int x, int y ) {
return true;
}
}
| 4,790 | DungeonTilemap | java | en | java | code | {"qsc_code_num_words": 665, "qsc_code_num_chars": 4790.0, "qsc_code_mean_word_length": 4.97443609, "qsc_code_frac_words_unique": 0.34285714, "qsc_code_frac_chars_top_2grams": 0.0471584, "qsc_code_frac_chars_top_3grams": 0.05652963, "qsc_code_frac_chars_top_4grams": 0.04836759, "qsc_code_frac_chars_dupe_5grams": 0.14117291, "qsc_code_frac_chars_dupe_6grams": 0.10852479, "qsc_code_frac_chars_dupe_7grams": 0.09159613, "qsc_code_frac_chars_dupe_8grams": 0.07224909, "qsc_code_frac_chars_dupe_9grams": 0.05411125, "qsc_code_frac_chars_dupe_10grams": 0.04171705, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01371636, "qsc_code_frac_chars_whitespace": 0.19331942, "qsc_code_size_file_byte": 4790.0, "qsc_code_num_lines": 162.0, "qsc_code_num_chars_line_max": 96.0, "qsc_code_num_chars_line_mean": 29.56790123, "qsc_code_frac_chars_alphabet": 0.8423913, "qsc_code_frac_chars_comments": 0.28141962, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10679612, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.12621359, "qsc_codejava_score_lines_no_logic": 0.25242718, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/TerrainFeaturesTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.watabou.noosa.Image;
import com.watabou.noosa.tweeners.ScaleTweener;
import com.watabou.utils.PointF;
import com.watabou.utils.RectF;
import com.watabou.utils.SparseArray;
//TODO add in a proper set of vfx for plants growing/withering, grass burning, discovering traps
public class TerrainFeaturesTilemap extends DungeonTilemap {
public static final int SIZE = 16;
private static TerrainFeaturesTilemap instance;
private SparseArray<Plant> plants;
private SparseArray<Trap> traps;
public TerrainFeaturesTilemap(SparseArray<Plant> plants, SparseArray<Trap> traps) {
super(Assets.TERRAIN_FEATURES);
this.plants = plants;
this.traps = traps;
map( Dungeon.level.map, Dungeon.level.width() );
instance = this;
}
protected int getTileVisual(int pos, int tile, boolean flat){
if (traps.get(pos) != null){
Trap trap = traps.get(pos);
if (!trap.visible)
return -1;
else
return (trap.active ? trap.color : Trap.BLACK) + (trap.shape * 16);
}
if (plants.get(pos) != null){
return plants.get(pos).image + 7*16;
}
int stage = (Dungeon.depth-1)/5;
if (Dungeon.depth == 21) stage--;
if (tile == Terrain.HIGH_GRASS){
return 9 + 16*stage + (DungeonTileSheet.tileVariance[pos] >= 50 ? 1 : 0);
} else if (tile == Terrain.FURROWED_GRASS){
//TODO
return 11 + 16*stage + (DungeonTileSheet.tileVariance[pos] >= 50 ? 1 : 0);
} else if (tile == Terrain.GRASS) {
return 13 + 16*stage + (DungeonTileSheet.tileVariance[pos] >= 50 ? 1 : 0);
} else if (tile == Terrain.EMBERS) {
return 9 * (16*5) + (DungeonTileSheet.tileVariance[pos] >= 50 ? 1 : 0);
}
return -1;
}
public static Image tile(int pos, int tile ) {
RectF uv = instance.tileset.get( instance.getTileVisual( pos, tile, true ) );
if (uv == null) return null;
Image img = new Image( instance.texture );
img.frame(uv);
return img;
}
public void growPlant( final int pos ){
final Image plant = tile( pos, map[pos] );
if (plant == null) return;
plant.origin.set( 8, 12 );
plant.scale.set( 0 );
plant.point( DungeonTilemap.tileToWorld( pos ) );
parent.add( plant );
parent.add( new ScaleTweener( plant, new PointF(1, 1), 0.2f ) {
protected void onComplete() {
plant.killAndErase();
killAndErase();
updateMapCell(pos);
}
} );
}
}
| 3,458 | TerrainFeaturesTilemap | java | en | java | code | {"qsc_code_num_words": 456, "qsc_code_num_chars": 3458.0, "qsc_code_mean_word_length": 5.37280702, "qsc_code_frac_words_unique": 0.38815789, "qsc_code_frac_chars_top_2grams": 0.03673469, "qsc_code_frac_chars_top_3grams": 0.09306122, "qsc_code_frac_chars_top_4grams": 0.08979592, "qsc_code_frac_chars_dupe_5grams": 0.16081633, "qsc_code_frac_chars_dupe_6grams": 0.10938776, "qsc_code_frac_chars_dupe_7grams": 0.0722449, "qsc_code_frac_chars_dupe_8grams": 0.0722449, "qsc_code_frac_chars_dupe_9grams": 0.0722449, "qsc_code_frac_chars_dupe_10grams": 0.0722449, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02419355, "qsc_code_frac_chars_whitespace": 0.17524581, "qsc_code_size_file_byte": 3458.0, "qsc_code_num_lines": 112.0, "qsc_code_num_chars_line_max": 97.0, "qsc_code_num_chars_line_mean": 30.875, "qsc_code_frac_chars_alphabet": 0.83485273, "qsc_code_frac_chars_comments": 0.25534991, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.02857143, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00892857, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05714286, "qsc_codejava_score_lines_no_logic": 0.27142857, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/DungeonWallsTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
public class DungeonWallsTilemap extends DungeonTilemap {
public DungeonWallsTilemap(){
super(Dungeon.level.tilesTex());
map( Dungeon.level.map, Dungeon.level.width() );
}
@Override
protected int getTileVisual(int pos, int tile, boolean flat){
if (flat) return -1;
if (DungeonTileSheet.wallStitcheable(tile)) {
if (pos + mapWidth < size && !DungeonTileSheet.wallStitcheable(map[pos + mapWidth])){
if (map[pos + mapWidth] == Terrain.DOOR){
return DungeonTileSheet.DOOR_SIDEWAYS;
} else if (map[pos + mapWidth] == Terrain.LOCKED_DOOR){
return DungeonTileSheet.DOOR_SIDEWAYS_LOCKED;
} else if (map[pos + mapWidth] == Terrain.OPEN_DOOR){
return DungeonTileSheet.NULL_TILE;
}
} else {
return DungeonTileSheet.stitchInternalWallTile(
tile,
(pos+1) % mapWidth != 0 ? map[pos + 1] : -1,
(pos+1) % mapWidth != 0 && pos + mapWidth < size ? map[pos + 1 + mapWidth] : -1,
pos + mapWidth < size ? map[pos + mapWidth] : -1,
pos % mapWidth != 0 && pos + mapWidth < size ? map[pos - 1 + mapWidth] : -1,
pos % mapWidth != 0 ? map[pos - 1] : -1
);
}
}
if (pos + mapWidth < size && DungeonTileSheet.wallStitcheable(map[pos+mapWidth])) {
return DungeonTileSheet.stitchWallOverhangTile(
tile,
(pos+1) % mapWidth != 0 ? map[pos + 1 + mapWidth] : -1,
map[pos + mapWidth],
pos % mapWidth != 0 ? map[pos - 1 + mapWidth] : -1
);
} else if (Dungeon.level.insideMap(pos) && (map[pos+mapWidth] == Terrain.DOOR || map[pos+mapWidth] == Terrain.LOCKED_DOOR) ) {
return DungeonTileSheet.DOOR_OVERHANG;
} else if (Dungeon.level.insideMap(pos) && map[pos+mapWidth] == Terrain.OPEN_DOOR ) {
return DungeonTileSheet.DOOR_OVERHANG_OPEN;
} else if (pos + mapWidth < size && (map[pos+mapWidth] == Terrain.STATUE || map[pos+mapWidth] == Terrain.STATUE_SP)){
return DungeonTileSheet.STATUE_OVERHANG;
} else if (pos + mapWidth < size && map[pos+mapWidth] == Terrain.ALCHEMY){
return DungeonTileSheet.ALCHEMY_POT_OVERHANG;
} else if (pos + mapWidth < size && map[pos+mapWidth] == Terrain.BARRICADE){
return DungeonTileSheet.BARRICADE_OVERHANG;
} else if (pos + mapWidth < size && map[pos+mapWidth] == Terrain.HIGH_GRASS){
return DungeonTileSheet.getVisualWithAlts(DungeonTileSheet.HIGH_GRASS_OVERHANG, pos + mapWidth);
} else if (pos + mapWidth < size && map[pos+mapWidth] == Terrain.FURROWED_GRASS){
return DungeonTileSheet.getVisualWithAlts(DungeonTileSheet.FURROWED_OVERHANG, pos + mapWidth);
}
return -1;
}
@Override
public boolean overlapsPoint( float x, float y ) {
return true;
}
@Override
public boolean overlapsScreenPoint( int x, int y ) {
return true;
}
}
| 3,780 | DungeonWallsTilemap | java | en | java | code | {"qsc_code_num_words": 448, "qsc_code_num_chars": 3780.0, "qsc_code_mean_word_length": 5.65625, "qsc_code_frac_words_unique": 0.30133929, "qsc_code_frac_chars_top_2grams": 0.13456985, "qsc_code_frac_chars_top_3grams": 0.08839779, "qsc_code_frac_chars_top_4grams": 0.09944751, "qsc_code_frac_chars_dupe_5grams": 0.47908445, "qsc_code_frac_chars_dupe_6grams": 0.37016575, "qsc_code_frac_chars_dupe_7grams": 0.33109708, "qsc_code_frac_chars_dupe_8grams": 0.31767956, "qsc_code_frac_chars_dupe_9grams": 0.2667719, "qsc_code_frac_chars_dupe_10grams": 0.13970008, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01371237, "qsc_code_frac_chars_whitespace": 0.20899471, "qsc_code_size_file_byte": 3780.0, "qsc_code_num_lines": 100.0, "qsc_code_num_chars_line_max": 129.0, "qsc_code_num_chars_line_mean": 37.8, "qsc_code_frac_chars_alphabet": 0.83377926, "qsc_code_frac_chars_comments": 0.20661376, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.140625, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.046875, "qsc_codejava_score_lines_no_logic": 0.125, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/tiles/CustomTilemap.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.tiles;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.Tilemap;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
public abstract class CustomTilemap implements Bundlable {
protected static final int SIZE = DungeonTilemap.SIZE;
public int tileX, tileY; //x and y coords for texture within a level
public int tileW = 1, tileH = 1; //width and height in tiles
protected Object texture;
protected Tilemap vis = null;
public void pos(int pos) {
pos( pos%Dungeon.level.width(), pos/Dungeon.level.width() );
}
public void pos(int tileX, int tileY){
this.tileX = tileX;
this.tileY = tileY;
}
public void setRect(int topLeft, int bottomRight){
setRect( topLeft%Dungeon.level.width(),
topLeft/Dungeon.level.width(),
bottomRight%Dungeon.level.width() - topLeft%Dungeon.level.width(),
bottomRight/Dungeon.level.width() - topLeft/Dungeon.level.width()
);
}
public void setRect(int tileX, int tileY, int tileW, int tileH){
this.tileX = tileX;
this.tileY = tileY;
this.tileW = tileW;
this.tileH = tileH;
}
//utility method for getting data for a simple image
//assumes tileW and tileH have already been set
protected int[] mapSimpleImage(int txX, int txY, int texW){
int[] data = new int[tileW * tileH];
int texTileWidth = texW/SIZE;
int x = txX, y = txY;
for (int i = 0; i < data.length; i++){
data[i] = x + (texTileWidth*y);
x++;
if ((x - txX) == tileW){
x = txX;
y++;
}
}
return data;
}
public Tilemap create(){
if (vis != null && vis.alive) vis.killAndErase();
vis = new Tilemap(texture, new TextureFilm( texture, SIZE, SIZE )){
@Override
protected NoosaScript script() {
//allow lighting for custom tilemaps
return NoosaScript.get();
}
};
vis.x = tileX*SIZE;
vis.y = tileY*SIZE;
return vis;
}
//x and y here are the coordinates tapped within the tile visual
public Image image(int tileX, int tileY){
if (vis == null){
return null;
} else {
return vis.image(tileX, tileY);
}
}
public String name(int tileX, int tileY){
return null;
}
public String desc(int tileX, int tileY){
return null;
}
private static final String TILE_X = "tileX";
private static final String TILE_Y = "tileY";
private static final String TILE_W = "tileW";
private static final String TILE_H = "tileH";
@Override
public void restoreFromBundle(Bundle bundle) {
tileX = bundle.getInt(TILE_X);
tileY = bundle.getInt(TILE_Y);
tileW = bundle.getInt(TILE_W);
tileH = bundle.getInt(TILE_H);
}
@Override
public void storeInBundle(Bundle bundle) {
bundle.put(TILE_X, tileX);
bundle.put(TILE_Y, tileY);
bundle.put(TILE_W, tileW);
bundle.put(TILE_H, tileH);
}
}
| 3,697 | CustomTilemap | java | en | java | code | {"qsc_code_num_words": 520, "qsc_code_num_chars": 3697.0, "qsc_code_mean_word_length": 4.96538462, "qsc_code_frac_words_unique": 0.32692308, "qsc_code_frac_chars_top_2grams": 0.03718048, "qsc_code_frac_chars_top_3grams": 0.05267235, "qsc_code_frac_chars_top_4grams": 0.03098373, "qsc_code_frac_chars_dupe_5grams": 0.18745159, "qsc_code_frac_chars_dupe_6grams": 0.11967467, "qsc_code_frac_chars_dupe_7grams": 0.05615802, "qsc_code_frac_chars_dupe_8grams": 0.05615802, "qsc_code_frac_chars_dupe_9grams": 0.05615802, "qsc_code_frac_chars_dupe_10grams": 0.05615802, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00668226, "qsc_code_frac_chars_whitespace": 0.19042467, "qsc_code_size_file_byte": 3697.0, "qsc_code_num_lines": 137.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 26.98540146, "qsc_code_frac_chars_alphabet": 0.85599733, "qsc_code_frac_chars_comments": 0.28401407, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10869565, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00755572, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.11956522, "qsc_codejava_score_lines_no_logic": 0.27173913, "qsc_codejava_frac_words_no_modifier": 0.91666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.