void writeIconDirEntry(ByteStream& stream, int width, int height, int offset) { stream.put(width == 256 ? 0 : width); //Specifies image width in pixels. Can be any number between 0 and 255. Value 0 means image width is 256 pixels. stream.put(height == 256 ? 0 : height); //Specifies image height in pixels. Can be any number between 0 and 255. Value 0 means image height is 256 pixels. stream.put(0); //Specifies number of colors in the color palette. Should be 0 if the image does not use a color palette. stream.put(0); //Reserved. Should be 0.[Notes 2] stream.write(convertShortToByteArrayLE((short)1)); //Specifies color planes. Should be 0 or 1.[Notes 3] stream.write(convertShortToByteArrayLE((short)32)); //Specifies bits per pixel. [Notes 4] stream.write(convertIntToByteArrayLE(width * height * 4 + 40)); //Specifies the size of the image's data in bytes stream.write(convertIntToByteArrayLE(offset)); //Specifies the offset of BMP or PNG data from the beginning of the ICO/CUR file }
void net::Server::sendPlayerCameraUpdate(const Client* to, Entity::ID followID) { ByteStream bs; // TODO: put this somewhere better // TODO: for now, this is the only server->client message on CHAN_PLAYERCMD, // but this should have a message type later. bs.write(followID, LE); auto packet = enet_packet_create(bs.data(), bs.size(), ENET_PACKET_FLAG_RELIABLE); enet_peer_send(to->peer, CHAN_PLAYERCMD, packet); }
void writeBMPHeader(ByteStream& stream, int width, int height) { stream.write(convertIntToByteArrayLE(bmpHeaderSize)); //the size of this header (40 bytes) stream.write(convertIntToByteArrayLE(width)); //the bitmap width in pixels (signed integer). stream.write(convertIntToByteArrayLE(height * 2)); //the bitmap height in pixels (signed integer). stream.write(convertShortToByteArrayLE((short)1)); //the number of color planes being used. Must be set to 1. stream.write(convertShortToByteArrayLE((short)32)); //the number of bits per pixel, which is the color depth of the image. Typical values are 1, 4, 8, 16, 24 and 32. stream.write(convertIntToByteArrayLE(0)); //the compression method being used. See the next table for a list of possible values. stream.write(convertIntToByteArrayLE(width * height * 4)); //the image size. This is the size of the raw bitmap data (see below), and should not be confused with the file size. stream.write(convertIntToByteArrayLE(0)); //the horizontal resolution of the image. (pixel per meter, signed integer) stream.write(convertIntToByteArrayLE(0)); //the vertical resolution of the image. (pixel per meter, signed integer) stream.write(convertIntToByteArrayLE(0)); //the number of colors in the color palette, or 0 to default to 2n. stream.write(convertIntToByteArrayLE(0)); //the number of important colors used, or 0 when every color is important; generally ignored. }
void Ball::writeBMP(ByteStream& stream, Image* image) { writeBMPHeader(stream, image->width(), image->height()); for (int y = image->height() - 1; y >= 0; --y) { for (int x = 0; x < image->width(); ++x) { //stream.put(image->b(x, y)); //stream.put(image->g(x, y)); //stream.put(image->r(x, y)); //stream.put(image->a(x, y)); stream.write(convertIntToByteArrayLE(image->argb(x, y))); } } }
int Client_TCP::send(ByteStream& stream) { // Add message size to head of stream int status = 0; ByteStream send; send.write(stream.getWriteIndex()); // msg size send = send + stream; // actual msg size_t tosend = stream.getWriteIndex() + sizeof(int); // bytes needed to be sent // Start sending char* head = send.getBufHead(); while (tosend > 0) { ssize_t bytes = ::send(sockfd, head, tosend, 0); if (bytes <= 0) { // send() was not successful perror("Sending unsuccessful"); return 1; } tosend -= (size_t) bytes; head += bytes; } return 0; }
void writeIcoHeader(ByteStream& stream) { stream.put(0); stream.put(0); //Reserved. Must always be 0. stream.write(convertShortToByteArrayLE((short)1)); //Specifies image type: 1 for icon (.ICO) image, 2 for cursor (.CUR) image. Other values are invalid. stream.write(convertShortToByteArrayLE((short)4)); //Specifies number of images in the file. }
void GLObject::print(ByteStream & str, int compact, int indent, int * cur_pos) const { int local_cur_pos = 0; if (!cur_pos) { cur_pos = &local_cur_pos; } GUTF8String buffer; const char * to_print=0; switch(type) { case NUMBER: to_print=buffer.format("%d",number); break; case STRING: { int length = string.length(); const char *data = (const char*)string; buffer = GUTF8String("\""); while (*data && length>0) { int span = 0; while (span<length && (unsigned char)(data[span])>=0x20 && data[span]!=0x7f && data[span]!='"' && data[span]!='\\' ) span++; if (span > 0) { buffer = buffer + GUTF8String(data, span); data += span; length -= span; } else { char buf[8]; static const char *tr1 = "\"\\tnrbf"; static const char *tr2 = "\"\\\t\n\r\b\f"; sprintf(buf,"\\%03o", (int)(((unsigned char*)data)[span])); for (int i=0; tr2[i]; i++) if (data[span] == tr2[i]) buf[1] = tr1[i]; if (buf[1]<'0' || buf[1]>'3') buf[2] = 0; buffer = buffer + GUTF8String(buf); data += 1; length -= 1; } } buffer = buffer + GUTF8String("\""); to_print = buffer; } break; case SYMBOL: to_print=buffer.format("%s",(const char *)symbol); break; case LIST: to_print=buffer.format("(%s",(const char *)name); break; case INVALID: break; } if (!compact && *cur_pos+strlen(to_print)>70) { char ch='\n'; str.write(&ch, 1); ch=' '; for(int i=0;i<indent;i++) str.write(&ch, 1); *cur_pos=indent; } str.write(to_print, strlen(to_print)); char ch=' '; str.write(&ch, 1); *cur_pos+=strlen(to_print)+1; if (type==LIST) { int indent=*cur_pos-strlen(to_print); for(GPosition pos=list;pos;++pos) list[pos]->print(str, compact, indent, cur_pos); str.write(") ", 2); *cur_pos+=2; } }
inline static void putchar(ByteStream & str, char ch) { str.write(&ch, 1); }