// ----------------------------------------------------------- Testing Purposes SEXP Ras_rle(SEXP vals_, SEXP eps_) { BEGIN_RCPP // switch(TYPEOF(x)) { // case LGLSXP: // PROTECT(ans = Rle_logical_constructor(x, counts)); // break; // case INTSXP: // PROTECT(ans = Rle_integer_constructor(x, counts)); // break; // case REALSXP: // PROTECT(ans = Rle_real_constructor(x, counts)); // break; // case CPLXSXP: // PROTECT(ans = Rle_complex_constructor(x, counts)); // break; // case STRSXP: // PROTECT(ans = Rle_string_constructor(x, counts)); // break; // case RAWSXP: // PROTECT(ans = Rle_raw_constructor(x, counts)); // break; // default: // error("Rle computation of these types is not implemented"); // } SEXP ret; double eps = Rcpp::as<double>(eps_); std::vector<double> vals = Rcpp::as< std::vector<double> >(vals_); // biosignals::Rle<double> rle = Rcpp::as< biosignals::Rle<double>(vals_); biosignals::Rle<double> rle(vals, eps); return Rcpp::wrap(rle); END_RCPP }
int main(void) { int n; char napis[201]; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%s", napis); rle(napis); } return 0; }
int main(int argc, char const *argv[]) { /* Run length encoding */ printf("Enter the string\n"); char str[100]; scanf("%s", str); rle(str); return 0; }
/* * Compresses an individual chunk using a specific format. The format is one * of the 'format' fields listed in the spec; one of the ZTR_FORM_ macros. */ int compress_chunk(ztr_t *ztr, ztr_chunk_t *chunk, int format, int option, int option2) { char *new_data = NULL; int new_len; switch (format) { case ZTR_FORM_RAW: return 0; case ZTR_FORM_RLE: new_data = rle(chunk->data, chunk->dlength, option, &new_len); if (entropy((unsigned char *)new_data, new_len) >= entropy((unsigned char *)chunk->data, chunk->dlength)) { xfree(new_data); return 0; } break; case ZTR_FORM_XRLE: new_data = xrle(chunk->data, chunk->dlength, option,option2, &new_len); break; case ZTR_FORM_XRLE2: new_data = xrle2(chunk->data, chunk->dlength, option, &new_len); break; case ZTR_FORM_ZLIB: new_data = zlib_huff(chunk->data, chunk->dlength, option, &new_len); break; case ZTR_FORM_DELTA1: new_data = decorrelate1(chunk->data, chunk->dlength, option, &new_len); break; case ZTR_FORM_DDELTA1: new_data = decorrelate1dyn(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_DELTA2: new_data = decorrelate2(chunk->data, chunk->dlength, option, &new_len); break; case ZTR_FORM_DDELTA2: new_data = decorrelate2dyn(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_DELTA4: new_data = decorrelate4(chunk->data, chunk->dlength, option, &new_len); break; case ZTR_FORM_16TO8: new_data = shrink_16to8(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_32TO8: new_data = shrink_32to8(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_FOLLOW1: new_data = follow1(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_ICHEB: new_data = ichebcomp(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_LOG2: new_data = log2_data(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_STHUFF: new_data = sthuff(ztr, chunk->data, chunk->dlength, option, option2, &new_len); break; case ZTR_FORM_QSHIFT: new_data = qshift(chunk->data, chunk->dlength, &new_len); break; case ZTR_FORM_TSHIFT: new_data = tshift(ztr, chunk->data, chunk->dlength, &new_len); break; } if (!new_data) { fprintf(stderr, "!!ERROR!!\n"); return -1; } /* fprintf(stderr, "Format %d => %d to %d\n", format, chunk->dlength, new_len); */ chunk->dlength = new_len; xfree(chunk->data); chunk->data = new_data; return 0; }
void main() { char s[] = "wwwwaaadexxxxxx"; rle(s); }
int main(int argc, char *argv[]) { int j, seg=0, done=0, ch, frames, i, startframe = 1, endframe = 0; uint32 temp,len; char *filename, *prefilename; if(argc < 5) { printf("vidconvert USAGE %s [-g gamma][-b brightness][-c contrast] -f frames -n prefilename [-s startframe][-e endframe]\n",argv[0]); exit(1); } while ((ch = getopt(argc, argv, "g:b:c:f:n:s:e:")) != EOF) { switch(ch) { case 'g': gamma = atoi(optarg); break; case 'b': bright = atoi(optarg); break; case 'c': contrast = atoi(optarg); break; case 's': startframe = atoi(optarg); break; case 'e': endframe = atoi(optarg); break; case 'f': frames = atoi(optarg); break; case 'n': prefilename = strdup(optarg); break; default: printf("vidconvert USAGE %s [-g gamma][-b brightness][-c contrast] -f frames -n prefilename [-s startframe][-e endframe]\n",argv[0]); } } if(!endframe) endframe = frames; if(strlen(prefilename)>11) { printf("invalid prefilename length.\n"); exit(1); } filename = malloc(17); sprintf(filename, "%s.rvd", prefilename); outfp = fopen(filename,"a"); if(!outfp) { printf("couldn't open output stream.\n"); exit(1); } maketab(); //generated from gamma contrast and brightness for(i = startframe; i<=frames; i++) { printf("Opening Frame %d\n", i); if(!endframe) break; endframe--; //Reset All variables... segbuf = NULL; seg = segsize = seglen = segin = yup = xup = ncomp = 0; heightDU = widthDU = colsDU = cols8 = maxy = linesize = restinv = ducount = 0; buff[0] = buff[1] = buff[2] = NULL; coltab = colloc = bmploc = bmpup = NULL; dc[0] = dc[1] = dc[2] = 0; reset(); //take into account for the zeros with greater frame totals if(frames < 100) { if(i<10) sprintf(filename, "%s 0%d.jpg", prefilename, i); else sprintf(filename, "%s %d.jpg", prefilename,i); } else { if(i<10) sprintf(filename, "%s 00%d.jpg", prefilename, i); else if(i<100) sprintf(filename, "%s 0%d.jpg", prefilename, i); else sprintf(filename, "%s %d.jpg", prefilename,i); } filefd = open(filename, O_READ); if (filefd == -1) { printf("Unable to open file %s... re-using previous frame.\n", filename); j=1; while(i-j > 0) { if(frames < 500) { if(i<10) sprintf(filename, "%s 0%d.jpg", prefilename, i-j); else sprintf(filename, "%s %d.jpg", prefilename,i-j); } else { if(i<10) sprintf(filename, "%s 00%d.jpg", prefilename, i-j); else if(i<100) sprintf(filename, "%s 0%d.jpg", prefilename, i-j); else sprintf(filename, "%s %d.jpg", prefilename,i-j); } filefd = open(filename, O_READ); if(filefd == -1) j++; else break; } if(i-j < 1) continue; } seg = loadseg(); if (seg == 0xd8) printf("It's a jpeg!\n"); else { printf("Image file %s, is not a JPEG '%d'... skipping it.\n", filename, seg); exit(1); } while(seg != 0xda) { seg = loadseg(); if(!seg) goto skiptonext; switch(seg) { case 0xdb: if(!segDQT()) goto skiptonext; break; case 0xc4: if(!segDHT()) goto skiptonext; break; case 0xda: segSOS(); break; case 0xc0: segSOF(); break; case 0xdd: segDRI(); break; } } bmpwidth = round8(width); bmpheight = round8(height); imgsize = ((bmpheight*bmpwidth)/8) + ((bmpwidth*bmpheight)/64); width8 = bmpwidth/8; temp = (uint32) width8 * bmpheight; len = temp/8+temp; bmpup = bmploc = calloc(len, 1); colloc = bmploc+temp; while (!done) { imagedata(); render(); yup += heightDU; if (yup >= height) { done=1; printf("Finished rendering frame %d\n", i); rle(); printf("Finished RLE encoding frame %d\n", i); } } done = 0; skiptonext: close(filefd); } fclose(outfp); return(1); }
int main() { char s[100] ="geeksforgeeks"; char d[100]; rle(s,d); std::cout<<d; }
SEXP biosonics_ping(SEXP bytes, SEXP Rspp, SEXP Rns, SEXP Rtype) { PROTECT(bytes = AS_RAW(bytes)); PROTECT(Rspp = AS_NUMERIC(Rspp)); int spp = (int)floor(0.5 + *REAL(Rspp)); PROTECT(Rns = AS_NUMERIC(Rns)); int ns = (int)floor(0.5 + *REAL(Rns)); PROTECT(Rtype = AS_NUMERIC(Rtype)); int type = (int)floor(0.5 + *REAL(Rtype)); //double *typep = REAL(type); //int beam = (int)floor(0.5 + *typep); #ifdef DEBUG Rprintf("biosonics_ping() decoded type:%d, spp:%d, ns:%d\n", type, spp, ns); #endif int byte_per_sample = 2; if (type == 1 || type == 2) { byte_per_sample = 4; } unsigned int nbytes = LENGTH(bytes); #ifdef DEBUG Rprintf("nbytes: %d (should be 2*ns for single-beam or 4*ns for split- and dual-beam)\n", nbytes); #endif unsigned char *bytep = RAW(bytes); SEXP res; PROTECT(res = allocVector(VECSXP, 3)); SEXP res_names; PROTECT(res_names = allocVector(STRSXP, 3)); SEXP res_a; PROTECT(res_a = allocVector(REALSXP, spp)); SEXP res_b; PROTECT(res_b = allocVector(REALSXP, spp)); SEXP res_c; PROTECT(res_c = allocVector(REALSXP, spp)); // Get static storage; FIXME: is this thread-safe? biosonics_allocate_storage(spp, byte_per_sample); #ifdef DEBUG Rprintf("allocVector(REALSXP, %d)\n", spp); #endif double *resap = REAL(res_a); double *resbp = REAL(res_b); double *rescp = REAL(res_c); if (type == 0) { // single-beam rle(bytep, ns, spp, 2); for (int k = 0; k < spp; k++) { resap[k] = biosonic_float(buffer[byte_per_sample * k], buffer[1 + byte_per_sample * k]); resbp[k] = 0.0; rescp[k] = 0.0; } } else if (type == 1) { // dual-beam rle(bytep, ns, spp, 4); for (int k = 0; k < spp; k++) { // Quote [1 p37 re dual-beam]: "For an RLE-expanded sample x, the low-order // word (ie, (USHORT)(x & 0x0000FFFF)) contains the narrow-beam data. The // high-order word (ie, (USHORT)((x & 0xFFFF0000) >> 16)) contains the // wide beam data." resap[k] = biosonic_float(buffer[ byte_per_sample * k], buffer[1 + byte_per_sample * k]); resbp[k] = biosonic_float(buffer[2 + byte_per_sample * k], buffer[3 + byte_per_sample * k]); resbp[k] = 0.0; } } else if (type == 2) { // split-beam rle(bytep, ns, spp, 4); for (int k = 0; k < spp; k++) { // Quote [1 p38 split-beam e.g. 01-Fish.dt4 example]: "the low-order word // (ie, (USHORT)(x & 0x0000FFFF)) contains the amplitude data. The // high-order byte (ie, (TINY)((x & 0xFF000000) >> 24)) contains the // raw X-axis angle data. The other byte // (ie, (TINY)((x & 0x00FF0000) >> 16)) contains the raw Y-axis angle data. resap[k] = biosonic_float(buffer[byte_per_sample * k], buffer[1 + byte_per_sample * k]); resbp[k] = (double)buffer[2 + byte_per_sample * k]; rescp[k] = (double)buffer[3 + byte_per_sample * k]; } } else { error("unknown type, %d", type); } SET_VECTOR_ELT(res, 0, res_a); SET_VECTOR_ELT(res, 1, res_b); SET_VECTOR_ELT(res, 2, res_c); SET_STRING_ELT(res_names, 0, mkChar("a")); SET_STRING_ELT(res_names, 1, mkChar("b")); SET_STRING_ELT(res_names, 2, mkChar("c")); setAttrib(res, R_NamesSymbol, res_names); UNPROTECT(9); return(res); }