/* * Copyright 2013 The LibYuv Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Convert an ARGB image to YUV. // Usage: yuvconvert src_argb.raw dst_yuv.raw
// options bool verbose = false; bool attenuate = false; bool unattenuate = false; int image_width = 0, image_height = 0; // original width and height int dst_width = 0, dst_height = 0; // new width and height int fileindex_org = 0; // argv argument contains the original file name. int fileindex_rec = 0; // argv argument contains the reconstructed file name. int num_rec = 0; // Number of reconstructed images. int num_skip_org = 0; // Number of frames to skip in original. int num_frames = 0; // Number of frames to convert. int filter = 1; // Bilinear filter for scaling.
static __inline uint32_t Abs(int32_t v) { return v >= 0 ? v : -v;
}
// Parse PYUV format. ie name.1920x800_24Hz_P420.yuv staticbool ExtractResolutionFromFilename(constchar* name, int* width_ptr, int* height_ptr) { // Isolate the .width_height. section of the filename by searching for a // dot or underscore followed by a digit. for (int i = 0; name[i]; ++i) { if ((name[i] == '.' || name[i] == '_') && name[i + 1] >= '0' &&
name[i + 1] <= '9') { int n = sscanf(name + i + 1, "%dx%d", width_ptr, height_ptr); // NOLINT if (2 == n) { returntrue;
}
}
} returnfalse;
}
staticvoid PrintHelp(constchar* program) {
printf("%s [-options] src_argb.raw dst_yuv.raw\n", program);
printf( " -s .... specify source resolution. " "Optional if name contains\n" " resolution (ie. " "name.1920x800_24Hz_P420.yuv)\n" " Negative value mirrors.\n");
printf(" -d .... specify destination resolution.\n");
printf(" -f ............ 0 = point, 1 = bilinear (default).\n");
printf(" -skip ....... Number of frame to skip of src_argb\n");
printf(" -frames .......... Number of frames to convert\n");
printf(" -attenuate ............. Attenuate the ARGB image\n");
printf(" -unattenuate ........... Unattenuate the ARGB image\n");
printf(" -v ..................... verbose\n");
printf(" -h ..................... this help\n"); exit(0);
}
staticint TileARGBScale(const uint8_t* src_argb, int src_stride_argb, int src_width, int src_height,
uint8_t* dst_argb, int dst_stride_argb, int destination_width, int destination_height,
libyuv::FilterMode filtering) { for (int y = 0; y < destination_height; y += kTileY) { for (int x = 0; x < destination_width; x += kTileX) { int clip_width = kTileX; if (x + clip_width > destination_width) {
clip_width = destination_width - x;
} int clip_height = kTileY; if (y + clip_height > destination_height) {
clip_height = destination_height - y;
} int r = libyuv::ARGBScaleClip(src_argb, src_stride_argb, src_width,
src_height, dst_argb, dst_stride_argb,
destination_width, destination_height, x, y,
clip_width, clip_height, filtering); if (r) { return r;
}
}
} return 0;
}
int main(int argc, constchar* argv[]) {
ParseOptions(argc, argv);
// Open original file (first file argument)
FILE* const file_org = fopen(argv[fileindex_org], "rb"); if (file_org == NULL) {
fprintf(stderr, "Cannot open %s\n", argv[fileindex_org]); exit(1);
}
// Open all files to convert to
FILE** file_rec = new FILE*[num_rec];
memset(file_rec, 0, num_rec * sizeof(FILE*)); // NOLINT for (int cur_rec = 0; cur_rec < num_rec; ++cur_rec) {
file_rec[cur_rec] = fopen(argv[fileindex_rec + cur_rec], "wb"); if (file_rec[cur_rec] == NULL) {
fprintf(stderr, "Cannot open %s\n", argv[fileindex_rec + cur_rec]);
fclose(file_org); for (int i = 0; i < cur_rec; ++i) {
fclose(file_rec[i]);
} delete[] file_rec; exit(1);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.