예제 #1
0
파일: main.cpp 프로젝트: axnjaxn/ReiTrei
void drawRow(Texture& screen, int r) {
  Vect4 color;
  for (int c = 0; c < screen.width(); c++) {
    color = screen.getColor(r, c);
    px->set(r, c, toByte(color[0]), toByte(color[1]), toByte(color[2]));
  }
}
예제 #2
0
파일: main.cpp 프로젝트: axnjaxn/ReiTrei
void redraw(const Texture& screen) {
  Vect4 color;
  for (int r = 0; r < screen.height(); r++) {
    for (int c = 0; c < screen.width(); c++) {
      color = screen.getColor(r, c);
      px->set(r, c, toByte(color[0]), toByte(color[1]), toByte(color[2]));
    }
  }

  px->redraw();
  SDL_RenderPresent(px->getRenderer());
}
예제 #3
0
	void DirectSoundVoice::seek( unsigned long millisecond )
	{
		unsigned long moveto = toByte( millisecond );
		if ( moveto >= m_audio->size() )
			moveto = m_audio->size() - 1; // 終端ピッタリには移動できない. AlignはDirectSoundが調整してくれる.

		m_dsbuffer.SetCurrentPosition( moveto );
	}
예제 #4
0
파일: dsp.cpp 프로젝트: taqu/opus
    //----------------------------------------------------------------------------
    void conv_Float1ToByte1(void* dst, const void* s, s32 numSamples)
    {
        LSbyte* d = reinterpret_cast<LSbyte*>(dst);
        const LSfloat* src = reinterpret_cast<const LSfloat*>(s);

        for(s32 i=0; i<numSamples; ++i){
            d[i] = toByte(src[i]);
        }
    }
예제 #5
0
QByteArray HTree::finalCode(QByteArray sizeName, QString fileName)
{
    QByteArray aux;
    QByteArray tmp;
    QByteArray head;
    QByteArray name;
    QByteArray code;

    /* Início da Setação dos dois primeiros bytes do cabeçalho*/
    aux = m_sizeTrash.append(m_sizeTree);
    for(int i = 0; i < 16; i++){
        tmp.append(aux.at(i));
        if(i%8 == 7 && i > 0){
            head.append((unsigned char)toByte(tmp));
            tmp.clear();
        }
    }
    /* Fim da Setação dos dois primeiros bytes do cabeçalho*/

    /* Início da Setação do terceiro byte do cabeçalho */
    name.append(toByte(sizeName));
    name.append(fileName);
    /* Fim da Setação do terceiro byte do cabeçalho */

    /* Início da Setação dos bytes do código no cabeçalho */
    aux = m_fileCode;
    for(long long int i = 0; i < m_fileCode.size(); i++){
        tmp.append((unsigned char)aux.at(i));
        if(i%8 == 7 && i > 0){
            code.append((unsigned char)toByte(tmp));
            tmp.clear();
        }
    }
    /* Fim da Setação dos bytes do código no cabeçalho */



    m_fileOut.append(head);
    m_fileOut.append(name);
    m_fileOut.append(m_treeCode);
    m_fileOut.append(code);

    return m_fileOut;
}
예제 #6
0
파일: dsp.cpp 프로젝트: taqu/opus
    void conv_Short1ToByte2(void* dst, const void* s, s32 numSamples)
    {
        LSbyte* d = reinterpret_cast<LSbyte*>(dst);
        const LSshort* src = reinterpret_cast<const LSshort*>(s);

        for(s32 i=0; i<numSamples; ++i){
            s32 j = i<<1;
            d[j+0] = d[j+1] = toByte(src[i]);
        }
    }
예제 #7
0
QVariant QDBusDemarshaller::toVariantInternal()
{
    switch (q_dbus_message_iter_get_arg_type(&iterator)) {
    case DBUS_TYPE_BYTE:
        return qVariantFromValue(toByte());
    case DBUS_TYPE_INT16:
	return qVariantFromValue(toShort());
    case DBUS_TYPE_UINT16:
	return qVariantFromValue(toUShort());
    case DBUS_TYPE_INT32:
        return toInt();
    case DBUS_TYPE_UINT32:
        return toUInt();
    case DBUS_TYPE_DOUBLE:
        return toDouble();
    case DBUS_TYPE_BOOLEAN:
        return toBool();
    case DBUS_TYPE_INT64:
        return toLongLong();
    case DBUS_TYPE_UINT64:
        return toULongLong();
    case DBUS_TYPE_STRING:
        return toString();
    case DBUS_TYPE_OBJECT_PATH:
        return qVariantFromValue(toObjectPath());
    case DBUS_TYPE_SIGNATURE:
        return qVariantFromValue(toSignature());
    case DBUS_TYPE_VARIANT:
        return qVariantFromValue(toVariant());

    case DBUS_TYPE_ARRAY:
        switch (q_dbus_message_iter_get_element_type(&iterator)) {
        case DBUS_TYPE_BYTE:
            // QByteArray
            return toByteArray();
        case DBUS_TYPE_STRING:
            return toStringList();
        case DBUS_TYPE_DICT_ENTRY:
            return qVariantFromValue(duplicate());

        default:
            return qVariantFromValue(duplicate());
        }

    case DBUS_TYPE_STRUCT:
        return qVariantFromValue(duplicate());

    default:
        qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'",
                 q_dbus_message_iter_get_arg_type(&iterator),
                 q_dbus_message_iter_get_arg_type(&iterator));
        return QVariant();
        break;
    };
}
예제 #8
0
파일: dsp.cpp 프로젝트: taqu/opus
    void conv_Float2ToByte1(void* dst, const void* s, s32 numSamples)
    {
        LSbyte* d = reinterpret_cast<LSbyte*>(dst);
        const LSfloat* src = reinterpret_cast<const LSfloat*>(s);

        for(s32 i=0; i<numSamples; ++i){
            s32 j = i<<1;
            f32 v = 0.5f*(src[j+0] + src[j+1]);
            d[i] = toByte(v);
        }
    }
예제 #9
0
QVariant QDBusDemarshaller::toVariantInternal()
{
    switch (q_dbus_message_iter_get_arg_type(&iterator)) {
    case DBUS_TYPE_BYTE:
        return QVariant::fromValue(toByte());
    case DBUS_TYPE_INT16:
	return QVariant::fromValue(toShort());
    case DBUS_TYPE_UINT16:
	return QVariant::fromValue(toUShort());
    case DBUS_TYPE_INT32:
        return toInt();
    case DBUS_TYPE_UINT32:
        return toUInt();
    case DBUS_TYPE_DOUBLE:
        return toDouble();
    case DBUS_TYPE_BOOLEAN:
        return toBool();
    case DBUS_TYPE_INT64:
        return toLongLong();
    case DBUS_TYPE_UINT64:
        return toULongLong();
    case DBUS_TYPE_STRING:
        return toStringUnchecked();
    case DBUS_TYPE_OBJECT_PATH:
        return QVariant::fromValue(toObjectPathUnchecked());
    case DBUS_TYPE_SIGNATURE:
        return QVariant::fromValue(toSignatureUnchecked());
    case DBUS_TYPE_VARIANT:
        return QVariant::fromValue(toVariant());

    case DBUS_TYPE_ARRAY:
        switch (q_dbus_message_iter_get_element_type(&iterator)) {
        case DBUS_TYPE_BYTE:
            // QByteArray
            return toByteArrayUnchecked();
        case DBUS_TYPE_STRING:
            return toStringListUnchecked();
        case DBUS_TYPE_DICT_ENTRY:
            return QVariant::fromValue(duplicate());

        default:
            return QVariant::fromValue(duplicate());
        }

    case DBUS_TYPE_STRUCT:
        return QVariant::fromValue(duplicate());

    case DBUS_TYPE_UNIX_FD:
        if (capabilities & QDBusConnection::UnixFileDescriptorPassing)
            return QVariant::fromValue(toUnixFileDescriptor());
        // fall through

    default:
//        qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'",
//                 q_dbus_message_iter_get_arg_type(&iterator),
//                 q_dbus_message_iter_get_arg_type(&iterator));
        char *ptr = 0;
        ptr += q_dbus_message_iter_get_arg_type(&iterator);
        q_dbus_message_iter_next(&iterator);

        // I hope you never dereference this pointer!
        return QVariant::fromValue<void *>(ptr);
    };
}
예제 #10
0
파일: decrypt.c 프로젝트: vonHub/Decoder
int main(int argc, char ** argv) {

    // Check arguments
    if (argc != 2 && argc != 3) {
        printf("Usage: decrypt [key]\n");
        exit(1);
    }

    if (argc == 3 && strcmp(argv[1], "-b")) {
        printf("Usage: decrypt -b [binary key]\n");
        exit(1);
    }

    if (argc == 3 && strlen(argv[2]) != 32) {
        printf("Needs a 32 bit key\n");
        exit(1);
    }

    // Get key
    if (argc == 3) {
        // Get 32 bit key from input
        int index;
        for (index = 0; index < 32; index++) {
            if (argv[2][index] == '1') {
                key += pow(2, 31 - index);
            }
        }
    } else {
        key = (unsigned int)strtoul(argv[1], NULL, 0);
    }

    char a = '\0';
    char b = '\0';
    int err = scanf("\\x%c%c", &a, &b);

    // Read in bytes, decode, and print to stdout
    while (err != 0) { // While the next byte exists

        unsigned int block = 0; // 32-bit encrypted block

        // Four bytes for 32 bit key size
        for (int i = 0; i < 4; i++) {

            // Check if current byte exists
            if (err == 0) {
                if (i == 0) break;
                printf("Error: input is not 32-bit aligned\n");
                exit(1);
            }

            // Add byte to block
            // Metasploit prints the payload with the least
            // siginificant byte first
            // Shift the byte just read over by the right amount
            unsigned char byte = toByte(a, b);
            block += byte << (8 * i);

            // Go get the next byte
            err = scanf("\\x%c%c", &a, &b);
        }
        // Now XOR the key with the block
        // And generate the new key
        // Note that the fact that unsigned ints are
        // naturally 32 bits long prevents us from
        // having to cut off any extra bits
        unsigned int original = block ^ key;
 
        // Debugging       
        //printf("Key: %u\n", key);
        //printf("Encrypted: %u\n", block);
        //printf("Decrypted: %u\n", original);
        
        key = original + key;
        printBlock(original);
    }
    printf("\n");

}
예제 #11
0
void Pixel::convertColorModel(ColorModel model) 
{
	// When converting between models other then RGB, first convert to RGB then to other model
	if (this->model != RGB)
		toRgb();
	
	if (model == RGB) return; // Nothing to do
	
	int R = c[0], G = c[1], B = c[2];
	double X,Y,Z,L_lab,a_lab,b_lab; // used in several conversions
	
	if (model == YUV) {
		// YUV formula
		/*double Y, U, V;
		Y = 0.299*R + 0.587*G + 0.114*B;
		U = 0.492*(B-Y);
		V = 0.877*(R-Y);
		
		// Ranges are now Ye[0,1], Ue[-0.436,0.436], Ve[-0.615,0.615]
		
		// Convert to byte:
		Y = toByte(Y*256);
		U = toByte((U+0.436)*256 / (0.436*2));
		V = toByte((V+0.615)*256 / (0.615*2));*/
		
		// The following is equivalent and comes from JPEG standard
		int Y = toByte ( 0.299 * R + 0.587 * G + 0.114 * B );
		int U = toByte ( 128 - 0.168736 * R - 0.331264 * G + 0.5 * B );
		int V = toByte ( 128 + 0.5 * R - 0.418688 * G - 0.081312 * B );
		
		c[0] = Y; c[1] = U; c[2] = V;
		return;
	}
	
	if (model == YIQ) {
		int Y = toByte ( 0.299 * R + 0.587 * G + 0.114 * B );
		int I = toByte ( (152 + 0.596 * R - 0.275 * G - 0.321 * B) / 304 * 255 );
		int Q = toByte ( (133 + 0.212 * R - 0.523 * G + 0.311 * B) / 266 * 255 );
		
		c[0] = Y; c[1] = I; c[2] = Q;
		
		return;
	}
	
	if (model == HSV) {
		int H, S, V;
		
		QColor color(R, G, B);
		color.getHsv(&H, &S, &V);
		
		H = (H*256)/360; // Rescale to 0-255
		if (H==256) H=255;
		
		c[0] = H; c[1] = S; c[2] = V;
		
		return;
	}
	
	if (model == HSL) {
		int H, S, L;
		
		QColor color(R, G, B);
		color.getHsl(&H, &S, &L);
		
		H = (H*256)/360; // Rescale to 0-255
		if (H==256) H=255;
		
		c[0] = H; c[1] = S; c[2] = L;
		
		return;
	}
	
	if (model == HSI) {
		int H, S, I;
		
		QColor color(R, G, B);
		color.getHsl(&H, &S, &I);
		
		H = (H*256)/360; // Rescale to 0-255
		if (H==256) H=255;
		
		I = (R+G+B)/765; // 765 = 3*255
		
		c[0] = H; c[1] = S; c[2] = I;
		
		return;
	}
	
	if (model == IHLS) {
		// More perceptually uniform variant of HSL color space
		// See: Hanbury and Serra "A 3D-polar coordinate colour representation suitable for image analysis" (2002)
		int H, S, L;
		
		QColor color(R, G, B);
		color.getHsl(&H, &S, &L);
		
		H = (H*256)/360; // Rescale to 0-255
		if (H==256) H=255;
		
		int M=qMax(R,qMax(G,B));
		int m=qMin(R,qMin(G,B));
		S = M-m;
		
		c[0] = H; c[1] = S; c[2] = L;
		
		return;
	}
	
	if (model == HMMD) { 
		// Color model used in MPEG-7 standard
		// See: Manjunath et al. "Color and texture descriptors" (2001)
		int H, S, V;
		
		QColor color(R, G, B);
		color.getHsv(&H, &S, &V);
		
		H = (H*256)/360; // Rescale to 0-255
		if (H==256) H=255;
		
		int M=qMax(R,qMax(G,B));
		int m=qMin(R,qMin(G,B));
		int D=M-m;
		
		c[0] = H; c[1] = M; c[2] = m; c[3] = D;
		
		return;
	}
	
	if (model == HY) {
		int H, S, V;
		
		QColor color(R, G, B);
		color.getHsv(&H, &S, &V);
		
		H = (H*256)/360; // Rescale to 0-255
		if (H==256) H=255;
		
		int Y = toByte ( 0.299 * R + 0.587 * G + 0.114 * B );
		
		c[0] = H; c[1] = Y;
		
		return;
	}
	
	if (model == XYZ || model == LAB || model == LUV || model == LCH) {
		// Convert RGB to range [0,1]
		double r(double(R)/255);
		double g(double(G)/255);
		double b(double(B)/255);
		
		// We assume that color is sRGB with decoding gamma of 2.2, as customary
		
		// Linearize sRGB
		if (r<0.04045) r=r/12.92; else r=pow((r+0.055)/1.055, 2.4);
		if (g<0.04045) g=g/12.92; else g=pow((g+0.055)/1.055, 2.4);
		if (b<0.04045) b=b/12.92; else b=pow((b+0.055)/1.055, 2.4);
		
		// Convert sRGB to XYZ using transformation matrix
		X = 0.4124564 * r + 0.3575761 * g + 0.1804375 * b;
		Y = 0.2126729 * r + 0.7151522 * g + 0.0721750 * b;
		Z = 0.0193339 * r + 0.1191920 * g + 0.9503041 * b;
	}

	if (model == XYZ) {
		c[0] = toByte(X*255);
		c[1] = toByte(Y*255);
		c[2] = toByte(Z*255);
		return;
	}
	
	if (model == LAB || model == LCH) {
		// Reference illuminant D65 white point
		double Xn = 0.95047;
		double Yn = 1;
		double Zn = 1.08883;
		
		double D = pow( 6.0 / 29.0, 3 );
		
		double Xfn( X / Xn ), Yfn( Y / Yn ), Zfn( Z / Zn );
		if ( Xfn > D ) Xfn = pow(Xfn,1.0/3.0); else Xfn = ( 1.0 / 3.0 ) * pow( (29.0 / 6.0), 2) * Xfn + ( 4.0 / 29.0 );
		if ( Yfn > D ) Yfn = pow(Yfn,1.0/3.0); else Yfn = ( 1.0 / 3.0 ) * pow( (29.0 / 6.0), 2) * Yfn + ( 4.0 / 29.0 );
		if ( Zfn > D ) Zfn = pow(Zfn,1.0/3.0); else Zfn = ( 1.0 / 3.0 ) * pow( (29.0 / 6.0), 2) * Zfn + ( 4.0 / 29.0 );
		
		L_lab = 116 * Yfn - 16;
		a_lab = 500 * (Xfn - Yfn);
		b_lab = 200 * (Yfn - Zfn);
	}
	
	if (model == LAB) {
		// Convert to byte
		c[0] = toByte( L_lab * 255 / 100 );
		
		// Actual gamut of RGB in CIE Lab space is [0,100], [-86,98], [-107,94];
		c[1] = toByte( (a_lab + 86)  * 255 /  (86 + 98) );
		c[2] = toByte( (b_lab + 107) * 255 / (107 + 94) );
		
		return;
	}
	
	if (model == LCH) {
		// a and b are in range [-127,128]
		a_lab = (a_lab+127) / 255;
		b_lab = (b_lab+127) / 255;
		
		double H = atan2(b_lab, a_lab);
		double C = sqrt(a_lab*a_lab + b_lab*b_lab);

		c[0] = toByte( L_lab * 255 / 100 );
		// H is in range [0.092, 1.37]
		c[1] = toByte( (H - 0.092) * 199 );
		// C is in range [0.533, 1.11]
		c[2] = toByte( (C - 0.533) * 440 );
		
		return;
	}
	
	if (model == LUV) {
		// Reference illuminant D65 white point
		double Xn = 0.95047;
		double Yn = 1;
		double Zn = 1.08883;
		
		double D = pow( 6.0 / 29.0, 3 );
		
		double Yfn( Y / Yn );
		if ( Yfn > D ) Yfn = pow(Yfn,1.0/3.0); else Yfn = ( 1.0 / 3.0 ) * pow( (29.0 / 6.0), 2) * Yfn + ( 4.0 / 29.0 );
		
		double Xfn((4*X) / (X + 15*Y + 3*Z));
		double Zfn((9*Y) / (X + 15*Y + 3*Z));
		
		double Xref((4*Xn) / (Xn + 15*Yn + 3*Zn));
		double Zref((9*Yn) / (Xn + 15*Yn + 3*Zn));

		double L = 116 * Yfn - 16;
		double u = 13 * L * ( Xfn - Xref );
		double v = 13 * L * ( Zfn - Zref );
		
		// Convert to byte
		c[0] = toByte( L*255 / 100 );
		c[1] = toByte( u + 127 );
		c[2] = toByte( v + 127 );
		
		return;
	}
	
	if (model == L1L2L3) {
		// See: Gevers and Smeulders "Color-based object recognition" (1999)
		int d1 = (R-G)*(R-G);
		int d2 = (R-B)*(R-B);
		int d3 = (G-B)*(G-B);
		double l1 = double(d1) / (d1+d2+d3);
		double l2 = double(d2) / (d1+d2+d3);
		double l3 = double(d3) / (d1+d2+d3);
		c[0] = toByte(l1);
		c[1] = toByte(l2);
		c[2] = toByte(l3);
	}
}